Last active
July 2, 2022 20:10
-
-
Save mscdex/941f9c6af6733d18e6e7 to your computer and use it in GitHub Desktop.
Revisions
-
mscdex revised this gist
Feb 6, 2016 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -46,7 +46,7 @@ server.on('upgrade', function(request, socket, body) { } }); server.listen(8000, '127.0.0.1'); app.use(express.static(__dirname + '/public')); app.use(term.middleware()); -
mscdex revised this gist
Feb 6, 2016 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,6 +3,6 @@ Instructions: 1. `npm install express faye-websocket ssh2 term.js` 2. Create a `public` subdirectory 3. Place `client.htm` in `public` 4. Edit the ssh connection details in `server.js`. See the documentation for the `connect()` method in the [ssh2 readme](https://github.com/mscdex/ssh2) for more information. 5. Start the server with `node server.js` 6. Visit [http://localhost:8000/client.htm](http://localhost:8000/client.htm) in a WebSocket-capable browser -
mscdex renamed this gist
Feb 6, 2016 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
mscdex created this gist
Feb 6, 2016 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,42 @@ <html> <head> <title>WebTerm</title> <script src="/term.js"></script> <script> window.addEventListener('load', function() { var Socket = window.MozWebSocket || window.WebSocket; socket = new Socket('ws://' + location.hostname + ':' + location.port); socket.onopen = function() { var term = new Terminal({ cols: 250, rows: 100, convertEol: true, useStyle: true, cursorBlink: true, screenKeys: true }); term.on('data', function(data) { socket.send(data); }); term.on('title', function(title) { document.title = title; }); term.open(document.body); socket.onmessage = function(event) { term.write(event.data); }; socket.onclose = function() { term.destroy(); }; }; }, false); </script> </head> <body> </body> </html> This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,8 @@ Instructions: 1. `npm install express faye-websocket ssh2 term.js` 2. Create a `public` subdirectory 3. Place `client.htm` in `public` 4. Edit the ssh connection details in `server.js` 5. Start the server with `node server.js` 6. Visit http://localhost:8000/client.htm in a WebSocket-capable browser This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,52 @@ var WebSocket = require('faye-websocket'); var express = require('express'); var app = express(); var server = require('http').Server(app); var term = require('term.js'); var ssh = require('ssh2'); server.on('upgrade', function(request, socket, body) { if (WebSocket.isWebSocket(request)) { var ws = new WebSocket(request, socket, body); var conn; ws.on('open', function() { conn = new ssh(); conn.on('ready', function() { ws.write('\n*** SSH CONNECTION ESTABLISHED ***\n'); conn.shell(function(err, stream) { if (err) { ws.write('\n*** SSH SHELL ERROR: ' + err.message + ' ***\n'); conn.end(); return; } // Force binary strings to be sent over websocket to prevent // getting a Blob on the browser side which term.js cannot // currently handle stream.setEncoding('binary'); stream.pipe(ws).pipe(stream).on('close', function() { conn.end(); }); }); }).on('close', function() { ws.write('\n*** SSH CONNECTION CLOSED ***\n'); ws.close(); }).connect({ host: '192.168.100.150', port: 22, username: 'foo', password: 'bar' }); }).on('close', function(event) { try { conn && conn.end(); } catch (ex) {} }); } }); server.listen(8000); app.use(express.static(__dirname + '/public')); app.use(term.middleware());