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: //lib/python3.9/site-packages/fail2ban/client/__pycache__/configreader.cpython-39.opt-2.pyc
a

6�&jZ]*�@s�dZdZdZddlZddlZddlmZmZddlm	Z	m
Z
mZdd	lm
Z
mZmZmZe
e�Zeed
�Zdd�ZGd
d�d�ZGdd�de
�ZGdd�de�ZdS)z?Cyril Jaquier, Yaroslav Halchenko, Serg G. Brester (aka sebres)z\Copyright (c) 2004 Cyril Jaquier, 2007 Yaroslav Halchenko, 2015 Serg G. Brester (aka sebres)ZGPL�N)�
NoOptionError�NoSectionError�)�sys�SafeConfigParserWithIncludes�logLevel�)�	getLogger�_as_bool�_merge_dicts�substituteRecursiveTags)�bool�intccsrt|ttf�rL|D]6}t|�dkr.|\}}}n|d\}}}|||fVqn"|D]}||\}}|||fVqPdS)z�Iterator over the options template with default options.
	
	Each options entry is composed of an array or tuple with:
		[[type, name, ?default?], ...]
	Or it is a dict:
		{name: [type, default], ...}
	rN)�
isinstance�list�tuple�len)�options�optname�opttype�optvalue�r�@/usr/lib/python3.9/site-packages/fail2ban/client/configreader.py�_OptionsTemplateGen)src@s�eZdZdZd"dd�Zdd�Zdd�Zed	d
��Zd#dd
�Z	d$dd�Z
dd�Zdd�Zd%dd�Z
dd�Zdd�Zd&dd�Zdifdd�Zd d!�ZdS)'�ConfigReaderzkGeneric config reader class.

	A caching adapter which automatically reuses already shared configuration.
	NcKsTd|_d|_|dur||_|dur6||_||_d|_n|jdurPtfi|��|_dS�N)�
_cfg_share�_cfg�_cfg_share_kwargs�_cfg_share_basedir�ConfigReaderUnshared)�selfZ
use_config�share_config�kwargsrrr�__init__Ds
zConfigReader.__init__cCs|jr|j�|�n||_dSr)r�
setBaseDirr�r!�basedirrrrr%RszConfigReader.setBaseDircCs|jr|j��S|jSdSr)r�
getBaseDirr�r!rrrr(Xs
zConfigReader.getBaseDircCs|jSr)rr)rrrr"^szConfigReader.share_configTcCsT|js|�|�|r(|jjdur(|jjSt�d||j���|j�|�}||j_|S)z� Overloads a default (not shared) read of config reader.

	  To prevent multiple reads of config files with it includes, reads into 
	  the config reader, if it was not yet cached/shared by 'name'.
	  Nz Loading configs for %s under %s )r�_create_unshared�read_cfg_files�logSys�infor(�read)r!�name�onceZretrrrr.bs
zConfigReader.read�cCsx|jsb|jdurb|j�|�|_|jsttfd|ji|j��|_|jdurT|j�|j�|j|j|<ntfi|j��|_dS)z� Allocates and share a config file by it name.

	  Automatically allocates unshared or reuses shared handle by given 'name' and 
	  init arguments inside a given shared storage.
	  Nr")rr�getr rrr%)r!r/rrrr*ws
