
    M/e\                         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j                  e      Z G d
 de	j                         Z G d de
j$                        Zy)zG Distribution specific override class for CentOS family (RHEL, Fedora)     N)Any)errors)util)apache_util)configurator)parser)	OsOptionsc                        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      Zd fdZdefdZd fdZ	d fdZ
ddZ x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returnc                     t        j                         }|d   j                         dk(  }	 t        |           y# t
        j                  $ r |r| j                          Y y w xY 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__s      J/usr/lib/python3/dist-packages/certbot_apache/_internal/override_centos.pyr"   zCentOSConfigurator.config_test    sa     ""$!!#x/	G!++ 	((*		s   < %A%#A%c                     t        j                         \  }}|dv }|syt        j                  |      t        j                  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_v9s        r(   _rhel9_or_newerz"CentOSConfigurator._rhel9_or_newer3   sS    "..0 #
 
 ..z:d>V>VWZ>[[    c                    t         |           | j                         r| 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                  st        d      | j                  j                  | j                  j                  d<   y )Nz+OS option apache_bin must be set for CentOSr   z1OS option restart_cmd_alt must be set for CentOS.)r!   _override_cmdsr7   optionsbin
ValueErrorr   get_modules_cmdget_includes_cmdget_defines_cmdr   r   r%   r'   s    r(   r:   z!CentOSConfigurator._override_cmdsD   s     
 !<<## !NOO*.,,*:*:DLL$$Q'.2ll.>.>DLL((+/3||/?/?DLL))!,.2ll.>.>DLL((+||++PQQ*.,,*:*:$$Q'r8   c                     	 t        j                  g d       t        |           y# t        j                  $ r#}t        j                  t        |            d}~ww xY w)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'   s     r(   r$   z&CentOSConfigurator._try_restart_fedoraW   sO    
	9OO=>
 		 %% 	9..s3x88	9s   ) AAAc                     t        | j                  j                  | | j                  j                  | j                        S )zInitializes the ApacheParser)CentOSParserr;   r   r   version)r%   s    r(   
get_parserzCentOSConfigurator.get_parserd   s2    LL$$dDLL,C,CT\\S 	Sr8   r   N)r   rI   )__name__
__module____qualname____doc__r	   OS_DEFAULTSr"   boolr7   r:   r$   rK   __classcell__r'   s   @r(   r   r      sf    ; &" $' *-$i0!<0.K& ";&Sr8   r   c                   D     e Zd ZdZdededdf fdZd	 fdZd	dZ xZS )
rI   z+CentOS specific ApacheParser override classargskwargsr   Nc                 2    d| _         t        |   |i | y )Nz/etc/sysconfig/httpd)sysconfig_filepr!   __init__)r%   rV   rW   r'   s      r(   rZ   zCentOSParser.__init__l   s    $:$)&)r8   c                 B    t         |           | j                          y)z: Override for update_runtime_variables for custom parsing N)r!   update_runtime_variablesparse_sysconfig_varrA   s    r(   r\   z%CentOSParser.update_runtime_variablesq   s     	(*  "r8   c                     t        j                  | j                  d      }|j                         D ]  \  }}|| j                  |<    y)z: Parses Apache CLI options from CentOS configuration file OPTIONSN)r   parse_define_filerY   items	variables)r%   defineskvs       r(   r]   z CentOSParser.parse_sysconfig_varw   sA    //0D0DiPMMO 	"DAq !DNN1	"r8   rL   )	rM   rN   rO   rP   r   rZ   r\   r]   rS   rT   s   @r(   rI   rI   j   s*    5*c *S *T *
#"r8   rI   )rP   loggingtypingr   certbotr   r   certbot_apache._internalr   r   r   %certbot_apache._internal.configuratorr	   	getLoggerrM   loggerApacheConfiguratorr   ApacheParserrI    r8   r(   <module>rp      s[    M     0 1 + ;			8	$XS88 XSv"6&& "r8   