From 23eb8b16b69f3eb0d731f774064fe393f70f8514 Mon Sep 17 00:00:00 2001 From: Tyler Murphy Date: Sun, 22 Jan 2023 16:00:31 -0500 Subject: console --- src/console.js | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 src/console.js (limited to 'src') diff --git a/src/console.js b/src/console.js new file mode 100644 index 0000000..c7f4089 --- /dev/null +++ b/src/console.js @@ -0,0 +1,81 @@ +const express = require('express') +const router = express.Router() +const sleep = ms => new Promise(r => setTimeout(r, ms)); + +const connections = [] + +router.get('/', async (req, res) => { + res.write(` + + + + + + XSSBook - Console + + + `) + res.write(new Array(2048).join(" ")) + await sleep(500) + connections.push(res) + while (true) { + res.write(" ") + await sleep(100) + } +}) + +function color(method) { + switch(method) { + case 'GET': + return '4ae04a' + case 'POST': + return 'b946db' + case 'PUT': + return 'ff9705' + case 'PATCH': + return `42caff` + case 'DELETE': + return `ff4a4a` + case 'HEAD': + return '424cff' + case 'OPTIONS': + return 'ff9757' + } +} + +function highlight(json) { + if (typeof json != 'string') { + json = JSON.stringify(json, undefined, 2); + } + json = json.replace(/&/g, '&').replace(//g, '>'); + return json.replace(/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g, function (match) { + var cls = 'number'; + if (/^"/.test(match)) { + if (/:$/.test(match)) { + cls = 'key'; + } else { + cls = 'string'; + } + } else if (/true|false/.test(match)) { + cls = 'boolean'; + } else if (/null/.test(match)) { + cls = 'null'; + } + return '' + match + ''; + }); +} + +async function update(ip, method, path, json) { + connections.forEach(con => { + con.write(` +
+ ${ip} + ${method} + ${path} + ${highlight(json)} +
+ `) + }) +} + +module.exports = { router, update }; \ No newline at end of file -- cgit v1.2.3-freya