
    i                     *   U d dl Zg dZd dlmZmZmZmZmZ d dl	Z	d dl
Z
d dlmZ ej                  rddlmZ  ej                   d      Zde	j"                  fd	Zd
eez  dede
j(                  dz  fdZdeez  dddeez  fdZg Zee   ed<   defdZy)    N)log_error_only_oncedump_requestget_networkloggertoo_many_requests)IPv4NetworkIPv6NetworkIPv4AddressIPv6Address
ip_network)r      )configbotdetectionrequestc                 "   | j                   d| j                  j                  d      z  z   d| j                  j                  d      z  z   d| j                  z  z   d| j                  j                  d      z  z   d| j                  j                  d	      z  z   d
| j                  j                  d      z  z   d| j                  j                  d      z  z   d| j                  j                  d      z  z   d| j                  j                  d      z  z   d| j                  j                  d      z  z   d| j                  j                  d      z  z   d| j                  j                  d      z  z   d| j                  j                  d      z  z   S )Nz || X-Forwarded-For: %szX-Forwarded-Forz || X-Real-IP: %sz	X-Real-IPz || form: %sz || Accept: %sAcceptz || Accept-Language: %szAccept-Languagez || Accept-Encoding: %szAccept-Encodingz || Content-Type: %szContent-Typez || Content-Length: %szContent-Lengthz || Connection: %s
Connectionz || User-Agent: %sz
User-Agentz || Sec-Fetch-Site: %szSec-Fetch-Sitez || Sec-Fetch-Mode: %szSec-Fetch-Modez || Sec-Fetch-Dest: %szSec-Fetch-Dest)pathheadersgetform)r   s    ,/root/searxng/searx/botdetection/_helpers.pyr   r      s   
#goo&9&9:K&L
L	M
 3 3K @
@	A 7<<
'	( W__00:
:		;
 $goo&9&9:K&L
L	M $goo&9&9:K&L
L	M !7??#6#6~#F
F	G #W__%8%89I%J
J	K !4!4\!B
B		C !4!4\!B
B
	C #W__%8%89I%J
J	K #W__%8%89I%J
J	K #W__%8%89I%J
J	K    networklog_msgreturnc                 n    t        j                  d| j                  |       t        j                  d      S )zReturns a HTTP 429 response object and writes a ERROR message to the
    'botdetection' logger.  This function is used in part by the filter methods
    to return the default ``Too Many Requests`` response.

    zBLOCK %s: %s)zToo Many Requestsi  )r   debug
compressedflaskmake_response)r   r   s     r   r   r   -   s,     LL!3!3W=9::r   real_ipcfgzconfig.Configc                 \    |d   }| j                   dk(  r|d   }t        |  d| d      }|S )ab  Returns the (client) network of whether the ``real_ip`` is part of.

    The ``ipv4_prefix`` and ``ipv6_prefix`` define the number of leading bits in
    an address that are compared to determine whether or not an address is part
    of a (client) network.

    .. code:: toml

       [botdetection]

       ipv4_prefix = 32
       ipv6_prefix = 48

    zbotdetection.ipv4_prefix   zbotdetection.ipv6_prefix/F)strict)versionr   )r"   r#   prefixr   s       r   r   r   8   sB      01F!/0G9AfX.u=GNr   _logged_errorserr_msgc                 j    | t         vr+t        j                  |        t         j                  |        y y )N)r*   r   errorappend)r+   s    r   r   r   S   s)    n$Wg& %r   )typingt__all__	ipaddressr   r	   r
   r   r   r    werkzeugsearxr   TYPE_CHECKING r   getChildRequestr   strResponser   r   r*   list__annotations__r    r   r   <module>r>      s    
_    ??		(%-- &;{[8 ;3 ;8K\K\_cKc ;{2  [[fMf 0 S	 ' 'r   