%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/ufw/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/ufw/__pycache__/frontend.cpython-312.pyc

�

#fd����|�dZddlZddlZddlZddlmZddlZddlmZm	Z	m
Z
ddlmZddl
Zd�Zd�ZGd�d	�Zy)
z'frontend.py: frontend interface for ufw�N)�UFWError)�error�warn�msg)�UFWBackendIptablesc��tjj�}dD]0}|jtjj	|���2dD]0}|jtjj|���2dD]0}|jtjj
|���2dD]0}|jtjj|���2dD]0}|jtjj|���2dD]0}|jtjj|���2gd�}|D]^}|jtjj|��|jtjj|���`t|�dkDrmd	}||j�d
k(rd}||j�dk7r=||j�dk7r'||j�|vr|j|d
�t|�dksd
|vr%t|�dkrtdd��t!��	|j#|d	d�}|S#t$$r#}td|j&z�Yd}~Sd}~wt($rtdd���wxYw)zEParse command. Returns tuple for action, rule, ip_version and dryrun.)	�enable�disable�helpz--helpz-h�versionz	--version�reload�reset)�list�info�default�update)�on�off�low�medium�high�full)�allow�deny�reject)N�verbose�numbered)�rawzbefore-rulesz
user-ruleszafter-rulesz
logging-rules�builtins�	listening�added)r�limitrr�insert�delete�prepend���	--dry-runr�route�rule�znot enough argsF)�do_exitNz%szInvalid syntax)�ufw�parser�	UFWParser�register_command�UFWCommandBasic�
UFWCommandApp�UFWCommandLogging�UFWCommandDefault�UFWCommandStatus�UFWCommandShow�UFWCommandRule�UFWCommandRouteRule�len�lowerr#r�
ValueError�
parse_commandr�value�	Exception)�argv�p�i�
rule_commands�idx�pr�es       �./usr/lib/python3/dist-packages/ufw/frontend.pyr<r<s����
�
����A�
�:��	
���3�:�:�5�5�a�8�9�:�3�8��	���3�:�:�3�3�A�6�7�8�<�<��	���3�:�:�7�7��:�;�<�)�<��	���3�:�:�7�7��:�;�<�+�;��	���3�:�:�6�6�q�9�:�;�A�9��	���3�:�:�4�4�Q�7�8�9�
 �M�
�>��	���3�:�:�4�4�Q�7�8�	���3�:�:�9�9�!�<�=�>��4�y�1�}�����9�?�?���+��C���9�?�?��	�)���9�?�?���'���9�?�?��
�-��K�K��V�$�
�4�y�1�}���,��T��Q��
���/��l���
�_�_�T�!�"�X�
&���I��
� �
�d�a�g�g����
�I��	��
���.�
��s�7J
�
	K�J4�4Kc�*�tdidtjj�dd�dd�dd�dd�d	d
�dd�d
d�dd�dd�dd�dd�dd�dd�dd�dd�dd�id d!�d"d#�d$d%�d&d'�d(d(�d)d)�d*d*�d+d,�d-d.�d/d0�d1d2�d3d3�d4d5�d6d7�d8d9�d:d;�d<d=��d>d?i�z�}|S)@zPrint help messagea+
Usage: %(progname)s %(command)s

%(commands)s:
 %(enable)-31s enables the firewall
 %(disable)-31s disables the firewall
 %(default)-31s set default policy
 %(logging)-31s set logging to %(level)s
 %(allow)-31s add allow %(rule)s
 %(deny)-31s add deny %(rule)s
 %(reject)-31s add reject %(rule)s
 %(limit)-31s add limit %(rule)s
 %(delete)-31s delete %(urule)s
 %(insert)-31s insert %(urule)s at %(number)s
 %(prepend)-31s prepend %(urule)s
 %(route)-31s add route %(urule)s
 %(route-delete)-31s delete route %(urule)s
 %(route-insert)-31s insert route %(urule)s at %(number)s
 %(reload)-31s reload firewall
 %(reset)-31s reset firewall
 %(status)-31s show firewall status
 %(statusnum)-31s show firewall status as numbered list of %(rules)s
 %(statusverbose)-31s show verbose firewall status
 %(show)-31s show firewall report
 %(version)-31s display version information

%(appcommands)s:
 %(applist)-31s list application profiles
 %(appinfo)-31s show information on %(profile)s
 %(appupdate)-31s update %(profile)s
 %(appdefault)-31s set default application policy
�progname�command�COMMAND�commands�Commandsr	r
rzdefault ARG�loggingz
logging LEVEL�level�LEVELrz
allow ARGSr*rz	deny ARGSrzreject ARGSr"z
limit ARGSr$zdelete RULE|NUM�urule�RULEr#zinsert NUM RULEr%zprepend RULEr)z
route RULEzroute-deletezroute delete RULE|NUMzroute-insertzroute insert NUM RULE�number�NUMr
r�status�	statusnumzstatus numbered�rules�RULES�
statusverbosezstatus verbose�showzshow ARGr�appcommandszApplication profile commands�applistzapp list�appinfozapp info PROFILE�profile�PROFILE�	appupdatezapp update PROFILE�
appdefaultzapp default ARG)�_r-�common�programName)�help_msgs rF�get_command_helprees�����>"*�
�C�J�J�*�*�"*�	�I�"*�	�Z�"*�
�8�"*�
�I�	"*�

�M�"*�
�O�
"*�
�'�"*�
�,�"*�
��"*�
��"*�
�=�"*�
�,�"*�
�$�"*�
�&�"*�
�$�"*� 
�N�!"*�"
�,�#"*�$
�0�%"*�&
�0�'"*�(
�5�)"*�*
�8�+"*�,
�'�-"*�.
�8�/"*�0
�'�1"*�2
�'�3"*�4
�*�5"*�6
��7"*�8
�I�9"*�:
�6�;"*�<
�J�="*�>
�&�?"*�@
�I�A"*�B
�*�C"*�D
�(�E"*�?A+�A,�H�F
��c��eZdZdZ		dd�Zd�Zd�Zd�Zdd�Zdd�Z	d	�Z
d
�Zd�Zdd�Z
dd
�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zdd�Zy)�UFWFrontend�UINc���|dk(r	t|||��|_ntd|z��t	d�|_t	d�|_t	d�|_y#t$r�wxYw)N�iptables)�rootdir�datadirzUnsupported backend type '%s'�n�y�yes)r�backendr>rra�norp�yes_full)�self�dryrun�backend_typerlrms     rF�__init__zUFWFrontend.__init__�sm���:�%�
�1�&�'�:A� C���
�:�l�K�L�L��C�&����S�6����%���
���
��
�s�A�A%c�t�d}d}|rd}d}|r|jj�r|s|jj�rd}|r5	|jj|jjdd|�d}|rm	|jj�|dk7r@	|jj|jjddd�t|�td	�}|S	|jj�td
�}|S#t$r}t|j�Yd}~��d}~wwxYw#t$r}|r|j}Yd}~��d}~wwxYw#t$r}t|j�Yd}~��d}~wwxYw#t$r}t|j�Yd}~��d}~wwxYw)zlToggles ENABLED state in <config_dir>/ufw/ufw.conf and starts or
           stops running firewall.
        �rrrpFT�conf�ENABLEDNz0Firewall is active and enabled on system startupz/Firewall stopped and disabled on system startup)
rq�
is_enabled�set_default�filesrrr=�start_firewallra�
stop_firewall)rt�enabled�res�
config_str�changedrE�	error_strs       rF�set_enabledzUFWFrontend.set_enabled�s������
���J����D�L�L�3�3�5��D�L�L�3�3�5��G��
����(�(����);�);�F�)C�)2�J�@�
�	��
(����+�+�-�
�B��#��L�L�,�,�T�\�\�-?�-?��-G�-6��>��i� ��F�G�C��
�
����*�*�,��E�F�C��
��A�
��a�g�g����
���
(�� !���I���
(�� �#��!�'�'�N�N��#���
��a�g�g����
�s`�4D�E�!4E$�.F�	D=�D8�8D=�	E!�	E�E!�$	F�-F�F�	F7�F2�2F7c�8�d}	|jj||�}|jj�r4|jj�|jj	�|S#t
$r }t
|j�Yd}~|Sd}~wwxYw)zSets default policy of firewallryN)rq�set_default_policyr|r�rrrr=)rt�policy�	directionr�rEs     rFr�zUFWFrontend.set_default_policy�s}����	��,�,�1�1�&�)�D�C��|�|�&�&�(����*�*�,����+�+�-��
���	��!�'�'�N�N��
��	�s�A*A0�0	B�9B�Bc��d}	|jj|�}|S#t$r }t|j�Yd}~|Sd}~wwxYw)zSets log level of firewallryN)rq�set_loglevelrrr=)rtrNr�rEs    rFr�zUFWFrontend.set_loglevelsK����	��,�,�+�+�E�2�C��
���	��!�'�'�N�N��
��	���!�	A
�A�A
c��	|jj||�}|S#t$r }t|j�Yd}~Sd}~wwxYw)zShows status of firewallN)rq�
get_statusrrr=)rtr�
show_count�outrEs     rFr�zUFWFrontend.get_statussH��	��,�,�)�)�'�:�>�C��
���	��!�'�'�N�N��
��	�s� �	A	�A�A	c��	|jj|�}|S#t$r }t|j�Yd}~Sd}~wwxYw)zShows raw output of firewallN)rq�get_running_rawrrr=)rt�
rules_typer�rEs    rF�get_show_rawzUFWFrontend.get_show_rawsF��	��,�,�.�.�z�:�C��
���	��!�'�'�N�N��
��	�s��	A�A�Ac���d}	tjj|jj	��}|jj�}t|j��}|j�|D�]}|jj	�s|dvr�#|d|zz
}t||j��}|j�|D�]�}|||D�]�}	|	d}
|
jd�r�|
jd�r�-d}|d|zz
}|
d	k(s|
d
k(r|dz
}d|	dz}
n'|d
|
zz
}tjj|
�}|dtjj!|	d�zz
}tj"j%d|dd||
dd��}|j'|j)d��|dk7r|j+d|�|j-�|jj/|�}
t1|
�dkDr[|dz
}|
D]Q}|dkDs�	|dz
t1|�ks�|d|tj2j4j7||dz
�fzz
}�S|dz
}��������|jj	�stjj9d�|S#t
$rt
d�}t|��wxYw)zMShows listening services and incoming rules that might affect
           themryzCould not get listening status)�tcp6�udp6z%s:
