From 76a3f4496b95f482a9567002c8a68ce41eed9507 Mon Sep 17 00:00:00 2001 From: tigerbot Date: Tue, 4 Apr 2017 12:22:39 -0600 Subject: [PATCH] removed cmd line logic useful only for the client --- bin/stunneld.js | 74 ++++++++++++++++--------------------------------- 1 file changed, 24 insertions(+), 50 deletions(-) diff --git a/bin/stunneld.js b/bin/stunneld.js index 6c055a8..9af5274 100755 --- a/bin/stunneld.js +++ b/bin/stunneld.js @@ -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 ') - .arguments('') - .action(function (url) { - program.url = url; - }) .option('--serve ', 'comma separated list of :: to which matching incoming http and https should forward (reverse proxy). Ex: https://john.example.com,tls:*:1337', collectProxies, [ ]) .option('--ports ', 'comma separated list of ports on which to listen. Ex: 80,443,1337', collectPorts, [ ]) .option('--secret ', '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); +if (!program.serve.length) { + throw new Error("must specify at least one server"); } -program.stunneld = location.protocol + '//' + location.hostname + (location.port ? ':' + location.port : ''); +var portsMap = {}; +var servernamesMap = {}; 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; + servernamesMap[proxy.hostname] = true; if (proxy.port) { - program.portsMap[proxy.port] = true; + 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'); +program.ports.forEach(function (port) { + portsMap[port] = true; +}); -if (!program.serve.length) { - throw new Error("must specify at least on server"); +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); }());