HEX
Server: Apache
System: Linux srv1.prosuiteplus.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: prosuiteplus (1001)
PHP: 8.3.20
Disabled: NONE
Upload Files
File: //usr/lib/python3/dist-packages/certbot/plugins/__pycache__/dns_common.cpython-38.pyc
U

�]�.�@s�dZddlZddlZddlmZddlZddlZddlm	Z	ddl
mZddl
mZddl
mZddl
mZdd	lmZdd
lmZddlmZe�e�Zej�ej�ej�ej�Gdd
�d
ej���ZGdd�de �Z!dd�Z"dd�Z#dd�Z$dS)z*Common code for DNS Authenticator Plugins.�N)�sleep)�
challenges)�errors)�
interfaces)�
filesystem)�os)�ops)�util)�commoncs�eZdZdZ�fdd�Zed dd��Zdd�Zd	d
�Zdd�Z	d
d�Z
ejdd��Z
ejdd��Zejdd��Zdd�Zd!dd�Zd"dd�Zedd��Zed#dd��Z�ZS)$�DNSAuthenticatorz"Base class for DNS  Authenticatorscstt|��||�d|_dS)NF)�superr�__init__�_attempt_cleanup)�self�config�name��	__class__��</usr/lib/python3/dist-packages/certbot/plugins/dns_common.pyr
szDNSAuthenticator.__init__�
cCs|d|tdd�dS)N�propagation-secondszjThe number of seconds to wait for DNS to propagate before asking the ACME server to verify the DNS record.)�default�type�help)�int)�cls�addZdefault_propagation_secondsrrr�add_parser_arguments!s
�z%DNSAuthenticator.add_parser_argumentscCstjgS�N)rZDNS01)rZ
unused_domainrrr�get_chall_pref)szDNSAuthenticator.get_chall_prefcCsdSrr�rrrr�prepare,szDNSAuthenticator.preparecCs||��d|_g}|D]@}|j}|�|�}|�|j�}|�|||�|�|�|j��qt	�
d|�d��t|�d��|S)NTz/Waiting %d seconds for DNS changes to propagater)
�_setup_credentialsr�domain�validation_domain_name�
validation�account_key�_perform�append�response�logger�info�confr)r�achallsZ	responses�achallr$r%r&rrr�perform/s
�zDNSAuthenticator.performcCs>|jr:|D].}|j}|�|�}|�|j�}|�|||�q
dSr)rr$r%r&r'�_cleanup)rr.r/r$r%r&rrr�cleanupFs
zDNSAuthenticator.cleanupcCs
t��dS)z@
        Establish credentials, prompting if necessary.
        N��NotImplementedErrorr!rrrr#Osz#DNSAuthenticator._setup_credentialscCs
t��dS)aX
        Performs a dns-01 challenge by creating a DNS TXT record.

        :param str domain: The domain being validated.
        :param str validation_domain_name: The validation record domain name.
        :param str validation: The validation record content.
        :raises errors.PluginError: If the challenge cannot be performed
        Nr3�rr$Zvalidation_namer&rrrr(Vs
zDNSAuthenticator._performcCs
t��dS)aX
        Deletes the DNS TXT record which would have been created by `_perform_achall`.

        Fails gracefully if no such record exists.

        :param str domain: The domain being validated.
        :param str validation_domain_name: The validation record domain name.
        :param str validation: The validation record content.
        Nr3r5rrrr1bszDNSAuthenticator._cleanupcCs0|�|�}|s,|�|�}t|j|�|�|�dS)a
        Ensure that a configuration value is available.

        If necessary, prompts the user and stores the result.

        :param str key: The configuration key.
        :param str label: The user-friendly label for this piece of information.
        N)r-�_prompt_for_data�setattrr�dest)r�key�label�configured_value�	new_valuerrr�
_configureos


zDNSAuthenticator._configureNcCsB|�|�}|s>|�||�}t|j|�|�tj�tj�|���dS)a
        Ensure that a configuration value is available for a path.

        If necessary, prompts the user and stores the result.

        :param str key: The configuration key.
        :param str label: The user-friendly label for this piece of information.
        N)	r-�_prompt_for_filer7rr8r�path�abspath�
expanduser)rr9r:�	validatorr;r<rrr�_configure_files

z DNSAuthenticator._configure_filecsN���fdd�}��|||�t��|��j�}�r>|����rJ�|�|S)a�
        As `_configure_file`, but for a credential configuration file.

        If necessary, prompts the user and stores the result.

        Always stores absolute paths to avoid issues during renewal.

        :param str key: The configuration key.
        :param str label: The user-friendly label for this piece of information.
        :param dict required_variables: Map of variable which must be present to error to display.
        :param callable validator: A method which will be called to validate the
            `CredentialsConfiguration` resulting from the supplied input after it has been validated
            to contain the `required_variables`. Should throw a `~certbot.errors.PluginError` to
            indicate any issue.
        cs*t|�j�}�r|����r&�|�dSr)�CredentialsConfigurationr8�require)�filenameZ
configuration��required_variablesrrBrr�__validator�s

