
    i
              
          d Z ddlmZ ddlmZmZmZ ddlmZ ddl	m
Z
  e
j                  d      Z
dd	gZ	 d
eez  dej                  deeef   fdZd
eez  dej                  deeef   fdZd
eez  dedej                  deeef   fdZy)a  .. _botdetection.ip_lists:

Method ``ip_lists``
-------------------

The ``ip_lists`` method implements :py:obj:`block-list <block_ip>` and
:py:obj:`pass-list <pass_ip>`.

.. code:: toml

   [botdetection.ip_lists]

   pass_ip = [
     '167.235.158.251', # IPv4 of check.searx.space
     '192.168.0.0/16',  # IPv4 private network
     'fe80::/10',       # IPv6 linklocal
   ]

   block_ip = [
     '93.184.216.34',   # IPv4 of example.org
     '257.1.1.1',       # invalid IP --> will be ignored, logged in ERROR class
   ]

    )Tuple)
ip_networkIPv4AddressIPv6Address   )config)loggerip_limitz167.235.158.251z2a01:04f8:1c1c:8fc2::/64real_ipcfgreturnc                     |j                  dd      rJt        D ]A  }t        |d      }| j                  |j                  k(  s*| |v s/dd|j                   dfc S  t        | d|      S )	zoChecks if the IP on the subnet is in one of the members of the
    ``botdetection.ip_lists.pass_ip`` list.
    z&botdetection.ip_lists.pass_searxng_orgTdefaultFstrictIP matches z in SEARXNG_ORG list.zbotdetection.ip_lists.pass_ip)getSEARXNG_ORGr   version
compressedip_is_subnet_of_member_in_list)r   r   nets      ,/root/searxng/searx/botdetection/ip_lists.pypass_ipr   1   su    
 ww7wF 	QCS/C#++-'S.{3>>*::OPPP	Q *'3RTWXX    c                 8    t        | d|      \  }}|r|dz  }||fS )zpChecks if the IP on the subnet is in one of the members of the
    ``botdetection.ip_lists.block_ip`` list.
    zbotdetection.ip_lists.block_ipzF To remove IP from list, please contact the maintainer of the service.)r   )r   r   blockmsgs       r   block_ipr    >   s0    
 09Y[^_JE3WW#:r   	list_namec                    |j                  |g       D ]E  }	 t        |d      }| j
                  |j
                  k(  s+| |v s0dd|j                   d| dfc S  dd	| d
fS # t        $ r t        j                  d||       Y rw xY w)Nr   Fr   zinvalid IP %s in %sTr   z in .z&IP is not a member of an item in the fz list)r   r   
ValueErrorr	   errorr   r   )r   r!   r   r   s       r   r   r   I   s     wwy"w- H	S/C ??ckk)gn;s~~&6d9+QGGGH :9+UKKK  	LL.Y?	s   A$$ BBN)__doc__typingr   	ipaddressr   r   r    r   _helpersr	   getChildr   Configboolstrr   r    r    r   r   <module>r0      s   6    		$ 
 O
Y[;. 
YV]] 
YuTSVYGW 
YkK/ fmm dTWiHX L;&L36L=C]]L
49Lr   