File: //usr/local/CyberCP/plogical/__pycache__/modSec.cpython-310.pyc
o
��h�j � @ s� d dl Z e j�d� d dlmZ d dlZd dlZd dlZd dl m
Z
d dlZd dlZd dl
Z
d dlmZ d dlmZ d dlmZ G dd � d �Zd
d� ZedkrTe� dS dS )
� Nz/usr/local/CyberCP)�CyberCPLogFileWriter)�virtualHostUtilities)�
mailUtilities)�ProcessUtilities)�installUtilitiesc @ s� e Zd ZdZdZdZedd� �Zedd� �Zedd � �Z ed
d� �Z
edd
� �Zedd� �Zedd� �Z
edd� �Zedd� �Zedd� �Zedd� �Zedd� �ZdS )�modSecz!/home/cyberpanel/modSecInstallLogz /home/cyberpanel/tempModSecRuleszcyberpanel.netc
C s
zgt �� t�� tjkst�� tjkrd} nd} t�| �}tt j
d��}tj||d�}W d � n1 s5w Y |dkrVtt j
d�}|�
d� |�� tj�d� W d S tt j
d�}|�
d
� |�� W dS ty� } ztj�t|�d � W Y d }~d S d }~ww )Nz#sudo yum install ols-modsecurity -yzFsudo DEBIAN_FRONTEND=noninteractive apt-get install ols-modsecurity -y�w)�stdout� �azCan not be installed.[404]
z[Could not Install]r zModSecurity Installed.[200]
z[installModSec])r � checkHomer �decideDistro�centos�cent8�shlex�split�openr �installLogPath�
subprocess�call�
writelines�close�loggingr �writeToFile�
BaseException�str)�command�cmd�f�resr �msg� r! �%/usr/local/CyberCP/plogical/modSec.py�
installModSec s.
�
"��zmodSec.installModSecc
C s: zwt j�tjd�} zt �| � W n
tj�d� Y d}t j�tjd�}t |��
� }|�� d}|D ]
}|�d�dkr@d} nq3|dkrSt |d �}|�
|� |�� t j�tjd
�}t j�|�sqd}t |d �} | �
|� | �� td� W d S ty� }
ztj�t|
�d
� tdt|
� � W Y d }
~
d S d }
~
ww )N�conf/modseczCModSecurity rules directory already exists. [installModSecConfigs]ag
module mod_security {
modsecurity on
modsecurity_rules `
SecDebugLogLevel 0
SecDebugLog /usr/local/lsws/logs/modsec.log
SecAuditEngine on
SecAuditLogRelevantStatus "^(?:5|4(?!04))"
SecAuditLogParts AFH
SecAuditLogType Serial
SecAuditLog /usr/local/lsws/logs/auditmodsec.log
SecRuleEngine On
`
modsecurity_rules_file /usr/local/lsws/conf/modsec/rules.conf
}
�conf/httpd_config.confFzmodule mod_security���Tza+�conf/modsec/rules.confzdSecRule ARGS "\.\./" "t:normalisePathWin,id:99999,severity:4,msg:'Drive Access' ,log,auditlog,deny"
�1,Nonez [installModSecConfigs]�0,)�os�path�joinr �Server_root�mkdirr r r r � readlines�reverse�find�writer �exists�printr r )r+ �initialConfigs�confFile�confData�modSecConfigFlag�items�conf�
rulesFilePath�initialRules�ruler r! r! r"