still playing peekaboo...
This commit is contained in:
parent
539fb4e62a
commit
f6011ade83
|
@ -63,6 +63,9 @@ module.exports.createTcpConnectionHandler = function (copts) {
|
||||||
|
|
||||||
//return;
|
//return;
|
||||||
conn.once('data', function (firstChunk) {
|
conn.once('data', function (firstChunk) {
|
||||||
|
conn.pause();
|
||||||
|
conn.unshift(firstChunk);
|
||||||
|
|
||||||
// BUG XXX: this assumes that the packet won't be chunked smaller
|
// BUG XXX: this assumes that the packet won't be chunked smaller
|
||||||
// than the 'hello' or the point of the 'Host' header.
|
// than the 'hello' or the point of the 'Host' header.
|
||||||
// This is fairly reasonable, but there are edge cases where
|
// This is fairly reasonable, but there are edge cases where
|
||||||
|
@ -70,10 +73,14 @@ module.exports.createTcpConnectionHandler = function (copts) {
|
||||||
// and so it should be fixed at some point in the future
|
// and so it should be fixed at some point in the future
|
||||||
|
|
||||||
// defer after return (instead of being in many places)
|
// defer after return (instead of being in many places)
|
||||||
|
function deferData(fn) {
|
||||||
|
if (fn) {
|
||||||
|
copts[fn](servername, conn)
|
||||||
|
}
|
||||||
process.nextTick(function () {
|
process.nextTick(function () {
|
||||||
conn.unshift(firstChunk);
|
|
||||||
conn.resume();
|
conn.resume();
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
var service = 'tcp';
|
var service = 'tcp';
|
||||||
var servername;
|
var servername;
|
||||||
|
@ -87,13 +94,13 @@ module.exports.createTcpConnectionHandler = function (copts) {
|
||||||
|
|
||||||
if (!copts.servernames.length) {
|
if (!copts.servernames.length) {
|
||||||
console.log("https => admin => setup => (needs bogus tls certs to start?)");
|
console.log("https => admin => setup => (needs bogus tls certs to start?)");
|
||||||
copts.httpsSetupServer(servername, conn);
|
deferData('httpsSetupServer');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (-1 !== copts.servernames.indexOf(servername)) {
|
if (-1 !== copts.servernames.indexOf(servername)) {
|
||||||
console.log("Lock and load, admin interface time!");
|
console.log("Lock and load, admin interface time!");
|
||||||
copts.httpsTunnel(servername, conn);
|
deferData('httpsTunnel');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -104,18 +111,19 @@ module.exports.createTcpConnectionHandler = function (copts) {
|
||||||
function run() {
|
function run() {
|
||||||
if (!servername) {
|
if (!servername) {
|
||||||
console.log("No SNI was given, so there's nothing we can do here");
|
console.log("No SNI was given, so there's nothing we can do here");
|
||||||
copts.httpsInvalid(servername, conn);
|
deferData('httpsInvalid');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var nextDevice = Devices.next(copts.deviceLists, servername);
|
var nextDevice = Devices.next(copts.deviceLists, servername);
|
||||||
if (!nextDevice) {
|
if (!nextDevice) {
|
||||||
console.log("No devices match the given servername");
|
console.log("No devices match the given servername");
|
||||||
copts.httpsInvalid(servername, conn);
|
deferData('httpsInvalid');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log("pipeWs(servername, service, socket, deviceLists['" + servername + "'])");
|
console.log("pipeWs(servername, service, socket, deviceLists['" + servername + "'])");
|
||||||
|
deferData();
|
||||||
pipeWs(servername, service, conn, nextDevice);
|
pipeWs(servername, service, conn, nextDevice);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,13 +131,12 @@ module.exports.createTcpConnectionHandler = function (copts) {
|
||||||
console.log("VHOST path", copts.config.vhost);
|
console.log("VHOST path", copts.config.vhost);
|
||||||
vhost = copts.config.vhost.replace(/:hostname/, (servername||''));
|
vhost = copts.config.vhost.replace(/:hostname/, (servername||''));
|
||||||
console.log("VHOST name", vhost);
|
console.log("VHOST name", vhost);
|
||||||
conn.pause();
|
|
||||||
//copts.httpsVhost(servername, conn);
|
//copts.httpsVhost(servername, conn);
|
||||||
//return;
|
//return;
|
||||||
require('fs').readdir(vhost, function (err, nodes) {
|
require('fs').readdir(vhost, function (err, nodes) {
|
||||||
console.log("VHOST error?", err);
|
console.log("VHOST error?", err);
|
||||||
if (err) { run(); return; }
|
if (err) { run(); return; }
|
||||||
if (nodes) { copts.httpsVhost(servername, conn); }
|
if (nodes) { deferData('httpsVhost'); }
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -156,6 +163,7 @@ module.exports.createTcpConnectionHandler = function (copts) {
|
||||||
if (/HTTP\//i.test(str)) {
|
if (/HTTP\//i.test(str)) {
|
||||||
if (!copts.servernames.length) {
|
if (!copts.servernames.length) {
|
||||||
console.log('copts.httpSetupServer', copts.httpSetupServer);
|
console.log('copts.httpSetupServer', copts.httpSetupServer);
|
||||||
|
deferData();
|
||||||
copts.httpSetupServer.emit('connection', conn);
|
copts.httpSetupServer.emit('connection', conn);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -166,15 +174,16 @@ module.exports.createTcpConnectionHandler = function (copts) {
|
||||||
if (/well-known/.test(str)) {
|
if (/well-known/.test(str)) {
|
||||||
// HTTP
|
// HTTP
|
||||||
if (Devices.exist(copts.deviceLists, servername)) {
|
if (Devices.exist(copts.deviceLists, servername)) {
|
||||||
|
deferData();
|
||||||
pipeWs(servername, service, conn, Devices.next(copts.deviceLists, servername));
|
pipeWs(servername, service, conn, Devices.next(copts.deviceLists, servername));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
copts.handleHttp(servername, conn);
|
deferData('handleHttp');
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
// redirect to https
|
// redirect to https
|
||||||
copts.handleInsecureHttp(servername, conn);
|
deferData('handleInsecureHttp');
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue