Ë
    M/ÅeS$  ã                   óÆ   — d 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  G d„ de
j"                  «      Z G d„ d«      Zy)z8Module contains classes used by the Apache Configurator.é    N)ÚAny)ÚIterable)ÚOptional)ÚPattern)ÚSet)ÚUnion)Úcommon)ÚApacheBlockNode)ÚAugeasBlockNode)ÚDualBlockNodec                   ó    ‡ — e Zd ZdZdedefd„Zdefd„Zde	fˆ fd„Z
dd defd„Zde	fd	„Zdd defd
„Zdefd„Zdedej                   fd„Zˆ xZS )ÚAddrzRepresents an Apache address.ÚotherÚreturnc                 óì   — t        || j                  «      r^| j                  |j                  k(  xsC | j                  d   |j                  d   k(  xr" | j                  «       xr |j                  «       S y)zTThis is defined as equivalent within Apache.

        ip_addr:* == ip_addr

        r   F)Ú
isinstanceÚ	__class__ÚtupÚis_wildcard©Úselfr   s     ú>/usr/lib/python3/dist-packages/certbot_apache/_internal/obj.pyÚ__eq__zAddr.__eq__   so   € ô �e˜TŸ^™^Ô,Ø—X‘X §¡Ñ*ò AØ—X‘X˜a‘[ E§I¡I¨a¡LÑ0ò @Ø×%Ñ%Ó'ò@Ø,1×,=Ñ,=Ó,?ðBð ó    c                 ó4   — dt        | j                  «      › d�S )Nz"certbot_apache._internal.obj.Addr(ú))Úreprr   ©r   s    r   Ú__repr__zAddr.__repr__   s   € Ø3´D¸¿¹³NÐ3CÀ1ÐEÐEr   c                 ó    •— t         ‰| �  «       S ©N)ÚsuperÚ__hash__)r   r   s    €r   r#   zAddr.__hash__"   s   ø€ ô ‰wÑÓ!Ð!r   Úaddrc                 óD   — |j                  «       | j                  «       kD  S )zAReturns if addr.get_addr() is more specific than self.get_addr().)Ú_rank_specific_addr©r   r$   s     r   Ú_addr_less_specificzAddr._addr_less_specific'   s!   € ð ×'Ñ'Ó)¨D×,DÑ,DÓ,FÑFÐFr   c                 óT   — | j                  «       dk(  ry| j                  «       dk(  ryy)zzReturns numerical rank for get_addr()

        :returns: 2 - FQ, 1 - wildcard, 0 - _default_
        :rtype: int

        Ú	_default_r   Ú*é   é   )Úget_addrr   s    r   r&   zAddr._rank_specific_addr,   s)   € ð �=‰=‹?˜kÒ)ØØ�]‰]‹_ Ò#ØØr   c                 óÎ   — | j                  |«      ry| j                  «       |j                  «       k(  r2| j                  «       s!| j                  «       |j                  «       k(  ryy)aÔ  Returns if address could conflict with correct function of self.

        Could addr take away service provided by self within Apache?

        .. note::IP Address is more important than wildcard.
            Connection from 127.0.0.1:80 with choices of *:80 and 127.0.0.1:*
            chooses 127.0.0.1:\*

        .. todo:: Handle domain name addrs...

        Examples:

        =========================================  =====
        ``127.0.0.1:\*.conflicts(127.0.0.1:443)``  True
        ``127.0.0.1:443.conflicts(127.0.0.1:\*)``  False
        ``\*:443.conflicts(\*:80)``                False
        ``_default_:443.conflicts(\*:443)``        True
        =========================================  =====

        TF)r(   r.   r   Úget_portr'   s     r   Ú	conflictszAddr.conflicts9   sN   € ð* ×#Ñ# DÔ)ØØ�]‰]‹_ §¡£Ò/Ø×ÑÔ! T§]¡]£_¸¿¹»Ò%GØØr   c                 óJ   — | j                   d   dk(  xs | j                   d    S )z'Returns if address has a wildcard port.r,   r+   )r   r   s    r   r   zAddr.is_wildcardU   s$   € à�x‰x˜‰{˜cÑ!Ò4¨¯©°!© _Ð4r   Úportc                 óH   — | j                  «       r| S | j                  |«      S )zÛReturns the least specific address that resolves on the port.

        Examples:

        - ``1.2.3.4:443`` -> ``1.2.3.4:<port>``
        - ``1.2.3.4:*`` -> ``1.2.3.4:*``

        :param str port: Desired port

        )r   Úget_addr_obj)r   r3   s     r   Úget_sni_addrzAddr.get_sni_addrY   s&   € ð ×ÑÔØˆKà× Ñ  Ó&Ð&r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Úboolr   Ústrr   Úintr#   r(   r&   r1   r   r	   r   r6   Ú__classcell__)r   s   @r   r   r      s‹   ø„ Ù'ð
˜Cð 
 Dó 
ðF˜#ó Fð"˜#õ "ð
G¨ð G°4ó Gð
 Só ð˜fð ¨ó ð85˜Tó 5ð' ð '¨¯©÷ 'r   r   c                   ó  — e Zd ZU dZ ej
                  d«      Zeed<   	 	 	 dde	de	de
