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.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)�GPL�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], ...}
	r	N)�
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�once�retrrrr/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!rr r&)r"r0rrrr+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*rrrr:�szConfigReader.sectionscCs(z|j�|�WSty"YdS0dS)NF)r�has_sectionr;)r"�secrrrr<�szConfigReader.has_sectioncCs&|r|j�||�S||jj�|i�vSr)r�
has_option�	_sectionsr4)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_sectionr;r�r"�section�argsr$rrrrE�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)rrr;r)r"rGrArrrr�szConfigReader.optionscCs6z|jj||||d�WSty0t|��Yn0dS)N)�raw�vars)rr4r;r)r"r=r@rIrJrrrr4�szConfigReader.getcOs<z|jj|g|�Ri|��WSty6t|��Yn0dSr)r�
getOptionsr;rrFrrrrK�szConfigReader.getOptions)NN)T)r3)T)F)�__name__�
__module__�__qualname__�__doc__r%r&r)�propertyr#r/r+r:r<r>rDrErr4rKrrrrr>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(rHr$rrrr%�szConfigReaderUnshared.__init__cCs|durtj}|�d�|_dS)N�/)r!�DEFAULT_BASEDIR�rstrip�_basedirr'rrrr&�szConfigReaderUnshared.setBaseDircCs|jSr)rTr*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)r6Zcf�Zconfig_files_readrr�
<listcomp>�r9z-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�existsrT�
ValueErrorr5�abspath�joinr-�debug�sorted�glob�appendr�filterrrr/�errorr)r)r"�filename�basenameZconfig_filesZ
config_dirZmissedrrVrr/�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�rJz/'%s' not defined in '%s'. Using default one: %rzWrong value for 'z' in 'z'. Using default one: '�')�dictrr4�	CONVERTERrr-rcrr^r[�warning�repr)
r"r=rZpOptionsZshouldExist�convert�valuesrrr�v�conv�errrrK�sF

����zConfigReaderUnshared.getOptions)N)NFT)
rLrMrNrOrRr%r&r)r/rKrrrrr!�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)NrU)rr%r5rXrYr\�setFile�setJailName�	_initOptsrh�_pOpts�	_defCache)r"Zfile_�jailNameZinitOptsr$rrrr%/s


z#DefinitionInitConfigReader.__init__cCs||_i|_dSr)�_filert)r"�fileNamerrrrr9sz"DefinitionInitConfigReader.setFilecCs|jSr)rxr*rrr�getFile=sz"DefinitionInitConfigReader.getFilecCs
||_dSr�Z	_jailName)r"rwrrrrs@sz&DefinitionInitConfigReader.setJailNamecCs|jSrr{r*rrr�getJailNameCsz&DefinitionInitConfigReader.getJailNamecCst�||j�Sr)rr/rxr*rrrr/FszDefinitionInitConfigReader.readcCs"|js|�|j�t�|j|j�Sr)rr+rxrr/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)rl�Initcs��d|�S)Nr)r4)r@r*rr�<lambda>\r9z7DefinitionInitConfigReader.getOptions.<locals>.<lambda>)rArLzknown/)rhrtrrrK�_configOpts�_optsrur<rr5r4)r"ZpOpts�all�getoptr@rnrr*rrKOs.�



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)rrir4r[r-rj)r"�optsZ
configOptsrrrrornrrr�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.
		r~rfN)rv�KeyErrorrZget_exrurrr[)r"rrnrrr�
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�rtrr�set�copyrZCONDITIONAL_RE�match�groups�addr
r�r[r�r�)r"r�Zcombinedoptsr7Zcondr�rrr�getCombined�s$�z&DefinitionInitConfigReader.getCombinedcCst�dSr)�NotImplementedErrorr*rrrrl�sz"DefinitionInitConfigReader.convertN)F)r)rLrMrNrOr�r%rrrzrsr|r/r}rKr�r�r�rlrrrrrq$s


rq)�
__author__�
__copyright__�__license__r`rX�configparserrrZconfigparserincrrrZhelpersr
rrr
rLr-rrirrr!rqrrrr�<module>s�ym