
­­­­­­­­­­­­­­­­­­
<!DOCTYPE html>
<html>
3
{j5                 @   s   d dl Z d dlmZ dd ZG dd dZG dd dZd	d
 Zdd ZG dd dZG dd dZ	G dd de	Z
G dd de	ZG dd de	ZG dd de	ZG dd de	ZG dd de	ZG dd de	Zdd  Zd!d" Zd#d$ ZdS )%    N)versionc             C   s   t j| }|j S )N)ospopenread)strZhandle r   //usr/share/lve/modlscapi/user/lve_diagnostic.pymyExec   s    
r	   c               @   s(   e Zd ZdZdZdZdZdZdd ZdS )	LiteSpeedFUnknownc             C   s^   t jjd| _t jjdrZttdjddkrZd| _dtdk| _d	td
k| _td}d S )Nz/usr/local/lswsz/usr/local/lsws/bin/litespeedzps aux|grep litespeed
   T1z4grep enableLVE /usr/local/lsws/conf/httpd_config.xml0z$grep -i phpSuexec\> httpd_config.xmlz%file -L /usr/local/lsws/bin/litespeed)	r   pathisfileexistlenr	   splitlvesuexec)selfZarchr   r   r   __init__   s    "zLiteSpeed.__init__N)	__name__
__module____qualname__r   r   r   r   ZcorrectArchr   r   r   r   r   r
      s   r
   c               @   st   e Zd ZdZdZdZdZdZdZdZ	dZ
dZdZdZdZdZdZdd Zdd Zdd Zd	d
 Zdd Zdd ZdS )
ApacheInfoFr   c             C   s   | j | d S )N)detect)r   r   r   r   r   r   8   s    zApacheInfo.__init__c             C   s2   t j| j t jdkrdS tdd| jj  dS d S )Nz2.2.0Ti  z=Unable to determine list of loaded modules, apache version %sF)r   LooseVersionprint_warningapache)r   r   r   r   check_version;   s    zApacheInfo.check_versionc             C   s   t | jjd| d dkS )N _moduler   )r   modulesfind)r   namer   r   r   isModuleB   s    zApacheInfo.isModulec             C   sv   | j rr| jd| _| jd| _| jd| _| jd| _| jd| _| jd| _| jd| _| jd| _	| jd	| _
d S )
NhostinglimitsfcgidZphp5cgicgidsuPHPfastcgidisable_suexecr   )
moduleInfor(   r)   r*   php_dsor+   r,   r-   r.   r/   r   )r   r   r   r   parseModulesE   s    zApacheInfo.parseModulesc             C   sH  t jj|| _| jrDt|d }|jddkrd }x.|jdD ] }|jddkr@|jdd}P q@W |d k	rtd| d | d	  t|d }|d k	rtd| d
 |  |jd}xX|D ]P}|jddkr||jdd d  | _|jddkr||j	dd d  | _
qW tj| jtjdkrDd| _t|d | _| j  d S )Nz -V 2>&1zSyntax errorr   r"   z
lsapi.conf: zmv z.SAVEz.SAVE r   zServer version:r   /zServer MPM:z2.2Tz -M 2>&1r$   r$   )r   r   r   r   r	   r&   r   replacer   rfindmpmr   r0   r%   r2   )r   r   tmpZ
lsapi_confslinesliner   r   r   r   Q   s0    

zApacheInfo.detectc             C   s   | j rxd| j d | j d | j d | j d | j d | j d | j d | j d	 | j	 d
 | j
 d | j }|S d S d S )NzApache verion: z, mpm=z, hostinglimits=z, cgi=z, cgid=z, fcgi=z
, fastcgi=z
, php DSO=z, suphp=z	, suexec=z, disable_suexec=)r   r   r8   r)   r+   r,   r*   r.   r1   r-   r   r/   )r   r   r   r   r   r   k   s    nzApacheInfo.strN)r   r   r   r   r   r8   r)   r*   r+   r1   r,   r-   r.   r/   r   r0   r%   r   r!   r(   r2   r   r   r   r   r   r   r   (   s(   r   c             C   s$   t d|  t ||  t d| d S )NzCODE: z
Solution: )print)code	error_str
error_listZsolutionr   r   r   print_errorz   s    
rA   c             C   s   t d|  t ||  d S )Nz	WARNING: )r=   )r>   r?   r@   r   r   r   r      s    
r   c               @   s4   e Zd ZdZdZdZdZdd Zdd Zdd Z	dS )	KernelNFc             C   s^   t djd| _| jjd| _| jdkrN| j| jd d  | _tjjd| _	nd| jk| _
d S )	Nz/bin/uname -rr   r   r      z/proc/lve/listZstabr$   )r	   rstrip
kernelNamer&   isLVEKernelr   r   r   r   isLVEEnabled
isVZKernel)r   r   r   r   r      s    
zKernel.__init__c             C   s   | j r| j rtj| jtjdkr&dS tj| jtjdkrNtdd| jd qtj| jtjdkrvtdd	| jd qtd
d| jd qtddf d n&| jrtddf d ntdd| jd d S )Nz0.8.28Tz0.8.0i  z*You are running bugy kernel LVE version %szUpgrade Kernelz0.7.0i  zoYou are running old kernel LVE version %s
 That version doesn't support multiple cores per LVE or memory limitsi  z5You are running very old, bugy kernel, LVE version %si  zLVE is not enabledzACheck /etc/sysconfig/lve file, and make sure lve rpm is installediM  zYou are running VZ or OpenVZzWCloudLinux is not compatible, see http://www.cloudlinux.com/vz-compat.php for more infoi  z9You are not running CloudLinux kernel. Your kernel is: %szCheck /boot/grub/grub.conf)rG   r   r   rA   rH   )r   r   r   r   check   s$    
