This commit is contained in:
AJ ONeal 2018-07-27 22:30:58 -06:00
parent f2b16a5bcb
commit 568bcdcab2
4 changed files with 45 additions and 17 deletions

View File

@ -57,8 +57,8 @@ function help() {
console.info('\ttelebit http /module/path # load a node module to handle all https traffic'); console.info('\ttelebit http /module/path # load a node module to handle all https traffic');
console.info(''); console.info('');
console.info('\ttelebit http none example.com # remove https handler from example.com'); console.info('\ttelebit http none example.com # remove https handler from example.com');
console.info('\ttelebit http 3001 example.com # forward https traffic for example.com to port 3001'); console.info('\ttelebit http 3001 sub.example.com # forward https traffic for sub.example.com to port 3001');
console.info('\ttelebit http /module/path example.com # forward https traffic for example.com to port 3001'); console.info('\ttelebit http /module/path sub # forward https traffic for sub.example.com to port 3001');
console.info(''); console.info('');
console.info('\ttelebit tcp none # remove all tcp handlers'); console.info('\ttelebit tcp none # remove all tcp handlers');
console.info('\ttelebit tcp 5050 # forward all tcp to port 5050'); console.info('\ttelebit tcp 5050 # forward all tcp to port 5050');
@ -644,6 +644,7 @@ function parseCli(/*state*/) {
} else if (/\/|\\/.test(argv[1])) { } else if (/\/|\\/.test(argv[1])) {
// looks like a path // looks like a path
argv[1] = path.resolve(argv[1]); argv[1] = path.resolve(argv[1]);
// TODO make a default assignment here
} else if (-1 === special.indexOf(argv[1])) { } else if (-1 === special.indexOf(argv[1])) {
console.error("Not sure what you meant by '" + argv[1] + "'."); console.error("Not sure what you meant by '" + argv[1] + "'.");
console.error("Remember: paths should begin with ." + path.sep + ", like '." + path.sep + argv[1] + "'"); console.error("Remember: paths should begin with ." + path.sep + ", like '." + path.sep + argv[1] + "'");
@ -669,6 +670,8 @@ function handleConfig(err, config) {
//console.log('CONFIG'); //console.log('CONFIG');
//console.log(config); //console.log(config);
state.config = config; state.config = config;
var verstr = [ pkg.name + ' daemon v' + state.config.version ];
console.info(verstr.join(' '));
if (err) { console.error(err); process.exit(101); return; } if (err) { console.error(err); process.exit(101); return; }

View File

@ -132,7 +132,22 @@ controllers.http = function (req, res, opts) {
var appname = getAppname(portOrPath); var appname = getAppname(portOrPath);
var subdomain = opts.body[1]; var subdomain = opts.body[1];
var remoteHost; var remoteHost;
if (subdomain) {
// Assign an FQDN to brief subdomains
// ex: foo => foo.rando.telebit.cloud
if (subdomain && !/\./.test(subdomain)) {
Object.keys(state.servernames).some(function (key) {
if (state.servernames[key].wildcard) {
subdomain += '.' + key;
}
});
}
if ('none' === portOrPath) {
delete state.servernames[subdomain];
remoteHost = 'none';
} else if (subdomain) {
// use a subdomain with this handler
var handlerName = getServername(state.servernames, subdomain); var handlerName = getServername(state.servernames, subdomain);
if (!handlerName) { if (!handlerName) {
active = false; active = false;
@ -143,6 +158,7 @@ controllers.http = function (req, res, opts) {
state.servernames[subdomain].handler = portOrPath; state.servernames[subdomain].handler = portOrPath;
remoteHost = subdomain; remoteHost = subdomain;
} else { } else {
// just replace the default domain
if (!Object.keys(state.servernames).sort(function (a, b) { if (!Object.keys(state.servernames).sort(function (a, b) {
return b.length - a.length; return b.length - a.length;
}).some(function (key) { }).some(function (key) {
@ -152,17 +168,21 @@ controllers.http = function (req, res, opts) {
return true; return true;
} }
if (state.servernames[key].wildcard) { if (state.servernames[key].wildcard) {
if (!state.servernames[appname + '.' + key]) { //var prefix = appname + '.' + key;
state.servernames[appname + '.' + key] = {}; var prefix = key;
if (!state.servernames[prefix]) {
state.servernames[prefix] = {};
} }
state.servernames[appname + '.' + key].handler = portOrPath; state.servernames[prefix].handler = portOrPath;
remoteHost = appname + '.' + key; remoteHost = prefix;
return true; return true;
} }
})) { })) {
Object.keys(state.servernames).some(function (key) { Object.keys(state.servernames).some(function (key) {
//var prefix = appname + '.' + key;
var prefix = key;
state.servernames[key].handler = portOrPath; state.servernames[key].handler = portOrPath;
remoteHost = appname + '.' + key; remoteHost = prefix;
return true; return true;
}); });
} }
@ -306,8 +326,10 @@ function serveControlsHelper() {
} }
if (/\b(config)\b/.test(opts.pathname) && /get/i.test(req.method)) { if (/\b(config)\b/.test(opts.pathname) && /get/i.test(req.method)) {
res.setHeader('Content-Type', 'appliCation/json'); var resp = JSON.parse(JSON.stringify(state.config));
res.end(JSON.stringify(state.config)); resp.version = pkg.version;
res.setHeader('Content-Type', 'application/json');
res.end(JSON.stringify(resp));
return; return;
} }
@ -552,6 +574,10 @@ function serveControlsHelper() {
res.end(JSON.stringify( res.end(JSON.stringify(
{ status: (state.config.disable ? 'disabled' : 'enabled') { status: (state.config.disable ? 'disabled' : 'enabled')
, ready: ((state.config.relay && (state.config.token || state.config.agreeTos)) ? true : false) , ready: ((state.config.relay && (state.config.token || state.config.agreeTos)) ? true : false)
, active: !!tun
, connected: 'maybe (todo)'
, version: pkg.version
, servernames: state.servernames
} }
)); ));
return; return;

View File

@ -157,15 +157,15 @@ module.exports.assign = function (state, tun, cb) {
//if (tun.data) { conn.write(tun.data); } //if (tun.data) { conn.write(tun.data); }
return conn; return conn;
} }
function fileDirTcp(conf, cb) { function fileDirTcp(opts, cb) {
var socketPair = require('socket-pair'); var socketPair = require('socket-pair');
var conn = socketPair.create(function (err, other) { var conn = socketPair.create(function (err, other) {
if (err) { cb(err); return; } if (err) { cb(err); return; }
if (conf._stat.isFile()) { if (opts.stat.isFile()) {
fs.createReadStream(conf.handler).pipe(other); fs.createReadStream(opts.config.handler).pipe(other);
} else { } else {
fs.readdir(conf.handler, function (err, nodes) { fs.readdir(opts.config.handler, function (err, nodes) {
other.write('\n' + nodes.join('\n') + '\n\n'); other.write('\n' + nodes.join('\n') + '\n\n');
other.end(); other.end();
}); });
@ -282,8 +282,7 @@ module.exports.assign = function (state, tun, cb) {
errorTcp(conf, cb); errorTcp(conf, cb);
return; return;
} }
conf._stat = stat; fileDirTcp({ config: conf, stat: stat }, cb);
fileDirTcp(conf, cb);
}); });
}); });
} }

View File

@ -1,6 +1,6 @@
{ {
"name": "telebit", "name": "telebit",
"version": "0.19.26", "version": "0.19.27",
"description": "Break out of localhost. Connect to any device from anywhere over any tcp port or securely in a browser. A secure tunnel. A poor man's reverse VPN.", "description": "Break out of localhost. Connect to any device from anywhere over any tcp port or securely in a browser. A secure tunnel. A poor man's reverse VPN.",
"main": "lib/remote.js", "main": "lib/remote.js",
"files": [ "files": [