This commit is contained in:
AJ ONeal 2018-05-31 14:48:12 -06:00
parent 5207012830
commit 8c1c8d8006
1 changed files with 44 additions and 43 deletions

View File

@ -55,17 +55,6 @@ module.exports.print = function (config) {
module.exports.assign = function (state, tun, cb) { module.exports.assign = function (state, tun, cb) {
var net = state.net || require('net'); var net = state.net || require('net');
if (!tun.name && !tun.serviceport) {
console.log('tun:\n',tun);
//console.warn(tun.data.toString());
cb(new Error("No routing information for ':tun_id'. Missing both 'name' and 'serviceport'."));
return;
}
if (!state.config.servernames) {
state.config.servernames = {};
}
var handlers = {}; var handlers = {};
handlers.http = function (socket) { handlers.http = function (socket) {
if (!state.greenlock) { if (!state.greenlock) {
@ -109,13 +98,6 @@ module.exports.assign = function (state, tun, cb) {
return conn; return conn;
} }
if ('http' === tun.service || 'https' === tun.service) {
if (!tun.name) {
cb(new Error("No routing information for ':tun_id'. Service '" + tun.service + "' is missing 'name'."));
return;
}
}
function redirectHttp(cb) { function redirectHttp(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) {
@ -127,31 +109,6 @@ module.exports.assign = function (state, tun, cb) {
return conn; return conn;
} }
var handled;
if ('http' === tun.service) {
// TODO match *.example.com
handled = Object.keys(state.config.servernames).some(function (sn) {
if (sn !== tun.name) { return; }
console.log('Found config match for PLAIN', tun.name);
if (!state.config.servernames[sn]) { return; }
if (false === state.config.servernames[sn].terminate) {
cb(new Error("insecure http not supported yet"));
return true;
}
console.log('Redirecting HTPTP for', tun.name);
redirectHttp(cb);
return true;
});
if (!handled) {
redirectHttp(cb);
}
return;
}
function defineProps(other, tun) { function defineProps(other, tun) {
Object.defineProperty(other, 'remoteFamily', { Object.defineProperty(other, 'remoteFamily', {
enumerable: false, enumerable: false,
@ -233,6 +190,50 @@ module.exports.assign = function (state, tun, cb) {
return conn; return conn;
} }
var handled;
if (!tun.name && !tun.serviceport) {
console.log('tun:\n',tun);
//console.warn(tun.data.toString());
cb(new Error("No routing information for ':tun_id'. Missing both 'name' and 'serviceport'."));
return;
}
if (!state.config.servernames) {
state.config.servernames = {};
}
if ('http' === tun.service || 'https' === tun.service) {
if (!tun.name) {
cb(new Error("No routing information for ':tun_id'. Service '" + tun.service + "' is missing 'name'."));
return;
}
}
if ('http' === tun.service) {
// TODO match *.example.com
handled = Object.keys(state.config.servernames).some(function (sn) {
if (sn !== tun.name) { return; }
console.log('Found config match for PLAIN', tun.name);
if (!state.config.servernames[sn]) { return; }
if (false === state.config.servernames[sn].terminate) {
cb(new Error("insecure http not supported yet"));
return true;
}
console.log('Redirecting HTPTP for', tun.name);
redirectHttp(cb);
return true;
});
if (!handled) {
redirectHttp(cb);
}
return;
}
if ('https' === tun.service) { if ('https' === tun.service) {
// TODO match *.example.com // TODO match *.example.com
handled = Object.keys(state.config.servernames).some(function (sn) { handled = Object.keys(state.config.servernames).some(function (sn) {