HEX
Server: LiteSpeed
System: Linux 112.webhostingindonesia.co.id 5.14.0-570.62.1.el9_6.x86_64 #1 SMP PREEMPT_DYNAMIC Tue Nov 11 10:10:59 EST 2025 x86_64
User: iyfwylsv (10313)
PHP: 8.2.30
Disabled: NONE
Upload Files
File: //usr/lib/python3.9/site-packages/fail2ban/server/__pycache__/datetemplate.cpython-39.opt-2.pyc
a

�dMfgC�@s0dZdZdZddlZddlZddlmZddlmZm	Z	m
Z
dd	lmZee
�Ze�d
�Ze�d�dfZe�d
�Ze�d�Ze�d�Ze�d�Ze�d�Ze�d�Ze�d�Ze�d�dd�fZe�d�Ze�d�Ze�d�Ze�dej�ZGdd�de�Z Gdd�de �Z!Gdd �d e �Z"Gd!d"�d"e �Z#dS)#z
Cyril Jaquierz Copyright (c) 2004 Cyril JaquierZGPL�N)�abstractmethod�)�reGroupDictStrptime�timeRE�getTimePatternRE�)�	getLoggerz(?<!(?:\(\?))(?<!\\)\((?!\?)z-^((?:\(\?\w+\))?\^?(?:\(\?\w+\))?)(.*?)(\$?)$z\1(\2)\3z((?:^|(?!<\\))\(\?[a-z]+\))z^\{UNB\}z
^\{\^LN-BEG\}z^\((?:\?:)?\^\|\\b\|\\W\)z\(\?=\\b\|\\W\|\$\)$z-^\(*(?:\(\?\w+\))?(?:\^|\(*\*\*|\((?:\?:)?\^)z!(?<!\\)(?:\$\)?|\\b|\\s|\*\*\)*)$z)^\(*(?:\(\?\w+\))?\(*\*\*|(?<!\\)\*\*\)*$cCs|���dd�S)Nz**�)�group�replace)�m�r
�@/usr/lib/python3.9/site-packages/fail2ban/server/datetemplate.py�<lambda>/�rz(^(?:\(\?\w+\))?(?:\^|\((?:\?:)?\^(?!\|))z(?<![\\\|])(?:\$\)?)$z(?<!\%)\%[aAbBpc]z(?<!\\)\{L?EPOCH\}c@sreZdZdZdZdZdZdZdd�Zdd	�Z	ddd�Z
ee	e
d
d�Zdd�Z
dd�Zeddd��Zedd��ZdS)�DateTemplatez�A template which searches for and returns a date from a log line.

	This is an not functional abstract class which other templates should
	inherit from.

	Attributes
	----------
	name
	regex
	��rrcCs.d|_d|_d|_d|_d|_d|_d|_dS)Nr	g�?r)�nameZweight�flags�hits�time�_regex�_cRegex��selfr
r
r�__init__JszDateTemplate.__init__cCs|jS�N)rrr
r
r�getRegexSszDateTemplate.getRegexTcCst|��}t�|�}|r&tjd|dd�}|o4t�|�}|oDt�|�}t�|�sdtd�td|�}d|_|r�|j|dkr�t	j
nt	jO_|dkr�d|}n d|}|j�
d�s�d|j|_|r�|jt	jO_|d	7}|jt	j@�st�|��r|jt	jO_|jt	j@�s.t�|��r.|jt	jO_td�td|�}|�rV|�d�|}||_t�d
d|�d|_dS)
a�Sets regex to use for searching for date in log line.

		Parameters
		----------
		regex : str
			The regex the template will use for searching for a date.
		wordBegin : bool
			Defines whether the regex should be modified to search at beginning of a
			word, by adding special boundary r'(?=^|\b|\W)' to start of regex.
			Can be disabled with specifying of ** at front of regex.
			Default True.
		wordEnd : bool
			Defines whether the regex should be modified to search at end of a word,
			by adding special boundary r'(?=\b|\W|$)' to end of regex.
			Can be disabled with specifying of ** at end of regex.
			Default True.

		Raises
		------
		re.error
			If regular expression fails to compile
		r	r)�countr�startz(?=^|\b|\W)z
