U
    ÓZj16  ã                   @   sò   d Z ddlmZ ddl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 e e¡ZejjZd2d	d
„Zd3dd„Zd4dd„Zdd„ Zdd„ Zdd„ Zdddddddddd d!d"d#d$d%d&d'gZd(d)„ Zd*d+„ Zd,d-„ Zd.d/„ Zd0d1„ Z dS )5z=Decide which plugins to use for authentication & installationé    )Úprint_functionN)Úerrors)Ú
interfaces)Úos)Úutilú<How would you like to authenticate and install certificates?c                 C   s   t | |||tjtjfƒS )zPick configurator plugin.)Úpick_pluginr   ÚIAuthenticatorÚ
IInstaller©ÚconfigÚdefaultÚpluginsÚquestion© r   ú\/var/www/html/TRUCKING_PROJECT/venv/lib/python3.8/site-packages/certbot/plugins/selection.pyÚpick_configurator   s       
þr   ú+How would you like to install certificates?c                 C   s   t | |||tjfƒS )zPick installer plugin.)r   r   r
   r   r   r   r   Úpick_installer   s        ÿr   ú4How would you like to authenticate with the ACME CA?c                 C   s   t | |||tjfƒS )zPick authentication plugin.)r   r   r	   r   r   r   r   Úpick_authenticator"   s        ÿr   c                    s”   t | ƒ\}‰ ˆ sdS | ‡ fdd„¡}| | ¡ | tjf¡}t|ƒdkrXt dˆ  ¡‚|r‚t	| 
¡ ƒd }t d|¡ | | ¡S t dˆ  ¡‚dS )	a/  
    Get an unprepared interfaces.IInstaller object.

    :param certbot.interfaces.IConfig config: Configuration
    :param certbot.plugins.disco.PluginsRegistry plugins:
        All plugins registered as entry points.

    :returns: Unprepared installer plugin or None
    :rtype: IPlugin or None
    Nc                    s
   | j ˆ kS ©N©Úname©Zp_ep©Úreq_instr   r   Ú<lambda>8   ó    z*get_unprepared_installer.<locals>.<lambda>é   zfFound multiple installers with the name %s, Certbot is unable to determine which one to use. Skipping.r   zSelecting plugin: %sz:Could not select or initialize the requested installer %s.)Úcli_plugin_requestsÚfilterÚinitÚverifyr   r
   Úlenr   ÚPluginSelectionErrorÚlistÚvaluesÚloggerÚdebug)r   r   Ú_Z
installersÚinstr   r   r   Úget_unprepared_installer)   s&    
ÿÿ
ÿr,   c           	         sê   ˆ dk	r|  ‡ fdd„¡}n| jr,t d¡‚| ¡  |¡}| | ¡ | |¡}| ¡  | 	¡ }t
|ƒdkržt d|¡ ttt |¡ƒ|ƒ}|dkr–dS | ¡ S t
|ƒdkrØt| ¡ ƒd }t d|¡ |jrÐdS | ¡ S t d	¡ dS dS )
aÖ  Pick plugin.

    :param certbot.interfaces.IConfig: Configuration
    :param str default: Plugin name supplied by user or ``None``.
    :param certbot.plugins.disco.PluginsRegistry plugins:
        All plugins registered as entry points.
    :param str question: Question to be presented to the user in case
        multiple candidates are found.
    :param list ifaces: Interfaces that plugins must provide.

    :returns: Initialized plugin.
    :rtype: IPlugin

    Nc                    s
   | j ˆ kS r   r   r   ©r   r   r   r   X   r   zpick_plugin.<locals>.<lambda>a  Missing command line flags. For non-interactive execution, you will need to specify a plugin on the command line.  Run with '--help plugins' to see a list of options, and see https://eff.org/letsencrypt-plugins for more detail on what the plugins do and how to use them.r   zMultiple candidate plugins: %sr   zSingle candidate plugin: %szNo candidate plugin)r!   Znoninteractive_moder   ÚMissingCommandlineFlagÚvisibleÚifacesr"   r#   ÚprepareÚ	availabler$   r(   r)   Úchoose_pluginr&   ÚsixÚ
