Browse Source

Added Functionality to Autologin with Username and Password

pull/122/head
Koushik M L N 7 years ago
parent
commit
a4f4db8594
  1. 1
      .gitignore
  2. 7
      cli.mjs
  3. 27
      wetty.mjs

1
.gitignore

@ -13,5 +13,6 @@ logs
results
npm-debug.log
.idea
node_modules/*
.esm-cache

7
cli.mjs

@ -25,6 +25,10 @@ const opts = optimist
demand : false,
description: 'ssh user',
},
sshpass: {
demand : false,
description: 'ssh password',
},
sshauth: {
demand : false,
description: 'defaults to "password", you can use "publickey,password" instead',
@ -52,6 +56,7 @@ if (opts.help) {
}
const sshuser = opts.sshuser || process.env.SSHUSER || '';
const sshpass = opts.sshpass || process.env.SSHPASS || '';
const sshhost = opts.sshhost || process.env.SSHHOST || 'localhost';
const sshauth = opts.sshauth || process.env.SSHAUTH || 'password,keyboard-interactive';
const sshport = opts.sshport || process.env.SSHPORT || 22;
@ -81,7 +86,7 @@ process.on('uncaughtException', err => {
console.error(`Error: ${err}`);
});
const tty = wetty(port, sshuser, sshhost, sshport, sshauth, sshkey, opts.ssl);
const tty = wetty(port, sshuser, sshpass, sshhost, sshport, sshauth, sshkey, opts.ssl);
tty.on('exit', code => {
console.log(`exit with code: ${code}`);
});

27
wetty.mjs

@ -6,6 +6,7 @@ import server from 'socket.io';
import { spawn } from 'node-pty';
import EventEmitter from 'events';
import favicon from 'serve-favicon';
import url from 'url';
const app = express();
app.use(favicon(`${__dirname}/public/favicon.ico`));
@ -36,12 +37,24 @@ function createServer(port, sslopts) {
});
}
function getCommand(socket, sshuser, sshhost, sshport, sshauth, sshkey) {
function getCommand(socket, sshuser, sshpass, sshhost, sshport, sshauth, sshkey) {
const { request } = socket;
const match = request.headers.referer.match('.+/ssh/.+$');
console.log("Match ", match);
console.log("user ", sshuser);
const sshAddress = sshuser ? `${sshuser}@${sshhost}` : sshhost;
const sshPath = sshuser || match ? 'ssh' : path.join(__dirname, 'bin/ssh');
const ssh = match ? `${match[0].split('/ssh/').pop()}@${sshhost}` : sshAddress;
console.log("Address ", sshAddress);
const referer = url.parse(request.headers.referer, true);
sshpass = referer.query.sshpass ? referer.query.sshpass : sshpass;
console.log("PASS ", sshpass);
let sshPath = ''
if (!sshpass)
sshPath = sshuser || match ? 'ssh' : path.join(__dirname, 'bin/ssh');
else
sshPath = ['sshpass', '-p', sshpass].join(' ');
console.log("PATH ", sshPath);
const ssh = match ? `${match[0].split('/ssh/').pop().split('?')[0]}@${sshhost}` : sshAddress;
console.log("SSH ", ssh);
const sshRemoteOptsBase = [
sshPath,
ssh,
@ -52,7 +65,7 @@ function getCommand(socket, sshuser, sshhost, sshport, sshauth, sshkey) {
]
const sshRemoteOpts = sshkey ? sshRemoteOptsBase.concat(['-i', sshkey])
: sshRemoteOptsBase
console.log(sshRemoteOpts);
return [
process.getuid() === 0 && sshhost === 'localhost'
? ['login', '-h', socket.client.conn.remoteAddress.split(':')[3]]
@ -62,12 +75,14 @@ function getCommand(socket, sshuser, sshhost, sshport, sshauth, sshkey) {
];
}
export default function start(port, sshuser, sshhost, sshport, sshauth, sshkey, sslopts) {
export default function start(port, sshuser, sshpass, sshhost, sshport, sshauth, sshkey, sslopts) {
console.log("START", port, sshuser, sshpass, sshhost, sshport, sshauth, sshkey, sslopts);
const events = new EventEmitter();
const io = server(createServer(port, sslopts), { path: '/wetty/socket.io' });
io.on('connection', socket => {
console.log(`${new Date()} Connection accepted.`);
const [args, ssh] = getCommand(socket, sshuser, sshhost, sshport, sshauth, sshkey);
const [args, ssh] = getCommand(socket, sshuser, sshpass, sshhost, sshport, sshauth, sshkey);
console.log("PIKA PIKA", args, ssh);
const term = spawn('/usr/bin/env', args, {
name: 'xterm-256color',
cols: 80,

Loading…
Cancel
Save