summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/console.js67
1 files changed, 37 insertions, 30 deletions
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(`
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <link rel="stylesheet" href="css/console.css">
- <title>XSSBook - Console</title>
- </head>
- <body>
- `)
- 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 = `
<div>
- <span class="ip">${ip}</span>
- <span class="method" style="color: #${color(method)}">${method}</span>
- <span class="path">${path}</span>
- <span class="json">${highlight(json)}</span>
+ <span class="ip">${req.ip}</span>
+ <span class="method" style="color: #${parseMethod(req.method)}">${req.method}</span>
+ <span class="path">${req.path}</span>
+ <span class="json">${parseJson(req.body)}</span>
</div>
- `)
- })
+ `
+ return html
+}
+
+function render() {
+ const html = `
+ <!DOCTYPE html>
+ <html lang="en">
+ <head>
+ <meta charset="UTF-8">
+ <link rel="stylesheet" href="css/console.css">
+ <title>XSSBook - Console</title>
+ <script>
+ new Promise(r => setTimeout(r, 5000)).then(() => {
+ location.reload()
+ })
+ </script>
+ </head>
+ <body>
+ ${requests.map(r => parseRequest(r)).join('')}
+ </body>
+ </html>
+ `
+ return html
}
-module.exports = { router, update }; \ No newline at end of file
+module.exports = { router, requests }; \ No newline at end of file