removed cmd line logic useful only for the client
This commit is contained in:
parent
ddce47346a
commit
76a3f4496b
|
@ -5,7 +5,6 @@
|
|||
var pkg = require('../package.json');
|
||||
|
||||
var program = require('commander');
|
||||
var url = require('url');
|
||||
var stunneld = require('../wstunneld.js');
|
||||
|
||||
function collectProxies(val, memo) {
|
||||
|
@ -63,70 +62,45 @@ function collectPorts(val, memo) {
|
|||
|
||||
program
|
||||
.version(pkg.version)
|
||||
//.command('jsurl <url>')
|
||||
.arguments('<url>')
|
||||
.action(function (url) {
|
||||
program.url = url;
|
||||
})
|
||||
.option('--serve <URL>', 'comma separated list of <proto>:<//><servername>:<port> to which matching incoming http and https should forward (reverse proxy). Ex: https://john.example.com,tls:*:1337', collectProxies, [ ])
|
||||
.option('--ports <PORT>', 'comma separated list of ports on which to listen. Ex: 80,443,1337', collectPorts, [ ])
|
||||
.option('--secret <STRING>', 'the same secret used by stunneld (used for JWT authentication)')
|
||||
.parse(process.argv)
|
||||
;
|
||||
|
||||
program.stunneld = program.stunneld || 'wss://tunnel.daplie.com';
|
||||
|
||||
var jwt = require('jsonwebtoken');
|
||||
var domainsMap = {};
|
||||
var tokenData = { name: null, domains: null };
|
||||
var location = url.parse(program.stunneld);
|
||||
|
||||
if (!location.protocol || /\./.test(location.protocol)) {
|
||||
program.stunneld = 'wss://' + program.stunneld;
|
||||
location = url.parse(program.stunneld);
|
||||
}
|
||||
program.stunneld = location.protocol + '//' + location.hostname + (location.port ? ':' + location.port : '');
|
||||
|
||||
program.serve.forEach(function (proxy) {
|
||||
domainsMap[proxy.hostname] = true;
|
||||
});
|
||||
tokenData.domains = Object.keys(domainsMap);
|
||||
tokenData.name = tokenData.domains[0];
|
||||
|
||||
if (!program.ports.length) {
|
||||
program.ports = [ 80, 443 ];
|
||||
}
|
||||
program.services = {};
|
||||
program.portsMap = {};
|
||||
program.servernamesMap = {};
|
||||
program.serve.forEach(function (proxy) {
|
||||
//program.services = { 'ssh': 22, 'http': 80, 'https': 443 };
|
||||
program.servernamesMap[proxy.hostname] = true;
|
||||
program.services[proxy.protocol] = proxy.port;
|
||||
if (proxy.port) {
|
||||
program.portsMap[proxy.port] = true;
|
||||
}
|
||||
});
|
||||
program.servernames = Object.keys(program.servernamesMap);
|
||||
program.ports = program.ports.concat(Object.keys(program.portsMap));
|
||||
program.token = program.token || jwt.sign(tokenData, program.secret || 'shhhhh');
|
||||
|
||||
if (!program.serve.length) {
|
||||
throw new Error("must specify at least on server");
|
||||
throw new Error("must specify at least one server");
|
||||
}
|
||||
|
||||
var portsMap = {};
|
||||
var servernamesMap = {};
|
||||
program.serve.forEach(function (proxy) {
|
||||
servernamesMap[proxy.hostname] = true;
|
||||
if (proxy.port) {
|
||||
portsMap[proxy.port] = true;
|
||||
}
|
||||
});
|
||||
program.ports.forEach(function (port) {
|
||||
portsMap[port] = true;
|
||||
});
|
||||
|
||||
var opts = {};
|
||||
opts.servernames = Object.keys(servernamesMap);
|
||||
opts.ports = Object.keys(portsMap);
|
||||
if (!opts.ports.length) {
|
||||
opts.ports = [ 80, 443 ];
|
||||
}
|
||||
|
||||
if (program.secret) {
|
||||
opts.secret = program.secret;
|
||||
} else {
|
||||
// TODO randomly generate and store in file?
|
||||
console.warn("[SECURITY] using default --secret 'shhhhh'");
|
||||
opts.secret = 'shhhhh';
|
||||
}
|
||||
|
||||
// TODO letsencrypt
|
||||
program.tlsOptions = require('localhost.daplie.com-certificates').merge({});
|
||||
if (!program.secret) {
|
||||
// TODO randomly generate and store in file?
|
||||
console.warn("[SECURITY] using default --secret 'shhhhh'");
|
||||
program.secret = 'shhhhh';
|
||||
}
|
||||
|
||||
//require('cluster-store').create().then(function (store) {
|
||||
//program.store = store;
|
||||
|
||||
stunneld.create(program);
|
||||
//});
|
||||
opts.tlsOptions = require('localhost.daplie.com-certificates').merge({});
|
||||
|
||||
stunneld.create(opts);
|
||||
}());
|
||||
|
|
Loading…
Reference in New Issue