^(?:\W{0,2})?z	{^LN-BEG}z(?=\b|\W|$)rz  constructed regex %sN)�strip�RE_GLOBALFLAGS�search�sub�RE_NO_WRD_BOUND_BEG�RE_NO_WRD_BOUND_END�
RE_GROUPED�RE_GROUPrr�
WORD_BEGIN�
LINE_BEGINr�
startswith�WORD_END�RE_LINE_BOUND_BEG�LINE_END�RE_LINE_BOUND_END�RE_DEL_WRD_BOUNDSr
r�logSys�logr)r�regex�	wordBegin�wordEndZgfZ
boundBeginZboundEndr
r
r�setRegexVs:


zDateTemplate.setRegexz!Regex used to search for date.
		)�docc
CsX|jsTzt�|j�|_Wn:tyR}z"t�d|j|j�|�WYd}~n
d}~00dS)z Compile regex by first usage.
		z Compile %r failed, expression %rN)r�re�compiler3�	Exceptionr1�errorr)r�er
r
r�
_compileRegex�szDateTemplate._compileRegexcGsH|js|��t�dd|j�|jj|g|�R�}|rD|jd7_|S)z1Check if regex for date matches on a log line.
		rz   search %sr)rr=r1r2r3r#r)r�line�args�	dateMatchr
r
r�	matchDate�szDateTemplate.matchDateNcCstd��dS)aQAbstract method, which should return the date for a log line

		This should return the date for a log line, typically taking the
		date from the part of the line which matched the templates regex.
		This requires abstraction, therefore just raises exception.

		Parameters
		----------
		line : str
			Log line, of which the date should be extracted from.
		default_tz: if no explicit time zone is present in the line
                            passing this will interpret it as in that time zone.

		Raises
		------
		NotImplementedError
			Abstract method, therefore always returns this.
		zgetDate() is abstractN)�NotImplementedError�rr>r@�
default_tzr
r
r�getDate�szDateTemplate.getDatec
Cs$t�dt�dt�dt�d|����S)Nr	)�RE_EXEANC_BOUND_BEGr$�RE_EXSANC_BOUND_BEG�RE_EXLINE_BOUND_BEG�RE_EXLINE_NO_BOUNDS)�patternr
r
r�unboundPattern�s
��zDateTemplate.unboundPattern)TT)NN)�__name__�
__module__�__qualname__�__doc__r*r.r)r,rrr6�propertyr3r=rArrE�staticmethodrKr
r
r
rr9s"	
@�rc@s$eZdZdZddd�Zd	dd�ZdS)
�	DateEpochz�A date template which searches for Unix timestamps.

	This includes Unix timestamps which appear at start of a line, optionally
	within square braces (nsd), or on SELinux audit log lines.

	Attributes
	----------
	name
	regex
	FNcs�t�|�|sdn||_||_d|_d�|r>|s4dn||_d�|r~t��fdd�|�}t�|�sld|d	}d
|_|�	|�n4|s�d�}|j	|dd
�nd�}|j	|ddd�dS)NZEpochrz\d{10,11}\b(?:\.\d{3,6})?Z	LongEpochz'\d{10,11}(?:\d{3}(?:\.\d{1,6}|\d{3})?)?csd�S)Nz(%s)r
)�v�ZepochREr
rr�rz$DateEpoch.__init__.<locals>.<lambda>�(�)rzf((?:^|(?P<square>(?<=^\[))|(?P<selinux>(?<=\baudit\()))%s)(?:(?(selinux)(?=:\d+\)))|(?(square)(?=\])))F�r4z*((?P<square>(?<=^\[))?%s)(?(square)(?=\]))r T)r4r5)
rrr�_longFrm�_grpIdx�RE_EPOCH_PATTERNr$r'r#r6)rZ
lineBeginOnlyrJZlongFrmr3r
rTrr�s&

