diff options
Diffstat (limited to 'api/lib')
-rw-r--r-- | api/lib/akLogMessage/index.js | 12 | ||||
-rw-r--r-- | api/lib/checkIfAllowedIP/index.js | 9 | ||||
-rw-r--r-- | api/lib/storeIncomingIP/index.js | 8 |
3 files changed, 24 insertions, 5 deletions
diff --git a/api/lib/akLogMessage/index.js b/api/lib/akLogMessage/index.js index 0df974a..59a1300 100644 --- a/api/lib/akLogMessage/index.js +++ b/api/lib/akLogMessage/index.js @@ -1,10 +1,11 @@ const { spawn } = require('child_process'); const config = require('../../config') -module.exports = (type, message) => { +function akLogMessage(type, message) +{ const command = spawn( - "ak", - ["log", "-m", "ak-daemon", type, message] + "ak-log", + ["-m", "ak-daemon", type, message] ); var buffer = ""; @@ -20,9 +21,10 @@ module.exports = (type, message) => { console.log(`error: ${error.message}`); }); - command.on("close", code => { - // res.send(JSON.parse(buffer)); + command.on("close", (code) => { + console.log(buffer); if (config.printDebug === "yes") console.log(buffer); console.log(`child process exited with code ${code}`); }); }; +module.exports = akLogMessage; diff --git a/api/lib/checkIfAllowedIP/index.js b/api/lib/checkIfAllowedIP/index.js new file mode 100644 index 0000000..2e50418 --- /dev/null +++ b/api/lib/checkIfAllowedIP/index.js @@ -0,0 +1,9 @@ +function checkIfAllowedIP(address) +{ + var test_cjdns = /^fc[0-9a-z]{1,2}:([0-9a-z]{1,4}:){1,6}[0-9a-z]{1,4}/ + var test_yggdrasil = /^2[0-9a-z]{1,2}:([0-9a-z]{1,4}:){1,6}[0-9a-z]{1,4}/ + var test_yggdrasil_sub = /^3[0-9a-z]{1,2}:([0-9a-z]{1,4}:){1,6}[0-9a-z]{1,4}/ + return (test_cjdns.test(address) || test_yggdrasil.test(address) || test_yggdrasil_sub.test(address)) ? true : false; +}; + +module.exports = checkIfAllowedIP; diff --git a/api/lib/storeIncomingIP/index.js b/api/lib/storeIncomingIP/index.js new file mode 100644 index 0000000..72273d0 --- /dev/null +++ b/api/lib/storeIncomingIP/index.js @@ -0,0 +1,8 @@ +const fs = require("node:fs"); +const config = require("../../config"); + +function storeIncomingIP(ip_address) +{ + fs.appendFileSync(`${config.peersDir}/incomingRequests`, `${ip_address}\n`); +} +module.exports = storeIncomingIP; |