�laddrz127.z::1z  %s z0.0.0.0z::z* z%s/0z%s z(%s)�exerNr+�inF)�action�protocol�dport�dstr��forward�6r�
r'z   [%2d] %s
z)Skipping tcp6 and udp6 (IPv6 is disabled))r-�util�parse_netstat_outputrq�use_ipv6r>rar�	get_rulesr�keys�sort�
startswith�get_if_from_ip�os�path�basenamerb�UFWRule�set_v6�endswith�
set_interface�	normalize�get_matchingr9r.r7�get_command�debug)rtr��d�err_msgrV�	protocols�proto�ports�port�item�addr�ifnamer*�matchingrAs               rF�get_show_listeningzUFWFrontend.get_show_listenings�����	$����-�-�d�l�l�.C�.C�.E�F�A�
���&�&�(�������N�	������3	$�E��<�<�(�(�*�u�8H�/H���7�e�$�$�C���5�����)�E��J�J�L��-
$���e�H�T�N�,$�D���=�D��?�?�6�2��?�?�5�1�!#���w��~�-���9�,�����4�K�C�#)�T�'�]�#;�D��5�4�<�/�C�%(�X�X�%<�%<�T�%B�F��v����(8�(8��e��(E�E�E�� #�z�z�1�1��;@��!�9�8<�6:�<@�:?� 2� 3�����E�N�N�3�$7�8�!�R�<� �.�.�t�V�<����(�$(�<�<�#<�#<�T�#B���x�=�1�,��4�K�C�%-�&��#$�q�5�Q��U�S��Z�-?�$'�?�a�(+�
�
�(A�(A�(M�(M�*/��!��*�)6�>&�,&�%&�C�&��t���Y,$�-
$�
3	$�j�|�|�$�$�&��H�H�N�N�F�G��
��A�	$��8�9�G��7�#�#�	$�s�7J?�? Kc���|jj�}td�}t|�dk(r|td�zSg}|jj�D]�}|jr-dt
jjj|�z}n)t
jjj|�}||vr�j|j|�|d|zz
}��|S)z!Shows added rules to the firewallz9Added user rules (see 'ufw status' for running firewall):rz
(None)�route %sz
ufw %s)rqr�rar9r�r-r.r8r�r7�append)rtrVr�r!�r�rstrs      rF�get_show_addedzUFWFrontend.get_show_addedfs������&�&�(���K�L���u�:��?���:��&�&������'�'�)�	%�A��y�y�!��
�
�6�6�B�B�1�E�F���z�z�0�0�<�<�Q�?���u�}���L�L����:��$�$�C�	%�"�
rfc��d}d}d}g}|jdk(r"|jdk(r|j|��n�g}	|j�r�|dk(r|jj|d�}n�|dk(r|jj|d�}n�|dk(r�|jj|d�}|jj|d�}|D]F}	|D]?}
|
j}d|
_|	j|
�r�(||
_|j|
��A�Hntd�|z}t|��t|�dk(rH|jjs2td	�}|dk(r|}|S|dk(r|d
z}|S|dk(r|dz|zd
z}|S|D]j}|j�}|j|_|j|j�|j|j �|j|��ln:|jj#|�}|j$dk7r|j'�d}
d}td�}|jj+d�}|jj+d�}t-|�D�]�\}}|}
|j$||zkDr&|t/|j$�d
zz
}t|��	|jj1��r�|dk(r�|j$dk(r |
dk(r|dk(rdnd}|j3|�n5|j$|kDr&|t/|j$�d
zz
}t|��|j5d�|jj7|�}�n�|dk(r�|j$dk(r |
dk(r|dk(rdnd}|j3|�nr|j$|kDr|j3|j$|z
�nD|j$dk7r5|j$|kr&|t/|j$�d
zz
}t|��|j5d�|jj7|�}�n�|dk(�r|j$}|j5d�|dk(r |
dk(r|dk(rdnd}|j3|�n[|jsO||kDrJ|jj9||z
|
zd�}|dkDr|j3|�n|j3d�|jj7|�}|js4|dkDr/|jj+d�}|j3|dz�|j5d�|dk(r |
dk(r|dk(rdnd}|j3|�n{|jso|j$dkDr`|j$|krQ|jj9|j$d�}|dkDr|j3||
z
�n|j3d�|dk7r|dz
}|js2|j$|kDr#|dk7r|j3|j$|z
�||jj7|�z
}n�td�|z}t|��|j$dk(r|
dk(r|dk(rdnd}|j3|�|dk(s|dk(r-|j5d�|jj7|�}n4|dk(rtd�}t|��td�|z}t|��|j<s���td�}t?j@|����|s||z
}|St|�dk(r
tC|�|Sd}tEtG|
dz��}|j'�|D];}|
dkDs�	||s�||j�}d|_	|j7||��=|td�z
}|r|td�z
}t|��|td�z
}t|��#t($r�wxYw#t$r}|j:}d}Yd}~��d}~wwxYw#t($r,d}td�jI�z}tA|�Y��wxYw)zUpdates firewall with rulery�v4F�v6T�bothzInvalid IP version '%s'rz"Could not delete non-existent rulez (v6)r�zInvalid position '�'���r'zIPv6 support not enabledNz Rule changed after normalizationzCould not back out rule '%s'z"
Error applying application rules.z# Some rules could not be unapplied.z( Attempted rules successfully unapplied.)%�dapp�sappr��removerq�get_app_rules_from_systemr��matchrarr9ru�dup_rule�
set_actionr��set_logtype�logtype�get_app_rules_from_template�position�reverser>�get_rules_count�	enumerate�strr��set_positionr��set_rule�find_other_positionr=�updated�warningsrrr�range�format_rule)rtr*�
ip_versionr�r��tmprV�tmprules�	tmprules6�xro�prev6r��count�	set_error�pos_err_msg�num_v4�num_v6rA�begin�user_posr@rE�warn_msg�
undo_error�indexes�j�backout_rules                            rFr�zUFWFrontend.set_rule�s������������9�9��?�t�y�y�B���L�L����H�2
��;�;�!�T�)�#'�<�<�#I�#I�CG��$P��#�t�+�#'�<�<�#I�#I�CG��$O��#�v�-�#'�<�<�#I�#I�CG��$P��$(�L�L�$J�$J�CG��%O�	�"*�7�A�%.�7��()����',���'(�w�w�q�z�+0�A�D�$,�O�O�A�$6�7�7�#$�$=�">�*�"M��&�w�/�/��8�}��)�$�,�,�2E�2E�� D�E��%��-�"%�C�
 #�
�	(�4�/�"%��-�C� #�
�(�6�1�"%��*�s�"2�W�"<�C�"�
�'�(���L�L�N��#'�;�;������T�[�[�1��
�
�d�l�l�3����Q��(�!�L�L�D�D�T�J�E��}�}��)��
�
�����	��,�-�����-�-�e�4�����-�-�d�3���e�$�c	(�D�A�q��E��z�z�F�V�O�+��s�1�:�:���4�4���{�+�+�Z
��<�<�(�(�*�!�T�)��:�:��+�).�!���!��A��E��N�N�5�1��Z�Z�&�0�'�3�q�z�z�?�S�+@�@�K�"*�;�"7�7������"�l�l�3�3�A�6��#�t�+��:�:��+�).�!���!��A��E��N�N�5�1��Z�Z�&�0��N�N�1�:�:��+>�?��Z�Z�1�_����v�1E�'�3�q�z�z�?�S�+@�@�K�"*�;�"7�7������"�l�l�3�3�A�6��#�v�-�#$�:�:�������#�r�>�).�!���!��A��E��N�N�5�1�!"���h��.?�!%��� @� @� (�6� 1�E� 9�4�!A�A� �1�u� !���q� 1�!"���q� 1�"�l�l�3�3�A�6�� !�x�x�H�q�L�%)�\�\�%A�%A�%�%H�F��N�N�8�a�<�8������#�r�>�).�!���!��A��E��N�N�5�1�!"���a�j�j�1�n��:�:��/�!%��� @� @����AF�!H�A� �1�u� !���q�5�y� 9�!"���q� 1��"�9��4�K�C� !�x�x�A�J�J��,?�#�r�>��N�N�1�:�:��+>�?��t�|�|�4�4�Q�7�7��"#�$=�">�*�"M��&�w�/�/��z�z�R�'�%*�a�Z�F�a�K��Q�����u�-�!�T�)�Z�6�-A������"�l�l�3�3�A�6��#�t�+�"#�$>�"?��&�w�/�/�"#�$=�">�*�"M��&�w�/�/��y�y��?�@���
�
�h�'�Gc	(�J��3�J�C�>�
�=��Z�1�_��'�N�8�
�1�J��5��q��>�*�G��O�O���
'���1�9��q��#(��8�#4�#4�#6�L�*.�L�'�'��
�
�l�J�?�
'�
�q�>�?�?�G���1�B�C�C���7�#�#��1�G�H�H���7�#�#��Y�
��
��H�
��'�'�� �	���
��6%�'�%)�
�#$�%C�#D�%&�]�]�_�$5���X��'�sQ�B<`�:A-`�(`�4`�B*`�Q`�:a�`�	a�'`;�;a�2a8�7a8c��	t|�}|jj�}|dks|t
|�kDrtd�|z}t|��|jj|�}|std�|z}t|��d|_d}|jrd}d}|�s|jr-dtjjj|�z}	n)tjjj|�}	td�|	|j |j"d	�z}
t%|
t&j(d
��t&j*j-�j/�j1�}|dk7r<||j j/�k7r||j2j/�k7rd
}d
}|r|j5||�}|Std�}|S#t$rtd�|z}t|��wxYw)zDelete rulezCould not find rule '%s'rzCould not find rule '%d'Tr�r�r�z=Deleting:
 %(rule)s