zDateEpoch.__init__cCsn|s|�|�}|rj|�|j�}|jr^t|�dkr^t|�dkrRd|vrRt|�d}nt|�d}t|�|fSdS)axMethod to return the date for a log line.

		Parameters
		----------
		line : str
			Log line, of which the date should be extracted from.
		default_tz: ignored, Unix timestamps are time zone independent

		Returns
		-------
		(float, str)
			Tuple containing a Unix timestamp, and the string of the date
			which was matched and in turned used to calculated the timestamp.
		�
��.i@Bi�N)rAr
rYrX�len�float)rr>r@rDrSr
r
rrE�s
zDateEpoch.getDate)FNF)NN�rLrMrNrOrrEr
r
r
rrR�s
rRcsheZdZdZe�\ZZe�e�Zd
�fdd�	Z	e
dd��Zejdd��Zd�fd	d
�	Z
ddd�Z�ZS)�DatePatternRegexz�Date template, with regex/pattern

	Parameters
	----------
	pattern : str
		Sets the date templates pattern.

	Attributes
	----------
	name
	regex
	pattern
	Ncs2tt|���d|_|dur.|j|fi|��dSr)�superrar�_patternr6)rrJ�kwargs��	__class__r
rr!szDatePatternRegex.__init__cCs|jS)aVThe pattern used for regex with strptime "%" time fields.

		This should be a valid regular expression, of which matching string
		will be extracted from the log line. strptime style "%" fields will
		be replaced by appropriate regular expressions, or custom regex
		groups with names as per the strptime fields can also be used
		instead.
		)rcrr
r
rrJ's
zDatePatternRegex.patterncCs|�|�dSr)r6)rrJr
r
rrJ3sTc
s�||_t�|�r$t�d|�}d}}|rBt�|�rBt�d|�}d}zL|j�d|�}||j|_|t}t	�|�rxd|}t
t|��|||�Wn4t
y�}ztd||f��WYd}~n
d}~00dS)Nr	Fr z%(\1)sz(?iu)zWFailed to set datepattern '%s' (may be an invalid format or unescaped percent char): %s)rcrIr#r$rH�
_patternRE�_patternNamerr�RE_ALPHA_PATTERNrbrar6r:�	TypeError)rrJr4r5Zfmtr3r<rer
rr67s 

zDatePatternRegex.setRegexcCs*|s|�|�}|r&t|��|d�|fSdS)a�Method to return the date for a log line.

		This uses a custom version of strptime, using the named groups
		from the instances `pattern` property.

		Parameters
		----------
		line : str
			Log line, of which the date should be extracted from.
		default_tz: optionally used to correct timezone

		Returns
		-------
		(float, str)
			Tuple containing a Unix timestamp, and the string of the date
			which was matched and in turned used to calculated the timestamp.
		)rDN)rAr�	groupdictrCr
r
rrENs
�zDatePatternRegex.getDate)N)TT)NN)rLrMrNrOrrgrhr8r9rrPrJ�setterr6rE�
__classcell__r
r
rerras



rac@s$eZdZdZddd�Zd	dd�ZdS)
�
DateTai64nz_A date template which matches TAI64N format timestamps.

	Attributes
	----------
	name
	regex
	FcCs"t�|�d|_|jd|d�dS)NZTAI64Nz
@[0-9a-f]{24}rW)rrrr6)rr4r
r
rrps
zDateTai64n.__init__NcCs:|s|�|�}|r6|�d�}|dd�}t|d�|fSdS)aqMethod to return the date for a log line.

		Parameters
		----------
		line : str
			Log line, of which the date should be extracted from.
		default_tz: ignored, since TAI is time zone independent

		Returns
		-------
		(float, str)
			Tuple containing a Unix timestamp, and the string of the date
			which was matched and in turned used to calculated the timestamp.
		rr�r\N)rAr
�int)rr>r@rD�valueZseconds_since_epochr
r
rrEvs

zDateTai64n.getDate)F)NNr`r
r
r
rrngs
rn)$�
__author__Z
__copyright__Z__license__r8r�abcr�strptimerrrZhelpersrrLr1r9r'r(r"rIrHrGrFr%r&r0r-r/ri�
IGNORECASErZ�objectrrRrarnr
r
r
r�<module>s8







�


?X