U
    ÓZj�  ã                   @   s²   d Z ddlZddlZddlmZ ddlmZ ddlm	Z	 ddlm
Z
 ddlmZ ddlmZ dd	lmZ dd
lmZ ddlmZ ej ej¡ej ej¡G dd„ dejƒƒƒZdS )zManual authenticator pluginé    N)Ú
challenges)ÚDict)Úachallenges)Úerrors)Úhooks)Ú
interfaces)Úreverter)Úos)Úcommonc                       s˜   e Zd ZdZdZdZdZdZdZdZ	dZ
‡ fd	d
„Zedd„ ƒZdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd „ Z‡  ZS )!ÚAuthenticatorzÔManual authenticator

    This plugin allows the user to perform the domain validation
    challenge(s) themselves. This either be done manually by the user or
    through shell scripts provided to Certbot.

    z2Manual configuration or run your own shell scriptsTai  Authenticate through manual configuration or custom shell scripts. When using shell scripts, an authenticator script must be provided. The environment variables available to this script depend on the type of challenge. $CERTBOT_DOMAIN will always contain the domain being authenticated. For HTTP-01 and DNS-01, $CERTBOT_VALIDATION is the validation string, and $CERTBOT_TOKEN is the filename of the resource requested when performing an HTTP-01 challenge. An additional cleanup script can also be provided and can use the additional variable $CERTBOT_AUTH_OUTPUT which contains the stdout output from the auth script.z‘Please deploy a DNS TXT record under the name
{domain} with the following value:

{validation}

Before continuing, verify the record is deployed.zuCreate a file containing just this data:

{validation}

And make it available on your web server at this URL:

