HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.104.1.lve.el8.x86_64 #1 SMP Tue Feb 10 20:07:30 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.29
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/__pycache__/pf.cpython-310.pyc
o

�N�g�%�@s|dZddlZddlZddlZddlmZmZe�e	�Z
dd�Zdd�Zdd	�Z
d
d�Zddd�Zdd�Zdd�Zdd�ZdS)z{
Control the OpenBSD packet filter (PF).

:codeauthor: Jasper Lievisse Adriaanse <j@jasper.la>

.. versionadded:: 2019.2.0
�N)�CommandExecutionError�SaltInvocationErrorcCs8ddg}td|vrtjj�d�rdSdd�td�fS)z�
    Only works on OpenBSD and FreeBSD for now; other systems with pf (macOS,
    FreeBSD, etc) need to be tested before enabling them.
    �FreeBSDZOpenBSD�os�pfctlTFzlThe pf execution module cannot be loaded: either the OS ({}) is not tested or the pfctl binary was not found)�
__grains__�salt�utils�path�which�format)Ztested_oses�r
�C/opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/pf.py�__virtual__s
�rcC�bi}tddddd�}|ddkrdd	d
�}|S|ddkr%d
dd
�}|Std|dgdd�d��)zk
    Enable the Packet Filter.

    CLI Example:

    .. code-block:: bash

        salt '*' pf.enable
    �cmd.run_allzpfctl -e�traceF�Zoutput_loglevel�python_shell�retcoderz
pf enabledT��comment�changes�stderrzpfctl: pf already enabledzpf already enabledzCould not enable pf��errorsr��info��__salt__r��ret�resultr
r
r�enable"�
�
�
��r#cCr)zm
    Disable the Packet Filter.

    CLI Example:

    .. code-block:: bash

        salt '*' pf.disable
    rzpfctl -drFrrrzpf disabledTrrzpfctl: pf not enabledzpf already disabledzCould not disable pfrrrr r
r
r�disableAr$r%cCs�ddi}td}|dkrgd�}ngd�}||vr td|����tdd	|��d
dd�}|d
dkr>td|dgdd�d��|S)a^
    Set the debug level which limits the severity of log messages printed by ``pf(4)``.

    level:
        Log level. Should be one of the following: emerg, alert, crit, err, warning, notice,
        info or debug (OpenBSD); or none, urgent, misc, loud (FreeBSD).

    CLI Example:

    .. code-block:: bash

        salt '*' pf.loglevel emerg
    rTrr)ZnoneZurgentZmiscZloud)ZemergZalertZcrit�err�warningZnoticer�debugzUnknown loglevel: rz	pfctl -x rFrrrz$Problem encountered setting loglevelrrr)rrrr)�levelr!ZmyosZ
all_levelsr"r
r
r�loglevel`s 

��r*�/etc/pf.confFcCshddi}dd|g}|rd|d<|�d�td|ddd	�}|d
dkr2td|��|d
gdd�d��|S)aA
    Load a ruleset from the specific file, overwriting the currently loaded ruleset.

    file:
        Full path to the file containing the ruleset.

    noop:
        Don't actually load the rules, just parse them.

    CLI Example:

    .. code-block:: bash

        salt '*' pf.load /etc/pf.conf.d/lockdown.conf
    rTrz-fFz-nrrrrrz!Problem loading the ruleset from rrr)�appendrr)�fileZnoopr!�cmdr"r
r
r�load�s

�r/cCs�i}gd�}ddg}||7}|��|vr|��}||vr#td|����d|��}td|ddd	�}|d
dkrPt�d|d
�rDd|d<nd|d<|d
|d<|Std|��|d
gdd�d��)a�
    Flush the specified packet filter parameters.

    modifier:
        Should be one of the following:

        - all
        - info
        - osfp
        - rules
        - sources
        - states
        - tables

        Please refer to the OpenBSD `pfctl(8) <https://man.openbsd.org/pfctl#T>`_
        documentation for a detailed explanation of each command.

    CLI Example:

    .. code-block:: bash

        salt '*' pf.flush states
    )�rules�statesrZosfp�allZsources�tablesZSources�Tables�Unknown modifier: zpfctl -v -F rrFrrrz^0.*rrTrzCould not flush rr)�titlerr�re�matchr)�modifierr!�
all_modifiers�capital_modifiersr.r"r
r
r�flush�s(

��r<cKsHi}gd�}||vrtd|����dd|d|g}|dvr%||�dg�7}n|dkr:|�d	d
�}|s5td��|�|�td|d
dd�}|ddkr}|dkrWd|d��i}|S|dkrd|ddd�}|St�d|d�rqd|d<nd|d<|d|d<|S|dkr�t�d|d�r�|ddd�}|Std|�d|��|dgdd�d��) a�
    Apply a command on the specified table.

    table:
        Name of the table.

    command:
        Command to apply to the table. Supported commands are:

        - add
        - delete
        - expire
        - flush
        - kill
        - replace
        - show
        - test
        - zero

        Please refer to the OpenBSD `pfctl(8) <https://man.openbsd.org/pfctl#T>`_
        documentation for a detailed explanation of each command.

    CLI Example:

    .. code-block:: bash

        salt '*' pf.table expire table=spam_hosts number=300
        salt '*' pf.table add table=local_hosts addresses='["127.0.0.1", "::1"]'
    )	�killr<�add�delete�expire�replace�show�testZzerozUnknown table command: rz-tz-T)r>r?rArC�	addressesr@�numberNz.need expire_number argument for expire commandrrF)Zoutput_levelrrrrBr�stdoutrCrT)r�matchesz^(0.*|no changes)rz^\d+/\d+ addresses match.$zCould not apply z
 on table rr)r�getr,r�splitr7r8r)Zcommand�table�kwargsr!Zall_commandsr.rEr"r
r
rrJ�sD
��
����rJcCs�ddi}dg}gd�}||7}|��|vr|��}||vr$td|����d|��}td|ddd	�}|d
dkrC|d�d
�|d<|Std|��|dgdd�d��)a#
    Show filter parameters.

    modifier:
        Modifier to apply for filtering. Only a useful subset of what pfctl supports
        can be used with Salt.

        - rules
        - states
        - tables

    CLI Example:

    .. code-block:: bash

        salt '*' pf.show rules
    rFr4)r0r1r3r5z	pfctl -s rrrrrrF�
rzCould not show rrr)r6rrrIr)r9r!r;r:r.r"r
r
rrBEs"
��rB)r+F)�__doc__�loggingr7Zsalt.utils.pathrZsalt.exceptionsrr�	getLogger�__name__�logrr#r%r*r/r<rJrBr
r
r
r�<module>s

0$9X