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

�N�gQ#�@s�dZddlZddlZddlZddlZdZzddlZddl	Zddl
ZdZWney/dZYnwe�e
�Zdd�Zdd�Z			
ddd�Z				
dd
d�Z					
ddd�Z			
ddd�Z	
ddd�ZdS)z�
Dynamic DNS Runner
==================

.. versionadded:: 2015.8.0

Runner to interact with DNS server and create/delete/update DNS records

:codeauthor: Nitin Madhok <nmadhok@g.clemson.edu>

�NFTcCstsdSdS)zg
    Check if required libs (python-dns) is installed and load runner
    only if they are present
    FT)�HAS_LIBS�rr�E/opt/saltstack/salt/lib/python3.10/site-packages/salt/runners/ddns.py�__virtual__!srcCsfd}|r1tj�tj�|��r1tjj�|��}tj	�
tjj�|��}Wd�|S1s,wY|S)N)
�os�path�isfile�
expanduser�salt�utils�filesZfopen�dnsZtsigkeyring�	from_text�json�load)�keyfile�keyringZ_frrr�_get_keyring,s
��r�5�hmac-md5cCs||vr
|�|d��d�}|�d|��}tj�||�}tj�||||	�}
tj�|�}tj	�tj
j||�}|
jD]}||j
vrI|d�||j�iSq7t|�}tjj||||
d�}|�|||�tj�||||	�}
|
��dkrv|d|�d�iS|d|�d	|�d
|��iS)a7
    Create a DNS record. The nameserver must be an IP address and the master running
    this runner must have create privileges on that server.

    CLI Example:

    .. code-block:: bash

        salt-run ddns.create domain.com my-test-vm 3600 A 10.20.30.40 my-tsig-key /etc/salt/tsig.keyring 10.0.0.1 5
    ��.z1Record of type '{}' already exists with ttl of {}�r�keyname�keyalgorithmrz!Failed to create record of type '�'zCreated record of type 'z': z -> )�replace�rstripr
�message�
make_query�query�udp�	rdatatyper�rdata�
rdataclass�IN�answer�items�format�ttlr�update�Update�add�rcode)�zone�namer)�rdtype�datarr�
nameserver�timeout�portr�fqdn�requestr&�rdata_valuer#�rrsetr�
dns_updaterrr�create5s.

����r:cCs@||vr
|�|d��d�}|�d|��}tj�||�}
tj�|
|||
�}|js+|diStj�	|�}tj
�	tjj||�}|jD]-}||j
vrk|j
}||jkri|	r_t|j�dks]t|j
�dkr_n
|d�||�iSnq>t|�}tjj||||d�}|�|||�tj�||||
�}|��dkr�|d|�d	�iS|d
|�d	�iS)a�
    Replace, or update a DNS record. The nameserver must be an IP address and the master running
    this runner must have update privileges on that server.

    .. note::

        If ``replace`` is set to True, all records for this name and type will first be deleted and
        then recreated. Default is ``replace=False``.

    CLI Example:

    .. code-block:: bash

        salt-run ddns.update domain.com my-test-vm 3600 A 10.20.30.40 my-tsig-key /etc/salt/tsig.keyring 10.0.0.1 5
    rr�No matching DNS record(s) found�z2Record of type '{}' already present with ttl of {}rrz!Failed to update record of type 'rzUpdated record of type ')rrr
rrr r!r&r"rr#r$r%r'r)�lenr(rr*r+r-)r.r/r)r0r1rrr2r3rr4rr5r6r&r7r#r8Zrrrr9rrrr*ks<


 ����r*c
Cs�||vr
|�|d��d�}|�d|��}
tj�|
|pd�}tj�||||�}|js-|
diSt|�}
tj	j
||
||	d�}|r]tj�|�}|rVtj
�tjj||�}|�||�n|�||�n|�|�tj�||||�}|��dkru|
diS|
diS)	z�
    Delete a DNS record.

    CLI Example:

    .. code-block:: bash

        salt-run ddns.delete domain.com my-test-vm my-tsig-key /etc/salt/tsig.keyring 10.0.0.1 5 A
    rr�ANYr;rrzFailed to delete DNS record(s)zDeleted DNS record(s))rrr
rrr r!r&rr*r+r"rr#r$r%�deleter-)r.r/rrr2r3r0r1r4rr5r6r&rr9r7r#rrrr?�s,�
r?c
Cs&g}
||vr|�|d��d�}|�d|��}t|||d|||||||	�}|
�||�|�d�ddd�}
t|
�}g}|dkr�|
�d�}|d8}|�|�d�d�|
�d	�}d�|�}|�d|��}t|||d
|�d�||||||	�}d||vr�|
�||�||
iS|dks?|
�||�||
iS)z�
    Create both A and PTR (reverse) records for a host.

    CLI Example:

    .. code-block:: bash

        salt-run ddns.add_host domain.com my-test-vm 3600 10.20.30.40 my-tsig-key /etc/salt/tsig.keyring 10.0.0.1 5
    rr�AN���r<r�{}.{}�
in-addr.arpa.�PTR�Created)	rrr:�append�splitr=�popr(�join)r.r/r)�iprrr2r3r4r�resr5�ret�parts�i�popped�p�rev_fqdnrrr�add_host�s^�



��rRcCs�g}||vr|�|d��d�}|�d|��}	tj�|	d�}
tj�|
|||�}z
dd�|jdjD�}Wnt	y>g}Ynwt
||||||||d�}
|�|
|	�d��|D]j}|�d�d	d	d
�}t
|�}g}|dkr�|�d�}|d8}|�|�d�d�|�d
�}d�|�}|�d|��}t
||||||d|	�d�||�
}
d|
|vr�|�|
|�d��|	|iS|dksm|�|
|�qW|	|iS)a
    Delete both forward (A) and reverse (PTR) records for a host only if the
    forward (A) record exists.

    CLI Example:

    .. code-block:: bash

        salt-run ddns.delete_host domain.com my-test-vm my-tsig-key /etc/salt/tsig.keyring 10.0.0.1 5
    rrr@cSsg|]}|j�qSr)�address)�.0rNrrr�
<listcomp>Eszdelete_host.<locals>.<listcomp>r)r4rz of type 'A'NrAr<rBrCrDZDeletedz of type 'PTR')rrr
rrr r!r&r'�
IndexErrorr?rFrGr=rHr(rI)r.r/rrr2r3r4rrKr5r6r&�ipsrLrJrMrNrOrPrQrrr�delete_host0sf
��



�
�rX)rr)Frr)NNrr)�__doc__�loggingrZsalt.utils.filesr
Zsalt.utils.jsonrZ	dns.queryr
Zdns.tsigkeyringZ
dns.update�ImportError�	getLogger�__name__�logrrr:r*r?rRrXrrrr�<module>sD�

�@
�J
�>
�N