Proceed with operation (%(yes)s|%(no)s)? )r*rprrF��output�newlinerory�Aborted)�intr>rarrqr�r9�get_rule_by_numberr�r�r�r-r.r8r�r7rprrr�sys�stdout�stdin�readliner:�striprsr�)
rtrR�forcernr�rVr*r��proceedr��prompt�ansr�s
             rF�delete_rulezUFWFrontend.delete_ruleOs���	$��F��A�
���&�&�(����6�Q��U��^��2�3�a�7�G��7�#�#��|�|�.�.�q�1����2�3�a�7�G��7�#�#�����
��7�7��J�����|�|�!��
�
�6�6�B�B�4�H�I���z�z�0�0�<�<�T�B���,�-�9=�8<���7;�w�w�1@�A�F�
��s�z�z�5�9��)�)�$�$�&�,�,�.�4�4�6�C��c�z�c�T�X�X�^�^�%5�5��d�m�m�)�)�+�+�������-�-��j�1�C��
��I�,�C��
��W�	$��2�3�f�<�G��7�#�#�	$�s�G)�)#Hc��d}|jd�rH|jd�}t|�dkDr|j|d�}|S|jd�}|S|dk(r|jd�}|S|jd�rOt	d	�}|jd
�}t|�dk7rt|��|j
|d|d�}|S|d
k(r|j|�}|S|dk(r|j�}|S|dk(r|jd�}|S|jd�rU|jd
�d}|dk(r|j�}|S|dk(r|j�}|S|j|�}|S|dk(r|jdd�}|S|dk(r|jd�}|S|dk(r|jd�}|S|dk(rV|jj�r/|jd�|jd�t	d�}|St	d�}|S|jd�r&|j|jd
�d|�}|S|dk(s|dk(s
|dk(s|dk(r�|j dk7rN	|jj#|j �}||j k7r||_|j%|d �|j2dk7rN	|jj#|j2�}||j2k7r||_|j%|d �|j5||�}|St	d#�|z}t|��#t
$rj}|j&st)|j*�t,j.j1|j �st	d!�}t|��Yd"}~��d"}~wwxYw#t
$rk}|j&st)|j*�t,j.j1|j2�st	d!�}t|��Yd"}~��d"}~wwxYw)$z�Perform action on rule. action, rule and ip_version are usually
           based on return values from parse_command().
        ryz
