ó
Y[c           @   s.  d  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 j e ƒ Z e j j Z e e d „ Z d „  Z d d „ Z d d	 „ Z d
 „  Z d „  Z d d „ Z d d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z  d d „ Z! d „  Z" d „  Z# d S(   s+   Contains UI methods for LE user operations.iÿÿÿÿN(   t   errors(   t
   interfaces(   t   utilc         C   s&  d } d } d } | r: |  r1 | | 7} t  } q@ t } n t  } xß t r!y8 t t j ƒ j |  rk | | n | d t ƒ\ } } Wn) t j k
 r¬ d } t j | ƒ ‚ n X| t j	 k ræ | rÔ t j
 d ƒ ‚ qt j
 d ƒ ‚ n, t j | ƒ rù | S| r| | 7} t  } n  t | ƒ }  qC Wd S(	   sJ  Prompt for valid email address.

    :param bool invalid: True if an invalid address was provided by the user
    :param bool optional: True if the user can use
        --register-unsafely-without-email to avoid providing an e-mail

    :returns: e-mail address
    :rtype: str

    :raises errors.Error: if the user cancels

    s-   There seem to be problems with that address. sB   Enter email address (used for urgent renewal and security notices)s°   

If you really want to skip this, you can run the client with --register-unsafely-without-email but make sure you then backup your account key from /etc/letsencrypt/accounts

t   force_interactiveso   You should register before running non-interactively, or provide --agree-tos and --email <email_address> flags.sH   An e-mail address or --register-unsafely-without-email must be provided.s#   An e-mail address must be provided.N(   t   Falset   Truet   z_utilR   t   IDisplayt   inputR    t   MissingCommandlineFlagt   display_utilt   OKt   ErrorR   t
   safe_emailt   bool(   t   invalidt   optionalt   invalid_prefixt   msgt   unsafe_suggestiont   suggest_unsafet   codet   email(    (    s7   /usr/lib/python2.7/dist-packages/certbot/display/ops.pyt	   get_email   s8    
			
	c         C   sb   g  |  D] } | j  ^ q } t t j ƒ j d | d t ƒ\ } } | t j k rZ |  | Sd Sd S(   su   Choose an account.

    :param list accounts: Containing at least one
        :class:`~certbot.account.Account`

    s   Please choose an accountR   N(	   t   slugR   R   R   t   menuR   R
   R   t   None(   t   accountst   acct   labelsR   t   index(    (    s7   /usr/lib/python2.7/dist-packages/certbot/display/ops.pyt   choose_accountH   s    c         C   sK   t  t j ƒ j | d |  d t ƒ\ } } | t j k rC | rC | Sg  Sd S(   s¾   Display screen to let user pick one or multiple values from the provided
    list.

    :param list values: Values to select from

    :returns: List of selected values
    :rtype: list
    t   tagsR   N(   R   R   R   t	   checklistR   R
   R   (   t   valuest   questionR   t   items(    (    s7   /usr/lib/python2.7/dist-packages/certbot/display/ops.pyt   choose_valuesY   s
    	c         C   s„   |  d k r  t j d ƒ t ƒ  St |  j ƒ  ƒ } t | ƒ } | sN t d ƒ St | | ƒ \ } } | t j	 k r| | r| | Sg  Sd S(   sQ  Display screen to select domains to validate.

    :param installer: An installer object
    :type installer: :class:`certbot.interfaces.IInstaller`

    :param `str` question: Overriding dialog question to ask the user if asked
        to choose from domain names.

    :returns: List of selected names
    :rtype: `list` of `str`

    s$   No installer, picking names manuallys1   No names were found in your configuration files. N(
   R   t   loggert   debugt   _choose_names_manuallyt   listt   get_all_namest   get_valid_domainst   _filter_namesR
   R   (   t	   installerR#   t   domainst   namesR   (    (    s7   /usr/lib/python2.7/dist-packages/certbot/display/ops.pyt   choose_namesi   s    c         C   sO   g  } xB |  D]: } y | j  t j | ƒ ƒ Wq t j k
 rF q q Xq W| S(   s¼   Helper method for choose_names that implements basic checks
     on domain names

    :param list domains: Domain names to validate
    :return: List of valid domains
    :rtype: list
    (   t   appendR   t   enforce_domain_sanityR    t   ConfigurationError(   R.   t   valid_domainst   domain(    (    s7   /usr/lib/python2.7/dist-packages/certbot/display/ops.pyR+   ˆ   s    c         C   s   t  |  d d „  ƒS(   s¢   Sort FQDNs by SLD (and if many, by their subdomains)

    :param list FQDNs: list of domain names

    :returns: Sorted list of domain names
    :rtype: list
    t   keyc         S   s   |  j  d ƒ d  d  d … d S(   Nt   .iÿÿÿÿi   (   t   split(   t   fqdn(    (    s7   /usr/lib/python2.7/dist-packages/certbot/display/ops.pyt   <lambda>    s    (   t   sorted(   t   FQDNs(    (    s7   /usr/lib/python2.7/dist-packages/certbot/display/ops.pyt   _sort_names˜   s    c         C   st   t  |  ƒ } | r | } n d } t t j ƒ j | d | d d d t ƒ\ } }  | g  |  D] } t | ƒ ^ q[ f S(   s  Determine which names the user would like to select from a list.

    :param list names: domain names

    :returns: tuple of the form (`code`, `names`) where
        `code` - str display exit code
        `names` - list of names selected
    :rtype: tuple

    s1   Which names would you like to activate HTTPS for?R    t   cli_flags	   --domainsR   (   R=   R   R   R   R!   R   t   str(   R/   t   override_questiont   sorted_namesR#   R   t   s(    (    s7   /usr/lib/python2.7/dist-packages/certbot/display/ops.pyR,   £   s    	!t    c   
      C   s  t  t j ƒ j |  d d d d t ƒ\ } } | t j k r‹t ƒ  } d } y t j | ƒ } Wn) t	 k
 rŠ g  } d j
 t j ƒ } n XxZ t | ƒ D]L \ } } y t j | ƒ | | <Wq˜ t j k
 rã } t | ƒ | | <q˜ Xq˜ Wt | ƒ rPd j
 t j ƒ } x. | D]& } | d j
 t j | | | ƒ } qW| d	 j
 t j ƒ } n  | r„t  t j ƒ j | d t ƒ}	 |	 rˆt ƒ  Sq‹| Sn  g  S(
   sÃ   Manually input names for those without an installer.

    :param str prompt_prefix: string to prepend to prompt for domains

    :returns: list of provided names
    :rtype: `list` of `str`

    sC   Please enter in your domain name(s) (comma and/or space separated) R>   s	   --domainsR   RC   si   Internationalized domain names are not presently supported.{0}{0}Would you like to re-enter the names?{0}s<   One or more of the entered domain names was not valid:{0}{0}s   {1}: {2}{0}s+   {0}Would you like to re-enter the names?{0}(   R   R   R   R   R   R
   R   t   dictt   separate_list_inputt   UnicodeEncodeErrort   formatt   ost   linesept	   enumerateR   R2   R    R3   R?   t   lent   yesnoR(   (
   t   prompt_prefixR   t   input_t   invalid_domainst   retry_messaget   domain_listt   iR5   t   et   retry(    (    s7   /usr/lib/python2.7/dist-packages/certbot/display/ops.pyR(   ¹   sD    				
c         C   sJ   t  t j ƒ j d j t |  ƒ t j t j j t	 |  ƒ ƒ ƒ d t
 ƒd S(   ss   Display a box confirming the installation of HTTPS.

    :param list domains: domain names which were enabled

    sd   Congratulations! You have successfully enabled {0}{1}{1}You should test your configuration at:{1}{2}t   pauseN(   R   R   R   t   notificationRG   t   _gen_https_namesRH   RI   t   joint   _gen_ssl_lab_urlsR   (   R.   (    (    s7   /usr/lib/python2.7/dist-packages/certbot/display/ops.pyt   success_installationï   s    	c         C   sJ   t  t j ƒ j d j t |  ƒ t j t j j t	 |  ƒ ƒ ƒ d t
 ƒd S(   s€   Display a box confirming the renewal of an existing certificate.

    :param list domains: domain names which were renewed

    sÑ   Your existing certificate has been successfully renewed, and the new certificate has been installed.{1}{1}The new certificate covers the following domains: {0}{1}{1}You should test your configuration at:{1}{2}RU   N(   R   R   R   RV   RG   RW   RH   RI   RX   RY   R   (   R.   (    (    s7   /usr/lib/python2.7/dist-packages/certbot/display/ops.pyt   success_renewalþ   s    	c         C   s/   t  t j ƒ j d j |  t j ƒ d t ƒd S(   s   Display a box confirming a certificate has been revoked.

    :param list cert_path: path to certificate which was revoked.

    s\   Congratulations! You have successfully revoked the certificate that was located at {0}{1}{1}RU   N(   R   R   R   RV   RG   RH   RI   R   (   t	   cert_path(    (    s7   /usr/lib/python2.7/dist-packages/certbot/display/ops.pyt   success_revocation  s
    c         C   s   g  |  D] } d | ^ q S(   sN   Returns a list of urls.

    :param list domains: Each domain is a 'str'

    s1   https://www.ssllabs.com/ssltest/analyze.html?d=%s(    (   R.   t   dom(    (    s7   /usr/lib/python2.7/dist-packages/certbot/display/ops.pyRY     s    c         C   s‰   t  |  ƒ d k r# d j |  d ƒ St  |  ƒ d k rE d j d |  ƒ St  |  ƒ d k r… d j d j d	 „  |  d
  Dƒ ƒ d |  d
 ƒ Sd S(   s    Returns a string of the https domains.

    Domains are formatted nicely with https:// prepended to each.

    :param list domains: Each domain is a 'str'

    i   s   https://{0}i    i   s%   https://{dom[0]} and https://{dom[1]}R^   s	   {0}{1}{2}s   , c         s   s   |  ] } d  | Vq d S(   s
   https://%sN(    (   t   .0R^   (    (    s7   /usr/lib/python2.7/dist-packages/certbot/display/ops.pys	   <genexpr>3  s    iÿÿÿÿs   , and https://RC   (   RK   RG   RX   (   R.   (    (    s7   /usr/lib/python2.7/dist-packages/certbot/display/ops.pyRW   %  s    c         K   s  | d  k	 rd y | | ƒ Wqd t j k
 r` } t j d | | d t ƒt d j | ƒ ƒ ‚ qd Xn  x³ t r|  | d | | \ } } | t j	 k ry | | ƒ | | f SWqt j k
 r} t j d | | d t ƒt
 j j t j ƒ j t | ƒ d t ƒqXqg | | f Sqg Wd  S(   Ns>   Encountered invalid default value "%s" when prompting for "%s"t   exc_infos   Invalid default "{0}"t   defaults/   Validator rejected "%s" when prompting for "%s"RU   (   R   R    R   R&   R'   R   t   AssertionErrorRG   R
   R   t   zopet	   componentt
   getUtilityR   R   RV   R?   R   (   t   methodt	   validatort   messageRa   t   kwargst   errorR   t   raw(    (    s7   /usr/lib/python2.7/dist-packages/certbot/display/ops.pyt   _get_validated:  s,    		
	/c         O   s%   t  t j j t j ƒ j |  | | Ž S(   s	  Like `~certbot.interfaces.IDisplay.input`, but with validation.

    :param callable validator: A method which will be called on the
        supplied input. If the method raises a `errors.Error`, its
        text will be displayed and the user will be re-prompted.
    :param list `*args`: Arguments to be passed to `~certbot.interfaces.IDisplay.input`.
    :param dict `**kwargs`: Arguments to be passed to `~certbot.interfaces.IDisplay.input`.
    :return: as `~certbot.interfaces.IDisplay.input`
    :rtype: tuple
    (   Rl   Rc   Rd   Re   R   R   R   (   Rg   t   argsRi   (    (    s7   /usr/lib/python2.7/dist-packages/certbot/display/ops.pyt   validated_inputU  s    c         O   s%   t  t j j t j ƒ j |  | | Ž S(   s=  Like `~certbot.interfaces.IDisplay.directory_select`, but with validation.

    :param callable validator: A method which will be called on the
        supplied input. If the method raises a `errors.Error`, its
        text will be displayed and the user will be re-prompted.
    :param list `*args`: Arguments to be passed to `~certbot.interfaces.IDisplay.directory_select`.
    :param dict `**kwargs`: Arguments to be passed to
        `~certbot.interfaces.IDisplay.directory_select`.
    :return: as `~certbot.interfaces.IDisplay.directory_select`
    :rtype: tuple
    (   Rl   Rc   Rd   Re   R   R   t   directory_select(   Rg   Rm   Ri   (    (    s7   /usr/lib/python2.7/dist-packages/certbot/display/ops.pyt   validated_directoryd  s    ($   t   __doc__t   loggingRH   t   zope.componentRc   t   certbotR    R   R   t   certbot.displayR
   t	   getLoggert   __name__R&   Rd   Re   R   R   R   R   R   R   R%   R0   R+   R=   R,   R(   RZ   R[   R]   RY   RW   Rl   Rn   Rp   (    (    (    s7   /usr/lib/python2.7/dist-packages/certbot/display/ops.pyt   <module>   s2   6			6							