zKernel.checkc             C   sN   d}| j r|d| j d 7 }n,| jr8|d| j d 7 }n|d| j d 7 }|S )NzKernel: zOK ()zVZ (z	Unknown ()rG   r   rH   rE   )r   resultr   r   r   r      s    z
Kernel.str)
r   r   r   r   rF   rH   rG   r   rI   r   r   r   r   r   rB      s   	rB   c               @   s8   e Zd ZdZdZdZdd Zdd Zdd	 Zd
d Z	dS )CPz
Unknown CPr   Nc             C   s   t d| _d| _t | _d S )Nz/usr/sbin/apachectlz
/etc/httpd)r   r    apache_pathrB   kernel)r   r   r   r   r      s    
zCP.__init__c             C   s   | j d | j d | jj  S )Nr"   )r'   r   rN   r   )r   r   r   r   r      s    zCP.strc             C   s   | j S )N)r'   )r   r   r   r   __str__   s    z
CP.__str__c             C   s   | j j  d S )N)rN   rI   )r   r   r   r   rI      s    zCP.check)
r   r   r   r'   r   rN   r   r   rO   rI   r   r   r   r   rL      s   rL   c                   s(   e Zd ZdZ fddZdd Z  ZS )CPanelcPanelc                sL   t t| j  td| _td| _tjj	dr<d| _
d| _nd| _
d| _d S )Nz/usr/local/cpanel/cpanel -Vz/usr/local/bin/apachectlz/etc/cpanel/ea4/is_ea4ZEA4z/etc/apache2ZEA3z/usr/local/apache)superrP   r   r	   r   r   r    r   r   existsearM   )r   )	__class__r   r   r      s    

zCPanel.__init__c             C   s   | j S )N)rT   )r   r   r   r   rO      s    zCPanel.__str__)r   r   r   r'   r   rO   __classcell__r   r   )rU   r   rP      s   rP   c                   s    e Zd Zd Z fddZ  ZS )Pleskc                s4   t t| j  td}|jdd | _td| _d S )Nz/bin/cat /usr/local/psa/versionr"   r   z/usr/sbin/apachectl)rR   rW   r   r	   r   r   r   r    )r   r9   )rU   r   r   r      s    zPlesk.__init__)r   r   r   r'   r   rV   r   r   )rU   r   rW      s   rW   c                   s    e Zd Zd Z fddZ  ZS )DirectAdminc                sf   t t| j  td}|jd}d| _td| _x0|D ](}|jddkr6|jdd j	 | _P q6W d S )	Nz1/usr/local/directadmin/custombuild/build versionsr   r   z/usr/sbin/apachectlz!Installed version of DirectAdmin:r   r3   r$   )
rR   rX   r   r	   r   r   r   r    r&   strip)r   r9   item)rU   r   r   r      s    


zDirectAdmin.__init__)r   r   r   r'   r   rV   r   r   )rU   r   rX      s   rX   c                   s(   e Zd ZdZ fddZdd Z  ZS )HSpherezH-Spherec                s8   t t| j  td}|jdd j | _| j | _d S )NzA/bin/cat /hsphere/local/home/cpanel/shiva/psoft_config/HS_VERSIONr   r   )	rR   r[   r   r	   r   rY   r   get_apache_typer    )r   r9   )rU   r   r   r      s    zHSphere.__init__c             C   s~   t jjdrvtd}|j }|j  xP|D ]H}|jdd j }|jdd j }|dkr*|dkrjtdS tdS q*W td	S )
Nz#/hsphere/shared/scripts/scripts.cfg=r   r   Zapache_versionr   z /hsphere/shared/apache/bin/httpdz%/hsphere/shared/apache2/bin/apachectlr4   )	r   r   r   open	readlinescloser   rY   r   )r   fr;   rZ   keyvaluer   r   r   r\      s    
zHSphere.get_apache_type)r   r   r   r'   r   r\   rV   r   r   )rU   r   r[      s   r[   c                   s(   e Zd ZdZ fddZdd Z  ZS )iWorx	InterWorxc                s,   t t| j  d| _| j | _td| _d S )Nz/usr/local/interworx/iworx.iniz/usr/sbin/apachectl)rR   rd   r   ini_filefind_versionr   r   r    )r   )rU   r   r   r     s    
ziWorx.__init__c             C   sj   yPt | jd}|j }W d Q R X |jdd jddjddjddjdd	 S  tk
rd   d S X d S )
Nrr      r   r4   r]   "[r   )r^   rf   r   r   r6   	Exception)r   Zini_infooutr   r   r   rg     s    0ziWorx.find_version)r   r   r   r'   r   rg   rV   r   r   )rU   r   rd   
  s   rd   c                   s    e Zd ZdZ fddZ  ZS )ISPMgr
