NineSec Team Shell
Server IP : 184.107.3.203  /  Your IP : 216.73.216.51
Web Server : Apache
System : Linux dedicated2.avenfashion.com.ph 4.18.0-553.40.1.el8_10.x86_64 #1 SMP Mon Feb 10 12:11:18 EST 2025 x86_64
User : adminteladeoro ( 1015)
PHP Version : 8.2.28
Disable Function : exec,passthru,shell_exec,system
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON
Directory (0755) :  /usr/libexec/kcare/python/kcarectl/__pycache__/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : //usr/libexec/kcare/python/kcarectl/__pycache__/process_utils.cpython-36.pyc
3

tHh9�@sfddlZddlZddlZddlmZddlmZejddd��Zdd	d
�Zdd�Z	d
d�Z
dd�ZdS)�N�)�	log_utils)�utilsTcCsR|pd}x*|D]"}tjj||�}tjj|�r|SqW|rJtdj||���ndSdS)N�	/usr/sbin�/sbin�/usr/bin�/binz{0} could not be found at {1})rrrr)�os�path�join�isfile�	Exception�format)�name�pathsZ	raise_exc�it�fname�r�3/usr/libexec/kcare/python/kcarectl/process_utils.py�find_cmds
rFc
Cs�|r
tjnd}|rtjnd}tj||||d�}|j�\}}|j}	|dk	rRtj|�}|dk	rdtj|�}tjt	j
d�j|j||dj|�d��|	||fS)N)�stdout�stderr�shellz�
       Call result for `{cmd}`:
       exit code {exit_code}
       === STDOUT ===
       {stdout}
       === STDERR ===
       {stderr}
       === END ===
    � )Z	exit_coderr�cmd)
�
subprocess�PIPE�Popen�communicate�
returncoder�nstrr�logdebug�textwrap�dedentrr)
Zcommand�catch_stdout�catch_stderrrrr�pZstdout_capturedZstderr_captured�coderrr�run_commands

	r(cCst|dd�\}}}|S)NT)r$)r()�args�_rrrr�check_output=sr+c	Cs�y�dddddt|�g}t|dd�\}}}|rFtjdj|d	�d
d�dS|j�}dddddt|�g}t|dd�\}}}|r�tjd
j|d	�d
d�dS|j�}t|�|fStk
r�}ztjdj||d�d
d�dSd}~XnXdS)NZpsz--no-headersz-o�ppidz-pT)r$z3Could not retrieve process parent PID for PID {pid})�pidF)�	print_msgZcommz-Could not retrieve process name for PID {pid}zJCould not retrieve process name and parent PID for PID {pid}, error: {err})r-�err)NN)NN)NN)�strr(r�loginfor�strip�intr
)	r-Zcmd_ppidr'rr*r,Zcmd_commr�errr� _get_parent_pid_and_process_nameBs$r5cCs�g}tj�}x<|dkrH|dkrHt|�\}}|j||f�|dkrBP|}qWtjddd�xJtt|��D]:\}\}}d|d}tjdj||p�d	|p�d	d
�dd�qfWdS)NrrzAgent parent processes chain:F)r.�-z->z{prefix} "{name}" (pid: {pid})�unknown)�prefixrr-)	r	�getpidr5�appendrr1�	enumerate�reversedr)Z
process_chainZcurrent_pidr,Zprocess_name�levelr-rr8rrr�log_all_parent_processes\sr>)NT)FFF)r	rr"�rr�cachedrr(r+r5r>rrrr�<module>s


NineSec Team - 2022