ok

Mini Shell

Direktori : /lib/python3.6/site-packages/certbot/plugins/__pycache__/
Upload File :
Current File : //lib/python3.6/site-packages/certbot/plugins/__pycache__/common.cpython-36.pyc

3

گa�B�@s
dZddlmZddlmZddlZddlZddlZddlZddlZddl	m
Z
ddl	mZddl	mZddl	m
Z
dd	l	mZdd
l	mZddl	mZddlZddlmZdd
lmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZ ddlm!Z"ddl#m$Z$ej%e&�Z'e(e(d�dd�Z)e(e(d�dd�Z*ej+d�Z,ej+dej-�Z.Gdd �d e"ed!�Z!Gd"d#�d#e e!ed!�ZGd$d%�d%eej/ed!�Z0Gd&d'�d'�Z1Gd(d)�d)�Z2e(e(e(ee(dd*�d+d,�Z3e(e(ee(e(e(fd-�d.d/�Z4dS)0zPlugin common functions.�)�ABCMeta)�abstractmethodN)�Any)�Callable)�Iterable)�List)�Optional)�Set)�Tuple)�achallenges)�
configuration)�crypto_util)�
interfaces)�errors)�reverter)�	constants)�
filesystem)�os)�	Installer)�Plugin)�
PluginStorage)�name�returncCs|dS)z9ArgumentParser options namespace (prefix of all options).�-�)rrr�/usr/lib/python3.6/common.py�option_namespace#srcCs|jdd�dS)z;ArgumentParser dest namespace (prefix of all destinations).r�_)�replace)rrrr�dest_namespace(srzX(^127\.0\.0\.1)|(^10\.)|(^172\.1[6-9]\.)|(^172\.2[0-9]\.)|(^172\.3[0-1]\.)|(^192\.168\.)z3^(([a-z0-9]|[a-z0-9][a-z0-9\-]*[a-z0-9])\.)*[a-z]+$cs�eZdZdZejedd��fdd�Zee	e
ddd�dd	���Zeej
edd
�dd��Zeed
�dd��Zeed�dd�Zeed
�dd��Zeed�dd�Zeed�dd�Zeejed�dd�Z�ZS)rzGeneric plugin.N)�configrrcst�j||�||_||_dS)N)�super�__init__r r)�selfr r)�	__class__rrr"7szPlugin.__init__.)�addrcCsdS)z�Add plugin arguments to the CLI argument parser.

        :param callable add: Function that proxies calls to
            `argparse.ArgumentParser.add_argument` prepending options
            with unique plugin name prefix.

        Nr)�clsr%rrr�add_parser_arguments<szPlugin.add_parser_arguments)�parserrrcs$tttdd���fdd�}|j|�S)zkInject parser options.

        See `~.certbot.interfaces.Plugin.inject_parser_options` for docs.

        N)�arg_name_no_prefix�args�kwargsrcs"�jdjt��|�f|�|�dS)Nz--{0}{1})�add_argument�formatr)r)r*r+)rr(rrr%Osz)Plugin.inject_parser_options.<locals>.add)�strrr')r&r(rr%r)rr(r�inject_parser_optionsGszPlugin.inject_parser_options)rcCs
t|j�S)z9ArgumentParser options namespace (prefix of all options).)rr)r#rrrrUszPlugin.option_namespace)rrcCs
|j|S)z'Option name (include plugin namespace).)r)r#rrrr�option_nameZszPlugin.option_namecCs
t|j�S)z;ArgumentParser dest namespace (prefix of all destinations).)rr)r#rrrr^szPlugin.dest_namespace)�varrcCs|j|jdd�S)z.Find a destination for given variable ``var``.rr)rr)r#r1rrr�destcszPlugin.destcCst|j|j|��S)z0Find a configuration value for variable ``var``.)�getattrr r2)r#r1rrr�confiszPlugin.conf)�failed_achallsrcCs(djtdd�|D���}dj|j|d�S)a9Human-readable string to help the user troubleshoot the authenticator.

        Shown to the user if one or more of the attempted challenges were not a success.

        Should describe, in simple language, what the authenticator tried to do, what went
        wrong and what the user should try as their "next steps".

        TODO: auth_hint belongs in Authenticator but can't be added until the next major
        version of Certbot. For now, it lives in .Plugin and auth_handler will only call it
        on authenticators that subclass .Plugin. For now, inherit from `.Plugin` to implement
        and/or override the method.

        :param list failed_achalls: List of one or more failed challenges
                                    (:class:`achallenges.AnnotatedChallenge` subclasses).

        :rtype str:
        z and cSsh|]
}|j�qSr)�typ)�.0�achallrrr�	<setcomp>�sz#Plugin.auth_hint.<locals>.<setcomp>z�The Certificate Authority couldn't externally verify that the {name} plugin completed the required {challs} challenges. Ensure the plugin is configured correctly and that the changes it makes are accessible from the internet.)r�challs)�join�sortedr-r)r#r5r:rrr�	auth_hintmszPlugin.auth_hint).N)�__name__�
__module__�__qualname__�__doc__rZNamespaceConfigr.r"�classmethodrrr'�argparse�ArgumentParserr/�propertyrr0rr2rr4rrZAnnotatedChallenger=�
__classcell__rr)r$rr4s	
r)�	metaclasscs�eZdZdZeedd��fdd�Zdeeeedd�dd	�Z	edd
�dd�Z
dd
�dd�Zdd
�dd�Zde
dd�dd�Zeed
�dd��Zeed
�dd��Zdd
�dd�Z�ZS)rz�An installer base class with reverter and ssl_dhparam methods defined.

    Installer plugins do not have to inherit from this class.

    N)r*r+rcs0t�j||�t|j|j�|_tj|j�|_dS)N)r!r"rr rZstoragerZReverter)r#r*r+)r$rrr"�szInstaller.__init__F)�
save_files�
save_notes�	temporaryrcCs\|r|jj}n|jj}y|||�Wn2tjk
rV}ztjt|���WYdd}~XnXdS)a�Add files to a checkpoint.

        :param set save_files: set of filepaths to save
        :param str save_notes: notes about changes during the save
        :param bool temporary: True if the files should be added to a
            temporary checkpoint rather than a permanent one. This is
            usually used for changes that will soon be reverted.

        :raises .errors.PluginError: when unable to add to checkpoint

        N)rZadd_to_temp_checkpoint�add_to_checkpointr�
ReverterError�PluginErrorr.)r#rHrIrJZcheckpoint_func�errrrrrK�s

zInstaller.add_to_checkpoint)�titlercCsHy|jj|�Wn2tjk
rB}ztjt|���WYdd}~XnXdS)z�Timestamp and save changes made through the reverter.

        :param str title: Title describing checkpoint

        :raises .errors.PluginError: when an error occurs

        N)r�finalize_checkpointrrLrMr.)r#rOrNrrrrP�szInstaller.finalize_checkpoint)rcCsFy|jj�Wn2tjk
r@}ztjt|���WYdd}~XnXdS)z�Revert all previously modified files.

        Reverts all modified files that have not been saved as a checkpoint

        :raises .errors.PluginError: If unable to recover the configuration

        N)r�recovery_routinerrLrMr.)r#rNrrrrQ�szInstaller.recovery_routinecCsFy|jj�Wn2tjk
r@}ztjt|���WYdd}~XnXdS)zkRollback temporary checkpoint.

        :raises .errors.PluginError: when unable to revert config

        N)r�revert_temporary_configrrLrMr.)r#rNrrrrR�sz!Installer.revert_temporary_config�)�rollbackrcCsHy|jj|�Wn2tjk
rB}ztjt|���WYdd}~XnXdS)z�Rollback saved checkpoints.

        :param int rollback: Number of checkpoints to revert

        :raises .errors.PluginError: If there is a problem with the input or
            the function is unable to correctly revert the configuration

        N)r�rollback_checkpointsrrLrMr.)r#rTrNrrrrU�s	zInstaller.rollback_checkpointscCstjj|jjtj�S)z(Full absolute path to ssl_dhparams file.)r�pathr;r �
config_dirrZSSL_DHPARAMS_DEST)r#rrr�ssl_dhparams�szInstaller.ssl_dhparamscCstjj|jjtj�S)z:Full absolute path to digest of updated ssl_dhparams file.)rrVr;r rWrZUPDATED_SSL_DHPARAMS_DIGEST)r#rrr�updated_ssl_dhparams_digest�sz%Installer.updated_ssl_dhparams_digestcCst|j|jtjtj�dS)zJCopy Certbot's ssl_dhparams file into the system's config dir if required.N)�install_version_controlled_filerXrYrZSSL_DHPARAMS_SRCZALL_SSL_DHPARAMS_HASHES)r#rrr�install_ssl_dhparams�s
zInstaller.install_ssl_dhparams)F)rS)r>r?r@rArr"r	r.�boolrKrPrQrR�intrUrErXrYr[rFrr)r$rr�s

rc@seZdZdZdS)�Configuratorzt
    A plugin that extends certbot.plugins.common.Installer
    and implements certbot.interfaces.Authenticator
    N)r>r?r@rArrrrr^�sr^c@s�eZdZdZd"eeefed�dd�Zeedd�dd��Z	ed	�d
d�Z
eeefd	�dd
�Zeed�dd�Z
ed	�dd�Zed	�dd�Zed	�dd�Zedd�dd�Zeeed�dd�Zed	�dd�Zeeed�dd �Zd!S)#�Addrz�Represents an virtual host address.

    :param str addr: addr part of vhost address
    :param str port: port number or \*, or ""

    F)�tup�ipv6cCs||_||_dS)N)r`ra)r#r`rarrrr"�sz
Addr.__init__)�str_addrrcCs�|jd�rh|jd�}|d|d�}d}t|�|dkrX||ddkrX||dd�}|||fdd	�S|jd�}||d
|df�SdS)zInitialize Addr from string.�[�]NrS���:T)rar)�
startswith�rfind�len�	partition)r&rbZendIndex�host�portr`rrr�
fromstrings

 
zAddr.fromstring)rcCs|jdrd|jS|jdS)NrSz%s:%sr)r`)r#rrr�__str__s

zAddr.__str__cCs|jr|j�|jdfS|jS)z5Normalized representation of addr/port tuple
        rS)ra�get_ipv6_explodedr`)r#rrr�normalized_tupleszAddr.normalized_tuple)�otherrcCs t||j�r|j�|j�kSdS)NF)�
isinstancer$rq)r#rrrrr�__eq__szAddr.__eq__cCs
t|j�S)N)�hashr`)r#rrr�__hash__%sz
Addr.__hash__cCs
|jdS)z Return addr part of Addr object.r)r`)r#rrr�get_addr(sz
Addr.get_addrcCs
|jdS)zReturn port.rS)r`)r#rrr�get_port,sz
Addr.get_port)rmrcCs|j|jd|f|j�S)z6Return new address object with same addr and new port.r)r$r`ra)r#rmrrr�get_addr_obj0szAddr.get_addr_obj)�addrrcCs|jd�}|jd�}|j|�S)z7Return IPv6 address in normalized form, helper functionrcrd)�lstrip�rstrip�
_explode_ipv6)r#rzrrr�_normalize_ipv64s

zAddr._normalize_ipv6cCs |jrdj|j|jd��SdS)zReturn IPv6 in normalized formrgrre)rar;r~r`)r#rrrrp:szAddr.get_ipv6_explodedcCs�ddddddddg}|jd�}t|�t|�kr>|dt|��}d}xZt|�D]N\}}|s^d}qLt|�dkrt|jd�}|s�t|�||<qLt|�||t|�<qLW|S)z#Explode IPv6 address for comparison�0rgrFTrS)�splitrj�	enumerater{r.)r#rz�resultZ	addr_listZ
append_to_end�i�blockrrrr}@s

