
    M/ep>                        d Z ddl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	 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 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# ddl"m Z  ddl$m%Z%  ejL                  e'      Z(dZ)ddgZ* G d de#jV                  ejX                        Z, G d d ejZ                        Z. G d! d"ejZ                        Z/d#e0d$e0fd%Z1y)&zWebroot plugin.    N)Any)Callable)DefaultDict)Dict)Iterable)List)Optional)Sequence)Set)Type)Union)
challenges)crypto_util)errors)
interfaces)cli)AnnotatedChallenge)
filesystem)os)ops)util)common)	safe_opena!  <?xml version="1.0" encoding="UTF-8" ?>
<!--Generated by Certbot-->
<configuration>
  <system.webServer>
      <staticContent>
          <remove fileExtension="."/>
          <mimeMap fileExtension="." mimeType="text/plain" />
      </staticContent>
  </system.webServer>
</configuration>
@20c5ca1bd58fa8ad5f07a2f1be8b7cbb707c20fcb607a8fc8db9393952846a97@8d31383d3a079d2098a9d0c0921f4ab87e708b9868dc3f314d54094c2fe70336c                       e Zd ZdZdZdZdefdZede	d   ddfd	       Z
d
ee   defdZdedeeej"                        fdZdededdf fdZd dZdee   deej,                     fdZdee   ddfdZdedee   dee   fdZdedee   dee   fdZd!dededee   fdZd dZdededefdZdedej,                  fdZ dee   ddfdZ! xZ"S )"AuthenticatorzWebroot Authenticator.zSaves the necessary validation files to a .well-known/acme-challenge/ directory within the nominated webroot path. A seperate HTTP server must be running and serving files from the webroot path. HTTP challenge only (wildcards not supported).zAuthenticator 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}).returnc                 V    | j                   j                  | j                  d            S )Npath)	MORE_INFOformatconfselfs    C/usr/lib/python3/dist-packages/certbot/_internal/plugins/webroot.py	more_infozAuthenticator.more_infoF   s     ~~$$TYYv%677    add).NNc                 F     |ddg t         d        |di t        d       y )Nr    z-wa  public_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)clsr)   s     r&   add_parser_argumentsz"Authenticator.add_parser_argumentsI   s0    FD"-?N	O 	E2&7/	0r(   failed_achallsc                      y)NzThe Certificate Authority failed to download the temporary challenge files created by Certbot. Ensure that the listed domains serve their content from the provided --webroot-path/-w and that files created there can be downloaded from the internet. )r%   r3   s     r&   	auth_hintzAuthenticator.auth_hint[   s    %r(   domainc                 $    t         j                  gS N)r   HTTP01)r%   r7   s     r&   get_chall_prefzAuthenticator.get_chall_prefa   s    !!""r(   argskwargsc                 |    t        |   |i | i | _        t        j                  t
              | _        g | _        y r9   )super__init__
