https://t.me/RX1948
Server : Apache
System : Linux iad1-shared-b8-43 6.6.49-grsec-jammy+ #10 SMP Thu Sep 12 23:23:08 UTC 2024 x86_64
User : dh_edsupp ( 6597262)
PHP Version : 8.2.26
Disable Function : NONE
Directory :  /lib/python3/dist-packages/fail2ban/server/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //lib/python3/dist-packages/fail2ban/server/__pycache__/datedetector.cpython-310.pyc
o

��_
L�@s�dZdZdZddlZddlZddlmZddlmZm	Z	m
Z
mZmZm
Z
ddlmZdd	lmZd
dlmZee�ZdZe�d
ej�Zejddd�Zddd�Zdd�fdd�ZGdd�de�ZGdd�de�Z Gdd�de�Z!dS)z'Cyril Jaquier and Fail2Ban Contributorsz Copyright (c) 2004 Cyril Jaquier�GPL�N)�Lock�)�re�DateTemplate�DatePatternRegex�
DateTai64n�	DateEpoch�RE_EPOCH_PATTERN)�validateTimeZone)�Utils�)�	getLogger�z(?<!\\)\{DATE\}i�i)�maxCount�maxTimecCs�|dur|}d|vr|��}t�|�}|sWd|vr?t�|�r't|d|vd�}n|dvr3t|dkd�}n|dvr?t|dkdd	�}|durW|d
vrSt|dkrNdnd
d�}nt|�}t�||�|S)N�%�EPOCH�LEPOCH)�pattern�longFrm)rz{^LN-BEG}EPOCHz^EPOCH)�
lineBeginOnly)rz{^LN-BEG}LEPOCHz^LEPOCHT)rr)�TAI64Nz{^LN-BEG}TAI64Nz^TAI64Nr�startF)�	wordBegin)	�upper�DD_patternCache�getr
�searchr	rr�set)r�key�template�r"�>/usr/lib/python3/dist-packages/fail2ban/server/datedetector.py�_getPatternTemplate,s&

r$cCsd|S�N�	{^LN-BEG}r"��sr"r"r#�<lambda>Dsr)cCsd||j�}t�|�}|s0|t|d|j��}t|d�rt�|�}|s0t|d�s,t|�}|St|�}|S)Nr)�namerr�getattr�regex�hasattrr$)r!�wrapr*�	template2r,r"r"r#�_getAnchoredTemplateDs




�r0c@sHeZdZdZdd�Zedd��Zdd�Zgd�Zed	d
��Z	dd�Z
d
S)�DateDetectorCachez7Implements the caching of the default templates list.
	cCst�|_t�|_dS�N)r�_DateDetectorCache__lock�list�_DateDetectorCache__templates��selfr"r"r#�__init__\szDateDetectorCache.__init__cCs^|jr|jS|j�|jr|jWd�S|��|jWd�S1s(wYdS)�6List of template instances managed by the detector.
		N)r5r3�_addDefaultTemplater6r"r"r#�	templates`s�$�zDateDetectorCache.templatescCs`|j}|�d�s&|�d�s&t|d�r&t|�}|j|kr&d|_|jd�|�|jd�|�dS)z&Cache Fail2Ban's default template.

		r&�^r,gY@rrN)r*�
startswithr-r0�weight�_DateDetectorCache__tmpcache�append)r7r!r*r/r"r"r#�_cacheTemplatels
z DateDetectorCache._cacheTemplate)zF%ExY(?P<_sep>[-/.])%m(?P=_sep)%d(?:T|  ?)%H:%M:%S(?:[.,]%f)?(?:\s*%z)?z)(?:%a )?%b %d %k:%M:%S(?:\.%f)?(?: %ExY)?z$(?:%a )?%b %d %ExY %k:%M:%S(?:\.%f)?z1%d(?P<_sep>[-/])%m(?P=_sep)(?:%ExY|%Exy) %k:%M:%Sz=%d(?P<_sep>[-/])%b(?P=_sep)%ExY[ :]?%H:%M:%S(?:\.%f)?(?: %z)?z%m/%d/%ExY:%H:%M:%Sz%m-%d-%ExY %k:%M:%S(?:\.%f)?rz{^LN-BEG}%H:%M:%Sz^<%m/%d/%Exy@%H:%M:%S>z%Exy%Exm%Exd  ?%H:%M:%Sz%b %d, %ExY %I:%M:%S %pz^%b-%d-%Exy %k:%M:%Sz6%ExY%Exm%Exd(?:T|  ?)%ExH%ExM%ExS(?:[.,]%f)?(?:\s*%z)?z1(?:%Z )?(?:%a )?%b %d %k:%M:%S(?:\.%f)?(?: %ExY)?z1(?:%z )?(?:%a )?%b %d %k:%M:%S(?:\.%f)?(?: %ExY)?rcCs<ttjdt�rttj�D]
\}}t|�}|tj|<q
tjS)Nr)�
isinstancer1�DEFAULT_TEMPLATES�str�	enumerater$)r7�i�dtr"r"r#�defaultTemplates�s
z"DateDetectorCache.defaultTemplatescCs>ggf|_|jD]}|�|�q|jd|jd|_|`dS)z<Add resp. cache Fail2Ban's default set of date templates.
		rrN)r?rHrAr5)r7rGr"r"r#r:�s


