This commit is contained in:
AJ ONeal 2018-06-01 01:36:49 -06:00
parent c54f121a85
commit 5abff544e9
1 changed files with 32 additions and 32 deletions

View File

@ -142,40 +142,40 @@ module.exports.assign = function (state, tun, cb) {
} }
function invokeHandler(conf, tlsSocket, tun, id) { function invokeHandler(conf, tlsSocket, tun, id) {
if (parseInt(conf.handler, 10)) { if (parseInt(conf.handler, 10)) {
// TODO http-proxy with proper headers and ws support // TODO http-proxy with proper headers and ws support
var conn = getNetConn(conf.handler); var conn = getNetConn(conf.handler);
console.info("Port-Forwarding '" + (tun.name || tun.serviceport) + "' to '" + conf.handler + "'"); console.info("Port-Forwarding '" + (tun.name || tun.serviceport) + "' to '" + conf.handler + "'");
conn.pipe(tlsSocket); conn.pipe(tlsSocket);
tlsSocket.pipe(conn); tlsSocket.pipe(conn);
return; return;
} }
var handle = tun.name || tun.port; var handle = tun.name || tun.port;
var handler; var handler;
var path = require('path'); var path = require('path');
var homedir = require('os').homedir(); var homedir = require('os').homedir();
var localshare = path.join(homedir, '.local/share/telebit/apps'); var localshare = path.join(homedir, '.local/share/telebit/apps');
if (/^~/.test(conf.handler)) { if (/^~/.test(conf.handler)) {
conf.handler = require('path').join(require('os').homedir(), conf.handler.replace(/^~(\/?)/, '')); conf.handler = require('path').join(require('os').homedir(), conf.handler.replace(/^~(\/?)/, ''));
} }
try { try {
handler = require(conf.handler); handler = require(conf.handler);
console.info("Handling '" + handle + ":" + id + "' with '" + conf.handler + "'"); console.info("Handling '" + handle + ":" + id + "' with '" + conf.handler + "'");
handler(tlsSocket, tun, id); handler(tlsSocket, tun, id);
} catch(e1) { } catch(e1) {
try { try {
handler = require(path.join(localshare, conf.handler)); handler = require(path.join(localshare, conf.handler));
console.info("Handling '" + handle + ":" + id + "' with '" + conf.handler + "'"); console.info("Handling '" + handle + ":" + id + "' with '" + conf.handler + "'");
handler(tlsSocket, tun, id); handler(tlsSocket, tun, id);
} catch(e2) { } catch(e2) {
console.error("Failed to load '" + conf.handler + "':", e1.message); console.error("Failed to load '" + conf.handler + "':", e1.message);
console.error("Failed to load '" + path.join(localshare, conf.handler) + "':", e2.message); console.error("Failed to load '" + path.join(localshare, conf.handler) + "':", e2.message);
console.warn("Using default handler for '" + handle + ":" + id + "'"); console.warn("Using default handler for '" + handle + ":" + id + "'");
handlers.https(tlsSocket, tun, id); handlers.https(tlsSocket, tun, id);
} }
} }
} }
function terminateTls(tun, cb) { function terminateTls(tun, cb) {