PATH:
opt
/
imunify360
/
venv
/
lib
/
python3.11
/
site-packages
/
defence360agent
/
wordpress
/
__pycache__
/
Editing: changelog_processor.cpython-311.pyc
� ���i�0 � �� � d Z ddlZddlZddlZddlmZ ddlmZ ddlm Z ddl mZmZ ddl mZ ddlmZ dd lmZ dd lmZ ddlmZ ej e� � ZdZd ZdZdZ G d� d� � ZdS )a� Processor for WordPress rule disable/enable changelog files. The PHP WordPress plugin writes rule change actions to changelog.php when a user disables or enables protection rules from the WordPress admin panel. This module reads, parses, and applies those actions to the agent database. The changelog.php file uses the same format as incident files: <?php __halt_compiler(); #{base64-encoded JSON for action 1} #{base64-encoded JSON for action 2} Each JSON action has the form: {"action": "disable"|"enable", "rule_id": "xyz", "ts": ...} The user_id stored with each action is the system UID of the WordPress site owner (site.uid). � N)�Path)�MessageType)�MessageSink)�WPSite� WordpressSite)�WPDisabledRule)� open_nofollow)�get_data_dir)�IncidentFileParser)�parse_php_with_embedded_jsonz changelog.phpzdisabled-rules.php�disable�enablec �t � e Zd ZdZdd�Zdee dedz dee fd�Zdededz de fd �Z d ededee fd�Z d edededz de fd�Zd ededede fd�Zedededz fd�� � Zedededede fd�� � Zdedede fd�Zed edededz deddf d�� � Zededede fd�� � ZdS )�ChangelogProcessora� Process WordPress rule disable/enable changelog files. Reads changelog.php from each site's data directory, applies disable/enable actions to the WPDisabledRule database, reports events to the correlation server, and deletes the file after processing. If no changelog exists (or no new entries), checks whether disabled-rules.php has been modified externally (e.g. backup restore) and flags the domain for regeneration. �returnNc �, � t � � | _ d S )N)r �parser)�selfs �b/opt/imunify360/venv/lib/python3.11/site-packages/defence360agent/wordpress/changelog_processor.py�__init__zChangelogProcessor.__init__6 s � � )�*�*����� �sites�sinkc � �� K � g }|D ]3}| � ||� � � d{V ��r|� |� � �4|r(t � dt |� � � � |S )a- Process changelog.php for all given sites. Args: sites: WordPress sites to process. sink: MessageSink for sending correlation events. Returns: Sites whose disabled rules were affected (needing disabled-rules.php regeneration). Nz(Changelog processing affected %d site(s))� _process_site�append�logger�info�len)r r r �affected�sites r �process_changelogs_for_sitesz/ChangelogProcessor.process_changelogs_for_sites; s� � � � � "$��� &� &�D��'�'��d�3�3�3�3�3�3�3�3� &�����%�%�%��� ��K�K�:��H� � � � � � �r r! c � �~ K � t |� � � d{V ��}|� � � sdS |t z }|� � � r| � |||� � � d{V ��rdS | � ||� � rdS n8# t $ r+}t � d|j |� � Y d}~nd}~ww xY wdS )z�Process changelog.php for a single site. Args: site: WordPress site to process. sink: MessageSink for sending correlation events. Returns: True if the site's disabled rules were affected. NFTz*Error processing changelog for site %s: %s) r �exists�CHANGELOG_FILENAME�_process_changelog_file�_is_disabled_rules_file_stale� Exceptionr �error�docroot)r r! r �data_dir�changelog_path�es r r z ChangelogProcessor._process_siteX s( � � � � �)�$�/�/�/�/�/�/�/�/�H��?�?�$�$� ��u�%�(:�:�N��$�$�&�&� ��5�5�"�D�$�� � � � � � � � � �4��1�1�$��A�A� ��t� �� � � � ��L�L�<���� � � � � � � � ����� ���� �us"