From cf7e1653cba2db458dd4b8cffa8b59572785cc70 Mon Sep 17 00:00:00 2001 From: Tyler Murphy Date: Sun, 22 Jan 2023 16:34:07 -0500 Subject: switch to auto reload console --- src/console.js | 67 ++++++++++++++++++++++++++++++++-------------------------- 1 file changed, 37 insertions(+), 30 deletions(-) (limited to 'src') diff --git a/src/console.js b/src/console.js index c7f4089..cbc8f51 100644 --- a/src/console.js +++ b/src/console.js @@ -1,30 +1,16 @@ const express = require('express') const router = express.Router() -const sleep = ms => new Promise(r => setTimeout(r, ms)); -const connections = [] +var requests = [] 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) + res.send(render()) + if(requests.length > 100) { + requests.splice(0, 50) } }) -function color(method) { +function parseMethod(method) { switch(method) { case 'GET': return '4ae04a' @@ -43,7 +29,7 @@ function color(method) { } } -function highlight(json) { +function parseJson(json) { if (typeof json != 'string') { json = JSON.stringify(json, undefined, 2); } @@ -65,17 +51,38 @@ function highlight(json) { }); } -async function update(ip, method, path, json) { - connections.forEach(con => { - con.write(` +function parseRequest(req) { + const html = `
- ${ip} - ${method} - ${path} - ${highlight(json)} + ${req.ip} + ${req.method} + ${req.path} + ${parseJson(req.body)}
- `) - }) + ` + return html +} + +function render() { + const html = ` + + + + + + XSSBook - Console + + + + ${requests.map(r => parseRequest(r)).join('')} + + + ` + return html } -module.exports = { router, update }; \ No newline at end of file +module.exports = { router, requests }; \ No newline at end of file -- cgit v1.2.3-freya