HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.109.1.lve.el8.x86_64 #1 SMP Thu Mar 5 20:23:46 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.30
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/__pycache__/vt_helper.cpython-310.pyc
o

�N�g��@s`dZddlZddlZddlZddlmZmZe�dej�Z	e�d�Z
e�e�Z
Gdd�d�ZdS)z�
    salt.utils.vt_helper
    ~~~~~~~~~~~~~~~~~~~~

    VT Helper

    This module provides the SSHConnection to expose an SSH connection object
    allowing users to programmatically execute commands on a remote server using
    Salt VT.
�N)�Terminal�TerminalExceptionz(?:.*)[Pp]assword(?: for .*)?:z.*\(yes\/no\).*c@s<eZdZdZddddddejdfd	d
�Zdd�Zd
d�ZdS)�
SSHConnectionz,
    SSH Connection to a remote server.
    �salt�passwordZ	localhostFz(Cmd)��c	
Cstd|�d|�d|��dddddddd�|_d}	t�|�|_||_|jjr�|j��\}
}|
rSt�	|
�rS|s>t
�d	�td
��|	|krO|j�
||j�|	d7}	q!td��|
rpt�	|
�rp|rit
�d
|�|j�
d�q!|j�
d�n
|
rz|j�	|
�rzdS|jjs%dSdS)a�
        Establishes a connection to the remote server.

        The format for parameters is:

        username (string): The username to use for this
            ssh connection. Defaults to root.
        password (string): The password to use for this
            ssh connection. Defaults to password.
        host (string): The host to connect to.
            Defaults to localhost.
        key_accept (boolean): Should we accept this host's key
            and add it to the known_hosts file? Defaults to False.
        prompt (string): The shell prompt (regex) on the server.
            Prompt is compiled into a regular expression.
            Defaults to (Cmd)
        passwd_retries (int): How many times should I try to send the password?
            Defaults to 3.
        linesep (string): The line separator to use when sending
            commands to the server. Defaults to os.linesep.
        ssh_args (string): Extra ssh args to use with ssh.
             Example: '-o PubkeyAuthentication=no'
        zssh z -l � TZtraceF)�shellZ
log_stdoutZlog_stdout_levelZ
log_stderrZlog_stderr_levelZ
stream_stdoutZ
stream_stderrrzFailure while authentication.z0Permission denied, no authentication information�zPassword authentication failedzAdding %s to known_hostsZyes�noN)r�conn�re�compile�	prompt_re�linesep�has_unread_data�recv�SSH_PASSWORD_PROMPT_RE�search�log�errorr�sendline�KEY_VALID_RE�info)�self�usernamer�hostZ
key_accept�promptZpasswd_retriesrZssh_argsZsent_passwd�stdout�stderr�r!�H/opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/vt_helper.py�__init__sF"�

��zSSHConnection.__init__cCs�|j�||j�g}g}|jjr7|j��\}}|r|�|�|r*t�d�|�|�|r3|j�	|�r3n|jjsd�
|�d�
|�fS)z�
        Send this command to the server and
        return a tuple of the output and the stderr.

        The format for parameters is:

        cmd (string): The command to send to the sever.
        zError while executing command.r)r
rrrr�appendr�debugrr�join)r�cmdZ
ret_stdoutZ
ret_stderrrr r!r!r"rls	


�zSSHConnection.sendlinecCs|jjddd�dS)z-
        Close the server connection
        T)�	terminate�killN)r
�close)rr!r!r"�close_connection�szSSHConnection.close_connectionN)	�__name__�
__module__�__qualname__�__doc__�osrr#rr+r!r!r!r"rs
�Or)r/�loggingr0rZ
salt.utils.vtrrr�Mrr�	getLoggerr,rrr!r!r!r"�<module>s