From fcec27fee165295fdb76723a929369ee0ff8ac7e Mon Sep 17 00:00:00 2001 From: Dorian Niemiec Date: Sun, 25 Aug 2024 13:09:58 +0200 Subject: [PATCH] Replace "SVR.JS" with references to svrjs.json file --- src/handlers/proxyHandler.js | 4 +++- src/index.js | 14 +++++++------- src/middleware/checkForbiddenPaths.js | 4 +++- src/middleware/defaultHandlerChecks.js | 6 ++++-- .../nonStandardCodesAndHttpAuthentication.js | 8 ++++---- .../staticFileServingAndDirectoryListings.js | 4 +++- 6 files changed, 24 insertions(+), 16 deletions(-) diff --git a/src/handlers/proxyHandler.js b/src/handlers/proxyHandler.js index 7dc2c55..1552852 100644 --- a/src/handlers/proxyHandler.js +++ b/src/handlers/proxyHandler.js @@ -1,4 +1,6 @@ const generateServerString = require("../utils/generateServerString"); +const svrjsInfo = require("../../svrjs.json"); +const { name } = svrjsInfo; let serverconsole = {}; let middleware = []; @@ -79,7 +81,7 @@ function proxyHandler(req, socket, head) { } } else { logFacilities.errmessage( - "SVR.JS doesn't support proxy without proxy mod.", + name + " doesn't support proxy without proxy mod.", ); if (!socket.destroyed) socket.end("HTTP/1.1 501 Not Implemented\n\n"); } diff --git a/src/index.js b/src/index.js index e6a9fd6..59b8924 100644 --- a/src/index.js +++ b/src/index.js @@ -3,7 +3,7 @@ const fs = require("fs"); const generateServerString = require("./utils/generateServerString.js"); const deleteFolderRecursive = require("./utils/deleteFolderRecursive.js"); const svrjsInfo = require("../svrjs.json"); -const { version } = svrjsInfo; +const { name, version } = svrjsInfo; let inspector = undefined; try { @@ -46,14 +46,14 @@ for ( args[i] == "/h" || args[i] == "/?" ) { - console.log("SVR.JS usage:"); + console.log(name + " usage:"); console.log( "node svr.js [-h] [--help] [-?] [/h] [/?] [--secure] [--reset] [--clean] [--disable-mods] [--single-threaded] [-v] [--version]", ); console.log("-h -? /h /? --help -- Displays help"); - console.log("--clean -- Cleans up files created by SVR.JS"); + console.log("--clean -- Cleans up files created by " + name); console.log( - "--reset -- Resets SVR.JS to default settings (WARNING: DANGEROUS)", + "--reset -- Resets " + name + " to default settings (WARNING: DANGEROUS)", ); console.log("--secure -- Runs HTTPS server"); console.log("--disable-mods -- Disables mods (safe mode)"); @@ -91,14 +91,14 @@ for ( process.singlethreaded = true; } else { console.log("Unrecognized argument: " + args[i]); - console.log("SVR.JS usage:"); + console.log(name + " usage:"); console.log( "node svr.js [-h] [--help] [-?] [/h] [/?] [--secure] [--reset] [--clean] [--disable-mods] [--single-threaded] [-v] [--version]", ); console.log("-h -? /h /? --help -- Displays help"); - console.log("--clean -- Cleans up files created by SVR.JS"); + console.log("--clean -- Cleans up files created by " + name); console.log( - "--reset -- Resets SVR.JS to default settings (WARNING: DANGEROUS)", + "--reset -- Resets " + name + " to default settings (WARNING: DANGEROUS)", ); console.log("--secure -- Runs HTTPS server"); console.log("--disable-mods -- Disables mods (safe mode)"); diff --git a/src/middleware/checkForbiddenPaths.js b/src/middleware/checkForbiddenPaths.js index dd3f711..5ab4c22 100644 --- a/src/middleware/checkForbiddenPaths.js +++ b/src/middleware/checkForbiddenPaths.js @@ -6,6 +6,8 @@ const { isIndexOfForbiddenPath, forbiddenPaths, } = require("../utils/forbiddenPaths.js"); +const svrjsInfo = require("../../svrjs.json"); +const { name } = svrjsInfo; forbiddenPaths.config = getInitializePath("./config.json"); forbiddenPaths.certificates = []; @@ -88,7 +90,7 @@ module.exports = (req, res, logFacilities, config, next) => { !config.exposeServerVersion ) { res.error(403); - logFacilities.errmessage("Access to SVR.JS script is denied."); + logFacilities.errmessage("Access to " + name + " script is denied."); return; } else if ( (isForbiddenPath(decodedHrefWithoutDuplicateSlashes, "svrjs") || diff --git a/src/middleware/defaultHandlerChecks.js b/src/middleware/defaultHandlerChecks.js index e2cc433..ad54cbe 100644 --- a/src/middleware/defaultHandlerChecks.js +++ b/src/middleware/defaultHandlerChecks.js @@ -1,4 +1,6 @@ const http = require("http"); +const svrjsInfo = require("../../svrjs.json"); +const { name } = svrjsInfo; module.exports = (req, res, logFacilities, config, next) => { if (req.isProxy) { @@ -6,7 +8,7 @@ module.exports = (req, res, logFacilities, config, next) => { eheaders["Content-Type"] = "text/html; charset=utf-8"; res.writeHead(501, http.STATUS_CODES[501], eheaders); res.write( - 'Proxy not implemented

Proxy not implemented

SVR.JS doesn\'t support proxy without proxy mod. If you\'re administator of this server, then install this mod in order to use SVR.JS as a proxy.

' + + 'Proxy not implemented

Proxy not implemented

SVR.JS doesn\'t support proxy without proxy mod. If you\'re administator of this server, then install this mod in order to use ' + name.replace(/&/g, "&").replace(//g, ">") + ' as a proxy.

' + config .generateServerString() .replace(/&/g, "&") @@ -15,7 +17,7 @@ module.exports = (req, res, logFacilities, config, next) => { "

", ); res.end(); - logFacilities.errmessage("SVR.JS doesn't support proxy without proxy mod."); + logFacilities.errmessage(name + " doesn't support proxy without proxy mod."); return; } diff --git a/src/middleware/nonStandardCodesAndHttpAuthentication.js b/src/middleware/nonStandardCodesAndHttpAuthentication.js index 07ebbdb..2cf9957 100644 --- a/src/middleware/nonStandardCodesAndHttpAuthentication.js +++ b/src/middleware/nonStandardCodesAndHttpAuthentication.js @@ -144,7 +144,7 @@ module.exports = (req, res, logFacilities, config, next) => { } else if (nonscode.scode == 410) { logFacilities.errmessage("Content is gone."); } else if (nonscode.scode == 418) { - logFacilities.errmessage("SVR.JS is always a teapot ;)"); + logFacilities.errmessage(name + " is always a teapot ;)"); } else { logFacilities.errmessage("Client fails receiving content."); } @@ -175,7 +175,7 @@ module.exports = (req, res, logFacilities, config, next) => { res.error( 500, new Error( - "SVR.JS doesn't support scrypt-hashed passwords on Node.JS versions without scrypt hash support.", + name + " doesn't support scrypt-hashed passwords on Node.JS versions without scrypt hash support.", ), ); return; @@ -214,7 +214,7 @@ module.exports = (req, res, logFacilities, config, next) => { res.error( 500, new Error( - "SVR.JS doesn't support PBKDF2-hashed passwords on Node.JS versions without crypto support.", + name + " doesn't support PBKDF2-hashed passwords on Node.JS versions without crypto support.", ), ); return; @@ -262,7 +262,7 @@ module.exports = (req, res, logFacilities, config, next) => { 'Basic realm="' + (authcode.realm ? authcode.realm.replace(/(\\|")/g, "\\$1") - : "SVR.JS HTTP Basic Authorization") + + : (name + " HTTP Basic Authorization")) + '", charset="UTF-8"'; const credentials = req.headers["authorization"]; if (!credentials) { diff --git a/src/middleware/staticFileServingAndDirectoryListings.js b/src/middleware/staticFileServingAndDirectoryListings.js index d0a48e7..510ecab 100644 --- a/src/middleware/staticFileServingAndDirectoryListings.js +++ b/src/middleware/staticFileServingAndDirectoryListings.js @@ -8,6 +8,8 @@ const ipMatch = require("../utils/ipMatch.js"); const createRegex = require("../utils/createRegex.js"); const sha256 = require("../utils/sha256.js"); const sizify = require("../utils/sizify.js"); +const svrjsInfo = require("../../svrjs.json"); +const { name } = svrjsInfo; // ETag-related let ETagDB = {}; @@ -937,7 +939,7 @@ module.exports = (req, res, logFacilities, config, next) => { } else { res.error(501); logFacilities.errmessage( - "SVR.JS doesn't support block devices, character devices, FIFOs nor sockets.", + name + " doesn't support block devices, character devices, FIFOs nor sockets.", ); return; }