zConfigReader._create_unsharedcCs2zdd�|j��D�WSty,gYS0dS)Ncss|]}|�d�s|VqdS)zKNOWN/N)�
startswith)�.0�nrrr�	<genexpr>��z(ConfigReader.sections.<locals>.<genexpr>)r�sections�AttributeErrorr)rrrr8�szConfigReader.sectionscCs(z|j�|�WSty"YdS0dS)NF)r�has_sectionr9)r!�secrrrr:�szConfigReader.has_sectioncCs&|r|j�||�S||jj�|i�vSr)r�
has_optionZ	_sectionsr2)r!r;�opt�withDefaultrrrr<�s�zConfigReader.has_optioncCs|j���|�dSr)rZget_defaults�update)r!�drrr�merge_defaults�szConfigReader.merge_defaultscOs<z|jj|g|�Ri|��WSty6t|��Yn0dSr)r�
merge_sectionr9r�r!�section�argsr#rrrrB�szConfigReader.merge_sectionFcCs0z|j�||�WSty*t|��Yn0dS)z�Return a list of option names for the given section name.

		Parameter `withDefault` controls the include of names from section `[DEFAULT]`
		N)rrr9r)r!rDr>rrrr�szConfigReader.optionscCs6z|jj||||d�WSty0t|��Yn0dS)N)�raw�vars)rr2r9r)r!r;r=rFrGrrrr2�szConfigReader.getcOs<z|jj|g|�Ri|��WSty6t|��Yn0dSr)r�
getOptionsr9rrCrrrrH�szConfigReader.getOptions)NN)T)r1)T)F)�__name__�
__module__�__qualname__�__doc__r$r%r(�propertyr"r.r*r8r:r<rArBrr2rHrrrrr>s 






rc@s@eZdZdZdZddd�Zdd�Zdd	�Zd
d�Zddd�Z	dS)r z�Unshared config reader (previously ConfigReader).

	Do not use this class (internal not shared/cached representation).
	Use ConfigReader instead.
	z
