o
    c                     @   s   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eZG dd de
jZdS )zH Distribution specific override class for Debian family (Ubuntu/Debian)     N)errors)util)
filesystem)os)apache_util)configurator)	OsOptions)VirtualHostc                       sh   e Zd ZdZedddddZdeddf fd	d
Zddede	ddfddZ
dede	ddfddZ  ZS )DebianConfiguratorz1Debian specific ApacheConfigurator override classa2enmoda2dismodT)enmoddismodhandle_moduleshandle_sitesvhostreturnNc              
      s  |j rdS d| jjtj|jf }tjtj|s"t	 
|S | jd| z	t|j| W n: tyl } z.tj|rRt||jkrRd|_ W Y d}~dS td||j|j d}t||j|d}~ww d|_ td|j |  jd|j 7  _dS )	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%s/sites-enabled/%sFTz)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__ U/opt/certbot/lib/python3.10/site-packages/certbot_apache/_internal/override_debian.pyr      sD   zDebianConfigurator.enable_siteFmod_nametempc                 C   s   t j| jjd}t j| jjd}t j|rt j|s%td| t	|}|D ]-}|d | jj
vrY| || | j| d||f }|sT|  j|t j 7  _t| q,| || | j| |sq|  jd| 7  _td| | j  dS )	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 %s module - %sz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*   r2   r3   
avail_pathr+   depsdepnoter0   r0   r1   
enable_modG   s0   

zDebianConfigurator.enable_modc                 C   s^   | j jdu s| j jdu st| j jstd| j|| j jd|g t	| j j|g dS )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*   r2   r3   r0   r0   r1   r8   u   s   z%DebianConfigurator._enable_mod_debian)F)__name__
__module____qualname____doc__r   OS_DEFAULTSr	   r   strboolrA   r8   __classcell__r0   r0   r.   r1   r
      s    -.r
   )rJ   loggingcertbotr   r   certbot.compatr   r   certbot_apache._internalr   r   %certbot_apache._internal.configuratorr   certbot_apache._internal.objr	   	getLoggerrG   r#   ApacheConfiguratorr
   r0   r0   r0   r1   <module>   s    
