diff options
author | Tom Smeding <t.j.smeding@uu.nl> | 2024-09-30 16:57:51 +0200 |
---|---|---|
committer | Tom Smeding <t.j.smeding@uu.nl> | 2024-09-30 16:57:51 +0200 |
commit | d5d25a365a186ca0efd46bcab36a7467de690571 (patch) | |
tree | 7eeed0afb89e53a8c0afc8cd2d0281fb725736d5 /modules/up_log | |
parent | 964dc37d6989d011ebaca89fe3a5846a7dcfa96a (diff) |
up_log module
Diffstat (limited to 'modules/up_log')
-rw-r--r-- | modules/up_log/.gitignore | 2 | ||||
-rw-r--r-- | modules/up_log/up_log.js | 29 |
2 files changed, 31 insertions, 0 deletions
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(); + }); +}; |