%PDF- %PDF-
Direktori : /usr/lib/python3/dist-packages/ufw/__pycache__/ |
Current File : //usr/lib/python3/dist-packages/ufw/__pycache__/util.cpython-312.pyc |
� ��e� � �2 � d Z ddlmZ ddlZddlZddlZddlZddlZddlZddl Z ddl Z ddlZddlZddl Z ddlZddlZddlmZ ddlmZmZ dZdZg d�Zg d�Zd d gZd� Zd� Zd � Zd� Zd� Zd9d�Zd� Z d� Z!d� Z"d� Z#d:d�Z$d� Z%d� Z&d� Z'd:d�Z(d� Z)ejT dfd�Z+d� Z,d� Z-d� Z.d � Z/ e j` � fd!�Z1 e j` � fd"�Z2d#� Z3d$� Z4d%� Z5d&� Z6d'� Z7d(� Z8d)� Z9d*� Z:d;d+�Z;d<d,�Z<d-� Z=d=d.�Z>d/� Z?d0� Z@d1� ZAd2� ZBd3� ZCd4� ZDd5� ZEd6� ZFd>d7�ZGd8� ZHy)?z"util.py: utility functions for ufw� )�print_functionN)�reduce)�mkstemp�mktempF)�tcp�udp�ipv6�esp�ah�igmp�gre�vrrp)r r r r r r r r c � � d} t j | � t j | d� d} t j | d� |dk( rd}|S d} |S # t $ r � w xY w# t $ r Y �>w xY w# t $ r Y |S w xY w)z8Get the protocol for a specified port from /etc/services� r r �any)�socket� getservbyname� Exception)�port�protos �*/usr/lib/python3/dist-packages/ufw/util.py�get_services_protor . s� � ��E�����T�"� ����T�5�)��� ����T�5�)��E�>��E� �L� �E� �L��% � � ��� � �� �� � ���L� �s3 �A �A% �A4 �A4 �A"�% A1�0A1�4 B� Bc � � d}d}| j d� }t |� dk( r|d }d}||fS t |� dk( r/|d }|d }|t v rt d|z � }t |� �||fS t d� }t |� �) zParse port or port and protocolr �/� r r � zInvalid port with protocol '%s'zBad port)�split�len�portless_protocols�_� ValueError)�p_strr r �tmp�err_msgs r �parse_port_protor% H s� � � �D��E� �+�+�c� �C� �3�x�1�}��1�v���� �%�=�� �S��Q���1�v���A����&�&��9�E�A�B�G��W�%�%� �%�=�� �J�-����!�!� c �p � t j st d� yt | � dkD st j d| � sy| j d� } t j t j |d � t |� dkD ryt |� dk( rt |d d � syy # t $ r Y yw xY w) zVerifies if valid IPv6 addressz"python does not have IPv6 support.F�+ z^[a-fA-F0-9:\./]+$r r r r T)r �has_ipv6�warnr �re�matchr � inet_pton�AF_INET6r �_valid_cidr_netmask��addr�nets r �valid_address6r3 \ s� � ��?�?�� 1�2�� �4�y�2�~�R�X�X�&;�T�B�� �*�*�S�/�C��������#�a�&�1� �3�x�!�|�� �S��Q��"�3�q�6�4�0���� � ���s �'B) �) B5�4B5c �Z � t | � dkD st j d| � sy| j d� } t j t j |d � t |d d� sy t |� dkD ryt |� dk( rt |d d� syy# t $ r Y yw xY w) zVerifies if valid IPv4 address� z^[0-9\./]+$Fr r r r T) r r+ r, r r r- �AF_INET�_valid_dotted_quadsr � valid_netmaskr0 s r �valid_address4r9 v s� � � �4�y�2�~�R�X�X�n�d�;�� �*�*�S�/�C���������Q��0�"�3�q�6�5�1�� 2� �3�x�!�|�� �S��Q���S��V�U�+���� � ���s �6B � B*�)B*c �6 � t | |� xs t | |� S )z(Verifies if valid cidr or dotted netmask)r/ r7 )�nm�v6s r r8 r8 � s � ��r�2�&�E�*=�b�"�*E�Er&