From d5d25a365a186ca0efd46bcab36a7467de690571 Mon Sep 17 00:00:00 2001 From: Tom Smeding Date: Mon, 30 Sep 2024 16:57:51 +0200 Subject: up_log module --- modules/up_log/.gitignore | 2 ++ modules/up_log/up_log.js | 29 +++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 modules/up_log/.gitignore create mode 100644 modules/up_log/up_log.js (limited to 'modules/up_log') diff --git a/modules/up_log/.gitignore b/modules/up_log/.gitignore new file mode 100644 index 0000000..955d2cc --- /dev/null +++ b/modules/up_log/.gitignore @@ -0,0 +1,2 @@ +accounts.json +log.txt diff --git a/modules/up_log/up_log.js b/modules/up_log/up_log.js new file mode 100644 index 0000000..609d705 --- /dev/null +++ b/modules/up_log/up_log.js @@ -0,0 +1,29 @@ +const cmn = require("../$common.js"); +const fs = require("fs"); +const bodyParser = require("body-parser"); + +let moddir = null; + +module.exports=function(app,io,_moddir){ + moddir = _moddir; + + let config, accounts; + try { + accounts = require("./accounts.json"); + } catch (e) { + console.error(e); + return false; + } + + app.post("/up_log/log", bodyParser.json(), cmn.authgen(accounts), (req,res) => { + if (typeof req.body.machine != "string") { + return res.sendStatus(400); + } + + const machine = req.body.machine.replace(/[^a-zA-Z0-9._-]/g, ""); + + fs.appendFileSync(moddir + "/log.txt", new Date().toISOString() + " machine=" + machine + "\n"); + + res.status(200).end(); + }); +}; -- cgit v1.2.3-70-g09d2