
¡\\2  ã               @   sÇ   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 e j e ƒ Z e j j e j ƒ Gd d	 „  d	 e j ƒ ƒ Z d S)
zH Distribution specific override class for Debian family (Ubuntu/Debian) é    N)Úerrors)Ú
interfaces)Úutil)Úapache_util)Úconfiguratorc            !       sÄ   e  Z d  Z d Z e d d d d d d d d	 d
 d d d d g d d d g d d d g d d d d d d d d d d d d d e j d d ƒ ƒ Z ‡  f d d  †  Z d! d" d# „ Z	 d$ d% „  Z
 ‡  S)&ÚDebianConfiguratorz1Debian specific ApacheConfigurator override classZserver_rootz/etc/apache2Z
vhost_rootz/etc/apache2/sites-availableZvhost_filesÚ*Z	logs_rootz/var/log/apache2ZctlZ
apache2ctlZversion_cmdz-vZrestart_cmdZgracefulZconftest_cmdZ
configtestÚenmodZa2enmodÚdismodZa2dismodZle_vhost_extz-le-ssl.confZhandle_modulesTZhandle_sitesZchallenge_locationZMOD_SSL_CONF_SRCÚcertbot_apachezoptions-ssl-apache.confc                sp  | j  r d Sd |  j j t j j | j ƒ f } t j j t j j | ƒ ƒ sf t	 t
 |  ƒ j | ƒ S|  j j d | ƒ y t j | j | ƒ Wn§ t k
 r9} z‡ t j j | ƒ rß t j j | ƒ | j k rß d | _  d St j d | | j | j ƒ d d d } t j | j | j | ƒ ƒ ‚ WYd d } ~ Xn Xd | _  t j 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.obj.VirtualHost`

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

        Nz%s/sites-enabled/%sFTz)Could not symlink %s to %s, got error: %sz+Encountered error while trying to enable a z,newly created VirtualHost located at {0} by zlinking to it from {1}zEnabling available site: %szEnabled site %s
)ÚenabledÚparserÚrootÚosÚpathÚbasenameZfilepÚisdirÚdirnameÚsuperr   Úenable_siteÚreverterZregister_file_creationÚsymlinkÚOSErrorÚislinkÚrealpathÚloggerZwarningÚstrerrorr   ÚNotSupportedErrorÚformatÚinfoÚ
save_notes)ÚselfZvhostÚenabled_pathÚerrZ	errstring)Ú	__class__© ú@/usr/lib/python3/dist-packages/certbot_apache/override_debian.pyr   (   s2    				zDebianConfigurator.enable_siteFc             C   sX  t  j j |  j j d ƒ } t  j j |  j j d ƒ } t  j j | ƒ s\ t  j j | ƒ ro t j d | ƒ ‚ t j	 | ƒ } x} | D]u } | d |  j j
 k r… |  j | | ƒ |  j j | ƒ d | | f } | sí |  j | t  j 7_ t j | ƒ q… W|  j | | ƒ |  j j | ƒ | s7|  j d | 7_ t j d | ƒ |  j 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   Zget_mod_depsÚmodulesÚ_enable_mod_debianZadd_modr    Úlinesepr   Údebugr   Zupdate_runtime_variables)r!   Úmod_nameÚtempZ
avail_pathr"   ZdepsZdepZnoter%   r%   r&   Ú
enable_modU   s*    &
zDebianConfigurator.enable_modc             C   sl   t  j |  j d ƒ ƒ s' t j d ƒ ‚ |  j j | |  j d ƒ d | g ƒ t  j |  j d ƒ | g ƒ d S)z,Assumes mods-available, mods-enabled layout.r
   zdUnable to find a2dismod, please make sure a2enmod and a2dismod are configured correctly for certbot.z-fr	   N)r   Z
exe_existsZoptionr   ZMisconfigurationErrorr   Zregister_undo_commandZ
run_script)r!   r-   r.   r%   r%   r&   r*   „   s    		z%DebianConfigurator._enable_mod_debian)Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚdictÚpkg_resourcesZresource_filenameZOS_DEFAULTSr   r/   r*   r%   r%   )r$   r&   r      s*   -/r   )r3   Zloggingr   r5   Zzope.interfaceÚzopeZcertbotr   r   r   r   r   r   Z	getLoggerr0   r   Z	interfaceZproviderZIPluginFactoryZApacheConfiguratorr   r%   r%   r%   r&   Ú<module>   s   