diff --git a/src/handlers/clientErrorHandler.js b/src/handlers/clientErrorHandler.js index 9fe81a9..ecc54b3 100644 --- a/src/handlers/clientErrorHandler.js +++ b/src/handlers/clientErrorHandler.js @@ -1,5 +1,6 @@ const fs = require("fs"); const http = require("http"); +const defaultPageCSS = require("../res/defaultPageCSS.js"); const generateErrorStack = require("../utils/generateErrorStack.js"); const serverHTTPErrorDescs = require("../res/httpErrorDescriptions.js"); const generateServerString = require("../utils/generateServerString.js"); @@ -263,49 +264,51 @@ function clientErrorHandler(err, socket) { // Disable custom error page for HTTP SSL error res.writeHead(errorCode, http.STATUS_CODES[errorCode], cheaders); res.write( - '{errorMessage}

{errorMessage}

{errorDesc}

{server}

' - .replace( - /{errorMessage}/g, - errorCode.toString() + - " " + - http.STATUS_CODES[errorCode] + '{errorMessage}

{errorMessage}

{errorDesc}

{server}

" + .replace( + /{errorMessage}/g, + errorCode.toString() + + " " + + http.STATUS_CODES[errorCode] + .replace(/&/g, "&") + .replace(//g, ">"), + ) + .replace(/{errorDesc}/g, serverHTTPErrorDescs[errorCode]) + .replace( + /{stack}/g, + stack + .replace(/&/g, "&") + .replace(//g, ">") + .replace(/\r\n/g, "
") + .replace(/\n/g, "
") + .replace(/\r/g, "
") + .replace(/ {2}/g, "  "), + ) + .replace( + /{server}/g, + ( + config.generateServerString() + + (!config.exposeModsInErrorPages || extName == undefined + ? "" + : " " + extName) + ) .replace(/&/g, "&") .replace(//g, ">"), - ) - .replace(/{errorDesc}/g, serverHTTPErrorDescs[errorCode]) - .replace( - /{stack}/g, - stack - .replace(/&/g, "&") - .replace(//g, ">") - .replace(/\r\n/g, "
") - .replace(/\n/g, "
") - .replace(/\r/g, "
") - .replace(/ {2}/g, "  "), - ) - .replace( - /{server}/g, - ( - config.generateServerString() + - (!config.exposeModsInErrorPages || extName == undefined - ? "" - : " " + extName) ) - .replace(/&/g, "&") - .replace(//g, ">"), - ) - .replace( - /{contact}/g, - config.serverAdministratorEmail - .replace(/&/g, "&") - .replace(//g, ">") - .replace(/\./g, "[dot]") - .replace(/@/g, "[at]"), - ), + .replace( + /{contact}/g, + config.serverAdministratorEmail + .replace(/&/g, "&") + .replace(//g, ">") + .replace(/\./g, "[dot]") + .replace(/@/g, "[at]"), + ), ); res.end(); } else { @@ -377,7 +380,9 @@ function clientErrorHandler(err, socket) { res.writeHead(errorCode, http.STATUS_CODES[errorCode], cheaders); res.write( ( - '{errorMessage}

{errorMessage}

{errorDesc}

' + + '{errorMessage}

{errorMessage}

{errorDesc}

" + (additionalError == 404 ? "" : "

Additionally, a {additionalError} error occurred while loading an error page.

") + diff --git a/src/handlers/requestHandler.js b/src/handlers/requestHandler.js index e45c311..c2c5320 100644 --- a/src/handlers/requestHandler.js +++ b/src/handlers/requestHandler.js @@ -1,6 +1,7 @@ const http = require("http"); const fs = require("fs"); const net = require("net"); +const defaultPageCSS = require("../res/defaultPageCSS.js"); const generateErrorStack = require("../utils/generateErrorStack.js"); const serverHTTPErrorDescs = require("../res/httpErrorDescriptions.js"); const fixNodeMojibakeURL = require("../utils/urlMojibakeFixer.js"); @@ -535,7 +536,9 @@ function requestHandler(req, res) { res.writeHead(errorCode, http.STATUS_CODES[errorCode], cheaders); res.write( ( - '{errorMessage}

{errorMessage}

{errorDesc}

' + + '{errorMessage}

{errorMessage}

{errorDesc}

" + (additionalError == 404 ? "" : "

Additionally, a {additionalError} error occurred while loading an error page.

") + diff --git a/src/middleware/defaultHandlerChecks.js b/src/middleware/defaultHandlerChecks.js index 1fec49f..7c1b9a1 100644 --- a/src/middleware/defaultHandlerChecks.js +++ b/src/middleware/defaultHandlerChecks.js @@ -1,4 +1,5 @@ const http = require("http"); +const defaultPageCSS = require("../res/defaultPageCSS.js"); const svrjsInfo = require("../../svrjs.json"); const { name } = svrjsInfo; @@ -8,7 +9,9 @@ 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 ' + + '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(/ { .replace(/&/g, "&") .replace(//g, ">") + - '' + '" : customDirListingHeader.replace( //i, "Directory: " + diff --git a/src/middleware/status.js b/src/middleware/status.js index 06b6115..048a91c 100644 --- a/src/middleware/status.js +++ b/src/middleware/status.js @@ -1,5 +1,6 @@ const http = require("http"); const os = require("os"); +const defaultPageCSS = require("../res/defaultPageCSS.js"); const sizify = require("../utils/sizify.js"); const svrjsInfo = require("../../svrjs.json"); const { name } = svrjsInfo; @@ -95,7 +96,9 @@ module.exports = (req, res, logFacilities, config, next) => { .replace(/&/g, "&") .replace(/</g, "<") .replace(/>/g, ">")) + - '' + '" : res.head.replace( //i, "" + diff --git a/src/res/defaultPageCSS.js b/src/res/defaultPageCSS.js new file mode 100644 index 0000000..26f6895 --- /dev/null +++ b/src/res/defaultPageCSS.js @@ -0,0 +1,5 @@ +// Default CSS used for the pages generated by SVR.JS +const defaultPageCSS = + 'html{background-color:#dfffdf;color:#000000;font-family:FreeSans, Helvetica, Tahoma, Verdana, Arial, sans-serif;margin:0.75em}body{background-color:#ffffff;padding:0.5em 0.5em 0.1em;margin:0.5em auto;width:90%;max-width:800px;-webkit-box-shadow:0 5px 10px 0 rgba(0, 0, 0, 0.15);-moz-box-shadow:0 5px 10px 0 rgba(0, 0, 0, 0.15);box-shadow:0 5px 10px 0 rgba(0, 0, 0, 0.15)}h1{text-align:center;font-size:2.25em;margin:0.3em 0 0.5em}code{background-color:#dfffdf;-webkit-box-shadow:0 2px 4px 0 rgba(0, 0, 0, 0.1);-moz-box-shadow:0 2px 4px 0 rgba(0, 0, 0, 0.1);box-shadow:0 2px 4px 0 rgba(0, 0, 0, 0.1);display:block;padding:0.2em;font-family:"DejaVu Sans Mono", "Bitstream Vera Sans Mono", Hack, Menlo, Consolas, Monaco, monospace;font-size:0.85em;margin:auto;width:95%;max-width:600px}table{width:95%;border-collapse:collapse;margin:auto;overflow-wrap:break-word;word-wrap:break-word;word-break:break-all;word-break:break-word;position:relative;z-index:0}table tbody{background-color:#ffffff;color:#000000}table tbody:after{-webkit-box-shadow:0 4px 8px 0 rgba(0, 0, 0, 0.175);-moz-box-shadow:0 4px 8px 0 rgba(0, 0, 0, 0.175);box-shadow:0 4px 8px 0 rgba(0, 0, 0, 0.175);content:\' \';position:absolute;top:0;left:0;right:0;bottom:0;z-index:-1}table img{margin:0;display:inline}th,tr{padding:0.15em;text-align:center}th{background-color:#007000;color:#ffffff}th a{color:#ffffff}td,th{padding:0.225em}td{text-align:left}tr:nth-child(odd){background-color:#dfffdf}hr{color:#ffffff}@media screen and (prefers-color-scheme: dark){html{background-color:#002000;color:#ffffff}body{background-color:#000f00;-webkit-box-shadow:0 5px 10px 0 rgba(127, 127, 127, 0.15);-moz-box-shadow:0 5px 10px 0 rgba(127, 127, 127, 0.15);box-shadow:0 5px 10px 0 rgba(127, 127, 127, 0.15)}code{background-color:#002000;-webkit-box-shadow:0 2px 4px 0 rgba(127, 127, 127, 0.1);-moz-box-shadow:0 2px 4px 0 rgba(127, 127, 127, 0.1);box-shadow:0 2px 4px 0 rgba(127, 127, 127, 0.1)}a{color:#ffffff}a:hover{color:#00ff00}table tbody{background-color:#000f00;color:#ffffff}table tbody:after{-webkit-box-shadow:0 4px 8px 0 rgba(127, 127, 127, 0.175);-moz-box-shadow:0 4px 8px 0 rgba(127, 127, 127, 0.175);box-shadow:0 4px 8px 0 rgba(127, 127, 127, 0.175)}tr:nth-child(odd){background-color:#002000}}'; + +module.exports = defaultPageCSS;