🔐 Sid Gifari File Manager Pro
v8.0.5 | 2026-06-17 09:02:12 | PHP 8.1.34
📂
/ (Root)
/
opt
/
imunify360
/
venv
/
lib
/
python3.11
/
site-packages
/
defence360agent
/
plugins
/
__pycache__
📍 /opt/imunify360/venv/lib/python3.11/site-packages/defence360agent/plugins/__pycache__
🔄 Refresh
✏️
Editing: feature_flags.cpython-311.pyc
Read Only
� h"甧� � � d Z ddlZddlZddlZddlZddlZddlZddlm Z ddl mZ ddlm Z mZmZmZmZmZmZ ddlmZmZ ddlmZmZ ej e� � ZdZd ed edefd�Z e d d� � Z!dZ"dZ#dZ$ G d� de� � Z%dS )u3 Feature flags synchronisation plugin (AV mode only). In IM360 mode the Go resident-agent handles feature-flag sync. In AV mode there is no resident-agent, so this plugin takes over. Periodically POSTs the local file checksum to the API and writes back any updated flags to ``/var/imunify360/feature_flags.json`` (legacy map ``{flag: true}`` on disk) and ``/var/imunify360/feature_flags`` (plain names, one per line). The POSTed checksum is over the canonical JSON **array** of enabled names, matching the correlation sync API—not over the on-disk map bytes. � N)�Core)� MessageSource)� FLAGS_PATH�FLAGS_PLAIN_PATH�enabled_flag_names_sorted�legacy_feature_flags_map_bytes�$plain_text_payload_for_enabled_flags�$serialize_feature_flags_file_payload�!sync_checksum_hex_from_flags_file)�IAIDTokenError�IndependentAgentIDAPI)�Scope�atomic_rewritez/api/sync/v1/feature-flags�name�default�returnc �� � t j � | � � }|s|S t |� � S # t $ r" t � d| ||� � |cY S w xY w)u� Read an int env var tolerantly. A non-numeric value (empty string, typo, etc.) must NOT raise at import time — the plugin lives in the AV agent entry point and a bad env var would otherwise kill the whole agent. z4feature-flags: %s=%r is not an int, using default %d)�os�environ�get�int� ValueError�logger�warning)r r �raws �Z/opt/imunify360/venv/lib/python3.11/site-packages/defence360agent/plugins/feature_flags.py�_env_intr + s| � � �*�.�.�� � �C�� ��� ��3�x�x���� � � ����B���� � � � �������s �4 �)A �A �$I360_FEATURE_FLAGS_SYNC_INTERVAL_SECi � � c � � e Zd Zej Zd� Zd� Zdefd�Z d� Z defd�Ze dej j defd�� � Ze dd �� � Zd S )�FeatureFlagsSyncc � �~ K � || _ || _ |� | � � � � � | _ d S �N)�_loop�_sink�create_task� _sync_loop�_task)�self�loop�sinks r � create_sourcezFeatureFlagsSync.create_sourceJ s7 � � � ��� ��� ��%�%�d�o�o�&7�&7�8�8�� � � � c � � K � | j �?| j � � � | j � d {V �� d S # t j $ r Y d S w xY wd S r$ )r) �cancel�asyncio�CancelledError�r* s r �shutdownzFeatureFlagsSync.shutdownO st � � � ��:�!��J������ ��j� � � � � � � � � ���)� � � ���� ���� "�!s � 3 �A�Ar c �* � t t � � S r$ )r r r3 s r �_local_checksumz FeatureFlagsSync._local_checksumW s � �0��<�<�<r. c � �| K � t j t � � � d {V �� t } t j � � st }n!| � � � � d {V ��pt }n;# t j $ r � t $ r t � dd�� � Y nw xY wt j |� � � d {V �� ��)NTzfeature flags sync failed��exc_info)r1 �sleep�_INITIAL_DELAY�_SYNC_INTERVALr � is_registered�_UNREGISTERED_DELAY�_do_syncr2 � Exceptionr r )r* �delays r r( zFeatureFlagsSync._sync_loopZ s� � � � ��m�N�+�+�+�+�+�+�+�+�+� '�"�E� K�,�:�<�<� D�/�E�E�"&�-�-�/�/�1�1�1�1�1�1�C�^�E����)� � � ��� K� K� K����:�T��J�J�J�J�J� K�����-��&�&�&�&�&�&�&�&�&� 's �<A( �(5B �B c � � K � t j � � � d {V ��}n+# t $ r t � d� � Y dS w xY wt j � � }|� d | j � � � d {V ��}t j d|i� � � � � }t j � d� � t z }t j � ||d|d�d�� � } |� d | j |� � � d {V ��}n�# t j j $ rq}d |j cxk rd k r-n n*t � d|j ||j |�� � n't � d|j ||j � � Y d }~dS d }~wt j j $ r,}t � d ||j � � Y d }~dS d }~wt2 $ r! t � d|d�� � Y dS w xY w t j |� � } n0# t j $ r t � d� � Y dS w xY w| � dd� � } | � d� � du rt � d� � | S | � d� � }|�"|� d | j |� � � d {V �� | S )Nz*no IAID token, skipping feature flags syncr �checksum�/zapplication/json)zContent-TypezX-Auth�POST)�data�headers�methodi� iX z$feature flags sync HTTP %s on %s: %sr8 z.feature flags sync connection failed on %s: %sz'feature flags sync request failed on %sTz&failed to parse feature flags responserA �changedFz'feature flags unchanged, skipping write�flags)r � get_tokenr r r r1 �get_event_loop�run_in_executorr6 �json�dumps�encoder �API_BASE_URL�rstrip� _SYNC_URL�urllib�request�Request�_blocking_request�error� HTTPError�code�reason�URLErrorr@ �loads�JSONDecodeErrorr �debug�_write_flags)r* �tokenr+ rC �payload�url�req� resp_body�e�result�server_delayrJ s r r? zFeatureFlagsSync._do_synci sq � � � � �/�9�;�;�;�;�;�;�;�;�E�E��� � � ��N�N�G�H�H�H��1�1� ���� �%�'�'���-�-�d�D�4H�I�I�I�I�I�I�I�I���*�j�(�3�4�4�;�;�=�=����&�&�s�+�+�i�7���n�$�$��� 2��� � � %� � ��' �"�2�2��d�,�c�� � � � � � � �I�I�� �|�%� � � � �a�f�"�"�"�"�s�"�"�"�"�"����:��F���H�� � � � � � ���:��F���H� � � � �1�1�1�1�1������|�$� � � � �N�N�@���� � � � �1�1�1�1�1������ � � ��L�L�9��� � � � � �1�1� ���� ��Z� �*�*�F�F���#� � � ��L�L�A�B�B�B��1�1� ���� �z�z�'�1�-�-���:�:�i� � �E�)�)��L�L�B�C�C�C���� � �7�#�#�����&�&�t�T�->��F�F�F�F�F�F�F�F�F��sL � �$A�A�3"D �H�*A&F�H�-!G�*H�H�H �)I�Ird c � � t j � | t �� � 5 }|� � � cd d d � � S # 1 swxY w Y d S )N)�timeout)rT rU �urlopen� _HTTP_TIMEOUT�read)rd �resps r rW z"FeatureFlagsSync._blocking_request� s� � � �^� #� #�C�� #� ?� ?� �4��9�9�;�;� � � � � � � � � � � � ���� � � � � � s �A�A�ANc � � t | t � � rt | � � }nt | � � }n># t $ r1 t � dt | � � j � � Y dS w xY wt t | � � � � } t j t j � t � � d�� � t! t |d�� � t# | � � }t! t$ |d�� � t � d|� � dS # t( $ r t � dd� � � Y dS w xY w) zHPersist flags: map on disk; checksum for next sync uses canonical array.z<feature flags sync: unexpected flags type %r, skipping writeNT)�exist_okF)�backupz%feature flags synced: %d flags activezfailed to write flags filer8 )� isinstance�listr r � TypeErrorr r �type�__name__�lenr r �makedirs�path�dirnamer r r r �info�OSErrorrX )rJ rF �n_active�plains r r` zFeatureFlagsSync._write_flags� sU � � ��%��&�&� C�5�e�<�<���;�E�B�B����� � � ��N�N�N��U���$� � � � �F�F� ���� �0��7�7�8�8�� F��K����� �3�3�d�C�C�C�C� �:�t�E�:�:�:�:�8��?�?�E��+�U�5�A�A�A�A��K�K�?��J�J�J�J�J��� F� F� F��L�L�5��L�E�E�E�E�E�E� F���s"