HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.104.1.lve.el8.x86_64 #1 SMP Tue Feb 10 20:07:30 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.29
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //lib64/python3.6/site-packages/zmq/ssh/__pycache__/tunnel.cpython-36.pyc
3

VS�_�1�@s�dZddlmZddlZddlZddlZddlZddlZddlZddl	Z	ddl
m
Z
mZddlm
Z
y4e	j��"e	jde�ddlZejjZWdQRXWn(ek
r�dZGdd�de�ZYnXd	d
lmZyddlZWnek
r�dZYnXddlmZd
d�Zejed�ej�Zd(dd�Zdd�Z dd�Z!d)dd�Z"d*dd�Z#d+dd�Z$dd�Z%d d!�Z&d,d"d#�Z'd-d$d%�Z(ej)d&k�r�e'Z*ne$Z*dd'dd#dgZ+dS).zXBasic ssh tunnel utilities, and convenience functions for tunneling
zeromq connections.
�)�print_functionN)�getpass�getuser)�Process�ignorec@seZdZdS)�SSHExceptionN)�__name__�
__module__�__qualname__�rr�/usr/lib64/python3.6/tunnel.pyrsr�)�forward_tunnel�)�bcCsbg}g}x>t|�D]2}tj�}|jd�|j|j�d�|j|�qWx|D]}|j�qNW|S)z4Select and return n random ports that are available.�rr
)rr)�range�socketZbind�appendZgetsockname�close)�nZportsZsockets�iZsockrrr�select_random_ports+s

rzpass(word|phrase):cCs*|dkrtjdk}|st}nt}|||�S)z�Attempt to make an ssh connection without a password.
    This is mainly used for requiring password input only once
    when many tunnels may be connected to the same server.
    
    If paramiko is None, the default for the platform is chosen.
    N�win32)�sys�platform�_try_passwordless_openssh�_try_passwordless_paramiko)�server�keyfile�paramiko�frrr�try_passwordless_ssh=s
r"cCs�tdkrtd��d|}|r(|d|7}|d7}tjj�}|jdd�d}tj||d�}x\y&|j|tgd	d
�}|dkr~t	d��Wn,tj
k
r�wZYqZtjk
r�d
SXdSqZWdS)z.Try passwordless login with shell ssh command.Nz!pexpect unavailable, use paramikozssh -f z -i z exit�SSH_ASKPASSz,Are you sure you want to continue connecting)�envg�������?)�timeoutrz2The authenticity of the host can't be established.TF)�pexpect�ImportError�os�environ�copy�pop�spawn�expect�
_password_patr�TIMEOUT�EOF)rr�cmdr$�
ssh_newkey�prrrrrLs(
rc
Cs�tdkr0d}tjdkr |d7}n|d7}t|��t|�\}}}tj�}|j�|jtj��y|j	||||dd�Wntj
k
r�dSX|j�dSdS)	z%Try passwordless login with paramiko.NzParamiko unavailable, rz=Paramiko is required for ssh tunneled connections on Windows.zuse OpenSSH.T)�username�key_filename�
look_for_keysF)r rrr'�
_split_server�	SSHClient�load_system_host_keys�set_missing_host_key_policy�
WarningPolicy�connectZAuthenticationExceptionr)rr�msgr4�port�clientrrrrgs"

r�<c	Cs&t||||||d�\}}|j|�|S)a\Connect a socket to an address via an ssh tunnel.
    
    This is a wrapper for socket.connect(addr), when addr is not accessible
    from the local machine.  It simply creates an ssh tunnel using the remaining args,
    and calls socket.connect('tcp://localhost:lport') where lport is the randomly
    selected local port of the tunnel.
    
    )r�passwordr r%)�open_tunnelr<)	r�addrrrrAr r%Znew_url�tunnelrrr�tunnel_connection~s	
rEc	Csrtd�d}|jd�\}}|jd�\}}	t|	�}	|dkrBtjdk}|rLt}
nt}
|
||	|||||d�}d||fS)	z�Open a tunneled connection from a 0MQ url.
    
    For use inside tunnel_connection.
    
    Returns
    -------
    
    (url, tunnel) : (str, object)
        The 0MQ url that has been forwarded, and the tunnel object
    r