/etc/fail2banNcOs,tj|g|�Ri|��d|_|�|�dSr)rr$r+r%)r!r'rEr#rrrr$�szConfigReaderUnshared.__init__cCs|durtj}|�d�|_dS)N�/)r �DEFAULT_BASEDIR�rstrip�_basedirr&rrrr%�szConfigReaderUnshared.setBaseDircCs|jSr)rQr)rrrr(�szConfigReaderUnshared.getBaseDircs^tj�|j�std|j��|�d�r2tj�|�}tj�|j|�}t�	d||j�|dg}|d}|t
t�d|��7}|�|d�|t
t�d|��7}t
ttjj|��}t|��r"t�	d	d
�|��t�||���fdd�|D�}|�rt�d
d
�|����rdSt�d||���dSt�d|d|��dd
�|�gtt|���dSdS)Nz/Base configuration directory %s does not exist �./z Reading configs for %s under %s z.confz.dz	%s/*.confz.localz
%s/*.localzReading config files: %sz, csg|]}|�vr|�qSrr)r4Zcf�Zconfig_files_readrr�
<listcomp>�r7z-ConfigReaderUnshared.read.<locals>.<listcomp>zCould not read config files: %sTz0Found no accessible config files for %r under %sFz(Found no accessible config files for %r zunder %szamong existing ones: )�os�path�existsrQ�
ValueErrorr3�abspath�joinr,�debug�sorted�glob�appendr�filterrrr.�errorr(r
)r!�filename�basenameZconfig_filesZ
config_dirZmissedrrSrr.�sD�


�

�
��zConfigReaderUnshared.readFTc
Cs.t�}|duri}t|�D�]\}}}	||vr0qzF|j|||d�}
|
||<|rtt�|�}|rt|
durhWq||
�||<Wqty�}z$|r��t�|�|	||<WYd}~qd}~0ty�|	dur�t�d|||	f�|	||<Yqt	�y&t�
d|d|dt|	�d�|	||<Yq0q|S)N�rGz/'%s' not defined in '%s'. Using default one: %rzWrong value for 'z' in 'z'. Using default one: '�')�dictrr2�	CONVERTERrr,r`rr[rX�warning�repr)
r!r;rZpOptionsZshouldExist�convert�valuesrrr�v�conv�errrrH�sF

����zConfigReaderUnshared.getOptions)N)NFT)
rIrJrKrLrOr$r%r(r.rHrrrrr �s
2r c@sxeZdZdZgZdd�Zdd�Zdd�Zdd	�Zd
d�Z	dd
�Z
dd�Zddd�Zdd�Z
dd�Zddd�Zdd�ZdS)�DefinitionInitConfigReaderz�Config reader for files with options grouped in [Definition] and
	[Init] sections.

	Is a base class for readers of filters and actions, where definitions
	in jails might provide custom values for options defined in [Init]
	section.
	cKsVtj|fi|��|�d�r(tj�|�}|�|�|�|�||_t	�|_
t	�|_dS)NrR)rr$r3rUrVrY�setFile�setJailName�	_initOptsre�_pOpts�	_defCache)r!Zfile_�jailNameZinitOptsr#rrrr$/s


z#DefinitionInitConfigReader.__init__cCs||_i|_dSr)�_filerq)r!ZfileNamerrrro9sz"DefinitionInitConfigReader.setFilecCs|jSr)rur)rrr�getFile=sz"DefinitionInitConfigReader.getFilecCs
||_dSr�Z	_jailName)r!rtrrrrp@sz&DefinitionInitConfigReader.setJailNamecCs|jSrrwr)rrr�getJailNameCsz&DefinitionInitConfigReader.getJailNamecCst�||j�Sr)rr.rur)rrrr.FszDefinitionInitConfigReader.readcCs"|js|�|j�t�|j|j�Sr)rr*rurr.r)rrr�readexplicitJsz'DefinitionInitConfigReader.readexplicitFcs
|s
t�}�jrt|�j�}tj�d�j|dd��_|�_��d�r��fdd�}�j	ddd�D]^}|dkrlq^d}|�
d	�s�|dur�||�}|�jd	|<|�jvr^|dur�||�}|�j|<q^|�r��d��r��	d�D]*}|dks�|�jvr�qڈ�d|��j|<q�dS)
N�
DefinitionF)ri�Initcs��d|�S)Nr{)r2)r=r)rr�<lambda>\r7z7DefinitionInitConfigReader.getOptions.<locals>.<lambda>)r>rIzknown/)rerqrrrH�_configOpts�_optsrrr:rr3r2)r!ZpOpts�allZgetoptr=rkrr)rrHOs.�



z%DefinitionInitConfigReader.getOptionscCsxt|�D]j\}}}t�|�}|r|�|�}|dur4qz||�||<Wqtypt�d||||�|||<Yq0qdS)z:Convert interpolated combined options to expected type.
		Nz/Wrong %s value %r for %r. Using default one: %r)rrfr2rXr,rg)r!�optsZ
configOptsrrrrlrkrrr�convertOptionsms


�z)DefinitionInitConfigReader.convertOptionsc
Cshz|j|WStybz|jjd||jd�}WntttfyNd}Yn0||j|<|YS0dS)z�Get combined definition option (as string) using pre-set and init
		options as preselection (values with higher precedence as specified in section).

		Can be used only after calling of getOptions.
		rzrcN)rs�KeyErrorrZget_exrrrrrX)r!rrkrrr�
getCombOption|s

z(DefinitionInitConfigReader.getCombOptionrcCs�|j}|jrt||j�}t|�s$iSt|���}|D]*}tj�|�}|r4|�	�\}}|�
|�q4t|||jd�}|s|t
d��|�||j�|S)N)�ignoreZaddreplz/recursive tag definitions unable to be resolved)r~rqrr�set�copyrZCONDITIONAL_RE�match�groups�addrr�rXr�r})r!r�Zcombinedoptsr5Zcondr�rrr�getCombined�s$�z&DefinitionInitConfigReader.getCombinedcCst�dSr)�NotImplementedErrorr)rrrri�sz"DefinitionInitConfigReader.convertN)F)r)rIrJrKrLr}r$rorvrprxr.ryrHr�r�r�rirrrrrn$s


rn)�
__author__Z
__copyright__Z__license__r]rUZconfigparserrrZconfigparserincrrrZhelpersr	r
rrrIr,rrfrrr rnrrrr�<module>s�ym