HEX
Server: Apache
System: Linux zacp120.webway.host 4.18.0-553.50.1.lve.el8.x86_64 #1 SMP Thu Apr 17 19:10:24 UTC 2025 x86_64
User: govancoz (1003)
PHP: 8.3.26
Disabled: exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Upload Files
File: //usr/lib/python3.6/site-packages/fail2ban/server/__pycache__/datetemplate.cpython-36.pyc
3

UB(d�1�@s0dZdZdZddlZddlZddlmZddlmZm	Z	m
Z
dd	lmZee
�Zejd
�Zejd�dfZejd
�Zejd�Zejd�Zejd�Zejd�Zejd�Zejd�Zejd�dd�fZejd�Zejd�Zejd�Zejdej�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|j�jdd�S)Nz**�)�group�replace)�m�r
�"/usr/lib/python3.6/datetemplate.py�<lambda>/srz(^(?:\(\?\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)r)rr
r
r�getRegexSszDateTemplate.getRegexTcCsv|j�}tj|�}|r&tjd|dd�}|o4tj|�}|oDtj|�}tj|�sdtdjtd|�}d|_|r�|j|dkr�t	j
nt	jO_|dkr�d|}n d|}|jj
d�s�d|j|_|r�|jt	jO_|d	7}|jt	j@o�tj|��r|jt	jO_|jt	j@�r0tj|��r0|jt	jO_tdjtd|�}|�rX|jd�|}||_tjd
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.
		)�doccCsV|jsRytj|j�|_Wn8tk
rP}ztjd|j|j�|�WYdd}~XnXdS)z Compile regex by first usage.
		z Compile %r failed, expression %rN)r�re�compiler0�	Exceptionr.�errorr)r�er
r
r�
_compileRegex�szDateTemplate._compileRegexcGsF|js|j�tjdd|j�|jj|f|��}|rB|jd7_|S)z1Check if regex for date matches on a log line.
		rz   search %sr)rr:r.r/r0r 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$tjdtjdtjdtjd|����S)Nr	)�RE_EXEANC_BOUND_BEGr!�RE_EXSANC_BOUND_BEG�RE_EXLINE_BOUND_BEG�RE_EXLINE_NO_BOUNDS)�patternr
r
r�unboundPattern�szDateTemplate.unboundPattern)TT)NN)�__name__�
__module__�__qualname__�__doc__r'r+r&r)rrr3�propertyr0r:r>rrA�staticmethodrGr
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�tj|�|sdn||_||_d|_d�|r>|s4dn||_d�|rpdtj�fdd�|�d	}d
|_|j|�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)�epochREr
rr�sz$DateEpoch.__init__.<locals>.<lambda>�)rzf((?:^|(?P<square>(?<=^\[))|(?P<selinux>(?<=\baudit\()))%s)(?:(?(selinux)(?=:\d+\)))|(?(square)(?=\])))F)r1z*((?P<square>(?<=^\[))?%s)(?(square)(?=\]))rT)r1r2)rrr�_longFrm�_grpIdx�RE_EPOCH_PATTERNr!r3)rZ
lineBeginOnlyrFZlongFrmr0r
)rQrr�s"
zDateEpoch.__init__cCsn|s|j|�}|rj|j|j�}|jr^t|�dkr^t|�dkrRd|krRt|�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)r>r
rTrS�len�float)rr;r=r@rPr
r
rrA�s
zDateEpoch.getDate)FNF)NN)rHrIrJrKrrAr
r
r
rrN�s

rNcsheZdZdZe�\ZZeje�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
	Ncs.tt|�j�d|_|dk	r*|j|f|�dS)N)�superr[r�_patternr3)rrF�kwargs)�	__class__r
rrszDatePatternRegex.__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.
		)r])rr
r
rrF%s
zDatePatternRegex.patterncCs|j|�dS)N)r3)rrFr
r
rrF1sTcs�||_tj|�r$tjd|�}d}}|rBtj|�rBtjd|�}d}yL|jjd|�}||j|_|t}t	j|�rxd|}t
t|�j|||�Wn2t
k
r�}ztd||f��WYdd}~XnXdS)Nr	Frz%(\1)sz(?iu)zWFailed to set datepattern '%s' (may be an invalid format or unescaped percent char): %s)r]rEr r!rD�
_patternRE�_patternNamerr�RE_ALPHA_PATTERNr\r[r3r7�	TypeError)rrFr1r2Zfmtr0r9)r_r
rr35s 

zDatePatternRegex.setRegexcCs*|s|j|�}|r&t|j�|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.
		)r@N)r>r�	groupdict)rr;r=r@r
r
rrALs

zDatePatternRegex.getDate)N)TT)NN)rHrIrJrKrr`rar5r6rrLrF�setterr3rA�
__classcell__r
r
)r_rr[
s


r[c@s$eZdZdZddd�Zd	dd�ZdS)
�
DateTai64nz`A date template which matches TAI64N formate timestamps.

	Attributes
	----------
	name
	regex
	FcCs"tj|�d|_|jd|d�dS)NZTAI64Nz
@[0-9a-f]{24})r1)rrrr3)rr1r
r
rrns
zDateTai64n.__init__NcCs:|s|j|�}|r6|jd�}|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�rWN)r>r
�int)rr;r=r@�valueZseconds_since_epochr
r
rrAts

zDateTai64n.getDate)F)NN)rHrIrJrKrrAr
r
r
rrges
rg)$�
__author__Z
__copyright__Z__license__r5r�abcrZstrptimerrrZhelpersrrHr.r6r$r%rrErDrCrBr"r#r-r*r,rb�
IGNORECASErU�objectrrNr[rgr
r
r
r�<module>s6











=X