/opt/imunify360/venv/lib/python3.11/site-packages/im360/plugins/__pycache__
� ���� � � � d dl Z d dlZd dlZd dlmZ d dlmZ d dlmZ d dl m Z d dlmZ d dl mZ d dlmZ d d lmZ ej e� � Z G d � de � � ZdS )� N)�Path)�ensure_line_in_file_bytes)�files)�IDSAwareMessageSink)�strategy)�send_to_socket)�RULES_CHECK_IN_PROGRESS)�csfc �L � e Zd Zej j ZdZd� Zd� Z de defd�Zd� Z dS ) �ExportWBListFc � � K � || _ d S )N)�_loop)�self�loops �P/opt/imunify360/venv/lib/python3.11/site-packages/im360/plugins/export_wblist.py�create_sinkzExportWBList.create_sink s � � � ��� � � � c �� � t t j � � � � � r&t � d� � t j S t � d� � t j S )a@ Determine which CSF post-hook script to use based on priority rules: - If /usr/local/csf/bin/csfpost.sh exists, use it (higher priority) - Otherwise use /etc/csf/csfpost.sh - Preserve any custom content from either script Returns path to the script that should be used. z7Using /usr/local/csf/bin/csfpost.sh as post-hook scriptz-Using /etc/csf/csfpost.sh as post-hook script)r r �CSF_POST_HOOK_SCRIPT_USR_LOCAL�exists�logger�info�CSF_POST_HOOK_SCRIPT_ETC)r s r �_determine_csf_post_hook_scriptz,ExportWBList._determine_csf_post_hook_script sc � � ��2�3�3�:�:�<�<� 0��K�K�I� � � � �5�5��K�K�G�H�H�H��/�/r �script_path�returnc � � t |� � }|j � dd�� � |� � � sM|� dt j � d� � � d�� � |� d� � dS |� � � }t j |v r\|� t j t j � � }|� |� � t � d|� � dS t |t j � � }|rt � d|� � |S ) a Preserve custom content in the CSF post-hook script by ensuring our IPSET_RESTORE_SCRIPT is added without removing other content. Handles upgrade from legacy rules_checker.py to the new ipset_sync.py RPC script. T)�parents�exist_okz #!/bin/sh �utf8� i� z*Replaced legacy ipset restore script in %sz%Added command to restore ipsets to %s)r �parent�mkdirr � write_textr �IPSET_RESTORE_SCRIPT�decode�chmod� read_bytes�IPSET_RESTORE_SCRIPT_LEGACY�replace�write_bytesr r r )r r �script�content�ipset_line_addeds r �_preserve_custom_contentz%ExportWBList._preserve_custom_content* sA � � �k�"�"��� ���D�4��8�8�8��}�}��� ����I�c�6�=�=�f�E�E�I�I�I� � � � �L�L������4��#�#�%�%���*�g�5�5��o�o��/��(�� �G� ���w�'�'�'��K�K�<�k� � � � �4�4���$� � �� � N��K�K�?��M�M�M��r c � �H K � t j � t j � � }t j � |d� � } t t j dt j |� � z � � }|rt � d� � | � � � }| � |� � }|s|r�t � d� � t j � � r-t# j d� � � d{V �� t j � � �-t j � � � d{V �� t) ddid � � � � d{V �� | � � � dS # t"