File: //lib/python3.9/site-packages/fail2ban/server/__pycache__/datetemplate.cpython-39.pyc
a
�dMfgC� @ s0 d Z dZdZddlZddlZddlmZ ddlmZm Z m
Z
dd lmZ ee
�Ze�d
�Ze�d�dfZe�d
�Ze�d�Ze�d�Ze�d�Ze�d�Ze�d�Ze�d�Ze�d�dd� fZe�d�Ze�d�Ze�d�Ze�dej�ZG dd� de�Z G dd� de �Z!G dd � d e �Z"G d!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+\))?\(*\*\*|(?<!\\)\*\*\)*$c C s | � � �dd�S )Nz**� )�group�replace)�m� r �@/usr/lib/python3.9/site-packages/fail2ban/server/datetemplate.py�<lambda>/ � r z(^(?:\(\?\w+\))?(?:\^|\((?:\?:)?\^(?!\|))z(?<![\\\|])(?:\$\)?)$z(?<!\%)\%[aAbBpc]z(?<!\\)\{L?EPOCH\}c @ sr e Zd ZdZdZdZdZdZdd� Zdd � Z ddd�Z
ee e
d
d�Zdd� 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
� � r r c C s. d| _ d| _d| _d| _d| _d| _d | _d S )Nr
g �?r )�nameZweight�flags�hits�time�_regex�_cRegex��selfr r r �__init__J s zDateTemplate.__init__c C s | j S �N)r r r r r �getRegexS s zDateTemplate.getRegexTc C st |� � }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| _dS )
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|$)r z constructed regex %sN)�strip�RE_GLOBALFLAGS�search�sub�RE_NO_WRD_BOUND_BEG�RE_NO_WRD_BOUND_END�
RE_GROUPED�RE_GROUPr r �
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 �setRegexV s:
zDateTemplate.setRegexz!Regex used to search for date.
)�docc
C sX | j sTzt�| j�| _ W n: tyR } z"t�d| j| j� |�W Y d}~n
d}~0 0 dS )z Compile regex by first usage.
z Compile %r failed, expression %rN)r �re�compiler4 � Exceptionr2 �errorr )r �er r r �
_compileRegex� s zDateTemplate._compileRegexc G sH | j s| �� t�dd| j� | j j|g|�R � }|rD| jd7 _|S )z1Check if regex for date matches on a log line.
r z search %sr )r r>