
    M/e                         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  ej                  e      Z G d de
j$                        Zy)zH Distribution specific override class for Debian family (Ubuntu/Debian)     N)errors)util)
filesystem)os)apache_util)configurator)	OsOptions)VirtualHostc                   n     e Zd ZdZ edddd      Zdeddf fd	Zdd
ede	ddfdZ
d
ede	ddfdZ xZS )DebianConfiguratorz1Debian specific ApacheConfigurator override classa2enmoda2dismodT)enmoddismodhandle_moduleshandle_sitesvhostreturnNc                    |j                   ry| j                  j                  dt        j                  j                  |j                        }t        j                  j                  t        j                  j                  |            st        | )  |      S | j                  j                  d|       	 t        j                  |j                  |       d|_         t$        j1                  d|j                         | xj2                  d|j                  z  z  c_        y# t        $ r}t        j                  j                  |      r.t!        j"                  |      |j                  k(  rd|_         Y d}~yt$        j'                  d||j                  |j(                         d}t+        j,                  |j/                  |j                  |            d}~ww xY w)	a  Enables an available site, Apache reload required.

        .. note:: Does not make sure that the site correctly works or that all
                  modules are enabled appropriately.

        :param vhost: vhost to enable
        :type vhost: :class:`~certbot_apache._internal.obj.VirtualHost`

        :raises .errors.NotSupportedError: If filesystem layout is not
            supported.

        Nz/sites-enabled/FTz)Could not symlink %s to %s, got error: %szmEncountered error while trying to enable a newly created VirtualHost located at {0} by linking to it from {1}zEnabling available site: %szEnabled site %s
)enabledparserrootr   pathbasenamefilepisdirdirnamesuperenable_sitereverterregister_file_creationsymlinkOSErrorislinkr   realpathloggererrorstrerrorr   NotSupportedErrorformatinfo
save_notes)selfr   enabled_patherr	errstring	__class__s        J/usr/lib/python3/dist-packages/certbot_apache/_internal/override_debian.pyr   zDebianConfigurator.enable_site   sn    == ))))%++68 ww}}RWW__\:; 7&u--,,ULA	KJJu{{L1 15;;?.<<#  	Kww~~l+
0C0C1 %1, !%LL;\S\\+2I **9+;+;EKK<H,J K K	Ks    9 D# #	G,AG9AGGmod_nametempc                    t         j                  j                  | j                  j                  d      }t         j                  j                  | j                  j                  d      }t         j                  j                  |      rt         j                  j                  |      st        j                  d|z        t        j                  |      }|D ]  }|dz   | j                  j                  vs| j                  ||       | j                  j                  |       d|d|}|s&| xj                  |t         j                  z   z  c_        t        j!                  |        | j                  ||       | j                  j                  |       |s| xj                  d|z  z  c_        t        j#                  d|       | j                  j%                          y	)
a  Enables module in Apache.

        Both enables and reloads Apache so module is active.

        :param str mod_name: Name of the module to enable. (e.g. 'ssl')
        :param bool temp: Whether or not this is a temporary action.

        :raises .errors.NotSupportedError: If the filesystem layout is not
            supported.
        :raises .errors.MisconfigurationError: If a2enmod or a2dismod cannot be
            run.

        zmods-availablezmods-enabledzIUnsupported directory layout. You may try to enable mod %s and try again._modulezEnabled dependency of z
 module - zEnabled %s module in Apache
zEnabled Apache %s moduleN)r   r   joinr   r   r   r   r)   r   get_mod_depsmodules_enable_mod_debianadd_modr,   linesepr&   debugr+   update_runtime_variables)r-   r3   r4   
avail_pathr.   depsdepnotes           r2   
enable_modzDebianConfigurator.enable_modG   sg    WW\\$++"2"24DE
ww||DKK$4$4nEww}}Z(l0K**!#+,- - ''1  	#Ci(;(;;''T2##C(AI3OOOtbjj'88OT"	# 	$/H%OO>IIO.9
 	,,.    c                    | j                   j                  ?| j                   j                  )t        j                  | j                   j                        st        j                  d      | j                  j                  || j                   j                  d|g       t        j                  | j                   j                  |g       y)z,Assumes mods-available, mods-enabled layout.NzdUnable to find a2dismod, please make sure a2enmod and a2dismod are configured correctly for certbot.z-f)
optionsr   r   r   
exe_existsr   MisconfigurationErrorr    register_undo_command
run_script)r-   r3   r4   s      r2   r:   z%DebianConfigurator._enable_mod_debianu   s    
 LL'4<<+=+=+Et||':':;..AB B 	++D4<<3F3Fh2WX++X67rD   )F)__name__
__module____qualname____doc__r	   OS_DEFAULTSr
   r   strboolrC   r:   __classcell__)r1   s   @r2   r   r      se    ;	K+ + +Z,/3 ,/d ,/t ,/\83 8d 8t 8rD   r   )rN   loggingcertbotr   r   certbot.compatr   r   certbot_apache._internalr   r   %certbot_apache._internal.configuratorr	   certbot_apache._internal.objr
   	getLoggerrK   r&   ApacheConfiguratorr    rD   r2   <module>r\      sI    N    %  0 1 ; 4			8	$q888 q8rD   