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.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 Jaquier�GPL�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��selfrrr�__init__JszDateTemplate.__init__cCs|jS�N)rrrrr�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_BOUNDSrr�logSys�logr)r�regex�	wordBegin�wordEndZgfZ
boundBeginZboundEndrrr�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�compiler4�	Exceptionr2�errorr)r�errr�
_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>r2r3r4r$r)r�line�args�	dateMatchrrr�	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?rA�
default_tzrrr�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)�patternrrr�unboundPattern�s
��zDateTemplate.unboundPattern)TT)NN)�__name__�
__module__�__qualname__�__doc__r+r/r*r-rrr7�propertyr4r>rBrrF�staticmethodrLrrrrr9s"	
@�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�ZepochRErrr�rz$DateEpoch.__init__.<locals>.<lambda>�(�)rzf((?:^|(?P<square>(?<=^\[))|(?P<selinux>(?<=\baudit\()))%s)(?:(?(selinux)(?=:\d+\)))|(?(square)(?=\])))F�r5z*((?P<square>(?<=^\[))?%s)(?(square)(?=\]))r!T)r5r6)
rrr�_longFrm�_grpIdx�RE_EPOCH_PATTERNr%r(r$r7)rZ
lineBeginOnlyrKZlongFrmr4rrUrr�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)rBrrZrY�len�float)rr?rArErTrrrrF�s
zDateEpoch.getDate)FNF)NN�rMrNrOrPrrFrrrrrS�s
rScsheZdZdZe�\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)�superrbr�_patternr7)rrK�kwargs��	__class__rrr!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.
		)rdrrrrrK's
zDatePatternRegex.patterncCs|�|�dSr)r7)rrKrrrrK3sTc
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)rdrJr$r%rI�
_patternRE�_patternNamerr�RE_ALPHA_PATTERNrcrbr7r;�	TypeError)rrKr5r6�fmtr4r=rfrrr77s 

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.
		)rEN)rBr�	groupdictrDrrrrFNs
�zDatePatternRegex.getDate)N)TT)NN)rMrNrOrPrrhrir9r:rrQrK�setterr7rF�
__classcell__rrrfrrbs



rbc@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}rX)rrrr7)rr5rrrrps
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)rBr�int)rr?rArE�valueZseconds_since_epochrrrrFvs

zDateTai64n.getDate)F)NNrarrrrrpgs
rp)$�
__author__�
__copyright__�__license__r9r�abcr�strptimerrrZhelpersr	rMr2r:r(r)r#rJrIrHrGr&r'r1r.r0rj�
IGNORECASEr[�objectrrSrbrprrrr�<module>s8







�


?X