diff options
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(); + }); +}; |