z<DNSAuthenticator._configure_credentials.<locals>.__validator)rCrDr-r8rE)rr9r:rHrB�_DNSAuthenticator__validatorZcredentials_configurationrrGr�_configure_credentials�s	
z'DNSAuthenticator._configure_credentialscsH�fdd�}tj|d���dd�\}}|tjkr4|St�d�����dS)z�
        Prompt the user for a piece of information.

        :param str label: The user-friendly label for this piece of information.
        :returns: The user's response (guaranteed non-empty).
        :rtype: str
        cs|st�d�����dS)NzPlease enter your {0}.)r�PluginError�format)�i�r:rrrI�sz6DNSAuthenticator._prompt_for_data.<locals>.__validatorzInput your {0}T�Zforce_interactive�{0} required to proceed.N)rZvalidated_inputrM�display_util�OKrrL)r:rJ�coder*rrOrr6�s
�

z!DNSAuthenticator._prompt_for_datacsJ��fdd�}tj|d���dd�\}}|tjkr6|St�d�����dS)a�
        Prompt the user for a path.

        :param str label: The user-friendly label for the file.
        :param callable validator: A method which will be called to validate the supplied input
            after it has been validated to be a non-empty path to an existing file. Should throw a
            `~certbot.errors.PluginError` to indicate any issue.
        :returns: The user's response (guaranteed to exist).
        :rtype: str
        cs8|st�d�����tj�|�}t|��r4�|�dS)Nz&Please enter a valid path to your {0}.)rrLrMrr?rA�
validate_file�rF�r:rBrrrI�sz6DNSAuthenticator._prompt_for_file.<locals>.__validatorzInput the path to your {0}TrPrQN)rZvalidated_directoryrMrRrSrrL)r:rBrJrTr*rrWrr>�s
�

z!DNSAuthenticator._prompt_for_file)r)N)NN)N)�__name__�
__module__�__qualname__�__doc__r
�classmethodrr r"r0r2�abc�abstractmethodr#r(r1r=rCrK�staticmethodr6r>�
__classcell__rrrrrs*	




%
rc@s@eZdZdZdd�fdd�Zdd�Zdd	�Zd
d�Zdd
�ZdS)rDz>Represents a user-supplied filed which stores API credentials.cCs|Srr)�xrrr�<lambda>��z!CredentialsConfiguration.<lambda>c
Csht|�zt�|�|_WnDtjk
r\}z$tjd|dd�t�d�	|���W5d}~XYnX||_
dS)z�
        :param str filename: A path to the configuration file.
        :param callable mapper: A transformation to apply to configuration key names
        :raises errors.PluginError: If the file does not exist or is not a valid format.
        z+Error parsing credentials configuration: %sT)�exc_infoz,Error parsing credentials configuration: {0}N)�validate_file_permissions�	configobjZ	ConfigObj�confobjZConfigObjErrorr+�debugrrLrM�mapper)rrFri�errrr
�s"z!CredentialsConfiguration.__init__c	Cs�g}|D]R}|�|�s4|�d�|�|�||��q|�|�s|�d�|�|�||��q|r�t�d�t|�dkrxdnd|jj	d�
|����dS)	z�Ensures that the supplied set of variables are all present in the file.

        :param dict required_variables: Map of variable which must be present to error to display.
        :raises errors.PluginError: If one or more are missing.
        z)Property "{0}" not found (should be {1}).z'Property "{0}" not set (should be {1}).z9Missing {0} in credentials configuration file {1}:
 * {2}��propertyZ
propertiesz
 * N)�_hasr)rMri�_getrrL�lenrgrF�join)rrHZmessages�varrrrrEs(
�
���z CredentialsConfiguration.requirecCs
|�|�S)z�Find a configuration value for variable `var`, as transformed by `mapper`.

        :param str var: The variable to get.
        :returns: The value of the variable.
        :rtype: str
        )rn�rrqrrrr-szCredentialsConfiguration.confcCs|�|�|jkSr)rirgrrrrrrm%szCredentialsConfiguration._hascCs|j�|�|��Sr)rg�getrirrrrrrn(szCredentialsConfiguration._getN)	rXrYrZr[r
rEr-rmrnrrrrrD�s
rDcCs<tj�|�st�d�|���tj�|�r8t�d�|���dS)z&Ensure that the specified file exists.zFile not found: {0}zPath is a directory: {0}N)rr?�existsrrLrM�isdirrVrrrrU,srUcCs"t|�t�|�rt�d|�dS)zHEnsure that the specified file exists and warn about unsafe permissions.z8Unsafe permissions on credentials configuration file: %sN)rUrZhas_world_permissionsr+ZwarningrVrrrre6s
recs&|�d���fdd�tdt���D�S)a�Return a list of progressively less-specific domain names.

    One of these will probably be the domain name known to the DNS provider.

    :Example:

    >>> base_domain_name_guesses('foo.bar.baz.example.com')
    ['foo.bar.baz.example.com', 'bar.baz.example.com', 'baz.example.com', 'example.com', 'com']

    :param str domain: The domain for which to return guesses.
    :returns: The a list of less specific domain names.
    :rtype: list
    �.csg|]}d��|d���qS)rvN)rp)�.0rN�Z	fragmentsrr�
<listcomp>Osz,base_domain_name_guesses.<locals>.<listcomp>r)�split�rangero)r$rrxr�base_domain_name_guesses?s
r|)%r[r]Zlogging�timerrfZzope.interface�zopeZacmerZcertbotrrZcertbot.compatrrZcertbot.displayrr	rRZcertbot.pluginsr
Z	getLoggerrXr+Z	interfaceZimplementerZIAuthenticatorZproviderZIPluginFactoryZPluginr�objectrDrUrer|rrrr�<module>s,
W=