itervaluesr'   Úmisconfigured)	r   r   r   r   r0   ÚfilteredZverifiedÚpreparedÚ	plugin_epr   r-   r   r   G   s2    ÿ


r   c           	      C   sÈ   dd„ | D ƒ}t dd„ | D ƒƒ}ttjƒ}dtjkrl|t dƒkrldd„ t| ƒD ƒd }|j|||d	�\}}n|j||d
d�\}}|tj	kr¾| | }|j
r¸ttjƒjd | ¡ ¡dd� qÂ|S q dS q dS )zûAllow the user to choose their plugin.

    :param list prepared: List of `~.PluginEntryPoint`.
    :param str question: Question to be presented to the user.

    :returns: Plugin entry point chosen by the user.
    :rtype: `~.PluginEntryPoint`

    c                 S   s    g | ]}|j |jrd nd ‘qS )z [Misconfigured]Ú )Zdescription_with_namer6   ©Ú.0r9   r   r   r   Ú
<listcomp>‡   s   þÿz!choose_plugin.<locals>.<listcomp>c                 s   s   | ]}|j V  qd S r   r   r;   r   r   r   Ú	<genexpr>Š   s     z choose_plugin.<locals>.<genexpr>ZCERTBOT_AUTO)ÚapacheÚnginxc                 S   s   g | ]\}}|j d kr|‘qS )r?   r   )r<   ÚnÚpr   r   r   r=   “   s     
 r   r-   T)Úforce_interactivezxThe selected plugin encountered an error while parsing your server configuration and cannot be used. The error was:

{0}F)ÚpauseN)ÚsetÚz_utilr   ZIDisplayr   ÚenvironÚ	enumerateZmenuÚdisplay_utilÚOKr6   ZnotificationÚformatr1   )	r8   r   ÚoptsÚnamesZdispZ
apache_idxÚcodeÚindexr9   r   r   r   r3   }   s(    
þ


þýr3   ÚwebrootÚmanualÚ
standaloneúdns-cloudflareúdns-cloudxnsúdns-digitaloceanúdns-dnsimpleúdns-dnsmadeeasyú
dns-gehirnú
dns-googleú
dns-linodeú
dns-luadnsú	dns-nsoneúdns-ovhúdns-rfc2136údns-route53údns-sakuracloudc                 C   sB   |r|  |¡jnd| _|r&|  |¡jnd| _t d| j| j¡ dS )zFUpdate the config entries to reflect the plugins we actually selected.Nz0Plugins selected: Authenticator %s, Installer %s)Z	find_initr   ÚauthenticatorÚ	installerr(   Úinfo)r   r   Úauthr+   r   r   r   Úrecord_chosen_plugins©   s     ÿre   c                 C   s>  t | ƒ\}}d}|dkrd}|dkr`d }}ddlm} |tkrh|shd |tj|¡}	t |	¡‚nd	 }}|d
krtd}|dks„|dkršd}| j	ršt
 d|¡ d }
}|dkrÄ||krÄt| ||ƒ }
}n&|sÌ|rÚt| |||ƒ}|rêt| ||ƒ}
t
 d|
|¡ |�r|�std||ƒ |�r(|
�s(td||ƒ t| ||
|ƒ ||
fS )a;  
    Figure out which configurator we're going to use, modifies
    config.authenticator and config.installer strings to reflect that choice if
    necessary.

    :raises errors.PluginSelectionError if there was a problem

    :returns: (an `IAuthenticator` or None, an `IInstaller` or None)
    :rtype: tuple
    NZenhancezMWhich installer would you like to use to configure the selected enhancements?ÚrunTr   ©Úcli_commandzéWith the {0} plugin, you probably want to use the "certonly" command, eg:{1}{1}    {2} certonly --{0}{1}{1}(Alternatively, add a --installer flag. See https://eff.org/letsencrypt-plugins{1} and "--help plugins" for more information.)FZcertonlyÚinstallzRSpecifying an authenticator doesn't make sense when running Certbot with verb "%s"z*Selected authenticator %s and installer %srb   ra   )r    Úcertbot.clirh   Únoninstaller_pluginsrK   r   Úlinesepr   r.   ra   r(   Úwarningr   r   r   r)   Údiagnose_configurator_problemre   )r   r   ZverbÚreq_authr   Zinstaller_questionZ	need_instZ	need_authrh   Úmsgra   rb   r   r   r   Úchoose_configurator_plugins±   sJ      üÿrq   c                 C   s6   |s| S | r2| |kr2d}t  | t| ƒt|ƒ¡¡‚|S )zé
    Setting configurators multiple ways is okay, as long as they all agree
    :param str previously: previously identified request for the installer/authenticator
    :param str requested: the request currently being processed
    zIToo many flags setting configurators/installers/authenticators {0} -> {1})r   r%   rK   Úrepr)Z
previouslyÚnowrp   r   r   r   Úset_configuratorñ   s    rt   c                 C   sŠ  | j  }}t|| jƒ}t|| jƒ}| jr<t|dƒ}t|dƒ}| jrVt|dƒ}t|dƒ}| jrft|dƒ}| jrvt|dƒ}| jr†t|dƒ}| j	r–t|dƒ}| j
r¦t|dƒ}| jr¶t|dƒ}| jrÆt|d	ƒ}| jrÖt|d
ƒ}| jræt|dƒ}| jröt|dƒ}| j�rt|dƒ}| j�rt|dƒ}| j�r,t|dƒ}| j�r>t|dƒ}| j�rPt|dƒ}| j�rbt|dƒ}| j�rtt|dƒ}t d||¡ ||fS )z¿
    Figure out which plugins the user requested with CLI and config options

    :returns: (requested authenticator string or None, requested installer string or None)
    :rtype: tuple
    r@   r?   rR   rP   rQ   rS   rT   rU   rV   rW   rX   rY   rZ   r[   r\   r]   r^   r_   r`   z+Requested authenticator %s and installer %s)Úconfiguratorrt   rb   ra   r@   r?   rR   rP   rQ   Zdns_cloudflareZdns_cloudxnsZdns_digitaloceanZdns_dnsimpleZdns_dnsmadeeasyZ
