The cross platform WebSocket implementation for SH
JavaScript CSS Other
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
cgi-bin
jquery.terminal
terminal.js
xterm.js
LICENSE
README.md
websocket.sh

README.md

websocket.sh

Copyright (C) 2016 Anton Skshidlevsky (meefik), MIT

The cross platform WebSocket implementation for SH. It works on busybox and ash for embedded systems (requires installed busybox applets).

Bash shell as a web terminal

Run web server httpd in websocket.sh directory. For JQuery Terminal Emulator:

cd jquery.terminal
WS_SHELL="sh" httpd -p 8080

For Terminal.js:

cd terminal.js
WS_SHELL="bash -i" httpd -p 8080

For xterm.js:

cd xterm.js
telnetd -p 5023 -l /bin/sh -f /etc/issue
WS_SHELL="telnet 127.0.0.1 5023" httpd -p 8080

Open the terminal in browser: http://localhost:8080/cgi-bin/terminal

Custom usage

Run websocket.sh:

WS_SHELL="sh" nc -l -p 5000 -e websocket.sh

Use from browser:

var port = 5000;
var ws = new WebSocket('ws://' + location.hostname + ':' + port);
ws.onmessage = function(msg) {
    // convert base64 to string
    var data = atob(msg.data);
    // decode utf-8 chars
    data = decodeURIComponent(escape(data));
    console.log('Received data: ', data);
}
ws.onclose = function() {
    console.log('Connection closed.');
}
// send command: ls /
var data = 'ls /';
// encode utf-8 chars
data = unescape(encodeURIComponent(data));
// convert string to base64
data = btoa(data);
ws.send(data);

Multiple socket connections

You can use busybox inetd for multiple connections to single port for websocket.sh:

export WS_SHELL="/path/to/script.sh"
inetd -e -f /path/to/inetd.conf
# /path/to/inetd.conf
5000	stream	tcp	nowait	root	/path/to/websocket.sh