z%DateDetectorCache._addDefaultTemplateN)�__name__�
__module__�__qualname__�__doc__r8�propertyr;rArCrHr:r"r"r"r#r1Ys
5
r1c@s0eZdZdZdZdd�Zedd��Zdd�Zd	S)
�DateDetectorTemplateztUsed for "shallow copy" of the template object.

	Prevents collectively usage of hits/lastUsed in cached templates
	�r!�hits�lastUsed�distancecCs||_d|_d|_d|_dS)Nr��rO)r7r!r"r"r#r8�s
zDateDetectorTemplate.__init__cCs|j|jjtd|j�S)Nr)rPr!r>�maxrRr6r"r"r#r>�szDateDetectorTemplate.weightcCst|j|�S)zF Returns attribute of template (called for parameters not in slots)
		)r+r!)r7r*r"r"r#�__getattr__�sz DateDetectorTemplate.__getattr__N)	rIrJrKrL�	__slots__r8rMr>rUr"r"r"r#rN�s
rNc@szeZdZdZe�Zdd�Zddd�Zdd�Zddd�Z	e
d
d��Zdd�Ze
dd��Z
e
jdd��Z
ddd�Zdd�Zd	S)�DateDetectorzjManages one or more date templates to find a date within a log line.

	Attributes
	----------
	templates
	cCs>t�|_t�|_d|_d|_d|_d|_d|_d|_	d|_
dS)Ni,)rN)rSNrSr)r4�_DateDetector__templatesr�_DateDetector__known_names�_DateDetector__unusedTime�_DateDetector__lastPos�_DateDetector__lastEndPos�_DateDetector__lastTemplIdx�_DateDetector__firstUnused�_DateDetector__preMatch�_DateDetector__default_tzr6r"r"r#r8�s
zDateDetector.__init__FcCsD|j}||jvr|rdStd|��|j�|�|j�t|��dS)Nz(There is already a template with name %s)r*rY�
ValueError�addrXr@rN)r7r!�	ignoreDupr*r"r"r#�_appendTemplate�s
�zDateDetector._appendTemplatecs�t|t�rK|�}d|vr|���t���}|sE�dvr)�fdd�}|�|�dSd�vr6|j|dd�dS�d	kr@td
��}nt|��}t��|�|�|�t	�
dt|dd
�|j�t	�
dt|dd
�|j�dS)a�Add a date template to manage and use in search of dates.

		Parameters
		----------
		template : DateTemplate or str
			Can be either a `DateTemplate` instance, or a string which will
			be used as the pattern for the `DatePatternRegex` template. The
			template will then be added to the detector.

		Raises
		------
		ValueError
			If a template already exists with the same name.
		r)r&z	{DEFAULT}cs�dkr
|jtj@SdSr%)�flagsr�
LINE_BEGIN)r!�r r"r#r)sz-DateDetector.appendTemplate.<locals>.<lambda>Nz{DATE}F)�preMatch�allDefaultsz{NONE}z{UNB}^z  date pattern `%r`: `%s`r�z  date pattern regex for %r: %s)rBrDrrr�addDefaultTemplater$rrd�logSys�infor+r*�debugr,)r7r!r�fltr"rgr#�appendTemplates2


�


��zDateDetector.appendTemplateNTcsht|j�dk}|r
tjjntjjD] }|dur||�sq�dur*t|�fdd�d�}|j||d�qdS)z0Add Fail2Ban's default set of date templates.
		rNcst��fdd���S)Ncs
