Stopped some server crashes, also added support for config file in SVR.JS installation directory

This commit is contained in:
svrjs 2023-07-30 01:57:27 +02:00
parent e94e5bba61
commit efc91731e1
2 changed files with 9 additions and 7 deletions

View file

@ -7,7 +7,7 @@ var os = require("os");
var url = require("url"); var url = require("url");
var easywafconfig = {}; var easywafconfig = {};
var logm = {}; var logm = {};
if (fs.existsSync("easywaf-config.json")) easywafconfig = JSON.parse(fs.readFileSync("easywaf-config.json").toString()) if (fs.existsSync(__dirname + "/../../../easywaf-config.json")) easywafconfig = JSON.parse(fs.readFileSync(__dirname + "/../../../easywaf-config.json").toString())
function createRegex(regex) { function createRegex(regex) {
var regexObj = regex.split("/"); var regexObj = regex.split("/");
if (regexObj.length == 0) throw new Error("Invalid regex!"); if (regexObj.length == 0) throw new Error("Invalid regex!");
@ -44,15 +44,17 @@ Mod.prototype.callback = function callback(req, res, serverconsole, responseEnd,
//REQ.BODY //REQ.BODY
function readableHandler() { function readableHandler() {
try { try {
req.body = req._readableState.buffer._getString(); if(req._readableState.buffer.head !== null) {
if (req.headers["content-type"] == "application/x-www-form-urlencoded") req.body = url.parse("?" + req.body.strip(), true).query; req.body = req._readableState.buffer.head.data.toString("latin1");
if (req.headers["content-type"] == "application/json") req.body = JSON.parse(req.body.strip()); if (req.headers["content-type"] == "application/x-www-form-urlencoded") req.body = url.parse("?" + req.body.strip(), true).query;
if (req.headers["content-type"] == "application/json") req.body = JSON.parse(req.body.strip());
}
} catch (ex) { } catch (ex) {
} }
//EASYWAF //EASYWAF
easyWaf(req, res, function() { easyWaf(req, res, function() {
if (href == "/easywaf-config.json" || (os.platform() == "win32" && href.toLowerCase() == "/easywaf-config.json")) { if ((href == "/easywaf-config.json" || (os.platform() == "win32" && href.toLowerCase() == "/easywaf-config.json")) && __dirname == process.cwd()) {
if (callServerError) { if (callServerError) {
callServerError(403, "easy-waf-integration/1.0.0"); callServerError(403, "easy-waf-integration/1.0.0");
} else { } else {

View file

@ -1,4 +1,4 @@
{ {
"name": "Integration with EasyWAF", "name": "Integration with EasyWAF",
"version": "1.1.1" "version": "1.1.2"
} }