File manager - Edit - /opt/imunify360/venv/lib/python3.11/site-packages/defence360agent/wordpress/__pycache__/incident_parser.cpython-311.pyc
Back
� tsiG � �h � d Z ddlZddlZddlZddlmZ ej e� � Z G d� d� � Z dS )z+Parser for WordPress plugin incident files.� N)�Pathc � � e Zd ZdZededee fd�� � Zede de dededz fd�� � Zed e de dededz fd �� � ZdS )�IncidentFileParsera' Parse incident files written by the WordPress plugin. These files have format: <?php __halt_compiler(); #{base64-encoded JSON data for incident} #{base64-encoded JSON data for incident} ... File pattern: wp-content/imunify-security/incidents/yyyy-mm-dd-hh.php � file_path�returnc �~ � g } t |dd�� � 5 }t |d� � D ]G\ }}|� � � }| � |||� � }|�|� |� � �H ddd� � n# 1 swxY w Y n5# t $ r(}t � d||� � g cY d}~S d}~ww xY w|S )aS Parse an incident file and return list of incident dictionaries. The file format is: - First line: <?php __halt_compiler(); - Following lines: #{base64-encoded JSON} Args: file_path: Path to the incident file Returns: List of parsed incident dictionaries �r�utf-8)�encoding� Nz"Error reading incident file %s: %s)�open� enumerate�strip� _process_line�append� Exception�logger�error)�clsr � incidents�f�line_num�line�incident�es �^/opt/imunify360/venv/lib/python3.11/site-packages/defence360agent/wordpress/incident_parser.py� parse_filezIncidentFileParser.parse_file s. � � � � ��i��w�7�7�7� 3�1�&/��1�o�o� 3� 3�N�H�d��:�:�<�<�D�"�0�0��x��K�K�H��+�!�(�(��2�2�2��3� 3� 3� 3� 3� 3� 3� 3� 3� 3� 3� 3���� 3� 3� 3� 3��� � � � ��L�L�4��� � � � �I�I�I�I�I�I����� ���� �sA �B �AA<�0B �<B � B �B �B � B:�B5�/B:�5B:r r Nc �> � |sdS |� d� � r#t � d||j � � dS |� d� � s,t � d||j |dd� � � dS |dd� }| � |||� � S )aD Process a single line from an incident file. Args: line: The line content (already stripped) line_num: Line number for logging file_path: Path to the file being processed Returns: Parsed incident dictionary or None if line should be skipped Nz<?phpz!Skipping PHP header line %d in %s�#z&Line %d in %s doesn't start with #: %s�2 r )� startswithr �debug�name�_process_encoded_line)r r r r �encoded_datas r r z IncidentFileParser._process_line<