x2go.rforward module

X2Go reverse SSH/Paramiko tunneling provides X2Go sound, X2Go printing and X2Go sshfs for folder sharing and mounting remote devices in X2Go terminal server sessions.

class x2go.rforward.X2GoRevFwChannelThread(channel, remote=None, **kwargs)[source]

Bases: Thread

Starts a thread for each incoming Paramiko/SSH data channel trough the reverse forwarding tunnel.

class x2go.rforward.X2GoRevFwTunnel(server_port, remote_host, remote_port, ssh_transport, session_instance=None, logger=None, loglevel=56)[source]

Bases: Thread

x2go.rforward.X2GoRevFwTunnel class objects are used to reversely tunnel X2Go audio, X2Go printing and X2Go folder sharing / device mounting through Paramiko/SSH.

cancel_port_forward(address, port)[source]

Cancel a port forwarding request. This cancellation request is sent to the server and on the server the port forwarding should be unregistered.

Parameters:
  • address (str) – remote server address

  • port (int) – remote port

notify()[source]

Notify an x2go.rforward.X2GoRevFwTunnel instance of an incoming Paramiko/SSH channel.

If an incoming reverse tunnel channel appropriate for this instance has been detected, this method gets called from the x2go.session.X2GoSession’s transport TCP handler.

The sent notification will trigger a thread.Condition() waiting for notification in X2GoRevFwTunnel.run().

pause()[source]

Prevent acceptance of new incoming connections through the Paramiko/SSH reverse forwarding tunnel. Also, any active connection on this x2go.rforward.X2GoRevFwTunnel instance will be closed immediately, if this method is called.

resume()[source]

Resume operation of the Paramiko/SSH reverse forwarding tunnel and continue accepting new incoming connections.

run()[source]

This method gets run once an x2go.rforward.X2GoRevFwTunnel has been started with its start() method. Use x2go.rforward.X2GoRevFwTunnel.stop_thread() to stop the reverse forwarding tunnel again. You can also temporarily lock the tunnel down with X2GoRevFwTunnel.pause() and X2GoRevFwTunnel.resume()).

X2GoRevFwTunnel.run() waits for notifications of an appropriate incoming Paramiko/SSH channel (issued by X2GoRevFwTunnel.notify()). Appropriate in this context means, that its start point on the X2Go server matches the class’s property server_port.

Once a new incoming channel gets announced by the notify() method, a new x2go.rforward.X2GoRevFwChannelThread instance will be initialized. As a data stream handler, the function x2go_rev_forward_channel_handler() will be used.

The channel will last till the connection gets dropped on the X2Go server side or until the tunnel gets paused by an X2GoRevFwTunnel.pause() call or stopped via the X2GoRevFwTunnel.stop_thread() method.

stop_thread()[source]

Stops this x2go.rforward.X2GoRevFwTunnel thread completely.

x2go.rforward.x2go_rev_forward_channel_handler(chan=None, addr='', port=0, parent_thread=None, logger=None)[source]

Handle the data stream of a requested channel that got set up by a x2go.rforward.X2GoRevFwTunnel (Paramiko/SSH reverse forwarding tunnel).

The channel (and the corresponding connections) close either …

Parameters:
x2go.rforward.x2go_transport_tcp_handler(chan, origin, server)[source]

An X2Go customized TCP handler for the Paramiko/SSH Transport() class.

Incoming channels will be put into Paramiko’s default accept queue. This corresponds to the default behaviour of Paramiko’s Transport class.

However, additionally this handler function checks the server port of the incoming channel and detects if there are Paramiko/SSH reverse forwarding tunnels waiting for the incoming channels. The Paramiko/SSH reverse forwarding tunnels are initiated by an x2go.session.X2GoSession instance (currently supported: reverse tunneling auf audio data, reverse tunneling of SSH requests).

If the server port of an incoming Paramiko/SSH channel matches the configured port of an x2go.rforward.X2GoRevFwTunnel instance, this instance gets notified of the incoming channel and a new x2go.rforward.X2GoRevFwChannelThread is started. This x2go.rforward.X2GoRevFwChannelThread then takes care of the new channel’s incoming data stream.

Parameters:
  • chan (paramiko.Channel object) – a Paramiko channel object

  • origin (tuple) – host/port tuple where a connection originates from

  • server (tuple) – host/port tuple where to connect to