t���Sr2)r�unboundPattern)�mr'r"r#r)7s
zCDateDetector.addDefaultTemplate.<locals>.<lambda>.<locals>.<lambda>)�RE_DATE_PREMATCH�subr'�rhr'r#r)7sz1DateDetector.addDefaultTemplate.<locals>.<lambda>)r.)rc)�lenrXrW�	_defCacher;rHr0rd)r7�filterTemplaterhrircr!r"rur#rk*s�
��zDateDetector.addDefaultTemplatecC�|jS)r9)rXr6r"r"r#r;;szDateDetector.templatesc
Cs�t|j�s	|��t��tkrtjndd�}|tdd|�d}d}d}|j}|t|j�k�r%|j|}|j}|j	t
jt
jB@rP|tdd|�|�
|�}|}n�|jd	|jd	}	}
|tdd
||	|
||	d|	�|jd||	|
�||
|
d�|jd�
||	d|	�|jdks�||	|jdkr�|jd��s�||
|
d�|jdks�||
d|jdkr�|jd��s�|tdd||	|
��|�
||	|
�}n|tdd
�|�
|�}|}|�r |��}	|��}
t|j�dk�s|j	t
jt
jB@�s|	|jd	k�r|
|jd	k�r|td|�n|td�||	|
|f}d}n|td�|�s�|tdt|j��d	}|jD]�}||k�rC|d7}�q6|tdd||j�|j}|�
|�}|�r�|��}	|��}
|td||	|j|jd	|j�|dt|j�k�r{nQ|j	t
jt
jB@�r�nE|	d	k�r�|j�r�|j|djj�s�n0|	|jk�s�|	|jd	k�r�|td�|	|dk�r�||	|
|f}d}|d7}�q6n|d7}�q6|�s�|d	�r�|\}}	}
}|td|�|j|}|j}|�r:|jd7_t��|_|	|_|j|k�r|jd7_|	||	d|	�||	f|_|
||
d||
|
d�f|_|�r3||jk�r3|�|�}||_||fS|td�dS)a�Attempts to find date on a log line using templates.

		This uses the templates' `matchDate` method in an attempt to find
		a date. It also increments the match hit count for the winning
		template.

		Parameters
		----------
		line : str
			Line which is searched by the date templates.

		Returns
		-------
		re.MatchObject, DateTemplate
			The regex match returned from the first successfully matched
			template.
		cWsdSr2r")�argsr"r"r#r)Vsz(DateDetector.matchTime.<locals>.<lambda>rz"try to match time for line: %.120sN)NrSrS���rSz/  try to match last anchored template #%02i ...rzJ  try to match last template #%02i (from %r to %r): ...%r==%r %s %r==%r...r
z+  boundaries are correct, search in part %rz,  boundaries show conflict, try whole searchz"  matched last time template #%02izB  ** last pattern collision - pattern change, reserve & search ...z8  ** last pattern not found - pattern change, search ...z search template (%i) ...z  try template #%02i: %sz2  matched time template #%02i (at %r <= %r, %r) %sz1  ** distance collision - pattern change, reservez  use best time template #%02iz
 no template.)NN)rvrXrkrl�getEffectiveLevel�logLevel�logr]r!rerrf�LINE_END�	matchDater[r\�isalnumr�endr*rRrP�timerQr^�_reorderTemplate)r7�liner~�match�found�ignoreBySearchrF�ddtemplr!rR�endposr"r"r#�	matchTimeAs�




� $
� 




�&


 

zDateDetector.matchTimecCryr2)r`r6r"r"r#�
default_tz�szDateDetector.default_tzcCst|�|_dSr2)rr`)r7�valuer"r"r#r��scCs�|dur	|�|�}|d}|durHz,|j||d|jd�}|dur;t��tkr8t�td|d|d�d�|j�|WSWdSt	yGYdSwdS)aAttempts to return the date on a log line using templates.

		This uses the templates' `getDate` method in an attempt to find
		a date. 
		For the faster usage, always specify a parameter timeMatch (the previous tuple result
		of the matchTime), then this will work without locking and without cycle over templates.

		Parameters
		----------
		line : str
			Line which is searched by the date templates.

		Returns
		-------
		float
			The Unix timestamp returned from the first successfully matched
			template or None if not found.
		Nrr)r�z&  got time %f for %r using template %s)
r��getDater`rlr|r}r~�groupr*ra)r7r��	timeMatchr!�dater"r"r#�getTime�s&
����zDateDetector.getTimecs�r�|j����t��tkrt�td��j��j|j��j�|j	�kr)|j	n�d�������fdd�}|�sL��dkrC�S�d�|�sL�S��=�g��d�<|j	t
��krw�|j	jrw|j	d7_	|j	t
��krw�|j	jsct��tkr�t�td����S�S)z�Reorder template (bubble up) in template list if hits grows enough.

		Parameters
		----------
		num : int
			Index of template should be moved.
		z%  -> reorder template #%02i, hits: %rr
csL��j}t��tkrt�td���|�j��j��|kp%���jkS)NzE  -> compare template #%02i & #%02i, weight %.3f > %.3f, hits %r > %r)r>rlr|r}r~rPrQ)�pweight�r��num�posr;�untimer>r"r#�	_moveable
s
�z0DateDetector._reorderTemplate.<locals>._moveablerrz"  -> moved template #%02i -> #%02i)rXrlr|r}r~rPrQrZr>r^rv)r7r�r�r"r�r#r��s0�zDateDetector._reorderTemplate)F)NNTr2)rIrJrKrLr1rwr8rdrprkrMr;r�r��setterr�r�r"r"r"r#rW�s"
	
*



$rWr2)"�
__author__�
__copyright__�__license__�copyr��	threadingr�datetemplaterrrrr	r
�strptimer�utilsr�helpersrrIrlr}�compile�
IGNORECASErs�Cacherr$r0�objectr1rNrWr"r"r"r#�<module>s& 
n

https://t.me/RX1948 - 2025