PATH:
opt
/
imunify360
/
venv
/
lib
/
python3.11
/
site-packages
/
im360
/
model
/
__pycache__
� ��i� � � � d Z ddlZddlZddlmZmZ ddlmZ ddlm Z ej e� � ZdZ G d� d� � Z G d � d e� � ZdS )zb Global whitelist as it was initially defined by https://cloudlinux.atlassian.net/browse/DEF-2307 � N)�Iterable�List)�IntegrityError)�fileszimunify360.txtc �| � e Zd Zed� � � Zeddee fd�� � Zedd�de e fd�� � Z dS )�GlobalWhitelistc � � | t k S )z�Check if file file_name should be loaded. Do not load imunify360.txt as it will be loaded separately in GlobalImunifyWhitelist. ��IM360_FILE_NAME)� file_names �Q/opt/imunify360/venv/lib/python3.11/site-packages/im360/model/global_whitelist.py�_allow_load_from_filez%GlobalWhitelist._allow_load_from_file s � � �O�+�+� N�returnc � � K � t t � � } t j � t j � � 4 �d {V �� t j t j � � }|� � � D ]x}|�||� dg � � v r\| � |d � � rA|� | � |� |d � � � � � � �y d d d � � �d {V �� n# 1 �d {V ��swxY w Y nb# t t f$ r'}t � d|� � g cY d }~S d }~wt $ r t � d� � g cY S w xY wt% |� � S )N�groups�name�urlz#Failed to load global whitelist: %szFailed to load global whitelist)�set�strr �Index�locked� WHITELISTS�items�getr �update� _load_file� localfilepath�FileNotFoundErrorr �logger�error� Exception� exception�list)�cls�group�result�local_index�item�es r �loadzGlobalWhitelist.load s � � � ��S����� ��{�)�)�%�*:�;�;� � � � � � � � �#�k�%�*:�;�;��'�-�-�/�/� � �D��}��$�(�(�8�R�2H�2H�)H�)H��4�4�T�&�\�B�B� �"�M�M� #���$/�$=�$=�d�5�k�$J�$J�!"� !"�� � ��� � � � � � � � � � � � � � � � � � � � � � � ���� � � � ��� "�>�2� � � ��L�L�>��B�B�B��I�I�I�I�I�I������ � � ����>�?�?�?��I�I�I� ���� �F�|�|�sH �/D �B,D�9D � D�D �D�D �E<�.E� E<�)E<�;E<)� log_errorc # �� K � |�t j }t |� � 5 }t |� � D ]�\ }}|� d� � d � � � }|s�5 t j |� � }|j dk r|� d� � }|V � �o# t $ r} |d|||dz � � Y d}~��d}~ww xY w ddd� � dS # 1 swxY w Y dS )zu :param file: file path :param log_error: what logging method to use [default: logger.error] N�#r � z/32z%s in %s line %d� )r r! �open� enumerate� partition�strip� ipaddress� ip_network�version�removesuffix� ValueError)r% �filer, �f�lnr) �ipr* s r r zGlobalWhitelist._load_file1 sk � � � � ����I� �$�Z�Z� �1�%�a�L�L� � ���D��~�~�c�*�*�1�-�3�3�5�5��� �� �"�-�d�3�3�B��z�Q���#�0�0��7�7�� �J�J�J�J�� "� � � ��I�*����Q��� � � � � � � ��������� � � � � � � � � � � � � ���� � � � � � s<