File manager - Edit - /opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/__pycache__/win_lgpo_netsh.cpython-310.pyc
Back
o ;j^ � @ s� d Z ddlZddlZddlmZ ddddddd �Zd ddddd d�Zddddddd�Zdd� Z dd� Z d)dd�Zd)dd�Zd)dd�Z d)dd �Zd*d!d"�Zd)d#d$�Zd)d%d&�Zd)d'd(�ZdS )+ax A salt util for modifying firewall settings. .. versionadded:: 2018.3.4 .. versionadded:: 2019.2.0 This util allows you to modify firewall settings in the local group policy in addition to the normal firewall settings. Parameters are taken from the netsh advfirewall prompt. This utility has been adapted to use powershell instead of the ``netsh`` command to make it compatible with non-English systems. It maintains the ``netsh`` commands and parameters, but it is using powershell under the hood. .. versionchanged:: 3008.0 .. note:: More information can be found in the advfirewall context in netsh. This can be accessed by opening a netsh prompt. At a command prompt type the following: .. code-block:: powershell c:\>netsh netsh>advfirewall netsh advfirewall>set help netsh advfirewall>set domain help Usage: .. code-block:: python import salt.utils.win_lgpo_netsh # Get the inbound/outbound firewall settings for connections on the # local domain profile salt.utils.win_lgpo_netsh.get_settings(profile='domain', section='firewallpolicy') # Get the inbound/outbound firewall settings for connections on the # domain profile as defined by local group policy salt.utils.win_lgpo_netsh.get_settings(profile='domain', section='firewallpolicy', store='lgpo') # Get all firewall settings for connections on the domain profile salt.utils.win_lgpo_netsh.get_all_settings(profile='domain') # Get all firewall settings for connections on the domain profile as # defined by local group policy salt.utils.win_lgpo_netsh.get_all_settings(profile='domain', store='lgpo') # Get all firewall settings for all profiles salt.utils.win_lgpo_netsh.get_all_settings() # Get all firewall settings for all profiles as defined by local group # policy salt.utils.win_lgpo_netsh.get_all_settings(store='lgpo') # Set the inbound setting for the domain profile to block inbound # connections salt.utils.win_lgpo_netsh.set_firewall_settings(profile='domain', inbound='blockinbound') # Set the outbound setting for the domain profile to allow outbound # connections salt.utils.win_lgpo_netsh.set_firewall_settings(profile='domain', outbound='allowoutbound') # Set inbound/outbound settings for the domain profile in the group # policy to block inbound and allow outbound salt.utils.win_lgpo_netsh.set_firewall_settings(profile='domain', inbound='blockinbound', outbound='allowoutbound', store='lgpo') � N)�CommandExecutionErrorZOFFZON� NotConfigured�False�True)r � � �off�on� notconfiguredZDisableZEnabler r )r r r �disable�enabler Z AllowOutboundZ BlockOutboundZAllowZBlock)r r � r � allowoutbound� blockoutboundc C s0 dddd�dddd�dddd�d�}|| | S )a` The "Inbound connections" setting is a combination of 2 parameters: - AllowInboundRules 0 = False 1 = True 2 = NotConfigured I don't see a way to set "AllowInboundRules" outside of PowerShell - DefaultInboundAction 0 = Not Configured 2 = Allow Inbound 4 = Block Inbound The settings are as follows: Rules Action 0 4 BlockInboundAlways 1 0 NotConfigured 1 2 AllowInbound 1 4 BlockInbound 2 0 NotConfigured 2 2 AllowInbound 2 4 BlockInbound r ZAllowInboundZBlockInboundAlways)r r r ZBlockInbound)r r r � )Zrule�action�settingsr r �M/opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/win_lgpo_netsh.py�_get_inbound_textl s ����r c C s ddddd�}|| � � S )N)r r )r r )r r )r r )�allowinbound�blockinbound�blockinboundalwaysr )�lower)�textr r r r �_get_inbound_settings� s �r �localc C sr dg}| r |� | � |�� dkr|�ddg� tjj�|�}|s$td��t|� � �D ]}|� d�r6|�|� q*|S )NzGet-NetFirewallProfile�lgpo�-PolicyStore� localhostz%LGPO NETSH: An unknown error occurredZCim)�appendr �extend�salt�utils�win_pwsh�run_dictr �list�keys� startswith�pop)�profile�store�cmdr �settingr r r �_get_all_settings� s �r- c C s� | � � dvr td| � ���|� � dvrtd|� ���|� � dvr'td|� ���t| |d�}t|d |d �t|d d�dt|d i|d t|d t|d |d d�t|d t|d t|d t|d d�d�}||� � S )a$ Get the firewall property from the specified profile in the specified store as returned by ``netsh advfirewall``. Args: profile (str): The firewall profile to query. Valid options are: - domain - public - private section (str): The property to query within the selected profile. Valid options are: - firewallpolicy : inbound/outbound behavior - logging : firewall logging settings - settings : firewall properties - state : firewalls state (on | off) store (str): The store to use. This is either the local firewall policy or the policy defined by local group policy. Valid options are: - lgpo - local Default is ``local`` Returns: dict: A dictionary containing the properties for the specified profile Raises: CommandExecutionError: If an error occurs ValueError: If the parameters are incorrect ��domain�public�private�Incorrect profile: )�state�firewallpolicyr �loggingzIncorrect section: �r r �Incorrect store: �r) r* �AllowInboundRules�DefaultInboundAction�DefaultOutboundAction)�Inbound�Outbound�State�Enabled�LogFileName� LogAllowed� LogBlocked�LogMaxSizeKilobytes)�FileName�LogAllowedConnections�LogDroppedConnections�MaxFileSize�NotifyOnListen�AllowLocalIPsecRules�AllowLocalFirewallRules�AllowUnicastResponseToMulticast)�InboundUserNotification�LocalConSecRules�LocalFirewallRules�UnicastResponseToMulticast)r4 r3 r5 r )r � ValueErrorr- r �OUTBOUND�ON_OFF�ENABLE_DISABLE)r) �sectionr* r �ret_settingsr r r �get_settings� s8 (� �� � ���rV c C s$ t d| d�t d| d�t d| d�d�S )a� Gets all properties for all profiles in the specified store Args: store (str): The store to use. This is either the local firewall policy or the policy defined by local group policy. Valid options are: - lgpo - local Default is ``local`` Returns: dict: A dictionary containing the specified settings for each profile r/ r8 r1 r0 )zDomain ProfilezPrivate ProfilezPublic Profile)�get_all_settings)r* r r r �get_all_profiles s �rX c C s� | � � dvr td| � ���|� � dvrtd|� ���t| |d�}|d t|d |d �t|d t|d t|d t|d t|d |d t|d t|d t|d d�}|S )a� Gets all the properties for the specified profile in the specified store Args: profile (str): The firewall profile to query. Valid options are: - domain - public - private store (str): The store to use. This is either the local firewall policy or the policy defined by local group policy. Valid options are: - lgpo - local Default is ``local`` Returns: dict: A dictionary containing the specified settings Raises: CommandExecutionError: If an error occurs ValueError: If the parameters are incorrect r. r2 r6 r7 r8 r@ r9 r: rH rI rJ rA rB rC r; r? rK )rD r<