HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.109.1.lve.el8.x86_64 #1 SMP Thu Mar 5 20:23:46 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.30
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/__pycache__/dnsmasq.cpython-310.pyc
o

�N�g��@srdZddlZddlZddlZddlZddlmZe�e	�Z
dd�Zdd�Zdd	�Z
ddd
�Zddd�Zdd�ZdS)z
Module for managing dnsmasq
�N)�CommandExecutionErrorcCstjj��rdSdS)z*
    Only work on POSIX-like systems.
    )FzMdnsmasq execution module cannot be loaded: only works on non-Windows systems.T)�salt�utils�platformZ
is_windows�rr�H/opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/dnsmasq.py�__virtual__srcCs(d}td|���}|d��}|dS)z{
    Shows installed version of dnsmasq.

    CLI Example:

    .. code-block:: bash

        salt '*' dnsmasq.version
    �
dnsmasq -v�cmd.runr���__salt__�
splitlines�split)�cmd�out�compsrrr�versions
rcCsFd}td|���}|d��}|d}|d��}||dd�d�S)	z�
    Shows installed version of dnsmasq and compile options.

    CLI Example:

    .. code-block:: bash

        salt '*' dnsmasq.fullversion
    r	r
rr��N)rzcompile optionsr)rrrZversion_numrrr�fullversion,s
r�/etc/dnsmasq.confTc		Ks0t|�}|g}|durAd|vrAt�|d�D]*}|�d�rq|�d�r$q|�d�r*q|�d�r5|�d�r5q|�d�|d|��qi}|D]P}|�d�rMqE||||<||vr�t||t�rx|D]}t	d	|d
|�d�|�d||��d
�q`qEt	d||�d||���qEt	d||�d||���qE|S)a�
    Sets a value or a set of values in the specified file. By default, if
    conf-dir is configured in this file, salt will attempt to set the option
    in any file inside the conf-dir where it has already been enabled. If it
    does not find it inside any files, it will append it to the main config
    file. Setting follow to False will turn off this behavior.

    If a config option currently appears multiple times (such as dhcp-host,
    which is specified at least once per host), the new option will be added
    to the end of the main config file (and not to any includes). If you need
    an option added to a specific include file, specify it as the config_file.

    :param string config_file: config file where settings should be updated / added.
    :param bool follow: attempt to set the config option inside any file within
        the ``conf-dir`` where it has already been enabled.
    :param kwargs: key value pairs that contain the configuration settings that you
        want set.

    CLI Examples:

    .. code-block:: bash

        salt '*' dnsmasq.set_config domain=mydomain.com
        salt '*' dnsmasq.set_config follow=False domain=mydomain.com
        salt '*' dnsmasq.set_config config_file=/etc/dnsmasq.conf domain=mydomain.com
    T�conf-dir�.�~Zbak�#�{}/{}�__zfile.sed�^z=.*�=)�path�beforeZafterzfile.append)
�
get_config�os�listdir�
startswith�endswith�append�format�
isinstance�strr
)	�config_file�follow�kwargs�dnsoptsZincludes�filenameZ
ret_kwargs�keyZconfigrrr�
set_config>s<




��r1cCspt|�}d|vr6t�|d�D]&}|�d�rq|�d�rq|�d�r(|�d�r(q|�td�|d|���q|S)aH
    Dumps all options from the config file.

    config_file
        The location of the config file from which to obtain contents.
        Defaults to ``/etc/dnsmasq.conf``.

    CLI Examples:

    .. code-block:: bash

        salt '*' dnsmasq.get_config
        salt '*' dnsmasq.get_config config_file=/etc/dnsmasq.conf
    rrrrr)�_parse_dnamasqr#r$r%r&�updater()r+r.r/rrrr"~s

�r"cCsi}tj�|�std|�d���tjj�|d��m}|D]a}tjj�	|�}|�
�s)q|�d�r/qd|vrm|�d�}|d|vrbt
||dt�rT||d}|g||d<||d�|d�
��q|d�
�||d<qd|vrug|d<|d�|�qWd	�|S1s�wY|S)
zH
    Generic function for parsing dnsmasq files including includes.
    zError: No such file '�'�rrrrrZunparsedN)r#r �isfilerrr�filesZfopenZstringutilsZ
to_unicode�stripr%rr)r*r')r/ZfileoptsZfp_�linerZtemprrrr2�s4

�
��r2)rT)r)�__doc__�loggingr#Zsalt.utils.filesrZsalt.utils.platformZsalt.exceptionsr�	getLogger�__name__�logrrrr1r"r2rrrr�<module>s



@