d   d	ed
edee	   dee
e	      deded    deeeeef      ddfd„Zde
e	   fd„Zde	fd„Zde	fd„Zdedefd„Zdefd„Zdee   defd„Zddd dedefd„Zy)ÚVirtualHostað  Represents an Apache Virtualhost.

    :ivar str filep: file path of VH
    :ivar str path: Augeas path to virtual host
    :ivar set addrs: Virtual Host addresses (:class:`set` of
        :class:`common.Addr`)
    :ivar str name: ServerName of VHost
    :ivar list aliases: Server aliases of vhost
        (:class:`list` of :class:`str`)

    :ivar bool ssl: SSLEngine on in vhost
    :ivar bool enabled: Virtual host is enabled
    :ivar bool modmacro: VirtualHost is using mod_macro
    :ivar VirtualHost ancestor: A non-SSL VirtualHost this is based on

    https://httpd.apache.org/docs/2.4/vhosts/details.html

    .. todo:: Any vhost that includes the magic _default_ wildcard is given the
              same ServerName as the main server.

    z^(?:.+://)?([^ :$]*)Ú
strip_nameNÚfilepathÚpathÚaddrsr   ÚsslÚenabledÚnameÚaliasesÚmodmacroÚancestorÚnoder   c                 ó¨   — || _         || _        || _        || _        |�|n	t	        «       | _        || _        || _        || _        |	| _	        |
| _
        y)zInitialize a VH.N)ÚfileprC   rD   rG   ÚsetrH   rE   rF   rI   rJ   rK   )r   rB   rC   rD   rE   rF   rG   rH   rI   rJ   rK   s              r   Ú__init__zVirtualHost.__init__ƒ   sS   € ð ˆŒ
ØˆŒ	ØˆŒ
ØˆŒ	Ø")Ð"5‘w¼3»5ˆŒØˆŒØˆŒØ ˆŒØ ˆŒØˆ�	r   c                 óÞ   — t        «       }|j                  | j                  «       | j                  �;|j	                  t
        j                  j                  | j                  «      d   «       |S )zReturn a set of all names.r   )rN   ÚupdaterH   rG   Úaddr@   rA   Úfindall)r   Ú	all_namess     r   Ú	get_nameszVirtualHost.get_names•   sQ   € ä!›eˆ	Ø×Ñ˜Ÿ™Ô&à�9‰9Ð Ø�M‰Mœ+×0Ñ0×8Ñ8¸¿¹ÓCÀAÑFÔGàÐr   c                 óf  — d| j                   › d| j                  › ddj                  d„ | j                  D «       «      › d| j                  �| j                  nd› ddj                  d	„ | j
                  D «       «      › d
| j                  rdnd› d| j                  rdnd› d| j                  rd› �S d› �S )NúFile: z
Vhost path: ú
Addresses: ú, c              3   ó2   K  — | ]  }t        |«      –— Œ y ­wr!   ©r<   ©Ú.0r$   s     r   ú	<genexpr>z&VirtualHost.__str__.<locals>.<genexpr>£   ó   è ø€ Ò#E°$¤C¨§IÑ#Eùó   ‚z
Name: Ú z

