HOME


Mini Shell 1.0
DIR: /usr/lib/python3/dist-packages/ufw/__pycache__/
Upload File :
Current File : //usr/lib/python3/dist-packages/ufw/__pycache__/applications.cpython-312.pyc
�

#fd����dZddlZddlZddlZddlZddlmZmZddlm	Z	ddl
Z
e
jddkrddlZnddl
Z
d�Zd�Zd�Zd	�Zd
�Zd�Zy)z'applications.py: common classes for ufw�N)�debug�warn)�UFWError�c���tjj|�std�}t	|��d}i}tj
|�}|j
�d}tjd�}|D�]}|dz|z}tjj|�s�,|j|�rtd|z��L|jd�sU|jd�sD|jd	�s3|jd
�s"|jd�s|jd�rtd
|z���d}		tj|�tj}	|	|kDrtd�|z}
t!|
���
||	z|kDrtd�|z}
t!|
���-||	z
}t"j$ddkrt'j(�}nt+j(�}	|j-|�|j/�D]�}t1|�dkDrtd�|z}
t!|
��+t3|�std�|z}
t!|
��P	t4j6j9|�td�|z}
t!|
����� |S#t$rtd�|z}
t!|
�Y��HwxYw#t$rtd�|z}
t!|
�Y��qwxYw#t$rYnwxYwd}
|j;|�D]^\}}t1|�dkDrtd�|z}
t!|
�d}
n0t1|�dkDs�@td�||d�z}
t!|
�d}
n|
r��i||vrtd�|z}
t!|
�i}|j;|�D]
\}}|||<�	t=||�|||<���#t$r}t!|�Yd}~���d}~wwxYw)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�ConfigParser�RawConfigParser�configparser�read�sections�len�valid_profile_name�ufw�util�get_services_proto�items�verify_profile)�profiles_dir�err_msg�max_size�profiles�files�
total_size�pat�f�abs_path�size�warn_msg�cdict�p�skip�keyr�pdict�es                  �2/usr/lib/python3/dist-packages/ufw/applications.py�get_profilesr; s����7�7�=�=��&��7�8���w����H��H��J�J�|�$�E�	�J�J�L��J�
�*�*�V�
�C�
�c���#�%��)���w�w�~�~�h�'���:�:�a�=��.�!�4�5���:�:�k�"�a�j�j��&=��:�:�l�#�q�z�z�)�'<��:�:�j�!�Q�Z�Z��_��/�Q�'�(����	��7�7�8�$�T�\�\�2�D��(�?��1�2�a�8�H���N�����x�'��E�F�!�L�H���N���d��
����A���"� �0�0�2�E� �0�0�2�E�	��J�J�x� ����!�1	�A��1�v��{��;�<��B���X���%�a�(��:�;�q�A���X���
����+�+�A�.��C�D��J���X���1	�ec�J�O��c�	��7�8�A�>�H���N��	��0�	��:�;�q�A�H���N��	��,�
��
���D�#�k�k�!�n�
�
��U��s�8�b�=� �!@�A�Q�G�H���N��D���u�:��$� �"/� 0�,-��"<� >�H���N��D��
����H�}��G�H�A�N���X���E�#�k�k�!�n�
#�
��U�"��c�
�
#�
��q�%�(�#������
��Q����
�sN�<&J�*K�8K-�"K�K�"K*�)K*�-	K9�8K9�2O�	O$�O�O$c�v�|dk(ry	t|�y#t$rYnwxYwtjd|�ryy)z0Only accept a limited set of characters for name�allFz ^[a-zA-Z0-9][a-zA-Z0-9 _\-\.+]*$T)�intrr�match)�names r:r#r#�sF���u�}��
��D�	����
��
��

�x�x�3�T�:��s��	 � c��gd�}|D]C}||vrtd�||d�z}t|��||r�)td�||d�z}t|��|djd�}	|D]h}tjj|�\}}|dk(rd|vsd	|vrt��tjjd
||�}	t|	��j	y
#t$r)}
t|
�td�|z}t|��d}
~
wwxYw)z'Make sure profile has everything needed)�title�description�portsz/Profile '%(fn)s' missing required field '%(f)s')�fnr0z1Profile '%(fn)s' has empty required field '%(f)s'rD�|�any�:�,�ACCEPTzInvalid ports in profile '%s'NT)
rr�splitr$r%�parse_port_proto�common�UFWRulerr)r@�profile�
app_fieldsr0r*rDr5�port�proto�ruler9s           r:r(r(�s&��2�J�
�	$���G���I�J� $�1�-�/�G��7�#�#�����K�L�"&�Q�/�1�G��7�#�#�	$�
�G��"�"�3�'�E� ��	�A��H�H�5�5�a�8�M�T�5���~�3�$�;�#��+��w�'�'��:�:�%�%�h��t�<�D��$�K�
	���� �
�a���3�4��=���w���� �s�"A-C�	D�$C>�>Dc�*�d}d}||vr
||r||}|S)z#Retrieve the title from the profile�rB��rO�srs   r:�	get_titlerY�s(��
�A��E����G�E�N��E�N���H�c�*�d}d}||vr
||r||}|S)z)Retrieve the description from the profilerUrCrVrWs   r:�get_descriptionr\�s(��
�A��E����G�E�N��E�N���HrZc�H�g}d}||vr||r||jd�}|S)z'Retrieve a list of ports from a profilerDrF)rK)rOrDrs   r:�	get_portsr^�s3���E��E����G�E�N����$�$�S�)���LrZ)�__doc__r
rr�ufw.utilr$rr�
ufw.commonrrrrrr;r#r(rYr\r^rVrZr:�<module>rbsY��-�"
�	��� ��
����A������u�p�(�@
�
�rZ