U
    ]                     @   s   d 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 ejejG d	d
 d
e
jZG dd dejZdS )z5 Distribution specific override class for Fedora 29+     N)errors)
interfaces)util)apache_utilconfigurator)parserc                       s   e Zd ZdZedddddddgdd	gdd
gddgddddddedddZ fddZdd Z	 fddZ
 fddZ  ZS )FedoraConfiguratorz5Fedora 29+ specific ApacheConfigurator override classz
/etc/httpdz/etc/httpd/conf.dz*.confz/var/log/httpdhttpdz-v	apachectlZgracefulrestartZ
configtestNz-le-ssl.confFcertbot_apachezcentos-options-ssl-apache.conf)server_root
vhost_rootZvhost_filesZ	logs_rootZctlZversion_cmdrestart_cmdrestart_cmd_altconftest_cmdZenmodZdismodZle_vhost_extZhandle_modulesZhandle_sitesZchallenge_locationZMOD_SSL_CONF_SRCc                    s6   zt t|   W n tjk
r0   |   Y nX dS )a(  
        Override config_test to mitigate configtest error in vanilla installation
        of mod_ssl in Fedora. The error is caused by non-existent self-signed
        certificates referenced by the configuration, that would be autogenerated
        during the first (re)start of httpd.
        N)superr	   config_testr   MisconfigurationError_try_restart_fedoraself	__class__ @/usr/lib/python3/dist-packages/certbot_apache/override_fedora.pyr   '   s    zFedoraConfigurator.config_testc                 C   s   t | d| d| j| dS )zInitializes the ApacheParserr   r   r   )FedoraParserZoptionversionr   r   r   r   
get_parser3   s      zFedoraConfigurator.get_parserc              
      sZ   zt dddg W n2 tjk
rF } ztt|W 5 d}~X Y nX tt|   dS )z]
        Tries to restart httpd using systemctl to generate the self signed keypair.
        Z	systemctlr   r
   N)	r   Z
run_scriptr   ZSubprocessErrorr   strr   r	   r   )r   errr   r   r   r   9   s
     z&FedoraConfigurator._try_restart_fedorac                    s<   t t|   d| jd d< d| jd d< d| jd d< dS )z
        Override the options dictionary initialization to keep using apachectl
        instead of httpd and so take advantages of this new bash script in newer versions
        of Fedora to restart httpd.
        r   r   r   r   r   N)r   r	   _prepare_optionsZoptionsr   r   r   r   r"   E   s    z#FedoraConfigurator._prepare_options)__name__
__module____qualname____doc__dictpkg_resourcesZresource_filenameZOS_DEFAULTSr   r   r   r"   __classcell__r   r   r   r   r	      s4    r	   c                       s4   e Zd ZdZ fddZ fddZdd Z  ZS )r   z/Fedora 29+ specific ApacheParser override classc                    s   d| _ tt| j|| d S )Nz/etc/sysconfig/httpd)sysconfig_filepr   r   __init__)r   argskwargsr   r   r   r+   S   s    zFedoraParser.__init__c                    s   t t|   |   dS )z: Override for update_runtime_variables for custom parsing N)r   r   update_runtime_variables_parse_sysconfig_varr   r   r   r   r.   X   s    z%FedoraParser.update_runtime_variablesc                 C   s*   t | jd}|D ]}|| | j|< qdS )z: Parses Apache CLI options from Fedora configuration file ZOPTIONSN)r   Zparse_define_filer*   Z	variables)r   Zdefineskr   r   r   r/   ^   s    z!FedoraParser._parse_sysconfig_var)r#   r$   r%   r&   r+   r.   r/   r)   r   r   r   r   r   Q   s   r   )r&   r(   Zzope.interfacezopeZcertbotr   r   r   r   r   r   r   Z	interfaceZproviderZIPluginFactoryZApacheConfiguratorr	   ZApacheParserr   r   r   r   r   <module>   s   B