1
0
Fork 0
forked from svrjs/svrjs

Add reverse DNS lookup support

This commit is contained in:
Dorian Niemiec 2023-08-28 03:44:04 +02:00
parent 94a7b319f6
commit 10f9e1b5f2
2 changed files with 53 additions and 28 deletions

View file

@ -3,7 +3,7 @@
"port": 80, "port": 80,
"pubport": 80, "pubport": 80,
"page404": "404.html", "page404": "404.html",
"timestamp": 1692915666757, "timestamp": 1693186939816,
"blacklist": [], "blacklist": [],
"nonStandardCodes": [], "nonStandardCodes": [],
"enableCompression": true, "enableCompression": true,
@ -90,4 +90,4 @@
"enableETag": true, "enableETag": true,
"disableUnusedWorkerTermination": false, "disableUnusedWorkerTermination": false,
"rewriteDirtyURLs": true "rewriteDirtyURLs": true
} }

77
svr.js
View file

@ -357,6 +357,7 @@ http.STATUS_CODES[497] = "HTTP Request Sent to HTTPS Port";
http.STATUS_CODES[598] = "Network Read Timeout Error"; http.STATUS_CODES[598] = "Network Read Timeout Error";
http.STATUS_CODES[599] = "Network Connect Timeout Error"; http.STATUS_CODES[599] = "Network Connect Timeout Error";
var url = require("url"); var url = require("url");
var dns = require("dns");
try { try {
var gracefulFs = require("graceful-fs"); var gracefulFs = require("graceful-fs");
if (!process.isBun) gracefulFs.gracefulify(fs); //Bun + graceful-fs + SVR.JS + requests about static content = 500 Internal Server Error! if (!process.isBun) gracefulFs.gracefulify(fs); //Bun + graceful-fs + SVR.JS + requests about static content = 500 Internal Server Error!
@ -865,21 +866,33 @@ if (host != "[offline]" || ifaceEx) {
return; return;
} }
pubip = d.toString(); pubip = d.toString();
if (!domain) { if (domain) {
if (pubip.indexOf(":") == -1) { ipRequestCompleted = true;
var parts = pubip.split("."); process.emit("ipRequestCompleted");
var p1 = parseInt(parts[0]).toString(16); } else {
var p2 = parseInt(parts[1]).toString(16); var callbackDone = false;
var p3 = parseInt(parts[2]).toString(16);
var p4 = parseInt(parts[3]).toString(16); var dnsTimeout = setTimeout(function() {
var pp = parseInt(pubport).toString(16); callbackDone = true;
domain = p1 + p2 + p3 + p4 + pp + ".nodesvr.doriantech.com"; ipRequestCompleted = true;
} else { process.emit("ipRequestCompleted");
domain = pubip.replace(/[^0-9a-zA-Z]/gi, "").toLowerCase() + ".nodesvrip6.doriantech.com"; }, 3000);
try {
dns.reverse(pubip, function(err, hostnames) {
if(callbackDone) return;
clearTimeout(dnsTimeout);
if(!err && hostnames.length > 0) domain = hostnames[0];
ipRequestCompleted = true;
process.emit("ipRequestCompleted");
});
} catch(err) {
clearTimeout(dnsTimeout);
callbackDone = true;
ipRequestCompleted = true;
process.emit("ipRequestCompleted");
} }
} }
ipRequestCompleted = true;
process.emit("ipRequestCompleted");
}); });
}); });
ipRequest.on("error", function () { ipRequest.on("error", function () {
@ -917,21 +930,33 @@ if (host != "[offline]" || ifaceEx) {
return; return;
} }
pubip = d.toString(); pubip = d.toString();
if (!domain) { if (domain) {
if (pubip.indexOf(":") == -1) { ipRequestCompleted = true;
var parts = pubip.split("."); process.emit("ipRequestCompleted");
var p1 = parseInt(parts[0]).toString(16); } else {
var p2 = parseInt(parts[1]).toString(16); var callbackDone = false;
var p3 = parseInt(parts[2]).toString(16);
var p4 = parseInt(parts[3]).toString(16); var dnsTimeout = setTimeout(function() {
var pp = parseInt(pubport).toString(16); callbackDone = true;
domain = p1 + p2 + p3 + p4 + pp + ".nodesvr.doriantech.com"; ipRequestCompleted = true;
} else { process.emit("ipRequestCompleted");
domain = pubip.replace(/[^0-9a-zA-Z]/gi, "").toLowerCase() + ".nodesvrip6.doriantech.com"; }, 3000);
try {
dns.reverse(pubip, function(err, hostnames) {
if(callbackDone) return;
clearTimeout(dnsTimeout);
if(!err && hostnames.length > 0) domain = hostnames[0];
ipRequestCompleted = true;
process.emit("ipRequestCompleted");
});
} catch(err) {
clearTimeout(dnsTimeout);
callbackDone = true;
ipRequestCompleted = true;
process.emit("ipRequestCompleted");
} }
} }
ipRequestCompleted = true;
process.emit("ipRequestCompleted");
}); });
}); });
ipRequest2.on("error", function () { ipRequest2.on("error", function () {