Your IP : 216.73.216.172


Current Path : /lib/python3/dist-packages/certbot/plugins/__pycache__/
Upload File :
Current File : //lib/python3/dist-packages/certbot/plugins/__pycache__/webroot.cpython-38.pyc

U

�]Q0�@sTdZddlZddlZddlZddlZddlZddlZddlZddl	Zddl
mZddlm
Z
mZmZmZddlmZddlmZddlmZddlmZdd	lmZdd
lmZddlmZddlmZdd
lmZddlmZddlm Z e�!e"�Z#ej$�%ej&�ej$�'ej(�Gdd�dej)���Z*Gdd�dej+�Z,Gdd�dej+�Z-dd�Z.dS)zWebroot plugin.�N)�
challenges)�Dict�Set�DefaultDict�List)�achallenges)�cli)�errors)�
interfaces)�os)�
filesystem)�ops)�util)�common)�	safe_opencs�eZdZdZdZdZdd�Zedd��Zdd	�Z	�fd
d�Z
dd
�Zdd�Zdd�Z
dd�Zdd�Zd!dd�Zdd�Zdd�Zdd�Zdd �Z�ZS)"�
AuthenticatorzWebroot Authenticator.z Place files in webroot directoryz�Authenticator plugin that performs http-01 challenge by saving
necessary validation resources to appropriate paths on the file
system. It expects that there is some other HTTP server configured
to serve all files under specified web root ({0}).cCs|j�|�d��S)N�path)�	MORE_INFO�format�conf��self�r�9/usr/lib/python3/dist-packages/certbot/plugins/webroot.py�	more_info-szAuthenticator.more_infocCs&|ddgtdd�|ditdd�dS)Nrz-wapublic_html / webroot path. This can be specified multiple times to handle different domains; each domain will have the webroot path that preceded it.  For instance: `-w /var/www/example -d example.com -d www.example.com -w /var/www/thing -d thing.net -d m.thing.net` (default: Ask))�default�action�help�mapa�JSON dictionary mapping domains to webroot paths; this implies -d for each entry. You may need to escape this from your shell. E.g.: --webroot-map '{"eg1.is,m.eg1.is":"/www/eg1/", "eg2.is":"/www/eg2"}' This option is merged with, but takes precedence over, -w / -d entries. At present, if you put webroot-map in a config file, it needs to be on a single line, like: webroot-map = {"example.com":"/var/www"}.)�_WebrootPathAction�_WebrootMapAction)�cls�addrrr�add_parser_arguments0s
��z"Authenticator.add_parser_argumentscCstjgS�N)r�HTTP01)r�domainrrr�get_chall_prefBszAuthenticator.get_chall_prefcs.tt|�j||�i|_t�t�|_g|_dSr$)	�superr�__init__�
full_roots�collections�defaultdict�set�	performed�
_created_dirs�r�args�kwargs��	__class__rrr)FszAuthenticator.__init__cCsdSr$rrrrr�prepareNszAuthenticator.preparecs$��|�����fdd�|D�S)Ncsg|]}��|��qSr)�_perform_single)�.0�achallrrr�
<listcomp>Vsz)Authenticator.perform.<locals>.<listcomp>)�
_set_webroots�_create_challenge_dirs)r�achallsrrr�performQs
zAuthenticator.performc	Cs�|�d�rD|�d�d}t�d|�|D]}|�d��|j|�q(n�ttt�|�d����}|D]b}|j|�d�kr`|�	|j|�}z|�
|�Wntk
r�YnX|�d|�||�d�|j<q`dS)Nr���z4Using the webroot path %s for all unmatched domains.rr)
r�logger�info�
setdefaultr&�listr-�sixZ
itervalues�_prompt_for_webroot�remove�
ValueError�insert)rr<�webroot_pathr8�known_webrootsZnew_webrootrrrr:Xs&
��zAuthenticator._set_webrootscCsBd}|dkr>|r0|�||�}|dkr<|�|�}q|�|d�}q|S)NT)�_prompt_with_webroot_list�_prompt_for_new_webroot)rr&rI�webrootrrrrDnsz!Authenticator._prompt_for_webrootcCsrtj�tj�}d|�d�}|jd�|�dg||dd�\}}|tj	krTt
�d��q|dkr`dS||d	SqdS)
Nz--rzSelect the webroot for {0}:zEnter a new webrootT)Zcli_flag�force_interactive�IEvery requested domain must have a webroot when using the webroot plugin.r�)�zopeZ	componentZ
getUtilityr
ZIDisplayZoption_nameZmenur�display_util�CANCELr	�PluginError)rr&rIZdisplayZ	path_flag�code�indexrrrrJ}s�

�z'Authenticator._prompt_with_webroot_listFcCsDtjtd�|�dd�\}}|tjkr8|s,dSt�d��nt|�SdS)NzInput the webroot for {0}:T)rMrN)r
Zvalidated_directory�_validate_webrootrrQrRr	rS)rr&Z
allowraiserTrLrrrrK�s�

�z%Authenticator._prompt_for_new_webrootcCsZ|�d�}|st�d��|��D�]2\}}tj�|tjj	�|j
|<t�d|j
|�t�
d�}z�tt�|j
|�dd�td�D]�}zrt�|d�|j�|�ztj||dddd	�Wn<ttfk
r�}zt�d
�t�d|�W5d}~XYnXWq�tk
�r@}z*|jtjtjfk�r0t�d�||���W5d}~XYq�Xq�W5t�
|�Xq dS)
Nrz�Missing parts of webroot configuration; please set either --webroot-path and --domains, or --webroot-map. Run with  --help webroot for examples.z-Creating root challenges validation dir at %s�r>)�keyi�T)Z	copy_userZ
copy_groupz3Unable to change owner and uid of webroot directory�
Error was: %sz=Couldn't create root for {0} http-01 challenge responses: {1})rr	rS�itemsrr�joinrr%Z
URI_ROOT_PATHr*r?�debug�umask�sortedrZget_prefixes�lenr�mkdirr/�appendZcopy_ownership_and_apply_mode�OSError�AttributeErrorr@�errnoZEEXISTZEISDIRr)rZpath_map�namer�	old_umask�prefixZ	exceptionrrrr;�sH
��
$�

"��z$Authenticator._create_challenge_dirscCstj�||j�d��S)N�token)rrr[Zchall�encode)r�	root_pathr8rrr�_get_validation_path�sz"Authenticator._get_validation_pathc	Cs�|��\}}|j|j}|�||�}t�d|�t�d�}z,t|ddd��}|�	|�
��W5QRXW5t�|�X|j|�|�|S)Nz#Attempting to save validation to %srW�wbi�)�mode�chmod)
Zresponse_and_validationr*r&rkr?r\rr]r�writerir.r")rr8ZresponseZ
validationrj�validation_pathrfZvalidation_filerrrr6�s
zAuthenticator._perform_singlec
Cs�|D]N}|j�|jd�}|dk	r|�||�}t�d|�t�|�|j|�|�qg}|j	r�|j	�
�}zt�|�WqXtk
r�}z(|�
d|�t�d|�t�d|�W5d}~XYqXXqX||_	t�d�dS)NzRemoving %srz3Challenge directory %s was not empty, didn't removerYzAll challenges cleaned up)r*�getr&rkr?r\rrEr.r/�pop�rmdirrbrGr@)rr<r8rjrpZnot_removedr�excrrr�cleanup�s$

 zAuthenticator.cleanup)F)�__name__�
__module__�__qualname__�__doc__Zdescriptionrr�classmethodr#r'r)r5r=r:rDrJrKr;rkr6ru�
__classcell__rrr3rr s$

)rc@seZdZdZddd�ZdS)r z%Action class for parsing webroot_map.NcsHt�t�|��D]2\}�t���|j��fdd�t�||�D��qdS)Nc3s|]}|�fVqdSr$r)r7�d�rHrr�	<genexpr>�sz-_WebrootMapAction.__call__.<locals>.<genexpr>)	rCZ	iteritems�json�loadsrV�webroot_map�updaterZadd_domains)r�parser�	namespacer��
option_string�domainsrr}r�__call__�s

�z_WebrootMapAction.__call__)N)rvrwrxryr�rrrrr �sr cs*eZdZdZ�fdd�Zddd�Z�ZS)rz&Action class for parsing webroot_path.cstt|�j||�d|_dS)NF)r(rr)�_domain_before_webrootr0r3rrr)�sz_WebrootPathAction.__init__NcCs\|jrt�d��|jr<|jd}|jD]}|j�||�q&n|jrHd|_|j�t|��dS)NzPIf you specify multiple webroot paths, one of them must precede all domain flagsr>T)	r�r	rSrHr�r�rArarV)rr�r�rHr�Zprev_webrootr&rrrr�s�

z_WebrootPathAction.__call__)N)rvrwrxryr)r�r{rrr3rr�srcCs&tj�|�st�|d��tj�|�S)z�Validates and returns the absolute path of webroot_path.

    :param str webroot_path: path to the webroot directory

    :returns: absolute path of webroot_path
    :rtype: str

    z% does not exist or is not a directory)rr�isdirr	rS�abspathr}rrrrVs	rV)/ry�argparser+rdrZloggingrCZzope.componentrPZzope.interfaceZacmerZacme.magic_typingrrrrZcertbotrrr	r
Zcertbot.compatrrZcertbot.displayr
rrQZcertbot.pluginsrZcertbot.utilrZ	getLoggerrvr?Z	interfaceZimplementerZIAuthenticatorZproviderZIPluginFactoryZPluginrZActionr rrVrrrr�<module>s:
P