diff options
author | kaotisk <kaotisk@arching-kaos.org> | 2025-03-18 01:42:44 +0200 |
---|---|---|
committer | kaotisk <kaotisk@arching-kaos.org> | 2025-03-18 01:42:44 +0200 |
commit | 1b005d0345ec24709c7cd8915cdb30cb30f59c91 (patch) | |
tree | 86257ec2a882ee064c1bd91d5057a4ea2e9c9e5c | |
parent | 95b1364f4aa1bafdcfcbae99387555c9d06c8ce2 (diff) | |
download | arching-kaos-tools-1b005d0345ec24709c7cd8915cdb30cb30f59c91.tar.gz arching-kaos-tools-1b005d0345ec24709c7cd8915cdb30cb30f59c91.tar.bz2 arching-kaos-tools-1b005d0345ec24709c7cd8915cdb30cb30f59c91.zip |
[api] exported function checkIfAllowedIP
-rwxr-xr-x | api/index.js | 9 | ||||
-rw-r--r-- | api/lib/checkIfAllowedIP/index.js | 8 | ||||
-rw-r--r-- | api/routes/getRemoteNodeInfo/index.js | 3 | ||||
-rw-r--r-- | api/routes/getRemotePeers/index.js | 4 |
4 files changed, 13 insertions, 11 deletions
diff --git a/api/index.js b/api/index.js index 91ae7be..3394a0d 100755 --- a/api/index.js +++ b/api/index.js @@ -14,6 +14,7 @@ const getRemoteNodeInfo = require('./routes/getRemoteNodeInfo/index.js'); const getRemotePeers = require('./routes/getRemotePeers/index.js'); const akLogMessage = require('./lib/akLogMessage'); +const checkIfAllowedIP = require('./lib/checkIfAllowedIP/index.js'); akLogMessage('INFO', 'akLogMessage loaded'); const serverOptions = { keepAliveTimeout: 60000 }; @@ -99,14 +100,6 @@ function processMethod(req, res) } } -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; -} - function requestParser(req, res) { printRequest(req); diff --git a/api/lib/checkIfAllowedIP/index.js b/api/lib/checkIfAllowedIP/index.js new file mode 100644 index 0000000..d9693d9 --- /dev/null +++ b/api/lib/checkIfAllowedIP/index.js @@ -0,0 +1,8 @@ + +module.exports = (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; +}; + diff --git a/api/routes/getRemoteNodeInfo/index.js b/api/routes/getRemoteNodeInfo/index.js index 6cfff4b..a88f528 100644 --- a/api/routes/getRemoteNodeInfo/index.js +++ b/api/routes/getRemoteNodeInfo/index.js @@ -6,6 +6,7 @@ const { spawn } = require('child_process'); const config = require("../../config.js"); +const checkIfAllowedIP = require('../../lib/checkIfAllowedIP/index.js'); module.exports = (req, res) => { var args = req.url.split("/"); @@ -15,7 +16,7 @@ module.exports = (req, res) => { ip = args[3]; } var test = /^fc[0-9a-z]{1,2}:([0-9a-z]{1,4}:){1,6}[0-9a-z]{1,4}/ - if (test.test(ip)) + if (checkIfAllowedIP(ip)) { const command = spawn("curl", ["--retry-max-time","3","-s",`http://[${ip}]:8610/v0/node_info`]); var buffer = ""; diff --git a/api/routes/getRemotePeers/index.js b/api/routes/getRemotePeers/index.js index 78dbba4..c75a98a 100644 --- a/api/routes/getRemotePeers/index.js +++ b/api/routes/getRemotePeers/index.js @@ -6,6 +6,7 @@ const { spawn } = require('child_process'); const config = require("../../config.js"); +const checkIfAllowedIP = require('../../lib/checkIfAllowedIP/index.js'); module.exports = (req, res) => { var args = req.url.split("/"); @@ -14,8 +15,7 @@ module.exports = (req, res) => { { ip = args[3]; } - var test = /^fc[0-9a-z]{1,2}:([0-9a-z]{1,4}:){1,6}[0-9a-z]{1,4}/ - if (test.test(ip)) + if (checkIfAllowedIP(ip)) { const command = spawn("curl", ["--retry-max-time","3","-s",`http://[${ip}]:8610/v0/peers`]); var buffer = ""; |