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. 35
      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
WORKDIR /app
RUN adduser -D -h /home/term -s /bin/sh term && \

35
cli.js

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

2
gulpfile.js

@ -37,4 +37,4 @@ gulp.task(
);
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');
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 sshAddress = sshuser ? `${sshuser}@${sshhost}` : sshhost;
const ssh = match ? `${match[0].split('/ssh/').pop()}@${sshhost}` : sshAddress;
let cmd;
let args;
if (process.getuid() === 0 && sshhost === 'localhost') {
cmd = '/usr/bin/login';
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];
const args =
process.getuid() === 0 && sshhost === 'localhost'
? ['login', '-h', socket.client.conn.remoteAddress.split(':')[3]]
: ['./bin/ssh', ssh, '-p', sshport, '-o', `PreferredAuthentications=${sshauth}`];
return [args, ssh];
}
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' });
io.on('connection', socket => {
console.log(`${new Date()} Connection accepted.`);
const [cmd, args, ssh] = getCommand(socket, sshuser, sshhost, sshport, sshauth);
const term = pty.spawn(cmd, args, {
const [args, ssh] = getCommand(socket, sshuser, sshhost, sshport, sshauth);
const term = pty.spawn('/usr/bin/env', args, {
name: 'xterm-256color',
cols: 80,
rows: 30,
});
console.log(`${new Date()} PID=${term.pid} STARTED on behalf of user=${ssh}`);
term.on('data', data => {
socket.emit('output', data);
});
term.on('data', data => socket.emit('output', data));
term.on('exit', code => {
console.log(`${new Date()} PID=${term.pid} ENDED`);
socket.emit('logout');
events.emit('exit', code);
});
socket.on('resize', ({ col, row }) => {
term.resize(col, row);
});
socket.on('resize', ({ col, row }) => term.resize(col, row));
socket.on('input', input => term.write(input));
socket.on('disconnect', () => {
term.end();

544
yarn.lock

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