Edit File: waf_rules_configurator.cpython-311.pyc
� P6h� � � � d Z ddlZddlmZ ddlmZ ddlmZ ddlm Z m Z ddlmZ ddlmZ dd lmZmZ dd lmZ ddlmZ ee� � ZdZd Z G d� de � � ZdS )z� A plugin responsible for periodically launching AppVersionDetector and optionally limiting ModSecurity rulesets for the sites that use various CMS. Currently it sets up and maintains a cron job to achieve this. � N)� getLogger)�SystemConfig)�MessageType)�MessageSink�expect)�Modsec)� web_server)� load_state� save_state)�HostingPanel)�try_restore_config_from_backupzK/opt/imunify360/venv/share/imunify360/scripts/update_components_versions.pyz/etc/cron.d/waf_configuratorc �R � e Zd Zd� Zd� Zd� Z eej � � d� � � Z dS )�WAFRuleSetConfiguratorc � �� K � t d� � � d� � | _ | j �| j t j k r't j | _ t � � � d {V �� d S d S �Nr �app_specific_ruleset)r �get�_app_specific_ruleset�Config�APP_SPECIFIC_RULESETr )�self�loops �Y/opt/imunify360/venv/lib/python3.11/site-packages/im360/plugins/waf_rules_configurator.py�create_sinkz"WAFRuleSetConfigurator.create_sink! s~ � � � �%/�0H�%I�%I�%M�%M�"�& � & ��"� �&�.��)�V�-H�H�H�)/�)D�D�&�0�2�2�2�2�2�2�2�2�2�2�2� I�H� c � �8 K � t dd| j i� � d S r )r r )r s r �shutdownzWAFRuleSetConfigurator.shutdown, s0 � � � ��$� #�T�%?�@� � � � � r c � �` K � t � � � � � }t j |� � }|j rWt |d� � � � � t j � � � d{V �� t � d� � dS dS # t t f$ r Y dS w xY w)z[ If app-specific httpd config exists and is not empty, truncate it �wNz%App specific ruleset config truncated) r �get_app_specific_waf_config�os�stat�st_size�open�closer �graceful_restart�logger�info�FileNotFoundError�NotImplementedError)r �config_path�sts r �_truncate_confz%WAFRuleSetConfigurator._truncate_conf2 s� � � � � E�&�.�.�D�D�F�F�K����%�%�B� �z� E��[�#�&�&�,�,�.�.�.� �1�3�3�3�3�3�3�3�3�3����C�D�D�D�D�D� E� E�� "�#6�7� � � ��D�D� ���s �4B �B-�,B-c � � K � t |d t � � r<t j }|| j k r'|| _ |s | � � � � d {V �� d S d S d S d S )N�conf)� isinstancer r r r r- )r �message�enableds r � truncate_confz$WAFRuleSetConfigurator.truncate_confB s� � � � ��g�f�o�|�4�4� 0��1�G��$�4�4�4�-4��*�� 0��-�-�/�/�/�/�/�/�/�/�/�/�/� 0� 0�4�4�0� 0r N) �__name__� __module__�__qualname__r r r- r r �ConfigUpdater3 � r r r r sm � � � � � � 3� 3� 3� � � �E� E� E� �V�K�$�%�%�0� 0� &�%�0� 0� 0r r )�__doc__r! �loggingr � defence360agent.contracts.configr �"defence360agent.contracts.messagesr �!defence360agent.contracts.pluginsr r �im360.contracts.configr r �defence360agent.subsysr �'defence360agent.subsys.persistent_stater r �!im360.subsys.panels.hosting_panelr �#im360.subsys.waf_rules_configuratorr r4 r'