{uri}
z�
(This must be set up in addition to the previous challenges; do not remove,
replace, or undo the previous challenge tasks yet.)
zþ
(This must be set up in addition to the previous challenges; do not remove,
replace, or undo the previous challenge tasks yet. Note that you might be
asked to create multiple distinct TXT records with the same name. This is
permitted by DNS standards.)
c                    sB   t t| ƒj||Ž t | j¡| _| j ¡  tƒ | _d| _	d| _
d S )NF)Úsuperr   Ú__init__r   ZReverterÚconfigÚrecovery_routineÚdictÚenvÚsubsequent_dns_challengeÚsubsequent_any_challenge)ÚselfÚargsÚkwargs©Ú	__class__© úY/var/www/html/TRUCKING_PROJECT/venv/lib/python3.8/site-packages/certbot/plugins/manual.pyr   C   s    
zAuthenticator.__init__c                 C   s*   |ddd� |ddd� |dddd	� d S )
Nú	auth-hookz8Path or command to execute for the authentication script)Úhelpúcleanup-hookz1Path or command to execute for the cleanup scriptúpublic-ip-logging-okÚ
store_truez5Automatically allows public IP logging (default: Ask))Úactionr   r   )ÚclsÚaddr   r   r   Úadd_parser_argumentsL   s    ÿÿÿz"Authenticator.add_parser_argumentsc                 C   s4   | j jr(|  d¡s(t d |  d¡¡¡‚|  ¡  d S )Nr   zdAn authentication script must be provided with --{0} when using the manual plugin non-interactively.)r   Znoninteractive_modeÚconfr   ÚPluginErrorÚformatÚoption_nameÚ_validate_hooks©r   r   r   r   ÚprepareU   s    þÿzAuthenticator.preparec                 C   sL   | j jrHdD ]:}|  |¡}|d k	r|  |¡d tdƒ … }t ||¡ qd S )N)r   r   z-hook)r   Zvalidate_hooksr$   r'   Úlenr   Zvalidate_hook)r   ÚnameÚhookZhook_prefixr   r   r   r(   ]   s    
zAuthenticator._validate_hooksc                 C   s   dS )Nz¦This plugin allows the user to customize setup for domain validation challenges either through shell scripts provided by the user or by performing the setup manually.r   r)   r   r   r   Ú	more_infoe   s    ÿzAuthenticator.more_infoc                 C   s   t jt jgS ©N)r   ÚHTTP01ÚDNS01)r   Údomainr   r   r   Úget_chall_prefk   s    zAuthenticator.get_chall_prefc                 C   sL   |   ¡  |  d¡r| j}n| j}g }|D ]}||ƒ | | |j¡¡ q(|S )Nr   )Ú_verify_ip_logging_okr$   Ú_perform_achall_with_scriptÚ_perform_achall_manuallyÚappendÚresponseÚaccount_key)r   ÚachallsZperform_achallÚ	responsesÚachallr   r   r   Úperformo   s    
zAuthenticator.performc                 C   s`   |   d¡s\d |  d¡¡}d}tj tj¡}|j||dd�rRt	| j
|  d¡dƒ n
t d¡‚d S )Nr   z--{0}zõNOTE: The IP of this machine will be publicly logged as having requested this certificate. If you're running certbot in manual mode on a machine that is not your server, please ensure you're okay with that.

Are you OK with your IP being logged?T)Úcli_flagÚforce_interactivez#Must agree to IP logging to proceed)r$   r&   r'   ÚzopeÚ	componentÚ
getUtilityr   ÚIDisplayZyesnoÚsetattrr   Údestr   r%   )r   r>   ÚmsgÚdisplayr   r   r   r4   |   s    
z#Authenticator._verify_ip_logging_okc                 C   sx   t |j| |j¡d�}t|jtjƒr6|j d¡|d< nt	j
 dd ¡ t	j
 |¡ |  d¡\}}| ¡ |d< || j|< d S )N)ZCERTBOT_DOMAINZCERTBOT_VALIDATIONÚtokenÚCERTBOT_TOKENr   ZCERTBOT_AUTH_OUTPUT)r   r2   Ú
validationr9   Ú
isinstanceÚchallr   r0   Úencoder	   ÚenvironÚpopÚupdateÚ_execute_hookÚstripr   )r   r<   r   Ú_Úoutr   r   r   r5   Š   s    
ÿz)Authenticator._perform_achall_with_scriptc                 C   sÐ   |  |j¡}t|jtjƒrH| jj||j d¡| j	j
|j |j¡|d�}n*t|jtjƒsZt‚| jj| |j¡|d�}t|jtjƒr˜| jr�|| j7 }d| _n| jr¨|| j7 }tj tj¡}|j|ddd� d| _d S )NrH   )r<   Zencoded_tokenÚportÚurirJ   )r2   rJ   TF)Úwrapr?   )rJ   r9   rK   rL   r   r0   Ú_HTTP_INSTRUCTIONSr&   rM   r   Zhttp01_portrV   r2   r1   ÚAssertionErrorÚ_DNS_INSTRUCTIONSZvalidation_domain_namer   Ú&_SUBSEQUENT_DNS_CHALLENGE_INSTRUCTIONSr   Ú"_SUBSEQUENT_CHALLENGE_INSTRUCTIONSr@   rA   rB   r   rC   Znotification)r   r<   rJ   rF   rG   r   r   r   r6   –   s.     
 ý
þ

z&Authenticator._perform_achall_manuallyc                 C   sZ   |   d¡rL|D ]<}| j |¡}d|kr4tj dd ¡ tj |¡ |  d¡ q| j ¡  d S )Nr   rI   )	r$   r   rO   r	   rN   rP   rQ   r   r   )r   r:   r<   r   r   r   r   Úcleanup®   s    
zAuthenticator.cleanupc                 C   s   t  |  |¡|  |¡¡S r/   )r   Úexecuter'   r$   )r   Ú	hook_namer   r   r   rQ   ¸   s    zAuthenticator._execute_hook)Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚdescriptionZhiddenÚlong_descriptionrZ   rX   r\   r[   r   Úclassmethodr#   r*   r(   r.   r3   r=   r4   r5   r6   r]   rQ   Ú__classcell__r   r   r   r   r      s,   ÿ
		

r   )rc   Zzope.componentr@   Zzope.interfaceZacmer   Zacme.magic_typingr   Zcertbotr   r   r   r   r   Zcertbot.compatr	   Zcertbot.pluginsr
   Z	interfaceZimplementerZIAuthenticatorÚproviderZIPluginFactoryZPluginr   r   r   r   r   Ú<module>   s   