From 502a9ded9c0692a786783f0ee592458a943c9a6b Mon Sep 17 00:00:00 2001 From: butlerx Date: Sat, 8 Apr 2017 20:58:25 +0100 Subject: [PATCH] add wrapper for ssh to prompt for user login --- app.js | 11 +++++++-- bin/ssh | 17 ++++++++++++++ package.json | 64 ++++++++++++++++++++++++++-------------------------- 3 files changed, 58 insertions(+), 34 deletions(-) create mode 100755 bin/ssh diff --git a/app.js b/app.js index c2f73a2..e101974 100644 --- a/app.js +++ b/app.js @@ -102,19 +102,26 @@ io.on('connection', function(socket){ } var term; - if (process.getuid() == 0) { + if (process.getuid() == 0 && sshhost == 'localhost') { term = pty.spawn('/usr/bin/env', ['login'], { name: 'xterm-256color', cols: 80, rows: 30 }); - } else { + } else if (sshuser) { term = pty.spawn('ssh', [sshuser + sshhost, '-p', sshport, '-o', 'PreferredAuthentications=' + sshauth], { name: 'xterm-256color', cols: 80, rows: 30 }); + } else { + term = pty.spawn('./bin/ssh', [sshhost, '-p', sshport, '-o', 'PreferredAuthentications=' + sshauth], { + name: 'xterm-256color', + cols: 80, + rows: 30 + }); } + console.log((new Date()) + " PID=" + term.pid + " STARTED on behalf of user=" + sshuser) term.on('data', function(data) { socket.emit('output', data); diff --git a/bin/ssh b/bin/ssh new file mode 100755 index 0000000..8ae0be8 --- /dev/null +++ b/bin/ssh @@ -0,0 +1,17 @@ +#!/usr/bin/perl + +my $user_at_address = $ARGV[0]; +my @u_a = split(/@/, $user_at_address); +if (defined $u_a[1]) { + if ( $^O == 'linux' ) { + exec ("/usr/bin/ssh $u_a[0]\@$u_a[1]"); + } +} +else { + print "Enter your username: "; + my $username = ; + chomp ( $username ); + if ( $^O == 'linux' ) { + exec ("/usr/bin/ssh $username\@$u_a[0]"); + } +} diff --git a/package.json b/package.json index 9c088d6..7e976e3 100644 --- a/package.json +++ b/package.json @@ -1,34 +1,34 @@ { - "name": "wetty", - "version": "0.2.0", - "dependencies": { - "express": "3.5.1", - "socket.io": "^1.3.7", - "pty.js": "^0.3.0", - "optimist": "^0.6" - }, - "devDependencies": { - "load-grunt-tasks": "^3.0", - "grunt": "^0.4", - "grunt-shell": "^1.1", - "grunt-mkdir": "^0.1", - "grunt-git": "^0.3", - "grunt-contrib-clean": "^0.6" - }, - "description": "Wetty = Web + tty. Terminal access in browser over http/https ", - "main": "app.js", - "repository": { - "type": "git", - "url": "git://github.com/krishnasrinivas/wetty.git" - }, - "author": "Krishna Srinivas (https://github.com/krishnasrinivas)", - "license": "MIT", - "bugs": { - "url": "https://github.com/krishnasrinivas/wetty/issues" - }, - "homepage": "https://github.com/krishnasrinivas/wetty", - "preferGlobal": "true", - "bin": { - "wetty": "./bin/wetty.js" - } + "name": "wetty", + "version": "0.2.0", + "dependencies": { + "express": "3.5.1", + "socket.io": "^1.3.7", + "pty.js": "^0.3.0", + "optimist": "^0.6" + }, + "devDependencies": { + "load-grunt-tasks": "^3.0", + "grunt": "^0.4", + "grunt-shell": "^1.1", + "grunt-mkdir": "^0.1", + "grunt-git": "^0.3", + "grunt-contrib-clean": "^0.6" + }, + "description": "Wetty = Web + tty. Terminal access in browser over http/https ", + "main": "app.js", + "repository": { + "type": "git", + "url": "git://github.com/krishnasrinivas/wetty.git" + }, + "author": "Krishna Srinivas (https://github.com/krishnasrinivas)", + "license": "MIT", + "bugs": { + "url": "https://github.com/krishnasrinivas/wetty/issues" + }, + "homepage": "https://github.com/krishnasrinivas/wetty", + "preferGlobal": "true", + "bin": { + "wetty": "./bin/wetty.js" + } }