ISPManagerc                s"   t t| j  d| _td| _d S )NZunkz/usr/sbin/apachectl)rR   rn   r   r   r   r    )r   )rU   r   r   r     s    zISPMgr.__init__)r   r   r   r'   r   rV   r   r   )rU   r   rn     s   rn   c                   s0   e Zd Zd Z fddZdd Zdd Z  ZS )CustomPanelc                s&   t t| j  | j  d| _d | _d S )Nz /usr/share/lve/modlscapi/custom/)rR   rp   r   config_readerroot_dirr    )r   )rU   r   r   r   %  s    zCustomPanel.__init__c             C   s   ddl }|j }|j| jd  |d }| j| |jd| _|jd| _|jd| _|jd| _	|jd	| _
| jrt| j| _dS )
zRead all configurations related to Custom Panel from config.ini in the 'root_dir' folder.
        config.ini file must include GLOBAL section.
        r   Nz
config.iniZGLOBALVERSIONZAPACHECTL_BIN_LOCATIONZDOC_URLZEXECUTABLE_BINZ
PANEL_NAME)configparserConfigParserr   rr   check_config_inigetr   Z	apachectldoc_url
executable
panel_namer   r    )r   rt   config	cp_configr   r   r   rq   +  s    
zCustomPanel.config_readerc             C   sV   dddddg}g }x$|D ]}|j |d kr|j| qW |rRtd|  td d S )Nr   Zapachectl_bin_locationrx   Zexecutable_binrz   z&Config file is missing required keys: r   )rw   appendr=   exit)r   r|   Zrequired_keysZmissing_keysrb   r   r   r   rv   >  s    
zCustomPanel.check_config_ini)r   r   r   r'   r   rq   rv   rV   r   r   )rU   r   rp   #  s   rp   c               C   s   t jjdrtS t jjdr tS t jjdr<t jjdr<tS t jjdrLtS t jjdr\tS t jjdrlt	S t jjdr|t
S tS )	Nz/usr/local/cpanel/cpanelz/usr/local/psa/versionz/usr/local/directadminz(/usr/local/directadmin/custombuild/buildz8/hsphere/local/home/cpanel/shiva/psoft_config/HS_VERSIONz/usr/local/ispmgrz/usr/local/interworx/iworx.iniz*/usr/share/lve/modlscapi/custom/config.ini)r   r   r   rP   rW   isdirrX   r[   rn   rd   rp   rL   r   r   r   r   _get_cp_classL  s    r   c               C   s   t  jS )a  
    Call this when you only need to detect Control Panel type, and don't need its complete properties.

    The function avoids creating an instance of CP successor class.
    This is safer for calling from installation scriptlets, when the system state can be inconsistent -
    because instance initialization tries to collect much more info than _get_cp_class().
    For example, 'apachectl' utility, used to gather server attributes into 'apache' instance variable,
    can fail half-way 'mod_lsapi' post-installation. Specifically:
    when the upgrade brings a non-backward compatible change of 'mod_lsapi.so'<->'liblscapi.so' binary interface,
    at the moment when we have 'liblscapi.so' already updated,
    but the new 'mod_lsapi.so' not yet copied into the Apache modules directory,
    'apachectl' would fail due to unloadable modules, print errors instead of Apache properties,
    and eventually produce installation failure.
    See CLOS-3184.
    )r   r'   r   r   r   r   get_cp_name]  s    r   c               C   s   t   S )z
    Call this when you want full Control Panel properties, not only its type.

    Properties can fail to be obtained, or be invalid, in intermediate machine state, like half-installed 'mod_lsapi'.
    See CLOS-3184.
    )r   r   r   r   r   get_cpo  s    r   )r   Z	distutilsr   r	   r
   r   rA   r   rB   rL   rP   rW   rX   r[   rd   rn   rp   r   r   r   r   r   r   r   <module>   s$   R1	)