forked from svrjs/svrjs
Fixed non-working blacklist
This commit is contained in:
parent
10f9e1b5f2
commit
1ebf19d768
5 changed files with 29 additions and 26 deletions
2
LICENSE
2
LICENSE
|
@ -1,6 +1,6 @@
|
||||||
MIT License
|
MIT License
|
||||||
|
|
||||||
Copyright (c) 2020 DorianTech S.A.
|
Copyright (c) 2020-2023 DorianTech
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
"port": 80,
|
"port": 80,
|
||||||
"pubport": 80,
|
"pubport": 80,
|
||||||
"page404": "404.html",
|
"page404": "404.html",
|
||||||
"timestamp": 1693186939816,
|
"timestamp": 1693313769931,
|
||||||
"blacklist": [],
|
"blacklist": [],
|
||||||
"nonStandardCodes": [],
|
"nonStandardCodes": [],
|
||||||
"enableCompression": true,
|
"enableCompression": true,
|
||||||
|
@ -90,4 +90,4 @@
|
||||||
"enableETag": true,
|
"enableETag": true,
|
||||||
"disableUnusedWorkerTermination": false,
|
"disableUnusedWorkerTermination": false,
|
||||||
"rewriteDirtyURLs": true
|
"rewriteDirtyURLs": true
|
||||||
}
|
}
|
|
@ -46,7 +46,7 @@
|
||||||
"rewriteMap": [<br/>
|
"rewriteMap": [<br/>
|
||||||
{<br/>
|
{<br/>
|
||||||
"definingRegex": "/\\/invoke500\\/\\?/",<br/>
|
"definingRegex": "/\\/invoke500\\/\\?/",<br/>
|
||||||
"replacements": dorians[<br/>
|
"replacements": [<br/>
|
||||||
{<br/>
|
{<br/>
|
||||||
"regex": "/\\/invoke500\\/\\?/",<br/>
|
"regex": "/\\/invoke500\\/\\?/",<br/>
|
||||||
"replacement": "/invoke500.svr?"<br/>
|
"replacement": "/invoke500.svr?"<br/>
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
<div style="display: inline-block; text-align: left; border-width: 2px; border-style: solid; border-color: gray; padding: 8px;">
|
<div style="display: inline-block; text-align: left; border-width: 2px; border-style: solid; border-color: gray; padding: 8px;">
|
||||||
MIT License<br/>
|
MIT License<br/>
|
||||||
<br/>
|
<br/>
|
||||||
Copyright (c) 2020 DorianTech S.A.<br/>
|
Copyright (c) 2020-2023 DorianTech<br/>
|
||||||
<br/>
|
<br/>
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy<br/>
|
Permission is hereby granted, free of charge, to any person obtaining a copy<br/>
|
||||||
of this software and associated documentation files (the "Software"), to deal<br/>
|
of this software and associated documentation files (the "Software"), to deal<br/>
|
||||||
|
|
45
svr.js
45
svr.js
|
@ -15,7 +15,7 @@
|
||||||
/*
|
/*
|
||||||
* MIT License
|
* MIT License
|
||||||
*
|
*
|
||||||
* Copyright (c) 2020 DorianTech S.A.
|
* Copyright (c) 2020-2023 DorianTech
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||||
*
|
*
|
||||||
|
@ -666,6 +666,9 @@ function ipBlockList(rawBlockList) {
|
||||||
|
|
||||||
// Function to add an IP or CIDR block to the block list
|
// Function to add an IP or CIDR block to the block list
|
||||||
instance.add = function (rawValue) {
|
instance.add = function (rawValue) {
|
||||||
|
// Add to raw block list
|
||||||
|
instance.raw.push(rawValue);
|
||||||
|
|
||||||
// Initialize variables
|
// Initialize variables
|
||||||
var beginIndex = instance.prepared.length;
|
var beginIndex = instance.prepared.length;
|
||||||
var cidrIndex = instance.cidrs.length;
|
var cidrIndex = instance.cidrs.length;
|
||||||
|
@ -751,7 +754,7 @@ function ipBlockList(rawBlockList) {
|
||||||
if (instance.cidrs.length == 0) return false;
|
if (instance.cidrs.length == 0) return false;
|
||||||
var ipParsedObject = (!isIPv6 ? ipv4ToInt : ipv6ToBlocks)(rawValue);
|
var ipParsedObject = (!isIPv6 ? ipv4ToInt : ipv6ToBlocks)(rawValue);
|
||||||
var checkMethod = (!isIPv6 ? checkIfIPv4CIDRMatches : checkIfIPv6CIDRMatches);
|
var checkMethod = (!isIPv6 ? checkIfIPv4CIDRMatches : checkIfIPv6CIDRMatches);
|
||||||
|
|
||||||
return instance.cidrs.some(function(iCidr) {
|
return instance.cidrs.some(function(iCidr) {
|
||||||
return checkMethod(ipParsedObject, iCidr);
|
return checkMethod(ipParsedObject, iCidr);
|
||||||
});
|
});
|
||||||
|
@ -1061,15 +1064,15 @@ var blacklist = ipBlockList(rawBlackList);
|
||||||
|
|
||||||
var nonStandardCodes = [];
|
var nonStandardCodes = [];
|
||||||
nonStandardCodesRaw.forEach(function (nonStandardCodeRaw) {
|
nonStandardCodesRaw.forEach(function (nonStandardCodeRaw) {
|
||||||
var nO = {};
|
var newObject = {};
|
||||||
Object.keys(nonStandardCodeRaw).forEach(function (nsKey) {
|
Object.keys(nonStandardCodeRaw).forEach(function (nsKey) {
|
||||||
if (nsKey != "users") {
|
if (nsKey != "users") {
|
||||||
nO[nsKey] = nonStandardCodeRaw[nsKey];
|
newObject[nsKey] = nonStandardCodeRaw[nsKey];
|
||||||
} else {
|
} else {
|
||||||
nO["users"] = ipBlockList(nonStandardCodeRaw.users);
|
newObject["users"] = ipBlockList(nonStandardCodeRaw.users);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
nonStandardCodes.push(nO);
|
nonStandardCodes.push(newObject);
|
||||||
});
|
});
|
||||||
|
|
||||||
var customHeaders = (configJSON.customHeaders == undefined ? {} : JSON.parse(JSON.stringify(configJSON.customHeaders)));
|
var customHeaders = (configJSON.customHeaders == undefined ? {} : JSON.parse(JSON.stringify(configJSON.customHeaders)));
|
||||||
|
@ -1163,13 +1166,13 @@ if (secure) {
|
||||||
cert = fs.readFileSync((configJSON.cert[0] != "/" && !configJSON.cert.match(/^[A-Z0-9]:\\/)) ? __dirname + "/" + configJSON.cert : configJSON.cert).toString();
|
cert = fs.readFileSync((configJSON.cert[0] != "/" && !configJSON.cert.match(/^[A-Z0-9]:\\/)) ? __dirname + "/" + configJSON.cert : configJSON.cert).toString();
|
||||||
var sniNames = Object.keys(sni);
|
var sniNames = Object.keys(sni);
|
||||||
var sniCredentials = [];
|
var sniCredentials = [];
|
||||||
for (var i = 0; i < sniNames.length; i++) {
|
sniNames.forEach(function (sniName) {
|
||||||
sniCredentials.push({
|
sniCredentials.push({
|
||||||
name: sniNames[i],
|
name: sniName,
|
||||||
cert: fs.readFileSync((sni[sniNames[i]].cert[0] != "/" && !sni[sniNames[i]].cert.match(/^[A-Z0-9]:\\/)) ? __dirname + "/" + sni[sniNames[i]].cert : sni[sniNames[i]].cert).toString(),
|
cert: fs.readFileSync((sni[sniName].cert[0] != "/" && !sni[sniName].cert.match(/^[A-Z0-9]:\\/)) ? __dirname + "/" + sni[sniName].cert : sni[sniName].cert).toString(),
|
||||||
key: fs.readFileSync((sni[sniNames[i]].key[0] != "/" && !sni[sniNames[i]].key.match(/^[A-Z0-9]:\\/)) ? __dirname + "/" + sni[sniNames[i]].key : sni[sniNames[i]].key).toString()
|
key: fs.readFileSync((sni[sniName].key[0] != "/" && !sni[sniName].key.match(/^[A-Z0-9]:\\/)) ? __dirname + "/" + sni[sniName].key : sni[sniName].key).toString()
|
||||||
});
|
});
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
var logFile = undefined;
|
var logFile = undefined;
|
||||||
|
@ -2091,16 +2094,16 @@ if (!cluster.isPrimary) {
|
||||||
});
|
});
|
||||||
return ph;
|
return ph;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (req.headers["x-svr-js-from-main-thread"] == "true" && (!req.socket.remoteAddress || req.socket.remoteAddress == "::1" || req.socket.remoteAddress == "::ffff:127.0.0.1" || req.socket.remoteAddress == "127.0.0.1" || req.socket.remoteAddress == "localhost" || req.socket.remoteAddress == host || req.socket.remoteAddress == "::ffff:" + host)) {
|
if (req.headers["x-svr-js-from-main-thread"] == "true" && (!req.socket.remoteAddress || req.socket.remoteAddress == "::1" || req.socket.remoteAddress == "::ffff:127.0.0.1" || req.socket.remoteAddress == "127.0.0.1" || req.socket.remoteAddress == "localhost" || req.socket.remoteAddress == host || req.socket.remoteAddress == "::ffff:" + host)) {
|
||||||
var headers = getCustomHeaders();
|
var headers = getCustomHeaders();
|
||||||
res.writeHead(204, "No Content", headers);
|
res.writeHead(204, "No Content", headers);
|
||||||
res.end();
|
res.end();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
req.url = fixNodeMojibakeURL(req.url);
|
req.url = fixNodeMojibakeURL(req.url);
|
||||||
|
|
||||||
res.writeHeadNative = res.writeHead;
|
res.writeHeadNative = res.writeHead;
|
||||||
res.writeHead = function (a, b, c) {
|
res.writeHead = function (a, b, c) {
|
||||||
if (parseInt(a) >= 400 && parseInt(a) <= 599) {
|
if (parseInt(a) >= 400 && parseInt(a) <= 599) {
|
||||||
|
@ -2110,7 +2113,7 @@ if (!cluster.isPrimary) {
|
||||||
}
|
}
|
||||||
res.writeHeadNative(a, b, c);
|
res.writeHeadNative(a, b, c);
|
||||||
};
|
};
|
||||||
|
|
||||||
var finished = false;
|
var finished = false;
|
||||||
res.on("finish", function () {
|
res.on("finish", function () {
|
||||||
if (!finished) {
|
if (!finished) {
|
||||||
|
@ -2979,7 +2982,7 @@ if (!cluster.isPrimary) {
|
||||||
response.end();
|
response.end();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
request.url = fixNodeMojibakeURL(request.url);
|
request.url = fixNodeMojibakeURL(request.url);
|
||||||
|
|
||||||
var headWritten = false;
|
var headWritten = false;
|
||||||
|
@ -3607,12 +3610,12 @@ if (!cluster.isPrimary) {
|
||||||
} else if (version.indexOf("Nightly-") === 0 && (href == "/crash.svr" || (os.platform() == "win32" && href.toLowerCase() == "/crash.svr"))) {
|
} else if (version.indexOf("Nightly-") === 0 && (href == "/crash.svr" || (os.platform() == "win32" && href.toLowerCase() == "/crash.svr"))) {
|
||||||
throw new Error("Intentionally crashed");
|
throw new Error("Intentionally crashed");
|
||||||
}
|
}
|
||||||
|
|
||||||
/////////////////////////////////////////////
|
/////////////////////////////////////////////
|
||||||
////THERE IS NO MORE "THE BOOK OF ZSOIE"!////
|
////THERE IS NO MORE "THE BOOK OF ZSOIE"!////
|
||||||
//// But it's in easteregg.tar.gz mod... ////
|
//// But it's in easteregg.tar.gz mod... ////
|
||||||
/////////////////////////////////////////////
|
/////////////////////////////////////////////
|
||||||
|
|
||||||
var pth = decodeURIComponent(href).replace(/\/+/g, "/").substr(1);
|
var pth = decodeURIComponent(href).replace(/\/+/g, "/").substr(1);
|
||||||
var readFrom = "./" + pth;
|
var readFrom = "./" + pth;
|
||||||
fs.stat(readFrom, function (err, stats) {
|
fs.stat(readFrom, function (err, stats) {
|
||||||
|
@ -4439,7 +4442,7 @@ if (!cluster.isPrimary) {
|
||||||
// Handle HTTP authentication
|
// Handle HTTP authentication
|
||||||
if (authIndex > -1) {
|
if (authIndex > -1) {
|
||||||
var authcode = nonStandardCodes[authIndex];
|
var authcode = nonStandardCodes[authIndex];
|
||||||
|
|
||||||
function checkIfPasswordMatches(list, password, callback, _i) {
|
function checkIfPasswordMatches(list, password, callback, _i) {
|
||||||
if(!_i) _i = 0;
|
if(!_i) _i = 0;
|
||||||
var cb = function (hash) {
|
var cb = function (hash) {
|
||||||
|
@ -4501,7 +4504,7 @@ if (!cluster.isPrimary) {
|
||||||
cb(hashedPassword);
|
cb(hashedPassword);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function authorizedCallback(bruteProtection) {
|
function authorizedCallback(bruteProtection) {
|
||||||
var ha = getCustomHeaders();
|
var ha = getCustomHeaders();
|
||||||
ha["WWW-Authenticate"] = "Basic realm=\"" + (authcode.realm ? authcode.realm.replace(/(\\|")/g, "\\$1") : "SVR.JS HTTP Basic Authorization") + "\", charset=\"UTF-8\"";
|
ha["WWW-Authenticate"] = "Basic realm=\"" + (authcode.realm ? authcode.realm.replace(/(\\|")/g, "\\$1") : "SVR.JS HTTP Basic Authorization") + "\", charset=\"UTF-8\"";
|
||||||
|
@ -5504,7 +5507,7 @@ function saveConfig() {
|
||||||
if (configJSONobj.enableETag === undefined) configJSONobj.enableETag = true;
|
if (configJSONobj.enableETag === undefined) configJSONobj.enableETag = true;
|
||||||
if (configJSONobj.disableUnusedWorkerTermination === undefined) configJSONobj.disableUnusedWorkerTermination = false;
|
if (configJSONobj.disableUnusedWorkerTermination === undefined) configJSONobj.disableUnusedWorkerTermination = false;
|
||||||
if (configJSONobj.rewriteDirtyURLs === undefined) configJSONobj.rewriteDirtyURLs = false;
|
if (configJSONobj.rewriteDirtyURLs === undefined) configJSONobj.rewriteDirtyURLs = false;
|
||||||
|
|
||||||
var configString = JSON.stringify(configJSONobj, null, 2);
|
var configString = JSON.stringify(configJSONobj, null, 2);
|
||||||
fs.writeFileSync(__dirname + "/config.json", configString);
|
fs.writeFileSync(__dirname + "/config.json", configString);
|
||||||
break;
|
break;
|
||||||
|
|
Reference in a new issue