rz://�:Nr)�remoteiprrAr%ztcp://127.0.0.1:%i)r�split�intrr�paramiko_tunnel�openssh_tunnel)rCrrrAr r%�lportZ	transportZip�rportZtunnelfrDrrrrB�s
rB�	127.0.0.1cCs�tdkrtd��d}|r$|d|7}d|krF|jd�\}}|d|7}d||f}	tj|	dd	�\}
}|s�t|
|
jd
�d|
jd���}d
|||||f}	tj|	dd	�\}
}|s�tjt|	j	ddd��|Sd||||||f}	t
jj�}
|
j
dd�d}tj|	|
d�}d}x�y(|j|tgdd�}|dk�r2td��Wnltjk
�rP�wYn�tjk
�r�|j�r�t|j�t|j�t|j�td|	��n|jSYn8X|�r�td�d}|dk�r�td|�}|j|�d}�qWdS)a4Create an ssh tunnel using command-line ssh that connects port lport
    on this machine to localhost:rport on server.  The tunnel
    will automatically close when not in use, remaining open
    for a minimum of timeout seconds for an initial connection.
    
    This creates a tunnel redirecting `localhost:lport` to `remoteip:rport`,
    as seen from `server`.
    
    keyfile and password may be specified, but ssh config is checked for defaults.
    
    Parameters
    ----------
    
    lport : int
        local port for connecting to the tunnel from this machine.
    rport : int
        port on the remote machine to connect to.
    server : str
        The ssh server to connect to. The full ssh server string will be parsed.
        user@server:port
    remoteip : str [Default: 127.0.0.1]
        The remote ip, specifying the destination of the tunnel.
        Default is localhost, which means that the tunnel would redirect
        localhost:lport on this machine to localhost:rport on the *server*.
        
    keyfile : str; path to public key file
        This specifies a key to be used in ssh login, default None.
        Regular default ssh keys will be used without specifying this argument.
    password : str; 
        Your ssh password to the ssh server. Note that if this is left None,
        you will be prompted for it if passwordless key based login is unavailable.
    timeout : int [default: 60]
        The time (in seconds) after which no activity will result in the tunnel
        closing.  This prevents orphaned tunnels from running forever.
    Nz(pexpect unavailable, use paramiko_tunnelzssh z-i rFz -p %sz%s -O check %sT)Zwithexitstatuss(pid=��)z&%s -O forward -L 127.0.0.1:%i:%s:%i %sz
-O forwardz	-O cancelr
z/%s -f -S none -L 127.0.0.1:%i:%s:%i %s sleep %ir#z,Are you sure you want to continue connecting)r$Fg�������?)r%rz2The authenticity of the host can't be established.ztunnel '%s' failed to startzPassword rejected, try againz%s's password: )r&r'rH�runrI�find�atexit�register�_stop_tunnel�replacer(r)r*r+r,r-r.rr/r0�
exitstatus�printZbefore�after�RuntimeError�pidrZsendline)rLrMrrGrrAr%Zsshr>r1�outputrWr[r$r2rDZfailedrrrrrK�s\$ 






rKcCstj|�dS)N)r&rQ)r1rrrrUsrUcCsNd|kr|jdd�\}}nt�}d|kr@|jd�\}}t|�}nd}|||fS)N�@r
rF�)rHrrI)rr4r>rrrr7s
r7cCs^tdkrtd��|dkr.t||�s.td|�}tt||||ft||d�d�}d|_|j�|S)a6launch a tunner with paramiko in a subprocess. This should only be used
    when shell ssh is unavailable (e.g. Windows).
    
    This creates a tunnel redirecting `localhost:lport` to `remoteip:rport`,
    as seen from `server`.
    
    If you are familiar with ssh tunnels, this creates the tunnel:
    
    ssh server -L localhost:lport:remoteip:rport
    
    keyfile and password may be specified, but ssh config is checked for defaults.
    
    
    Parameters
    ----------
    
    lport : int
        local port for connecting to the tunnel from this machine.
    rport : int
        port on the remote machine to connect to.
    server : str
        The ssh server to connect to. The full ssh server string will be parsed.
        user@server:port
    remoteip : str [Default: 127.0.0.1]
        The remote ip, specifying the destination of the tunnel.
        Default is localhost, which means that the tunnel would redirect
        localhost:lport on this machine to localhost:rport on the *server*.
        
    keyfile : str; path to public key file
        This specifies a key to be used in ssh login, default None.
        Regular default ssh keys will be used without specifying this argument.
    password : str; 
        Your ssh password to the ssh server. Note that if this is left None,
        you will be prompted for it if passwordless key based login is unavailable.
    timeout : int [default: 60]
        The time (in seconds) after which no activity will result in the tunnel
        closing.  This prevents orphaned tunnels from running forever.
    
    NzParamiko not availablez%s's password: )rrA)�target�args�kwargsT)	r r'rrr�_paramiko_tunnel�dictZdaemon�start)rLrMrrGrrAr%r3rrrrJs(

rJc
Cst|�\}}}tj�}|j�|jtj��y|j||||d|d�Wn>tk
r�}	z"td|||	f�t	j
d�WYdd}	~	XnXtjtjtj
�yt||||j��Wn^tk
r�td�t	j
d�Yn:tk
�r
}	ztd|	�t	j
d	�WYdd}	~	XnXdS)
z�Function for actually starting a paramiko tunnel, to be passed
    to multiprocessing.Process(target=this), and not called directly.
    T)r4r5r6rAz"*** Failed to connect to %s:%d: %rr
Nz'SIGINT: Port forwarding stopped cleanlyrz%Port forwarding stopped uncleanly: %s�)r7r r8r9r:r;r<�	ExceptionrXr�exit�signal�SIGINT�SIG_IGNrZ
get_transport�KeyboardInterrupt)
rLrMrrGrrAr4r>r?�errrrbFs&rbr�
ssh_tunnel)N)NNNr@)NNNr@)rNNNr@)rNNNr@)NN),�__doc__Z
__future__rrSr(�rerhrr�warningsrrZmultiprocessingr�catch_warnings�simplefilter�DeprecationWarningr Z
ssh_exceptionrr'rfZforwardrr&Zutils.strtypesrr�compile�
IGNORECASEr.r"rrrErBrKrUr7rJrbrrm�__all__rrrr�<module>sP





Z
7
"