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 eeZG d
d de	jZG dd de
jZdS )zG Distribution specific override class for CentOS family (RHEL, Fedora)     N)Any)errors)util)apache_util)configurator)parser)	OsOptionsc                       s   e Zd ZdZeddddddddgdd	gdd
gddgddZd fddZdefddZd fddZ	d fddZ
dddZ  ZS )CentOSConfiguratorz1CentOS specific ApacheConfigurator override classz
/etc/httpdz/etc/httpd/conf.dz*.confz/var/log/httpd	apachectlhttpdz-vgracefulrestart
configtest)server_root
vhost_rootvhost_files	logs_rootctl
apache_binversion_cmdrestart_cmdrestart_cmd_altconftest_cmdchallenge_locationreturnNc                    sN   t  }|d  dk}zt   W dS  tjy&   |r%|   Y dS  w )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.
        r   fedoraN)r   get_os_infolowersuperconfig_testr   MisconfigurationError_try_restart_fedora)selfos_infor   	__class__ U/opt/certbot/lib/python3.10/site-packages/certbot_apache/_internal/override_centos.pyr       s   zCentOSConfigurator.config_testc                 C   s4   t  \}}|dv }|sdS t |t dk}|S )N)
centoszcentos linux
cloudlinuxoloraclerhelredhatenterpriseserverzred hat enterprise linux server
scientificzscientific linuxF9)r   r   parse_loose_version)r"   os_name
os_versionrhel_derivedat_least_v9r&   r&   r'   _rhel9_or_newer3   s   
z"CentOSConfigurator._rhel9_or_newerc                    s   t    |  r1| jjstd| jj| jjd< | jj| jjd< | jj| jjd< | jj| jj	d< | jj
s9td| jj| jj
d< d S )Nz+OS option apache_bin must be set for CentOSr   z1OS option restart_cmd_alt must be set for CentOS.)r   _override_cmdsr5   optionsbin
ValueErrorr   get_modules_cmdget_includes_cmdget_defines_cmdr   r   r"   r$   r&   r'   r6   D   s   
z!CentOSConfigurator._override_cmdsc              
      sJ   z	t g d W n tjy } ztt|d}~ww t   dS )z^
        Tries to restart httpd using systemctl to generate the self signed key pair.
        )	systemctlr   r   N)r   
run_scriptr   SubprocessErrorr    strr   r   )r"   errr$   r&   r'   r!   W   s   z&CentOSConfigurator._try_restart_fedoraCentOSParserc                 C   s   t | jj| | jj| jS )zInitializes the ApacheParser)rC   r7   r   r   versionr=   r&   r&   r'   
get_parserd   s   zCentOSConfigurator.get_parserr   N)r   rC   )__name__
__module____qualname____doc__r   OS_DEFAULTSr   boolr5   r6   r!   rE   __classcell__r&   r&   r$   r'   r	      s(    r	   c                       sF   e Zd ZdZdededdf fddZd fdd	Zdd
dZ  ZS )rC   z+CentOS specific ApacheParser override classargskwargsr   Nc                    s   d| _ t j|i | d S )Nz/etc/sysconfig/httpd)sysconfig_filepr   __init__)r"   rN   rO   r$   r&   r'   rQ   l   s   zCentOSParser.__init__c                    s   t    |   dS )z: Override for update_runtime_variables for custom parsing N)r   update_runtime_variablesparse_sysconfig_varr=   r$   r&   r'   rR   q   s   
z%CentOSParser.update_runtime_variablesc                 C   s.   t | jd}| D ]	\}}|| j|< qdS )z: Parses Apache CLI options from CentOS configuration file OPTIONSN)r   parse_define_filerP   items	variables)r"   defineskvr&   r&   r'   rS   w   s   z CentOSParser.parse_sysconfig_varrF   )	rG   rH   rI   rJ   r   rQ   rR   rS   rM   r&   r&   r$   r'   rC   j   s
    rC   )rJ   loggingtypingr   certbotr   r   certbot_apache._internalr   r   r   %certbot_apache._internal.configuratorr   	getLoggerrG   loggerApacheConfiguratorr	   ApacheParserrC   r&   r&   r&   r'   <module>   s    
[