dns_gehirnZ
dns_googleZ
dns_linodeZ
dns_luadnsZ	dns_nsoneZdns_ovhZdns_rfc2136Zdns_route53Zdns_sakuracloudr(   r)   )r   r   ro   r   r   r   r      sZ    





















r    c                 C   sd   |r,||krd  |¡}qVd  ||| j¡}n*| dkrLddlm} d  |¡}n
d  | ¡}t |¡‚dS )	a>  
    Raise the most helpful error message about a plugin being unavailable

    :param str cfg_type: either "installer" or "authenticator"
    :param str requested: the plugin that was requested
    :param .PluginsRegistry plugins: available plugins

    :raises error.PluginSelectionError: if there was a problem
    z8The requested {0} plugin does not appear to be installedzkThe {0} plugin is not working; there may be problems with your existing configuration.
The error was: {1!r}rb   r   rg   zûCertbot doesn't know how to automatically configure the web server on this system. However, it can still get a certificate for you. Please run "{0} certonly" to do so. You'll need to manually configure your web server to use the resulting certificate.z/{0} could not be determined or is not installedN)rK   Úproblemrj   rh   r   r%   )Zcfg_typeÚ	requestedr   rp   rh   r   r   r   rn   8  s     þü
rn   )r   )r   )r   )!Ú__doc__Ú
__future__r   Úloggingr4   Zzope.componentZzopeZcertbotr   r   Zcertbot.compatr   Zcertbot.displayr   rI   Ú	getLoggerÚ__name__r(   Ú	componentZ
getUtilityrF   r   r   r   r,   r   r3   rk   re   rq   rt   r    rn   r   r   r   r   Ú<module>   sL   
 þ
 ÿ
 ÿ
6'
         ý@7