-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
gh-pages build from: master@8bfd58724faf5557d77cf53f9ea73b03f6a8bfa2 …
…([email protected]:searxng/botdetection.git)
- Loading branch information
0 parents
commit 2382a5a
Showing
29 changed files
with
5,521 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<html><head><META http-equiv='refresh' content='0;URL=index.html'></head></html> |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,179 @@ | ||
<!DOCTYPE html> | ||
|
||
<html lang="en" data-content_root="../../"> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
<title>botdetection.ip_lists — Bot Detection (20231023.0)</title> | ||
<link rel="stylesheet" type="text/css" href="../../_static/pygments.css?v=4f649999" /> | ||
<link rel="stylesheet" type="text/css" href="../../_static/botdetection.css?v=52e4ff28" /> | ||
<link rel="stylesheet" type="text/css" href="../../_static/tabs.css?v=a5c4661c" /> | ||
<script src="../../_static/documentation_options.js?v=1f698d06"></script> | ||
<script src="../../_static/doctools.js?v=888ff710"></script> | ||
<script src="../../_static/sphinx_highlight.js?v=dc90522c"></script> | ||
<script src="../../_static/tabs.js?v=3030b3cb"></script> | ||
<link rel="index" title="Index" href="../../genindex.html" /> | ||
<link rel="search" title="Search" href="../../search.html" /> | ||
</head><body> | ||
<div class="related" role="navigation" aria-label="related navigation"> | ||
<h3>Navigation</h3> | ||
<ul> | ||
<li class="right" style="margin-right: 10px"> | ||
<a href="../../genindex.html" title="General Index" | ||
accesskey="I">index</a></li> | ||
<li class="right" > | ||
<a href="../../py-modindex.html" title="Python Module Index" | ||
>modules</a> |</li> | ||
<li class="nav-item nav-item-0"><a href="../../index.html">Bot Detection (20231023.0)</a> »</li> | ||
<li class="nav-item nav-item-1"><a href="../index.html" accesskey="U">Module code</a> »</li> | ||
<li class="nav-item nav-item-this"><a href="">botdetection.ip_lists</a></li> | ||
</ul> | ||
</div> | ||
|
||
<div class="document"> | ||
<div class="documentwrapper"> | ||
<div class="bodywrapper"> | ||
<div class="body" role="main"> | ||
|
||
<h1>Source code for botdetection.ip_lists</h1><div class="highlight"><pre> | ||
<span></span><span class="c1"># SPDX-License-Identifier: AGPL-3.0-or-later</span> | ||
<span class="c1"># lint: pylint</span> | ||
<span class="sd">""".. _botdetection.ip_lists:</span> | ||
|
||
<span class="sd">Method ``ip_lists``</span> | ||
<span class="sd">-------------------</span> | ||
|
||
<span class="sd">The ``ip_lists`` method implements IP :py:obj:`block- <block_ip>` and</span> | ||
<span class="sd">:py:obj:`pass-lists <pass_ip>`.</span> | ||
|
||
|
||
<span class="sd">Config</span> | ||
<span class="sd">~~~~~~</span> | ||
|
||
<span class="sd">.. code:: toml</span> | ||
|
||
<span class="sd"> [botdetection.ip_lists]</span> | ||
|
||
<span class="sd"> pass_ip = [</span> | ||
<span class="sd"> '140.238.172.132', # IPv4 of check.searx.space</span> | ||
<span class="sd"> '192.168.0.0/16', # IPv4 private network</span> | ||
<span class="sd"> 'fe80::/10' # IPv6 linklocal</span> | ||
<span class="sd"> ]</span> | ||
<span class="sd"> block_ip = [</span> | ||
<span class="sd"> '93.184.216.34', # IPv4 of example.org</span> | ||
<span class="sd"> '257.1.1.1', # invalid IP --> will be ignored, logged in ERROR class</span> | ||
<span class="sd"> ]</span> | ||
|
||
|
||
<span class="sd">Implementations</span> | ||
<span class="sd">~~~~~~~~~~~~~~~</span> | ||
|
||
<span class="sd">"""</span> | ||
<span class="c1"># pylint: disable=unused-argument</span> | ||
|
||
<span class="kn">from</span> <span class="nn">__future__</span> <span class="kn">import</span> <span class="n">annotations</span> | ||
<span class="kn">from</span> <span class="nn">typing</span> <span class="kn">import</span> <span class="n">Tuple</span> | ||
<span class="kn">from</span> <span class="nn">ipaddress</span> <span class="kn">import</span> <span class="p">(</span> | ||
<span class="n">ip_network</span><span class="p">,</span> | ||
<span class="n">IPv4Address</span><span class="p">,</span> | ||
<span class="n">IPv6Address</span><span class="p">,</span> | ||
<span class="p">)</span> | ||
|
||
<span class="kn">from</span> <span class="nn">.</span> <span class="kn">import</span> <span class="n">config</span> | ||
<span class="kn">from</span> <span class="nn">._helpers</span> <span class="kn">import</span> <span class="n">logger</span> | ||
|
||
<span class="n">logger</span> <span class="o">=</span> <span class="n">logger</span><span class="o">.</span><span class="n">getChild</span><span class="p">(</span><span class="s1">'ip_limit'</span><span class="p">)</span> | ||
|
||
|
||
<div class="viewcode-block" id="pass_ip"> | ||
<a class="viewcode-back" href="../../index.html#botdetection.ip_lists.pass_ip">[docs]</a> | ||
<span class="k">def</span> <span class="nf">pass_ip</span><span class="p">(</span><span class="n">real_ip</span><span class="p">:</span> <span class="n">IPv4Address</span> <span class="o">|</span> <span class="n">IPv6Address</span><span class="p">,</span> <span class="n">cfg</span><span class="p">:</span> <span class="n">config</span><span class="o">.</span><span class="n">Config</span><span class="p">)</span> <span class="o">-></span> <span class="n">Tuple</span><span class="p">[</span><span class="nb">bool</span><span class="p">,</span> <span class="nb">str</span><span class="p">]:</span> | ||
<span class="w"> </span><span class="sd">"""Checks if the IP on the subnet is in one of the members of the</span> | ||
<span class="sd"> ``botdetection.ip_lists.pass_ip`` list.</span> | ||
<span class="sd"> """</span> | ||
<span class="k">return</span> <span class="n">ip_is_subnet_of_member_in_list</span><span class="p">(</span><span class="n">real_ip</span><span class="p">,</span> <span class="s1">'botdetection.ip_lists.pass_ip'</span><span class="p">,</span> <span class="n">cfg</span><span class="p">)</span></div> | ||
|
||
|
||
|
||
<div class="viewcode-block" id="block_ip"> | ||
<a class="viewcode-back" href="../../index.html#botdetection.ip_lists.block_ip">[docs]</a> | ||
<span class="k">def</span> <span class="nf">block_ip</span><span class="p">(</span><span class="n">real_ip</span><span class="p">:</span> <span class="n">IPv4Address</span> <span class="o">|</span> <span class="n">IPv6Address</span><span class="p">,</span> <span class="n">cfg</span><span class="p">:</span> <span class="n">config</span><span class="o">.</span><span class="n">Config</span><span class="p">)</span> <span class="o">-></span> <span class="n">Tuple</span><span class="p">[</span><span class="nb">bool</span><span class="p">,</span> <span class="nb">str</span><span class="p">]:</span> | ||
<span class="w"> </span><span class="sd">"""Checks if the IP on the subnet is in one of the members of the</span> | ||
<span class="sd"> ``botdetection.ip_lists.block_ip`` list.</span> | ||
<span class="sd"> """</span> | ||
|
||
<span class="n">block</span><span class="p">,</span> <span class="n">msg</span> <span class="o">=</span> <span class="n">ip_is_subnet_of_member_in_list</span><span class="p">(</span><span class="n">real_ip</span><span class="p">,</span> <span class="s1">'botdetection.ip_lists.block_ip'</span><span class="p">,</span> <span class="n">cfg</span><span class="p">)</span> | ||
<span class="k">if</span> <span class="n">block</span><span class="p">:</span> | ||
<span class="n">msg</span> <span class="o">+=</span> <span class="s2">" To remove IP from list, please contact the maintainer of the service."</span> | ||
<span class="k">return</span> <span class="n">block</span><span class="p">,</span> <span class="n">msg</span></div> | ||
|
||
|
||
|
||
<span class="k">def</span> <span class="nf">ip_is_subnet_of_member_in_list</span><span class="p">(</span> | ||
<span class="n">real_ip</span><span class="p">:</span> <span class="n">IPv4Address</span> <span class="o">|</span> <span class="n">IPv6Address</span><span class="p">,</span> <span class="n">list_name</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">cfg</span><span class="p">:</span> <span class="n">config</span><span class="o">.</span><span class="n">Config</span> | ||
<span class="p">)</span> <span class="o">-></span> <span class="n">Tuple</span><span class="p">[</span><span class="nb">bool</span><span class="p">,</span> <span class="nb">str</span><span class="p">]:</span> | ||
|
||
<span class="k">for</span> <span class="n">net</span> <span class="ow">in</span> <span class="n">cfg</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">list_name</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="p">[]):</span> | ||
<span class="k">try</span><span class="p">:</span> | ||
<span class="n">net</span> <span class="o">=</span> <span class="n">ip_network</span><span class="p">(</span><span class="n">net</span><span class="p">,</span> <span class="n">strict</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span> | ||
<span class="k">except</span> <span class="ne">ValueError</span><span class="p">:</span> | ||
<span class="n">logger</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">"invalid IP </span><span class="si">%s</span><span class="s2"> in </span><span class="si">%s</span><span class="s2">"</span><span class="p">,</span> <span class="n">net</span><span class="p">,</span> <span class="n">list_name</span><span class="p">)</span> | ||
<span class="k">continue</span> | ||
<span class="k">if</span> <span class="n">real_ip</span><span class="o">.</span><span class="n">version</span> <span class="o">==</span> <span class="n">net</span><span class="o">.</span><span class="n">version</span> <span class="ow">and</span> <span class="n">real_ip</span> <span class="ow">in</span> <span class="n">net</span><span class="p">:</span> | ||
<span class="k">return</span> <span class="kc">True</span><span class="p">,</span> <span class="sa">f</span><span class="s2">"IP matches </span><span class="si">{</span><span class="n">net</span><span class="o">.</span><span class="n">compressed</span><span class="si">}</span><span class="s2"> in </span><span class="si">{</span><span class="n">list_name</span><span class="si">}</span><span class="s2">."</span> | ||
<span class="k">return</span> <span class="kc">False</span><span class="p">,</span> <span class="sa">f</span><span class="s2">"IP is not a member of an item in the f</span><span class="si">{</span><span class="n">list_name</span><span class="si">}</span><span class="s2"> list"</span> | ||
</pre></div> | ||
|
||
<div class="clearer"></div> | ||
</div> | ||
</div> | ||
</div> | ||
<span id="sidebar-top"></span> | ||
<div class="sphinxsidebar" role="navigation" aria-label="main navigation"> | ||
<div class="sphinxsidebarwrapper"> | ||
|
||
|
||
|
||
|
||
<h3><a href="../../index.html">Table of Contents</a></h3> | ||
|
||
<h3>Project Links</h3> | ||
<ul> | ||
<li><a href="https://github.com/searxng/botdetection/tree/master">Source</a> | ||
|
||
<li><a href="https://github.com/searxng/botdetection/issues">Issue Tracker</a> | ||
</ul><h3>Navigation</h3> | ||
<ul> | ||
<li><a href="../../index.html">Overview</a> | ||
<ul> | ||
<li><a href="../index.html">Module code</a> | ||
|
||
|
||
</ul> | ||
</li> | ||
</ul> | ||
</li> | ||
</ul> | ||
<div id="searchbox" style="display: none" role="search"> | ||
<h3 id="searchlabel">Quick search</h3> | ||
<div class="searchformwrapper"> | ||
<form class="search" action="../../search.html" method="get"> | ||
<input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/> | ||
<input type="submit" value="Go" /> | ||
</form> | ||
</div> | ||
</div> | ||
<script>document.getElementById('searchbox').style.display = "block"</script> | ||
</div> | ||
</div> | ||
<div class="clearer"></div> | ||
</div> | ||
|
||
<div class="footer" role="contentinfo"> | ||
© Copyright SearXNG team. | ||
</div> | ||
<script src="../../_static/version_warning_offset.js"></script> | ||
|
||
</body> | ||
</html> |
Oops, something went wrong.