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__/ddns.cpython-310.pyc
o

�N�gL�
@s�dZddlZddlZddlZe�e�ZzddlZ	ddl
Z	ddlZ	dZWne
y7ZzdZWYdZ[ndZ[wwdd�Zddd�Zd	d
�Z				
ddd�Zddd�Z				
ddd�Z					
ddd�ZdS)aM
Support for RFC 2136 dynamic DNS updates.

:depends:   - dnspython Python module
:configuration: If you want to use TSIG authentication for the server, there
    are a couple of optional configuration parameters made available to
    support this (the keyname is only needed if the keyring contains more
    than one key)::

        keyfile: keyring file (default=None)
        keyname: key name in file (default=None)
        keyalgorithm: algorithm used to create the key
                      (default='HMAC-MD5.SIG-ALG.REG.INT').
            Other possible values: hmac-sha1, hmac-sha224, hmac-sha256,
                hmac-sha384, hmac-sha512


    The keyring file needs to be in json format and the key name needs to end
    with an extra period in the file, similar to this:

    .. code-block:: json

        {"keyname.": "keycontent"}
�NTFcCstrdSdS)z)
    Confirm dnspython is available.
    Zddns)FzDThe ddns execution module cannot be loaded: dnspython not installed.)�dns_support�rr�E/opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/ddns.py�__virtual__+srcKs>|dur|}||vr||}|Stdd|���}|sd}|S)z�
    Return a value for 'name' from command line args then config file options.
    Specify 'key' if the config file option is not the same as 'name'.
    Nz
config.optionzddns.)Z__salt__)�name�key�kwargs�valuerrr�_config7s�r
cCsRd}|r'tjj�|��}tj�tjj�|��}Wd�|S1s"wY|S�N)	�salt�utils�filesZfopen�dnsZtsigkeyring�	from_text�json�load)�keyfile�keyringZ_frrr�_get_keyringGs
��r�	127.0.0.1��5c
Ks�t|||d|||||f	i|��}	|	durdS|�d|�d�}
|�d�ddd�}g}t|�dkrb|�d�}
|�|
�d�d�|�d	�}d�|�}t|||d
|
||||f	i|��}|r\dSt|�dks0|	S)z�
    Add, replace, or update the A and PTR (reverse) records for a host.

    CLI Example:

    .. code-block:: bash

        salt ns1 ddns.add_host example.com host1 60 10.1.1.1
    �AF�.N����r�{}.{}�
in-addr.arpa.�PTRT)�update�split�len�pop�append�format�join)�zoner�ttl�ip�
nameserver�replace�timeout�portr�res�fqdn�parts�popped�p�ptrrrr�add_hostOs( 


���
r4cKs|�d|��}tj�|d�}tj�||||�}z
dd�|jdjD�}	Wnty/g}	Ynwt||f|||d�|��}
|d}|	D]E}|�	d�ddd�}g}
t
|�d	kr�|�d�}|
�|�d
�
d�|�d�}d�|
�}t||d|f|||d�|��}t
|�d	ksW|r�d
}
qC|
S)z�
    Delete the forward and reverse records for a host.

    Returns true if any records are deleted.

    CLI Example:

    .. code-block:: bash

        salt ns1 ddns.delete_host example.com host1
    rrcSsg|]}|j�qSr)�address)�.0�irrr�
<listcomp>�szdelete_host.<locals>.<listcomp>r)r*r,r-NrrrrrT)r�message�
make_query�query�udp�answer�items�
IndexError�deleter!r"r#r$r%r&)r'rr*r,r-rr/�requestr=�ipsr.r)r0r1r2r3rrr�delete_hostysR����


�����rCc	KsLt|�}|dd�dkr|}
n|�d|��}
tj�|
|�}tj�||||�}tj�|�}tj�tj	j
||�}
ttd
i|	���}tdi|	��}tdi|	��pNd}d}|j
D]}|
|jvrr||jkrrt|j
�d	ksnt|j�d	krrd
}nqTtjj||||d�}|r�|�|||
�n|s�|�|||
�ndStj�||||�}|��dkr�dSd
S)a[
    Add, replace, or update a DNS record.
    nameserver must be an IP address and the minion running this module
    must have update privileges on that server.
    If replace is true, first deletes all records for this name and type.

    CLI Example:

    .. code-block:: bash

        salt ns1 ddns.update example.com host1 60 A 10.0.0.1
    rNrr�keyname�keyalgorithm�HMAC-MD5.SIG-ALG.REG.INTFrT�rrDrEr�r�rD�rE)�strrr9r:r;r<�	rdatatyper�rdata�
rdataclass�INrr
r=r>r(r"r �Updater+�add�rcode)r'rr(�rdtype�datar*r,r+r-rr/rAr=rMrrDrEZis_existZrrset�
dns_updaterrrr �s>


��r cKst|�}|dd�dkr|}n|�d|��}tj�||pd�}	tj�|	|||�}
|
js-dSttd
i|���}tdi|��}tdi|��pEd}
tj	j
||||
d	�}|rrtj�|�}|rktj
�tjj||�}|�||�n|�||�n|�|�tj�||||�}
|
��d
kr�dSdS)z|
    Delete a DNS record.

    CLI Example:

    .. code-block:: bash

        salt ns1 ddns.delete example.com host1 A
    rNr�ANYrrDrErFrGrFTrHrIrJ)rKrr9r:r;r<r=rr
r rPrLrrMrNrOr@rR)r'rrSrTr*r,r-rr/rAr=rrDrErUrMrrrr@�s2�
r@r)rTrr)rrr)rrFr)NNrrr)�__doc__�loggingZsalt.utils.filesrZsalt.utils.json�	getLogger�__name__�logZ	dns.queryrZdns.tsigkeyringZ
dns.updater�ImportError�err
rr4rCr r@rrrr�<module>sD
��


�
*8
�C