????

Your IP : 3.137.208.89


Current Path : /opt/imunify360/venv/lib/python3.11/site-packages/im360/__pycache__/
Upload File :
Current File : //opt/imunify360/venv/lib/python3.11/site-packages/im360/__pycache__/aibolit_job.cpython-311.pyc

�

��g|���dZddlZddlZddlZddlZddlZddlZddlmZm	Z	ddl
mZddlm
Z
gd�ZdZed��Zed	��Zed
��ZdZdZd
Zdejd�d�Zedd�d�Zedd�d�Zdd�d�Zefd�Zdedefd�ZdS)zHelper functions to kick off the aibolit scan on file upload.

See {modsec,pureftpd}-on-upload scripts for the example usage.

�N)�	ExitStack�suppress)�Path)�NamedTemporaryFile)�RESIDENT_DIR�RESIDENT_IN_DIR_NOTIFY_REL_PATH�RESIDENT_IN_DIR_UPLOAD_REL_PATH�UPLOAD_TIMEOUT�create_notify_job�create_remaining_time_func�create_upload_job�$notify_aibolit_start_it_if_necessaryz./var/run/defence360agent/aibolit-resident.sockz /var/imunify360/aibolit/residentzin/upload-jobszin/notify-jobs��
g�������?)�
start_time�timerc�.�����������fd�}|S)z�Create remaining_time() function.

    Start the timer if start_time is None otherwise use given value as
    the start time.

    remaining_time() raises TimeoutError in *timeout*
    seconds after the *start_time* according to the *timer*.

    c�B�������z
z
}|dkrt�|S)Nr)�TimeoutError)�	time_leftr�timeoutrs ����F/opt/imunify360/venv/lib/python3.11/site-packages/im360/aibolit_job.py�remaining_timez2create_remaining_time_func.<locals>.remaining_time8s-����u�u�w�w��3�4�	���>�>������)rrrrs``` rrr*s=���������J���������r)�resident_dir_pathrc��t||tzd�tj����z|���dS)z-Create PID.upload_job in the resident/in dir.z
{}.upload_job��job_pathrN)�
create_jobr	�format�os�getpid��filesrrs   rr
r
AsR���
�"�
)�*�
�
 �
 �����
-�
-�.�������rc��t||tzd�tj����z|���dS)z.Create UUID.notify_job in the resident/in dir.z
{}.notify_jobrN)r rr!�uuid�uuid4r$s   rrrLsR���
�"�
)�*�
�
 �
 �����
.�
.�/�������r)rc��d�|D��}t|tjd|i���d����dS)Nc��g|];}tjtj|�����d����<S)�ascii)�base64�	b64encoder"�fsencode�decode)�.0�fns  r�
<listcomp>zcreate_job.<locals>.<listcomp>Zs9��O�O�O�2�V�
�b�k�"�o�o�
.�
.�
5�
5�g�
>�
>�O�O�Orr%r+)�write_atomic�json�dumps�encode)r%rrs   rr r WsW��
P�O��O�O�O�E����
�G�U�#�$�$�+�+�G�4�4�����rc��tjtjtj��5}|�|��|�t
��|�d��ddd��dS#1swxYwYdS)zZNotify aibolit that there is a file to scan.

    Start/restart aibolit if necessary.
    �1N)�socket�AF_UNIX�
SOCK_DGRAM�
settimeout�connect�AIBOLIT_STARTUP_SOCKET�send)r�socks  rrras���
��v�~�v�'8�	9�	9��T����� � � ����+�,�,�,��	�	�$������������������������s�AA<�<B�B�path�contentc���t��5}tt|j��d���5��fd�}|�|����|��ddd��n#1swxYwYt
�j���|��|�	��ddd��dS#1swxYwYdS)z�Write *content* to *path* atomically.

    Ignore fsync() issues:
    https://stackoverflow.com/questions/12003805/threadsafe-and-fault-tolerant-file-writes
    F)�dir�deletec���tt��5tj�j��ddd��dS#1swxYwYdS)N)r�FileNotFoundErrorr"�remove�name)�output_files�r�cleanupzwrite_atomic.<locals>.cleanup|s�����/�0�0�0�0��I�k�.�/�/�/�0�0�0�0�0�0�0�0�0�0�0�0����0�0�0�0�0�0s�=�A�AN)
rr�str�parent�callback�writerrI�replace�pop_all)rArB�stackrKrJs    @rr3r3qsV���
�����
��D�K� � ��
�
�
�
	'�
�
0�
0�
0�
0�
0�
�N�N�7�#�#�#����g�&�&�&�
	'�
	'�
	'�
	'�
	'�
	'�
	'�
	'�
	'�
	'�
	'����
	'�
	'�
	'�
	'�	
�[�
���&�&�t�,�,�,�
�
�
������������������������s4�$C�0A0�$C�0A4	�4C�7A4	�8>C�C�
C)�__doc__r,r4r"r9�timer'�
contextlibrr�pathlibr�tempfiler�__all__r>rr	r�
STUCK_TIMEOUTr
�STARTUP_SOCKET_TIMEOUT�	monotonicrr
rr r�bytesr3rrr�<module>r]s�����
�
�
�
�����	�	�	�	�
�
�
�
���������*�*�*�*�*�*�*�*�������'�'�'�'�'�'�
	�	�	��J���t�6�7�7��"&�$�'7�"8�"8��"&�$�'7�"8�"8���
����� �t�~������.3?�������3?�������,0������2H�
�
�
�
� �t��e������r