Browse Source

Fix installation from npm (#23)

* Moved the command,args choice to a function

+ Add files to the package.json

* Using js export

* fix on package.json
pull/126/head
nosemeocurrenada 8 years ago
committed by Cian Butler
parent
commit
a72fce14c7
  1. 1
      app.js
  2. 2
      index.js
  3. 7
      package.json
  4. 33
      wetty.js

1
app.js

@ -1,4 +1,3 @@
#! /usr/bin/env node
require('@std/esm');
require('./cli');
module.exports = require('./wetty').default;

2
index.js

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

7
package.json

@ -54,7 +54,7 @@
},
"homepage": "https://github.com/butlerx/wetty",
"preferGlobal": "true",
"main": "app.js",
"main": "index.js",
"bin": {
"wetty": "./app.js"
},
@ -64,7 +64,10 @@
},
"files": [
"bin",
"public"
"public",
"app.js",
"cli.js",
"wetty.js"
],
"scripts": {
"lint": "eslint .",

33
wetty.js

@ -36,21 +36,32 @@ function createServer(port, sslopts) {
});
}
export default (port, globalsshuser, sshhost, sshport, sshauth, sslopts) => {
function getCommand(socket, sshuser, sshhost, sshport, sshauth) {
const request = socket.request;
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];
}
export default function start(port, sshuser, sshhost, sshport, sshauth, sslopts) {
const httpserv = createServer(port, sslopts);
const events = new EventEmitter();
const io = server(httpserv, { path: '/wetty/socket.io' });
io.on('connection', socket => {
const request = socket.request;
console.log(`${new Date()} Connection accepted.`);
const match = request.headers.referer.match('.+/ssh/.+$');
const sshAddress = globalsshuser ? `${globalsshuser}@${sshhost}` : sshhost;
const ssh = match ? `${match[0].split('/ssh/').pop()}@${sshhost}` : sshAddress;
const cmd = process.getuid() === 0 && sshhost === 'localhost' ? '/usr/bin/login' : './bin/ssh';
const args =
cmd === './bin/ssh'
? [ssh, '-p', sshport, '-o', `PreferredAuthentications=${sshauth}`]
: ['-h', socket.client.conn.remoteAddress.split(':')[3]];
const [cmd, args, ssh] = getCommand(socket, sshuser, sshhost, sshport, sshauth);
const term = pty.spawn(cmd, args, {
name: 'xterm-256color',
cols: 80,
@ -77,4 +88,4 @@ export default (port, globalsshuser, sshhost, sshport, sshauth, sslopts) => {
});
});
return events;
};
}

Loading…
Cancel
Save