Skip to content

Commit

Permalink
gh-pages build from: master@8bfd58724faf5557d77cf53f9ea73b03f6a8bfa2 …
Browse files Browse the repository at this point in the history
…([email protected]:searxng/botdetection.git)
  • Loading branch information
return42 committed Jan 9, 2024
0 parents commit 2382a5a
Show file tree
Hide file tree
Showing 29 changed files with 5,521 additions and 0 deletions.
Empty file added .nojekyll
Empty file.
1 change: 1 addition & 0 deletions 404.html
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>
231 changes: 231 additions & 0 deletions _modules/botdetection/_helpers.html

Large diffs are not rendered by default.

498 changes: 498 additions & 0 deletions _modules/botdetection/config.html

Large diffs are not rendered by default.

179 changes: 179 additions & 0 deletions _modules/botdetection/ip_lists.html
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 &#8212; 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> &#187;</li>
<li class="nav-item nav-item-1"><a href="../index.html" accesskey="U">Module code</a> &#187;</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">&quot;&quot;&quot;.. _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- &lt;block_ip&gt;` and</span>
<span class="sd">:py:obj:`pass-lists &lt;pass_ip&gt;`.</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"> &#39;140.238.172.132&#39;, # IPv4 of check.searx.space</span>
<span class="sd"> &#39;192.168.0.0/16&#39;, # IPv4 private network</span>
<span class="sd"> &#39;fe80::/10&#39; # IPv6 linklocal</span>
<span class="sd"> ]</span>
<span class="sd"> block_ip = [</span>
<span class="sd"> &#39;93.184.216.34&#39;, # IPv4 of example.org</span>
<span class="sd"> &#39;257.1.1.1&#39;, # invalid IP --&gt; will be ignored, logged in ERROR class</span>
<span class="sd"> ]</span>


<span class="sd">Implementations</span>
<span class="sd">~~~~~~~~~~~~~~~</span>

<span class="sd">&quot;&quot;&quot;</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">&#39;ip_limit&#39;</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">-&gt;</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">&quot;&quot;&quot;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"> &quot;&quot;&quot;</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">&#39;botdetection.ip_lists.pass_ip&#39;</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">-&gt;</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">&quot;&quot;&quot;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"> &quot;&quot;&quot;</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">&#39;botdetection.ip_lists.block_ip&#39;</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">&quot; To remove IP from list, please contact the maintainer of the service.&quot;</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">-&gt;</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">&quot;invalid IP </span><span class="si">%s</span><span class="s2"> in </span><span class="si">%s</span><span class="s2">&quot;</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">&quot;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">.&quot;</span>
<span class="k">return</span> <span class="kc">False</span><span class="p">,</span> <span class="sa">f</span><span class="s2">&quot;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&quot;</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">
&#169; Copyright SearXNG team.
</div>
<script src="../../_static/version_warning_offset.js"></script>

</body>
</html>
Loading

0 comments on commit 2382a5a

Please sign in to comment.