zAddr._explode_ipv6N)F)r>r?r@rAr
r.r\r"rBrnrorqrrtr]rvrwrxryrr~rpr}rrrrr_�sr_c@sLeZdZdZed�dd�Zdejee	dd�dd�Z
eejd	�d
d�ZdS)
�ChallengePerformeravAbstract base for challenge performers.

    :ivar configurator: Authenticator and installer plugin
    :ivar achalls: Annotated challenges
    :vartype achalls: `list` of `.KeyAuthorizationAnnotatedChallenge`
    :ivar indices: Holds the indices of challenges from a larger array
        so the user of the class doesn't have to.
    :vartype indices: `list` of `int`

    )�configuratorcCs||_g|_g|_dS)N)r��achalls�indices)r#r�rrrr"eszChallengePerformer.__init__N)r8�idxrcCs$|jj|�|dk	r |jj|�dS)z�Store challenge to be performed when perform() is called.

        :param .KeyAuthorizationAnnotatedChallenge achall: Annotated
            challenge.
        :param int idx: index to challenge in a larger array

        N)r��appendr�)r#r8r�rrr�	add_challjs	zChallengePerformer.add_chall)rcCs
t��dS)z�Perform all added challenges.

        :returns: challenge responses
        :rtype: `list` of `acme.challenges.KeyAuthorizationChallengeResponse`


        N)�NotImplementedError)r#rrr�performwszChallengePerformer.perform)N)
r>r?r@rAr^r"rZ"KeyAuthorizationAnnotatedChallengerr]r�rr�rrrrr�Ys
r�)�	dest_path�digest_path�src_path�
all_hashesrcs�tj���dd���fdd��dd����fdd�}tjj��sJ|�dStj��}|�kr`dS||krp|�nLtjj��r�t�d��}|j�}WdQRX|�kr�dS��tjd����dS)	a�Copy a file into an active location (likely the system's config dir) if required.

       :param str dest_path: destination path for version controlled file
       :param str digest_path: path to save a digest of the file in
       :param str src_path: path to version controlled file found in distribution
       :param list all_hashes: hashes of every released version of the file
    N)rc	s$t�d��}|j��WdQRXdS)N�w)�open�write)Zfile_h)�current_hashr�rr�_write_current_hash�sz<install_version_controlled_file.<locals>._write_current_hashcstj�����dS)N)�shutilZcopyfiler)r�r�r�rr�_install_current_file�sz>install_version_controlled_file.<locals>._install_current_file�rzh%s has been manually modified; updated file saved to %s. We recommend updating %s for security purposes.)	r
Z	sha256sumrrV�isfiler��read�loggerZwarning)r�r�r�r�r�Zactive_file_digest�fZsaved_digestr)r�r�r�r�r�rrZ�s&	

rZ)�test_dir�pkgrcCs�ttd�dd�}|d�}|d�}|d�}tj|tj�tj|tj�tj|tj�tj|tjj	d|��}t
j|tjj	||�dd	�|||fS)
z5Setup the directories necessary for the configurator.)�prefixrcSstjtj|��S)a�Return the real path of a temp directory with the specified prefix

        Some plugins rely on real paths of symlinks for working correctly. For
        example, certbot-apache uses real paths of configuration files to tell
        a virtual host from another. On systems where TMP itself is a symbolic
        link, (ex: OS X) such plugins will be confused. This function prevents
        such a case.
        )r�realpath�tempfileZmkdtemp)r�rrr�expanded_tempdir�s	z#dir_setup.<locals>.expanded_tempdirZtempr ZworkZtestdataT)Zsymlinks)r.r�chmodrZCONFIG_DIRS_MODE�
pkg_resourcesZresource_filenamerrVr;r�Zcopytree)r�r�r�Ztemp_dirrWZwork_dirZtest_configsrrr�	dir_setup�sr�)5rA�abcrrrCZlogging�rer�r�Ztypingrrrrrr	r
r�Zcertbotrrr
rrrZcertbot._internalrZcertbot.compatrrZcertbot.interfacesrZAbstractInstallerrZAbstractPluginZcertbot.plugins.storagerZ	getLoggerr>r�r.rr�compileZprivate_ips_regex�
IGNORECASEZhostname_regexZ
Authenticatorr^r_r�rZr�rrrr�<module>sT

Thb)2

Zerion Mini Shell 1.0