HEX
Server: nginx/1.30.4
System: Linux d-twindigital-web-1.host-ed.eu 4.18.0-553.141.2.el8_10.x86_64 #1 SMP Wed Jul 8 10:28:18 EDT 2026 x86_64
User: u_twindigital_html (1009)
PHP: 8.3.30
Disabled: NONE
Upload Files
File: //lib/python3.6/site-packages/fail2ban/server/__pycache__/jail.cpython-36.pyc
3

=�Z]� �@sXdZdZdZddlZddlZddlmZddlmZm	Z	m
Z
ee�ZGd	d
�d
e
�ZdS)z.Cyril Jaquier, Lee Clemens, Yaroslav HalchenkozPCopyright (c) 2004 Cyril Jaquier, 2011-2012 Lee Clemens, 2012 Yaroslav HalchenkoZGPL�N�)�Actions�)�	getLogger�extractOptions�MyTimec@s�eZdZdZddddgZd1dd	�Zd
d�Zdd
�Zdd�Zdd�Z	dd�Z
dd�Zedd��Z
edd��Zedd��Zedd��Zedd��Zejd d��Zd2d"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd3d-d.�Zd/d0�ZdS)4�JailagFail2Ban jail, which manages a filter and associated actions.

	The class handles the initialisation of a filter, and actions. It's
	role is then to act as an interface between the filter and actions,
	passing bans detected by the filter, for the actions to then act upon.

	Parameters
	----------
	name : str
		Name assigned to the jail.
	backend : str
		Backend to be used for filter. "auto" will attempt to pick
		the most preferred backend method. Default: "auto"
	db : Fail2BanDb
		Fail2Ban persistent database instance. Default: `None`

	Attributes
	----------
	name
	database
	filter
	actions
	idle
	status
	Z	pyinotifyZgaminZpollingZsystemd�autoNcCsb||_t|�dkr tjd|�||_tj�|_d|_tj	d|j
�|dk	rX|j|�||_dS)N�z]Jail name %r might be too long and some commands might not function correctly. Please shortenzCreating new jail '%s')
�	_Jail__db�len�logSys�warning�_Jail__name�queueZQueue�_Jail__queue�
_Jail__filter�info�name�_setBackend�backend)�selfrrZdb�r�/usr/lib/python3.6/jail.py�__init__Ds

