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