2019-09-03 16:31:37 +02:00
|
|
|
var express = require('express');
|
|
|
|
var pty = require('node-pty');
|
2019-09-03 16:15:30 +02:00
|
|
|
|
|
|
|
const app = express();
|
|
|
|
const expressWs = require('express-ws')(app);
|
|
|
|
|
|
|
|
// Serve static assets from ./static
|
2019-09-03 16:31:37 +02:00
|
|
|
app.use(express.static('./'));
|
2019-09-03 16:15:30 +02:00
|
|
|
|
|
|
|
// Instantiate shell and set up data handlers
|
|
|
|
expressWs.app.ws('/shell', (ws, req) => {
|
|
|
|
// Spawn the shell
|
|
|
|
const shell = pty.spawn('/bin/bash', [], {
|
|
|
|
name: 'xterm-color',
|
|
|
|
cwd: process.env.PWD,
|
|
|
|
env: process.env
|
|
|
|
});
|
|
|
|
// For all shell data send it to the websocket
|
|
|
|
shell.on('data', (data) => {
|
|
|
|
ws.send(data);
|
|
|
|
});
|
|
|
|
// For all websocket data send it to the shell
|
|
|
|
ws.on('message', (msg) => {
|
|
|
|
shell.write(msg);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
// Start the application
|
|
|
|
app.listen(9774);
|