Aliases: c              3   ó    K  — | ]  }|–— Œ y ­wr!   © )r]   rG   s     r   r^   z&VirtualHost.__str__.<locals>.<genexpr>¥   s   è ø€ Ò!@¨4¤$Ñ!@ùs   ‚z
TLS Enabled: ÚYesÚNoz
Site Enabled: z
mod_macro Vhost: )	rM   rC   ÚjoinrD   rG   rH   rE   rF   rI   r   s    r   Ú__str__zVirtualHost.__str__Ÿ   sÊ   € à�T—Z‘Z�Lð !ØŸ9™9˜+ð &ØŸ)™)Ñ#E¸$¿*¹*Ô#EÓEÐFð GØ"&§)¡)Ð"7�T—Y’Y¸RÐ@ð AØŸ	™	Ñ!@°4·<±<Ô!@Ó@ÐAð BØ%)§X¢X™E°4Ð8ð 9Ø&*§l¢l™U¸Ð=ð > Ø)-¯ª ÐAðCð		
ð =AÐAðCð		
r   c           	      óÐ   — d| j                   › ddj                  d„ | j                  D «       «      › ddj                  | j                  «       «      › d| j                  rd› d	�	S d› d	�	S )
z5Return a representation of VHost to be used in dialogrW   rX   rY   c              3   ó2   K  — | ]  }t        |«      –— Œ y ­wr!   r[   r\   s     r   r^   z+VirtualHost.display_repr.<locals>.<genexpr>¯   r_   r`   z
Names: z
HTTPS: rd   re   ú
)rM   rf   rD   rU   rE   r   s    r   Údisplay_reprzVirtualHost.display_repr«   sz   € ð �T—Z‘Z�Lð !ØŸ)™)Ñ#E¸$¿*¹*Ô#EÓEÐFð GØ—i‘i §¡Ó 0Ó1Ð2ð 3Ø#Ÿxšx�eÐ2°"ð6ð	
ð .2Ð2°"ð6ð	
r   r   c                 ó¶  — t        || j                  «      rÃ| j                  |j                  k(  xr¨ | j                  |j                  k(  xr� | j                  |j                  k(  xrr | j                  «       |j                  «       k(  xrO | j                  |j                  k(  xr4 | j                  |j                  k(  xr | j                  |j                  k(  S y)NF)	r   r   rM   rC   rD   rU   rE   rF   rI   r   s     r   r   zVirtualHost.__eq__´   s³   € Ü�e˜TŸ^™^Ô,Ø—J‘J %§+¡+Ñ-ò 4°$·)±)¸u¿z¹zÑ2Iò 4Ø—J‘J %§+¡+Ñ-ò4à—N‘NÓ$¨¯©Ó(9Ñ9ò4ð —H‘H §	¡	Ñ)ò4ð —L‘L E§M¡MÑ1ò	4ð
 —M‘M U§^¡^Ñ3ð5ð r   c           	      óÞ   — t        | j                  | j                  t        | j                  «      t        | j                  «       «      | j                  | j                  | j                  f«      S r!   )	ÚhashrM   rC   ÚtuplerD   rU   rE   rF   rI   r   s    r   r#   zVirtualHost.__hash__¿   sM   € Ü�T—Z‘Z §¡Ü˜4Ÿ:™:Ó&¬¨d¯n©nÓ.>Ó(?Ø—X‘X˜tŸ|™|¨T¯]©]ð<ó =ð 	=r   c                 ó\   — |D ]'  }| j                   D ]  }|j                  |«      sŒ  y Œ) y)aE  See if vhost conflicts with any of the addrs.

        This determines whether or not these addresses would/could overwrite
        the vhost addresses.

        :param addrs: Iterable Addresses
        :type addrs: Iterable :class:~obj.Addr

        :returns: If addresses conflicts with vhost
        :rtype: bool

        TF)rD   r1   )r   rD   Úpot_addrr$   s       r   r1   zVirtualHost.conflictsÄ   s:   € ð ò 	 ˆHØŸ
™
ò  �Ø—>‘> (Õ+Úñ ð	 ð r   ÚvhostÚgenericc                 ó   — |s;|j                  «       | j                  «       k7  ry| j                  €| j                  ry| j                  ryt        |j                  «      t        | j                  «      k7  ryt        «       }|j                  D ]o  }| j                  D ]]  }|j                  «       |j                  «       k(  sŒ%||k7  sŒ+|j                  «       |vsŒ>|j                  |j                  «       «        Œn  y y)aX  Determines if the vhost is the same 'server'.

        Used in redirection - indicates whether or not the two virtual hosts
        serve on the exact same IP combinations, but different ports.
        The generic flag indicates that that we're trying to match to a
        default or generic vhost

        .. todo:: Handle _default_

        FT)rU   rG   rH   ÚlenrD   rN   r.   rR   )r   rr   rs   Úalready_foundr$   Ú
local_addrs         r   Úsame_serverzVirtualHost.same_server×   sä   € ñ Ø�‰Ó  D§N¡NÓ$4Ò4Øð �y‰yÐ$¨¯ªØð �YŠYØô ˆu�{‰{Óœs 4§:¡:›Ò.Øô #&£%ˆà—K‘Kò 	ˆDØ"Ÿj™jò �
Ø×'Ñ'Ó)¨T¯]©]«_Ó<Ø" dÓ*Ø"×+Ñ+Ó-°]ÒBð
 "×%Ñ% j×&9Ñ&9Ó&;Ô<Ùðñ ð	ð r   )NNFNN)F)r7   r8   r9   r:   ÚreÚcompilerA   r   Ú__annotations__r<   r   r;   r   r   r
   r   r   rO   rU   rg   rk   r   r   r=   r#   r   r   r1   rx   rc   r   r   r@   r@   j   s)  … ñð, %˜"Ÿ*™*Ð%<Ó=€J�Ó=ð [_ØMQØZ^ñ ð ¨Cð ¸¸F¹ð È$ð ØðØ&.¨s¡mðØEMÈcÐRUÉhÑEWðàðà3;¸MÑ3Jðð    o°ÈÐ&UÑ VÑWðð ó	ð$˜3˜s™8ó ð

˜ó 

ð
˜có 
ð	˜Cð 	 Dó 	ð=˜#ó =ð
˜x¨™~ð °$ó ñ&1 ð 1¸ð 1È$ô 1r   r@   )r:   ry   Útypingr   r   r   r   r   r   Úcertbot.pluginsr	   Ú%certbot_apache._internal.apacheparserr
   Ú%certbot_apache._internal.augeasparserr   Ú#certbot_apache._internal.dualparserr   r   r@   rc   r   r   ú<module>r�      sH   ðÙ >Û 	Ý Ý Ý Ý Ý Ý å "Ý AÝ AÝ =ôW'ˆ6�;‰;ô W'÷t^ò ^r   