/opt/imunify360/venv/lib/python3.11/site-packages/im360/subsys/__pycache__
� y��|�J�� �> � d dl Z d dlZd dlZd dlmZ d dlmZ d dlmZ d dl m Z mZmZ d dl mZmZ d dlmZ d dlmZ d d lmZ d dlmZ d dlmZ d d lmZ d dlmZmZ d dlm Z d dl!m"Z" ej# e$� � Z%dZ&dZ' G d� de(� � Z)de*fd�Z+d� Z,de*fd�Z-d� Z.dS )� N)�CancelledError)�Version)�Path)�BACKUP_EXTENSION� CheckRunError�atomic_rewrite)�MODSEC�Index)� web_server)�APACHE)�GenericPanel� )�map_components_versions_to_tags)�HostingPanel)�CorazaModSecurity)�safe_update_config�graceful_restart)�is_apache2nginx_enabled)�is_force_use_corazazD/var/lib/cloudlinux-app-version-detector/components_versions.sqlite3ztags_matching.jsonc � � e Zd ZdS )�NotSupportedWebserverErrorN)�__name__� __module__�__qualname__� � �X/opt/imunify360/venv/lib/python3.11/site-packages/im360/subsys/waf_rules_configurator.pyr r $ s � � � � � ��Dr r �returnc � � K � t � � } t � � st � � rdS | � � � � d{V ��}t | t � � r|t k S |t k rdS t j � � � d{V ��}t j � � � d{V ��}n=# t $ r � t $ r&}t � d|� � Y d}~dS d}~ww xY w|t d� � k od|v S )z�Apache >= 2.4 is supported and security2_module installed. - litespeed is not supported - nginx is not supported Apache is expected to be running, otherwise False is returned In case of any error, False is returned also TNFz-Error occurs while getting Apache version: %sz2.4s security2_module)r r r �get_web_server� isinstancer r r �apache_version�apache_modulesr � Exception�logger�errorr )�hp� webserver�version�modules�excs r �is_webserver_supportedr, ( s? � � � � ���B���� � 7� 9� 9� ��t��'�'�)�)�)�)�)�)�)�)�I��"�l�#�#� #� �F�"�"��F����u��"�1�3�3�3�3�3�3�3�3��"�1�3�3�3�3�3�3�3�3����� � � � �� � � ����D�c�J�J�J��u�u�u�u�u��������� �g�e�n�n�$�G�)<��)G�Gs �72B* �*C$�>C�C$c � �R K � t � � � d{V ��st d� � �t � � } t | � � � � � }t | t � � }t |� � }|� � � o|� � � |k }|sf|r0t ||d�� � rt � d� � dS dS t ||� � � d{V ��rt � d� � dS dS t � d� � dS )zO Update modsec config file with enabled tags for specific directories. NzkWAF rules configurator supports only apache webserver with version >= 2.4 or apache2nginx and ModSecurity 2F)�backupz2App specific rules config was successfully updatedz-WAF Rules Set Config was successfully updatedz*WAF Rules Set Config is already up to date)r, r r r �get_app_specific_waf_configr! r � _rules_config�exists� read_textr r% �infor )�panel�config_path� is_coraza� new_config�is_uptodates r �update_waf_rules_configr9 H so � � � � (�)�)�)�)�)�)�)�)� �(� ?� � � � �N�N�E��u�8�8�:�:�;�;�K� �5�"3�4�4�I��y�)�)�J� �����F��!6�!6�!8�!8�J�!F� � � B�� M� �k�:�e�D�D�D� ����H�� � � � � � � (��Z�@�@�@�@�@�@�@�@� M����K�L�L�L�L�L� M� M� ���@�A�A�A�A�Ar r6 c � � t j � t j t � � t � � }t |d�� � 5 }t j |� � }d d d � � n# 1 swxY w Y t t || � � S )Nzutf-8)�encoding)�os�path�joinr � files_pathr �MAPPING_FILE�open�json�loadr �COMPONENTS_VERSION_DB)r6 �mapping_path�f�tagss r r0 r0 n s� � ��7�<�<�� 0�� 8� 8�,�G�G�L� �l�W� -� -� -� ���y��|�|��� � � � � � � � � � ���� � � � �*��t�Y�� � s �A/�/A3�6A3c � �| K � t � � � � � } n# t $ r Y dS w xY wt j � | t z � � r_t j | t z | � � t � � � d{V �� dS # t $ r t � d� � Y dS w xY wdS )uI In case if Agent starts and config backup is present — then it is required to restore it: original .conf files must be replaced by the backup file and then WS restart command must be applied. In this case we assume that backed up configuration file is correct and none config checks are performed. Nz2Web server failed to start with a backed up config)r r/ �NotImplementedErrorr<