logging-onrar'rzlogging-offrzdefault-zUnsupported default policy�-r+r&rrTzstatus-verboseTrYr r!zstatus-numberedFr	r
r
�Firewall reloadedz&Firewall not enabled (skipping reload)zdelete-rrrr"r��Invalid profile nameN�Unsupported action '%s')r��splitr9r�rarr�rr�r�r�r�r�rqr|rr��find_application_name�set_portr�rr=r-�applications�valid_profile_namer�r�)	rtr�r*r�rr�r�r�rEs	         rF�	do_actionzUFWFrontend.do_action�sh�������\�*��,�,�s�#�C��3�x�!�|��'�'��A��/��X�
�U�'�'��-��T�
�S�}�
$��#�#�E�*�C�P�
�O�
�
�z�
*��4�5�G��,�,�s�#�C��3�x�1�}��w�'�'��)�)�#�a�&�#�a�&�9�C�D�
�C�w�
��*�*�U�#�C�@�
��x�
��/�/�#�C�|�
�{�'�
'��/�/�$�'�C�x�
�w�
�
�v�
&��,�,�s�#�A�&�C��k�!��-�-�/��p�
�o����)�)�+��l�
�i�'�'��,��h�
�g�(�
(��/�/�%��.�C�d�
�c�x�
��"�"�4�(�C�`�
�_�y�
 ��"�"�5�)�C�\�
�[�x�
��|�|�&�&�(�� � ��'�� � ��&��+�,��R�
�O�@�A��N�
�M�
�
�y�
)��"�"�6�<�<��#4�Q�#7��?�C�J�
�I�w�
�&�F�"2�f��6H�
�w�
��y�y�B��0��,�,�<�<�T�Y�Y�G�C��d�i�i�'�$'��	��
�
�c�5�1��y�y�B��0��,�,�<�<�T�Y�Y�G�C��d�i�i�'�$'��	��
�
�c�5�1��-�-��j�1�C�
�
��1�2�f�=�G��7�#�#��3 �0��;�;��a�g�g���+�+�>�>�t�y�y�I�"#�$:�";��&�w�/�/�J��	0�� �0��;�;��a�g�g���+�+�>�>�t�y�y�I�"#�$:�";��&�w�/�/�J��	0�s4�A
M�A
O
�	O
� A O�O
�
	Q�A P<�<Qc��d}	|jj|�}|S#t$r }t|j�Yd}~|Sd}~wwxYw)z+Sets default application policy of firewallryN)rq�set_default_application_policyrrr=)rtr�r�rEs    rFrz*UFWFrontend.set_default_application_policy�sK����	��,�,�=�=�f�E�C��
���	��!�'�'�N�N��
��	�r�c��t|jjj��}|j	�td�}|D]
}|d|zz
}�|S)z*Display list of known application profileszAvailable applications:�
  %s)rrq�profilesr�r�ra)rt�namesr�rns    rF�get_application_listz UFWFrontend.get_application_list�sU���T�\�\�*�*�/�/�1�2��
�
�
���*�+���	#�A��H��N�"�D�	#��rfc���g}|dk(r>t|jjj��}|j	�nFt
jj|�std�}t|��|j|�d}|D�]�}||jjvs|jj|std�|z}t|��t
jj||jj|�std�}t|��|td�|zz
}|td�t
jj|jj|�zz
}|td�t
jj|jj|�zz
}t
jj|jj|�}t|�d	kDsd
|dvr|td�z
}n|td
�z
}|D]
}|d|zz
}�||t|�d	z
k7s���|dz
}���t
j j#|�S)zDisplay information on profile�allr	ryzCould not find profile '%s'zInvalid profilezProfile: %s
z
Title: %s
zDescription: %s

r'�,rzPorts:zPort:rz

--

)rrqrr�r�r-rrrarr��verify_profile�	get_title�get_description�	get_portsr9r��	wrap_text)rt�pnamerr�r��namer�r@s        rF�get_application_infoz UFWFrontend.get_application_info�s<�����E�>�����.�.�3�3�5�6�E��J�J�L��#�#�6�6�u�=��2�3���w�'�'��L�L������	%�D��4�<�<�0�0�0��<�<�(�(��.��9�:�d�C���w�'�'��#�#�2�2�4��|�|�$�$�T�*�,��-�.���w�'�'��A�o�&�$�/�/�D��A�m�$��(8�(8�(B�(B�(,���(=�(=�d�(C�)E�F�
F�D�
�A�+�,�-0�-=�-=�-M�-M�-1�\�\�-B�-B�4�-H�.J�K�
K�D��$�$�.�.�t�|�|�/D�/D�T�/J�K�E��5�z�A�~���a�����(��#����'�
�"���
'����A��&��
'��u�S��Z��\�*�*���$��;	%�>�x�x�!�!�$�'�'rfc��d}d}d}	|jjr tjj	�rd}|dk(rwt
|jjj��}|j�|D]4}|jj|�\}}|s�$|dk7r|dz
}||z
}|}�6n(|jj|�\}}|dk7r|dz
}|rU|jj�r;|r+	|jj�|td�z
}|S|td�z
}|S#t
$rd}Y��wxYw#t
$r�wxYw)�Refresh application profileryTFrr�rzSkipped reloading firewall)rq�	do_checksr-r��	under_sshr>rrr�r��update_app_ruler|�_reload_user_rulesra)	rtr]r��allow_reload�trigger_reloadrr@r��founds	         rF�application_updatezUFWFrontend.application_updates_��������	!��|�|�%�%�#�(�(�*<�*<�*>�$���e���D�L�L�1�1�6�6�8�9�H��M�M�O��
+��#�|�|�;�;�A�>���e���b�y��t����C�K�D�%*�N�

+�&*�\�\�%A�%A�'�%J�"�T�>��r�z������d�l�l�5�5�7����L�L�3�3�5���-�.�.������6�7�7�����?�	!�!�L�		!��2!����s�6D;�E
�;E
�	E
�
Ec��d}d}|dk(rtd�}t|��|jjd}|dk(r(tj
j
d|�d|�d��|S|d	k(rd
}n)|dk(rd}n!|d
k(rd
}ntd�|z}t|��dg}|jjr|jd�|||gz
}	t|�}d|jvr9|j|j|jd|jd�}|S|j|jdd�}|S#t$r�wxYw)r$ryrz%Cannot specify 'all' with '--add-new'�default_application_policy�skipzPolicy is 'z', not adding profile 'r��acceptr�droprrzUnknown policy '%s'r-r(r*�iptype)rarrq�defaultsr-r�r�rur�r<r>�datarr�)rtr]r�r�r�r�argsrDs        rF�application_addzUFWFrontend.application_addBsV�������e���?�@�G��7�#�#��,�,�'�'�(D�E���f���H�H�N�N�"�G�-�
.��K�
��
 ��F�
��
��F�
��
 ��F��-�.�'�:�G��7�#�#��y���<�<����K�K��$��&�'�#�#��	��t�$�B��R�W�W���>�>�"�)�)�R�W�W�V�_�"$�'�'�(�"3�5�D�
���>�>�"�)�)�R��4�D�����	��	�s�	D:�:Ec���d}|dk(r|jd�}|S|dk(r|jd�}|S|dk(r|jd�}|S|dk(r|jd	�}|S|d
k(r|j�}|S|dk(r|j|�}|S|dk(s|d
k(r?|j|�}d}|d
k(r|j	|�}|dk7r
|dk7r|dz
}||z}|Std�|z}t
|��)zzPerform action on profile. action and profile are usually based on
           return values from parse_command().
        ryz
default-allowrzdefault-denyrzdefault-rejectrzdefault-skipr/rrrzupdate-with-newr�r
)rrr"r,r6rar)rtr�r]r��str1�str2r�s       rF�do_application_actionz!UFWFrontend.do_application_actionlsO�����_�$��5�5�g�>�C�0�
�/�~�
%��5�5�f�=�C�,�
�+�'�
'��5�5�h�?�C�(�
�'�~�
%��5�5�f�=�C�$�
�#�v�
��+�+�-�C� �
��v�
��+�+�G�4�C��
��x�
�6�->�#>��*�*�7�3�D��D��*�*��+�+�G�4���r�z�d�b�j�������+�C�
�
��1�2�f�=�G��7�#�#rfc��d}|jjr�tjj	�r�td�|j|jd�z}t|tjd��tjj�j�j�}|dk7r ||jk7r||jk7rd}|S)z6If running under ssh, prompt the user for confirmationTzWCommand may disrupt existing ssh connections. Proceed with operation (%(yes)s|%(no)s)? �rprrFr�ro)rqr%r-r�r&rarprrrr�r�r�r�r:rrs)rtrrrs    rF�continue_under_sshzUFWFrontend.continue_under_ssh�s������<�<�!�!�c�h�h�&8�&8�&:��C�D� $������8�:�F�
��s�z�z�5�9��)�)�$�$�&�,�,�.�4�4�6�C��c�z�c�T�X�X�o�#����2F����rfc��d}td�|j|jd�z}|jjrCt
jj�r%td�|j|jd�z}|jjr�|s�tt
jj|�tjd��tjj�j�j�}|dk7r+||jk7r||j k7r
td�}|S|jj#�r||j%d�z
}|jj'�}|S)	zReset the firewallryzTResetting all rules to installed defaults. Proceed with operation (%(yes)s|%(no)s)? r<zResetting all rules to installed defaults. This may disrupt existing ssh connections. Proceed with operation (%(yes)s|%(no)s)? Fr�ror�)rarprrrqr%r-r�r&rrr�r�r�r�r:rrsr|r�r)rtrr�rrs     rFrzUFWFrontend.reset�s)�����2�3� �H�H�D�G�G�4�6���<�<�!�!�c�h�h�&8�&8�&:��6�7�!%������8�:�F�
�<�<�!�!�%�����"�"�6�*�3�:�:�u�M��)�)�$�$�&�,�,�.�4�4�6�C��c�z�c�T�X�X�o�#����2F��	�l���
��<�<�"�"�$��4�#�#�E�*�*�C��l�l� � �"���
rf)rkNN)FF)r)F)�__name__�
__module__�__qualname__�__doc__rwr�r�r�r�r�r�r�r�rrrrr"r,r6r:r=r�rfrFrhrh�sv���,6�'+�!� 4�l����F�P�:J�X/�bT�l��,(�\)�V(�T�@�rfrh)rBr�r�r��
ufw.commonr�ufw.utilr-rrr�ufw.backend_iptablesr�
ufw.parserr<rerhrCrfrF�<module>rHs?��-�"
�
����%�%�3��E�PE�PD�Drf

Zerion Mini Shell 1.0