full_rootscollectionsdefaultdictset	performed_created_dirsr%   r<   r=   	__class__s      r&   r@   zAuthenticator.__init__e   s7    $)&)*,DOD[D[\_D`(*r(   c                      y r9   r5   r$   s    r&   preparezAuthenticator.preparel   s    r(   achallsc                     | j                  |       | j                          |D cg c]  }| j                  |       c}S c c}w r9   )_set_webroots_create_challenge_dirs_perform_single)r%   rK   achalls      r&   performzAuthenticator.performo   s;    7###%;BC$$V,CCCs   Ac                 f   | j                  d      r]| j                  d      d   }t        j                  d|       |D ]-  }| j                  d      j                  |j                  |       / y t        t        | j                  d      j                                     }|D ]~  }|j                  | j                  d      vs!| j                  |j                  |      }	 |j                  |       |j                  d|       || j                  d      |j                  <    y # t        $ r Y >w xY w)Nr    z4Using the webroot path %s for all unmatched domains.r.   r   )r#   loggerinfo
setdefaultr7   listrD   values_prompt_for_webrootremove
ValueErrorinsert)r%   rK   webroot_pathrP   known_webrootsnew_webroots         r&   rM   zAuthenticator._set_webrootsv   s   99V99V,R0LKKN$&! I		% ++FMM<HI "#dii&6&=&=&?"@AN! B==		%(88"&":":6==;I#KK&--k: #))![96ADIIe$V]]3B & s    D$$	D0/D0r^   c                     d }|=|r&| j                  ||      }|$| j                  |      }n| j                  |d      }|=|S )NT)_prompt_with_webroot_list_prompt_for_new_webroot)r%   r7   r^   webroots       r&   rY   z!Authenticator._prompt_for_webroot   sX    o88P?"::6BG 66vtD o r(   c                     d| j                  d      z   }	 t        j                  dj                  |      dg|z   |d      \  }}|t        j                  k(  rt        j                  d      |dk(  rd S ||d	z
     S )
Nz--r    TzSelect the webroot for {0}:zEnter a new webroot)cli_flagforce_interactiveIEvery requested domain must have a webroot when using the webroot plugin.r      )option_namedisplay_utilmenur"   CANCELr   PluginError)r%   r7   r^   	path_flagcodeindexs         r&   ra   z'Authenticator._prompt_with_webroot_list   s    4++F33	&++-44V<&'.8"d<KD% |***((=> > !A:4D>%!)+DDr(   
allowraisec                     t        j                  t        dj                  |      d      \  }}|t        j
                  k(  r|sy t        j                  d      t        |      S )NzInput the webroot for {0}:T)rf   rg   )r   validated_directory_validate_webrootr"   rj   rl   r   rm   )r%   r7   rq   ro   rc   s        r&   rb   z%Authenticator._prompt_for_new_webroot   se    //(//7"$g <&&&$$9: : !))r(   c           
         | j                  d      }|st        j                  d      |j                         D ]"  \  }}t        j
                  j                  |t        j
                  j                  t        j                  j                              | j                  |<   t        j                  d| j                  |          t        j                  d      5  t!        t#        j$                  | j                  |         d d t&              D ]o  }t        j
                  j)                  |      r#	 t        j*                  |d       | j,                  j/                  |       	 t        j0                  ||ddd	       q 	 d d d        t        j:                  rct        j
                  j                  | j                  |   d      }t        j
                  j=                  |      r%t        j?                  d| j                  |          t        j?                  d| j                  |          tA        |dd      5 }|jC                  tD               d d d        % y # t2        t4        f$ r6}t        j7                  d
       t        j                  d|       Y d }~!d }~ww xY w# t2        $ r*}t        j                  dj9                  ||            d }~ww xY w# 1 sw Y   ^xY w# 1 sw Y   xY w)Nr.   zMissing 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   rS   )keyi  T)	copy_user
copy_groupz3Unable to change owner and uid of webroot directoryError was: %sz=Couldn't create root for {0} http-01 challenge responses: {1}
web.configzPA web.config file has not been created in %s because another one already exists.zGCreating a web.config file in %s to allow IIS to serve challenge files.w  modechmod)#r#   r   rm   itemsr   r    joinnormcaser   r:   URI_ROOT_PATHrA   rT   debugr   
temp_umasksortedr   get_prefixeslenisdirmkdirrF   appendcopy_ownership_and_apply_modeOSErrorAttributeErrorwarningr"   
POSIX_MODEexistsrU   r   write_WEB_CONFIG_CONTENT)r%   path_mapnamer    prefix	exceptionweb_config_path
web_configs           r&   rN   z$Authenticator._create_challenge_dirs   s   99U#$$01 1 #..* .	:JD$$&GGLLrww7G7G!!//81 %2DOOD!LLH.0 &&u- P %T%6%6tt7L%Mcr%RX[\ PFww}}V, !P
 #((7**11&9E&DD $fetPTVPP8 (("$'',,tt/Dl"S77>>/2KK !IJN//Z^J_a 89=9NPSF :*$$%89: :[.	:6 !(8 E"NN+`a"LL)DDE # P$0077=vdI7NP PP+P PH: :sa   AK31J(%I ?K>K+ J%	/+J 	J( J%	%J((	K	1%K	K	KK(	+K5		root_pathrP   c                 t    t         j                  j                  ||j                  j	                  d            S )Ntoken)r   r    r   challencode)r%   r   rP   s      r&   _get_validation_pathz"Authenticator._get_validation_path   s&    ww||Iv||':':7'CDDr(   c                    |j                         \  }}| j                  |j                     }| j                  ||      }t        j                  d|       t        j                  d      5  t        |dd      5 }|j                  |j                                d d d        d d d        | j                  |   j                  |       |S # 1 sw Y   1xY w# 1 sw Y   5xY w)Nz#Attempting to save validation to %srv   wbr}   r~   )response_and_validationrA   r7   r   rT   r   r   r   r   r   r   rE   r)   )r%   rP   response
validationr   validation_pathvalidation_files          r&   rO   zAuthenticator._perform_single   s    %==?*OOFMM2	33IvF:OL ""5) 	;?UC ;%%j&7&7&9:;	; 	y!%%f-	; ;	; 	;s$   *C9 C	C	C	CCc                    |D ]8  }| j                   j                  |j                  d       }|-| j                  ||      }t        j                  d|       t        j                  |       | j                  |   j                  |       t        j                  rt        j                  j                  |d      }t        j                  j                  |      st        j                  |      }|t         v r-t        j#                  d|       t        j                  |       #t        j#                  d|       ; g }| j$                  r=| j$                  j'                         }	 t        j(                  |       | j$                  r=|| _        t        j                  d       y # t*        $ rH}	|j-                  d|       t        j#                  d|       t        j                  d|	       Y d }	~	vd }	~	ww xY w)	NzRemoving %sr{   z4Cleaning web.config file generated by Certbot in %s.zQNot cleaning up the web.config file in %s because it is not generated by Certbot.r   z3Challenge directory %s was not empty, didn't removerz   zAll challenges cleaned up)rA   getr7   r   rT   r   r   rZ   rE   r   r   r    r   r   r   	sha256sum_WEB_CONFIG_SHA256SUMSrU   rF   poprmdirr   r\   )
r%   rK   rP   r   r   r   r   not_removedr    excs
             r&   cleanupzAuthenticator.cleanup   s    	^F++FMM4@I$"&";";Iv"N]O<		/*y)008!,,&(ggll9l&KOww~~o6$/$9$9/$J	$(>>"KK(^(13IIo6"KK )RS\^#	^( "$  %%))+D3    )01  3""1d+QSWX_c223s   (F' '	G80>G33G8)r   N)F)#__name__
__module____qualname____doc__descriptionr!   strr'   classmethodr   r2   r   r   r6   r   r   r   	Challenger;   r   r@   rJ   ChallengeResponserQ   rM   r	   rY   ra   boolrb   rN   r   rO   r   __classcell__rH   s   @r&   r   r   8   s    @K
6I83 8 0x	': 0t 0 0"&-?(@ &S &#S #Xd:;O;O6P-Q #+c +S +T +Dt$67 DDA]A]<^ DBX.@%A Bd B,# tCy XVY] E E26s)E@HE*c *t *PXY\P] *5:nEc E;M ERU E&8 Z=Y=Y 2t$67 2D 2r(   r   c                   p    e Zd ZdZ	 d	dej
                  dej                  deee	e
   df   dee   ddf
dZy)
r0   z%Action class for parsing webroot_map.Nparser	namespacewebroot_mapoption_stringr   c                     |y t        j                  t        |            j                         D ]H  \  }t	              |j
                  j                  fdt        j                  ||      D               J y )Nc              3   &   K   | ]  }|f 
 y wr9   r5   ).0dr]   s     r&   	<genexpr>z-_WebrootMapAction.__call__.<locals>.<genexpr>,  s      )P&'L!)Ps   )	jsonloadsr   r   rt   r   updater   add_domains)r%   r   r   r   r   domainsr]   s         @r&   __call__z_WebrootMapAction.__call__%  st     %)ZZK0@%A%G%G%I 	P!G\,\:L!!(( )P+.??9g+N)P P	Pr(   r9   )r   r   r   r   argparseArgumentParser	Namespacer   r   r
   r   r	   r   r5   r(   r&   r0   r0   "  s[    / 15Px66 P8CUCU P#C#$<=P (P9=Pr(   r0   c                        e Zd ZdZdededdf fdZ	 ddej                  dej                  d	e	e
ee   df   d
ee
   ddf
dZ xZS )r/   z&Action class for parsing webroot_path.r<   r=   r   Nc                 2    t        |   |i | d| _        y )NF)r?   r@   _domain_before_webrootrG   s      r&   r@   z_WebrootPathAction.__init__3  s    $)&)&+#r(   r   r   r]   r   c                 ^   |y | j                   rt        j                  d      |j                  r=|j                  d   }|j                  D ]  }|j
                  j                  ||         n|j                  rd| _         |j                  j                  t        t        |                   y )NzPIf you specify multiple webroot paths, one of them must precede all domain flagsrS   T)
r   r   rm   r]   r   r   rV   r   rt   r   )r%   r   r   r]   r   prev_webrootr7   s          r&   r   z_WebrootPathAction.__call__7  s     &&$$<= = !! %11"5L#++ G%%00FG*.D'%%&7L8I&JKr(   r9   )r   r   r   r   r   r@   r   r   r   r   r   r
   r	   r   r   r   s   @r&   r/   r/   0  sv    0,c ,S ,T , 15Lx66 L8CUCU L$S(3-%=>L (L9=Lr(   r/   r]   r   c                     t         j                  j                  |       st        j                  | dz         t         j                  j                  |       S )zValidates 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)r   r    r   r   rm   abspath)r]   s    r&   rt   rt   M  s>     77==&  0W!WXX77??<((r(   )2r   r   rB   r   loggingtypingr   r   r   r   r   r   r	   r
   r   r   r   acmer   certbotr   r   r   certbot._internalr   certbot.achallengesr   certbot.compatr   r   certbot.displayr   r   rj   certbot.pluginsr   certbot.utilr   	getLoggerr   rT   r   r   Pluginr   Actionr0   r/   r   rt   r5   r(   r&   <module>r      s                        ! 2 %   0 "   "			8	$   GF g2FMM:#;#; g2TP PL L:)C )C )r(   