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/123/head
nosemeocurrenada 7 years ago
committed by cbutler
parent
commit
8d4fd327ac
No known key found for this signature in database GPG Key ID: 9EB3D625BD14DDEC
  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,20 +36,35 @@ function createServer(port, sslopts) {
});
}
export default (port, globalsshuser, sshhost, sshport, sshauth, sslopts) => {
function getCommand(socket, sshuser, sshhost, sshport, sshauth) {
const { request } = socket;
const match = request.headers.referer.match('.+/ssh/.+$');
const sshAddress = sshuser ? `${sshuser}@${sshhost}` : sshhost;
const ssh = match ? `${match[0].split('/ssh/').pop()}@${sshhost}` : sshAddress;
return [
process.getuid() === 0 && sshhost === 'localhost'
? ['login', '-h', socket.client.conn.remoteAddress.split(':')[3]]
: [
path.join(__dirname, 'bin/ssh'),
ssh,
'-p',
sshport,
'-o',
`PreferredAuthentications=${sshauth}`,
],
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;
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 args = process.getuid() === 0 && sshhost === 'localhost'
? ['login', '-h', socket.client.conn.remoteAddress.split(':')[3]]
: [ssh, '-p', sshport, '-o', `PreferredAuthentications=${sshauth}`];
const [args, ssh] = getCommand(socket, sshuser, sshhost, sshport, sshauth);
const term = pty.spawn('/usr/bin/env', args, {
name: 'xterm-256color',
cols: 80,
@ -76,4 +91,4 @@ export default (port, globalsshuser, sshhost, sshport, sshauth, sslopts) => {
});
});
return events;
};
}

Loading…
Cancel
Save