HEX
Server: LiteSpeed
System: Linux l24.yourwebhosting.net 5.14.0-611.54.3.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Thu May 7 16:31:24 EDT 2026 x86_64
User: turkishi (1582)
PHP: 8.1.34
Disabled: NONE
Upload Files
File: //opt/imunify360/venv/lib64/python3.11/site-packages/im360/__pycache__/aibolit_job.cpython-311.pyc
�

�z�
������dZddlZddlZddlZddlZddlZddlZddlmZm	Z	ddl
mZddlm
Z
gd�ZdZed��Zed	��Zed
��ZdZdZdejd
�d�Zedd�d�Zedd�d�Zdd�d�Zd�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��
)�
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_time7s-����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
@sR���
�"�
)�*�
�
 �
 �����
-�
-�.�������rc��t||tzd�tj����z|���dS)z.Create UUID.notify_job in the resident/in dir.z
{}.notify_jobrN)r rr!�uuid�uuid4r$s   rrrKsR���
�"�
)�*�
�
 �
 �����
.�
.�/�������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>Ys9��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 VsW��
P�O��O�O�O�E����
�G�U�#�$�$�+�+�G�4�4�����rc�D�tjtjtj��5}|�d��|�t
��	|�d��n#ttf$rYnwxYwddd��dS#1swxYwYdS)zZNotify aibolit that there is a file to scan.

    Start/restart aibolit if necessary.
    F�1N)	�socket�AF_UNIX�
SOCK_DGRAM�setblocking�connect�AIBOLIT_STARTUP_SOCKET�send�BlockingIOError�InterruptedError)�socks rrr`s���
��v�~�v�'8�	9�	9��T�����������+�,�,�,�	��I�I�d�O�O�O�O���!1�2�	�	�	��D�	������������������������s5�0B�A1�0B�1B�B�B�B�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�writerrK�replace�pop_all)rCrD�stackrMrLs    @rr3r3psV���
�����
��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
�	monotonicrr
rr r�bytesr3rrr�<module>r^s�����
�
�
�
�����	�	�	�	�
�
�
�
���������*�*�*�*�*�*�*�*�������'�'�'�'�'�'�
	�	�	��J���t�6�7�7��"&�$�'7�"8�"8��"&�$�'7�"8�"8���
��� �t�~������.3?�������3?�������,0������
�
�
� �t��e������r