diff --git a/Dockerfile b/Dockerfile index 26117c3..39030d4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,6 +2,7 @@ FROM node:lts-alpine USER node WORKDIR /app ENV NODE_ENV production +ENV TZ Europe/Warsaw COPY --chown=node:node index.mjs ./ EXPOSE 3000 CMD ["node", "./index.mjs"] diff --git a/index.mjs b/index.mjs index 313a0d4..ed3a723 100644 --- a/index.mjs +++ b/index.mjs @@ -2,13 +2,20 @@ import { createServer } from 'node:http'; import { clearInterval, setInterval } from 'node:timers'; const server = createServer((req, res) => { + const connOpenDate = new Date(); + const attacker = req.headers['x-forwarded-for']; + const host = req.headers['x-targeted-host']; + console.log( - `Caught ${req.headers['x-forwarded-for']} on ${req.method} ${req.url}` + `[${connOpenDate.toLocaleString()}] ${attacker} targeted ${host} on ${ + req.method + } ${req.url}` ); - let msg = ':) you are an idiot hahahahaha :)'; + const msg = ':) you are an idiot hahahahaha :)'; let charIdx = 0; - let intervalId = setInterval(() => { + + const intervalId = setInterval(() => { if (charIdx === msg.length) { charIdx = 0; res.write('\n'); @@ -17,7 +24,16 @@ const server = createServer((req, res) => { } }, 3000); - res.once('close', () => clearInterval(intervalId)); + res.once('close', () => { + const connCloseDate = new Date(); + const timeDiff = connCloseDate.getTime() - connOpenDate.getTime(); + const diffText = new Date(timeDiff).toISOString().substring(11, 19); + + clearInterval(intervalId); + console.log( + `[${connCloseDate.toLocaleString()}] ${attacker} aborted connection after ${diffText}` + ); + }); }); server.listen(3000);