2017 © Pedro Peláez
 

project socketty

SSH terminal over web sockets

image

magnusjt/socketty

SSH terminal over web sockets

  • Friday, September 11, 2015
  • by magnusjt
  • Repository
  • 3 Watchers
  • 3 Stars
  • 43 Installations
  • JavaScript
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 2 Versions
  • 8 % Grown

The README.md

socketty

Interactive terminals over websockets with a php backend. It can for instance be used to create interactive SSH sessions, but should work with any command. At the same time, an existing php backend can be used to perform authorization and authentication., (*1)

Uses the following tech:, (*2)

  • ratchet - Websockets with PHP
  • reactphp - Async IO in PHP through an event loop
  • term.js - Terminal emulation in the browser
  • reactjs - For the rest of the UI
  • python's pty module - For emulating a pty which php can interact with using normal pipes

alt tag, (*3)

Usage

The project consists of a PHP backend which manages the client connections, and a frontend which emulates the terminal. In order to run the backend server, create a composer dependency on this project, and follow the example in ./server.php:, (*4)

composer require magnusjt/socketty

Here you can customize:, (*5)

  • Authentication - Implement the AuthenticatorInterface. If you want to reuse sessions from an existing site, you will need to do this through memcached
  • Authorization - Same as Authentication, but in this case you may also authorize the command and command arguments.
  • Port to use for websockets
  • Allowed hosts
  • Logging - The project uses the psr LoggerInterface, so anything goes (Monolog is a nice option)
  • Spawner - Generates a command string to be executed. Commands can be enabled and disabled here.

Backend example: See ./server.php, (*6)

Frontend: Install by adding the following to npm dependencies: "socketty": "git://github.com/magnusjt/socketty.git#master", (*7)

Frontend example (needs to be compiled with browserify and babelify):, (*8)

var Socketty = require('socketty');
var domNodeId = 'app'; // ID of the dom node to open the app in
var wssUrl = 'wss://localhost:5678'; // Websocket URL

// Create some presets
var opts = [
    {
        name: 'SSH',
        open: true,
        list: [
            {cmd: 'ssh vagrant@127.0.0.1', 'name': 'Vagrant SSH'},
        ]
    },
    {
        name: 'Ping',
        open: false,
        list: [
            {cmd: 'ping 127.0.0.1', 'name': 'Ping localhost'},
        ]
    }
];

Socketty.start(domNodeId, wssUrl, opts);

Development

  • Install frontend dependencies with npm install.
  • Install backend dependencies with composer install
  • Copy and rename a Vagrantfile and vagrant_bootstrap.sh file
  • Start virtual server with vagrant up
  • Start websocket server with php server.php
  • Open browser and go to https://localhost:5678/login.php to pretend to login
  • Open browser and go to https://localhost:5678 and spawn some terminals into the virtual server
  • Build frontend stuff with gulp build and gulp watchify
  • NB: apache and haproxy may need to be started manually after a reboot:, (*9)

    service httpd start
    /usr/local/sbin/haproxy -f /vagrant/haproxy.cfg -p /var/run/haproxy.pid -D
    

About SSL

In order to have secure web sockets, the vagrant install includes haproxy which terminates all ssl requests., (*10)

How it works

First of all, reactphp is used together with an event loop to acheive async calls with PHP. A sub component of reactphp called child-processes uses PHP's proc_open to connect to a child process and its pipes. For programs that require a tty (such as ssh and its interactive password prompt), we would really like to use PHP's pty pipes, but these are sadly not available on most systems. To get around this, all comands are opened through a python script, which uses the pty module to simulate a pty., (*11)

The Versions

11/09 2015

dev-master

9999999-dev

SSH terminal over web sockets

  Sources   Download

MIT

The Requires

 

The Development Requires

ssh web-sockets

24/08 2015

1.0.0

1.0.0.0

SSH terminal over web sockets

  Sources   Download

MIT

The Requires

 

The Development Requires

ssh web-sockets