U
    ÔZj’  ã                   @   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__© úa/var/www/html/TRUCKING_PROJECT/venv/lib/python3.8/site-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   )ÚFedoraParserÚ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   Ú
run_scriptr   Ú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_optionsÚoptionsr   r   r   r   r%   E   s    z#FedoraConfigurator._prepare_options)Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚdictÚpkg_resourcesÚ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   r0   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   r3   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 ÚOPTIONSN)r   Zparse_define_filer/   Ú	variables)r   ZdefinesÚkr   r   r   r4   ^   s    z!FedoraParser._parse_sysconfig_var)r'   r(   r)   r*   r0   r3   r4   r.   r   r   r   r   r   Q   s   r   )r*   r,   Zzope.interfaceZzopeZcertbotr   r   r   r   r   r   r   Z	interfaceÚproviderZIPluginFactoryZApacheConfiguratorr	   ZApacheParserr   r   r   r   r   Ú<module>   s   B