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 pkg = require('../package.json');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
var program = require('commander');
 | 
					var program = require('commander');
 | 
				
			||||||
var url = require('url');
 | 
					 | 
				
			||||||
var stunneld = require('../wstunneld.js');
 | 
					var stunneld = require('../wstunneld.js');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function collectProxies(val, memo) {
 | 
					function collectProxies(val, memo) {
 | 
				
			||||||
@ -63,70 +62,45 @@ function collectPorts(val, memo) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
program
 | 
					program
 | 
				
			||||||
  .version(pkg.version)
 | 
					  .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('--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('--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)')
 | 
					  .option('--secret <STRING>', 'the same secret used by stunneld (used for JWT authentication)')
 | 
				
			||||||
  .parse(process.argv)
 | 
					  .parse(process.argv)
 | 
				
			||||||
  ;
 | 
					  ;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
program.stunneld = program.stunneld || 'wss://tunnel.daplie.com';
 | 
					if (!program.serve.length) {
 | 
				
			||||||
 | 
					  throw new Error("must specify at least one server");
 | 
				
			||||||
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 : '');
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					var portsMap = {};
 | 
				
			||||||
 | 
					var servernamesMap = {};
 | 
				
			||||||
program.serve.forEach(function (proxy) {
 | 
					program.serve.forEach(function (proxy) {
 | 
				
			||||||
  domainsMap[proxy.hostname] = true;
 | 
					  servernamesMap[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) {
 | 
					  if (proxy.port) {
 | 
				
			||||||
    program.portsMap[proxy.port] = true;
 | 
					    portsMap[proxy.port] = true;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
program.servernames = Object.keys(program.servernamesMap);
 | 
					program.ports.forEach(function (port) {
 | 
				
			||||||
program.ports = program.ports.concat(Object.keys(program.portsMap));
 | 
					  portsMap[port] = true;
 | 
				
			||||||
program.token = program.token || jwt.sign(tokenData, program.secret || 'shhhhh');
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if (!program.serve.length) {
 | 
					var opts = {};
 | 
				
			||||||
  throw new Error("must specify at least on server");
 | 
					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
 | 
					// TODO letsencrypt
 | 
				
			||||||
program.tlsOptions = require('localhost.daplie.com-certificates').merge({});
 | 
					opts.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);
 | 
					 | 
				
			||||||
//});
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					stunneld.create(opts);
 | 
				
			||||||
}());
 | 
					}());
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user