Browse Source

use /usr/bin/env

pull/123/head
butlerx 7 years ago
committed by cbutler
parent
commit
c9879818d0
No known key found for this signature in database GPG Key ID: 9EB3D625BD14DDEC
  1. 2
      Dockerfile
  2. 37
      cli.js
  3. 2
      gulpfile.js
  4. 2
      index.js
  5. 9
      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 && \

37
cli.js

@ -53,9 +53,14 @@ const sshauth = opts.sshauth || process.env.SSHAUTH || 'password,keyboard-intera
const sshport = opts.sshport || process.env.SSHPOST || 22;
const port = opts.port || process.env.PORT || 3000;
loadSSL(opts).then(ssl => {
opts.ssl = 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)),
};
}
resolve({});
});
return {};
} catch (err) {
throw err;
}
}

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;

9
wetty.js

@ -63,7 +63,6 @@ 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 [args, ssh] = getCommand(socket, sshuser, sshhost, sshport, sshauth);
const term = pty.spawn('/usr/bin/env', args, {
name: 'xterm-256color',
@ -72,17 +71,13 @@ export default function start(port, sshuser, sshhost, sshport, sshauth, sslopts)
});
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