z
Jail.__init__cCsd|jj|jfS)Nz%s(%r))�	__class__�__name__r)rrrr�__repr__Ssz
Jail.__repr__cCs6t|�\}}|j�}|j}|dkr`||jkrNtjd||f�td||f��||j|�d�}x�|D]�}t|d|j��}yJ|f|�|dkr�||kr�tj	d||f�ntj
d|�t|�|_dSt
k
�r}z*tj|dkr�tjntjd||f�WYdd}~XqfXqfWtjd|j�td|j��dS)Nr	z.Unknown backend %s. Must be among %s or 'auto'z_init%sz9Could only initiated %r backend whenever %r was requestedzInitiated %r backendz)Backend %r failed to initialize due to %sz,Failed to initialize any backend for Jail %r)r�lower�	_BACKENDSr
�error�
ValueError�index�getattr�
capitalizerrr�_Jail__actions�ImportError�log�logging�DEBUGZERRORr�RuntimeError)rrZbeArgsZbackends�bZ
initmethod�errrrVs8



$zJail._setBackendcKs2ddlm}tjd|j|f�||f|�|_dS)Nr)�
FilterPollzJail '%s' uses poller %r)Z
filterpollr-r
rrr)r�kwargsr-rrr�_initPolling|szJail._initPollingcKs2ddlm}tjd|j|f�||f|�|_dS)Nr)�FilterGaminzJail '%s' uses Gamin %r)Zfiltergaminr0r
rrr)rr.r0rrr�
_initGamin�szJail._initGamincKs2ddlm}tjd|j|f�||f|�|_dS)Nr)�FilterPyinotifyzJail '%s' uses pyinotify %r)Zfilterpyinotifyr2r
rrr)rr.r2rrr�_initPyinotify�szJail._initPyinotifycKs2ddlm}tjd|j|f�||f|�|_dS)Nr)�
FilterSystemdzJail '%s' uses systemd %r)Z
filtersystemdr4r
rrr)rr.r4rrr�_initSystemd�szJail._initSystemdcCs|jS)zName of jail.
		)r)rrrrr�sz	Jail.namecCs|jS)z;The database used to store persistent data for the jail.
		)r)rrrr�database�sz
Jail.databasecCs|jS)z;The filter which the jail is using to monitor log files.
		)r)rrrr�filter�szJail.filtercCs|jS)z2Actions object used to manage actions for jail.
		)r%)rrrr�actions�szJail.actionscCs|jjp|jjS)z-A boolean indicating whether jail is idle.
		)r7�idler8)rrrrr9�sz	Jail.idlecCs||j_||j_dS)N)r7r9r8)r�valuerrrr9�s�basiccCs$d|jj|d�fd|jj|d�fgS)zThe status of the jail.
		�Filter)�flavorr)r7�statusr8)rr=rrrr>�szJail.statuscCs0|jj|�|jr,|jdk	r,|jj||�dS)zQAdd a fail ticket to the jail.

		Used by filter to add a failure for banning.
		N)rZput�restoredr6ZaddBan)r�ticketrrr�
putFailTicket�szJail.putFailTicketcCs,y|jjd�}|Stjk
r&dSXdS)zTGet a fail ticket from the jail.

		Used by actions to get a failure for banning.
		FN)r�getrZEmpty)rr@rrr�
getFailTicket�s
zJail.getFailTicketcCs�y�|jdk	r�|jj�}x�|jj||d�D]�}|jj|j�dd�s(d|_|j|�}tj	�|j
�}|d	krx|dkrx||8}|d
kr�|dkr�q(|jtj	��|j|�|j
|�q(WWn<tk
r�}z tjd|tj�tjkd�WYdd}~XnXdS)z5Restore any previous valid bans from the database.
		N)Zjail�
forbantimeT)Z
log_ignorerrz%s)�exc_info���rF)r6r8Z
getBanTimeZgetCurrentBansr7ZinIgnoreIPListZgetIPr?rZtimeZgetTimeZsetTimeZ
setBanTimerA�	Exceptionr
r �getEffectiveLevelr(r))rrDr@ZbtmZdiftmr,rrr�restoreCurrentBans�s"



zJail.restoreCurrentBanscCs<tjd|j�|jj�|jj�|j�tjd|j�dS)z�Start the jail, by starting filter and actions threads.

		Once stated, also queries the persistent database to reinstate
		any valid bans.
		zStarting jail %rzJail %r startedN)r
�debugrr7�startr8rIr)rrrrrK�s


z
Jail.startTcCs�|rtjd|j�xt|j|jfD]d}y|r2|j�|r>|j�Wq tk
r�}z&tjd||j|tj	�t
jkd�WYdd}~Xq Xq W|r�tjd|j�dS)z9Stop the jail, by stopping filter and actions threads.
		zStopping jail %rzStop %r of jail %r failed: %s)rENzJail %r stopped)
r
rJrr7r8�stop�joinrGr rHr(r)r)rrLrM�objr,rrrrL�s(z	Jail.stopcCs|jj�p|jj�S)z?Check jail "isAlive" by checking filter and actions threads.
		)r7�isAliver8)rrrrrO
szJail.isAlive)r	N)r;)TT)r�
__module__�__qualname__�__doc__rrrrr/r1r3r5�propertyrr6r7r8r9�setterr>rArCrIrKrLrOrrrrr$s,
&
	
r)�
__author__Z
__copyright__Z__license__r(rr8rZhelpersrrrrr
�objectrrrrr�<module>s