HEX
Server: Apache
System: Linux scp1.abinfocom.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: confeduphaar (1010)
PHP: 8.1.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //usr/lib/python3/dist-packages/ufw/__pycache__/applications.cpython-38.pyc
U

��\��@s�dZddlZddlZddlZddlZddlmZmZddlm	Z	ddl
Z
e
jddkr`ddlZnddl
Z
dd�Zdd	�Zd
d�Zdd
�Zdd�Zdd�ZdS)z'applications.py: common classes for ufw�N)�debug�warn)�UFWError�cCsftj�|�std�}t|��d}i}t�|�}|��d}t�d�}|D�]}|d|}tj�	|�shqH|�
|�r�td|�qH|�d�s�|�d�s�|�d	�s�|�d
�s�|�d�s�|�d�r�td
|�qHd}	zt�
|�t
j}	Wn.tk
�rtd�|}
t|
�YqHYnX|	|k�r2td�|}
t|
�qH||	|k�rVtd�|}
t|
�qH||	7}tjddk�rxt��}nt��}z|�|�Wn.tk
�r�td�|}
t|
�YqHYnX|��D�]�}t|�dk�r�td�|}
t|
��q�t|��std�|}
t|
��q�z*tj�|�td�|}
t|
�W�q�Wntk
�rTYnXd}
|�|�D]h\}}t|�dk�r�td�|}
t|
�d}
�q�t|�dk�rdtd�||d�}
t|
�d}
�qΐqd|
�rؐq�||k�r�td�|}
t|
�i}|�|�D]\}}|||<�qzt||�|||<Wn,tk
�rZ}zt|�W5d}~XYnX�q�qH|S)zwGet profiles found in profiles database.  Returns dictionary with
       profile name as key and tuples for fields
    z!Profiles directory does not existi�rz^\.�/zSkipping '%s': hidden filez	.dpkg-newz	.dpkg-oldz
.dpkg-distz.rpmnewz.rpmsave�~z
Skipping '%s'zSkipping '%s': couldn't statzSkipping '%s': too bigz*Skipping '%s': too many files read alreadyrzSkipping '%s': couldn't process�@zSkipping '%s': name too longzSkipping '%s': invalid namez$Skipping '%s': also in /etc/servicesFzSkipping '%s': field too longTiz4Skipping '%(value)s': value too long for '%(field)s')�value�fieldz(Duplicate profile '%s', using last foundN)�os�path�isdir�_r�listdir�sort�re�compile�isfile�searchr�endswith�stat�ST_SIZE�	Exceptionr�sys�version_info�ConfigParserZRawConfigParser�configparser�readZsections�len�valid_profile_name�ufw�utilZget_services_proto�items�verify_profile)Zprofiles_dir�err_msgZmax_sizeZprofiles�filesZ
total_sizeZpat�fZabs_path�sizeZwarn_msgZcdict�p�skip�keyr	Zpdict�e�r,�2/usr/lib/python3/dist-packages/ufw/applications.py�get_profiles s�



����





�


 r.cCsD|dkrdSzt|�WdStk
r.YnXt�d|�r@dSdS)z0Only accept a limited set of characters for name�allFz ^[a-zA-Z0-9][a-zA-Z0-9 _\-\.+]*$T)�intrr�match)�namer,r,r-r�src
Csdddg}|D]J}||kr6td�||d�}t|��q||std�||d�}t|��q|d�d�}zV|D]L}tj�|�\}}|dkr�d	|ks�d
|kr�t|��tj�d||�}	t|	�qnWn>t	k
r�}
z t|
�td�|}t|��W5d
}
~
XYnXdS)z'Make sure profile has everything needed�title�description�portsz/Profile '%(fn)s' missing required field '%(f)s')�fnr&z1Profile '%(fn)s' has empty required field '%(f)s'�|�any�:�,ZACCEPTzInvalid ports in profile '%s'NT)
rr�splitr r!Zparse_port_proto�commonZUFWRulerr)r2�profileZ
app_fieldsr&r$r5r(Zport�protoZruler+r,r,r-r#�s2
�
�
r#cCs$d}d}||kr ||r ||}|S)z#Retrieve the title from the profile�r3r,�r=�sr
r,r,r-�	get_title�s
rBcCs$d}d}||kr ||r ||}|S)z)Retrieve the description from the profiler?r4r,r@r,r,r-�get_description�s
rCcCs*g}d}||kr&||r&||�d�}|S)z'Retrieve a list of ports from a profiler5r7)r;)r=r5r
r,r,r-�	get_ports�s
rD)�__doc__rrrZufw.utilr rrZ
ufw.commonrrrrrr.rr#rBrCrDr,r,r,r-�<module>s 
x