Browse Source

use /usr/bin/env

pull/126/head
butlerx 7 years ago
parent
commit
a00c5598b9
No known key found for this signature in database GPG Key ID: B37CA765BAA89170
  1. 2
      Dockerfile
  2. 37
      cli.js
  3. 2
      gulpfile.js
  4. 2
      index.js
  5. 29
      wetty.js
  6. 544
      yarn.lock

2
Dockerfile

@ -1,4 +1,4 @@
FROM node:boron-alpine FROM node:8-alpine
MAINTAINER butlerx@notthe.cloud MAINTAINER butlerx@notthe.cloud
WORKDIR /app WORKDIR /app
RUN adduser -D -h /home/term -s /bin/sh term && \ RUN adduser -D -h /home/term -s /bin/sh term && \

37
cli.js

@ -53,9 +53,14 @@ const sshauth = opts.sshauth || process.env.SSHAUTH || 'password';
const sshport = opts.sshport || process.env.SSHPOST || 22; const sshport = opts.sshport || process.env.SSHPOST || 22;
const port = opts.port || process.env.PORT || 3000; const port = opts.port || process.env.PORT || 3000;
loadSSL(opts).then(ssl => { loadSSL(opts)
opts.ssl = ssl; .then(ssl => {
}); opts.ssl = ssl;
})
.catch(err => {
console.error(`Error: ${err}`);
process.exit(1);
});
process.on('uncaughtException', err => { process.on('uncaughtException', err => {
console.error(`Error: ${err}`); console.error(`Error: ${err}`);
@ -69,22 +74,16 @@ tty.on('disconnect', () => {
console.log('disconnect'); console.log('disconnect');
}); });
function loadSSL({ sslkey, sslcert }) { async function loadSSL({ sslkey, sslcert }) {
return new Promise((resolve, reject) => { try {
if (sslkey && sslcert) { if (sslkey && sslcert) {
const ssl = {}; return {
fs key : await fs.readFile(path.resolve(sslkey)),
.readFile(path.resolve(sslkey)) cert: await fs.readFile(path.resolve(sslcert)),
.then(key => { };
ssl.key = key;
})
.then(fs.readFile(path.resolve(sslcert)))
.then(cert => {
ssl.cert = cert;
})
.then(resolve(ssl))
.catch(reject);
} }
resolve({}); return {};
}); } catch (err) {
throw err;
}
} }

2
gulpfile.js

@ -37,4 +37,4 @@ gulp.task(
); );
gulp.task('default', ['compress']); gulp.task('default', ['compress']);
gulp.task('upgrade', ['hterm', 'compress'], () => del(['./libapps'])); gulp.task('upgrade', ['hterm'], () => del(['./libapps']));

2
index.js

@ -1,2 +1,2 @@
require('@std/esm'); require('@std/esm');
module.exports = require('./wetty'); module.exports = require('./wetty').default;

29
wetty.js

@ -41,17 +41,11 @@ function getCommand(socket, sshuser, sshhost, sshport, sshauth) {
const match = request.headers.referer.match('.+/ssh/.+$'); const match = request.headers.referer.match('.+/ssh/.+$');
const sshAddress = sshuser ? `${sshuser}@${sshhost}` : sshhost; const sshAddress = sshuser ? `${sshuser}@${sshhost}` : sshhost;
const ssh = match ? `${match[0].split('/ssh/').pop()}@${sshhost}` : sshAddress; const ssh = match ? `${match[0].split('/ssh/').pop()}@${sshhost}` : sshAddress;
const args =
let cmd; process.getuid() === 0 && sshhost === 'localhost'
let args; ? ['login', '-h', socket.client.conn.remoteAddress.split(':')[3]]
if (process.getuid() === 0 && sshhost === 'localhost') { : ['./bin/ssh', ssh, '-p', sshport, '-o', `PreferredAuthentications=${sshauth}`];
cmd = '/usr/bin/login'; return [args, ssh];
args = ['-h', socket.client.conn.remoteAddress.split(':')[3]];
} else {
cmd = path.join(__dirname, 'bin/ssh');
args = [ssh, '-p', sshport, '-o', `PreferredAuthentications=${sshauth}`];
}
return [cmd, args, ssh];
} }
export default function start(port, sshuser, sshhost, sshport, sshauth, sslopts) { export default function start(port, sshuser, sshhost, sshport, sshauth, sslopts) {
@ -60,26 +54,21 @@ export default function start(port, sshuser, sshhost, sshport, sshauth, sslopts)
const io = server(httpserv, { path: '/wetty/socket.io' }); const io = server(httpserv, { path: '/wetty/socket.io' });
io.on('connection', socket => { io.on('connection', socket => {
console.log(`${new Date()} Connection accepted.`); console.log(`${new Date()} Connection accepted.`);
const [args, ssh] = getCommand(socket, sshuser, sshhost, sshport, sshauth);
const [cmd, args, ssh] = getCommand(socket, sshuser, sshhost, sshport, sshauth); const term = pty.spawn('/usr/bin/env', args, {
const term = pty.spawn(cmd, args, {
name: 'xterm-256color', name: 'xterm-256color',
cols: 80, cols: 80,
rows: 30, rows: 30,
}); });
console.log(`${new Date()} PID=${term.pid} STARTED on behalf of user=${ssh}`); console.log(`${new Date()} PID=${term.pid} STARTED on behalf of user=${ssh}`);
term.on('data', data => { term.on('data', data => socket.emit('output', data));
socket.emit('output', data);
});
term.on('exit', code => { term.on('exit', code => {
console.log(`${new Date()} PID=${term.pid} ENDED`); console.log(`${new Date()} PID=${term.pid} ENDED`);
socket.emit('logout'); socket.emit('logout');
events.emit('exit', code); events.emit('exit', code);
}); });
socket.on('resize', ({ col, row }) => { socket.on('resize', ({ col, row }) => term.resize(col, row));
term.resize(col, row);
});
socket.on('input', input => term.write(input)); socket.on('input', input => term.write(input));
socket.on('disconnect', () => { socket.on('disconnect', () => {
term.end(); term.end();

544
yarn.lock

File diff suppressed because it is too large
Loading…
Cancel
Save