diff --git a/index.js b/index.js index 4ca64c1..c8058b4 100644 --- a/index.js +++ b/index.js @@ -1031,10 +1031,10 @@ app.get("/api/healthcheck", (req, res) => { }); // logCall function (caller, callee) -const logCall = (caller, callee) => { +const logCall = (caller, callee, srcIp) => { pool.getConnection().then(conn => { - conn.query('INSERT INTO callLogs (caller, callee, timestamp) VALUES (?, ?, ?)', - [caller, callee, Math.floor(Date.now())]).catch(err => { + conn.query('INSERT INTO callLogs (caller, callee, timestamp, srcIp) VALUES (?, ?, ?, ?)', + [caller, callee, Math.floor(Date.now()), srcIp]).catch(err => { console.error('Error logging call:', err); }).finally(() => { conn.release(); @@ -1043,6 +1043,7 @@ const logCall = (caller, callee) => { } const genCall = (req, res, apiKey, ani, number) => { + const srcIp = process.env.PROXY_HEADER ? req.headers[process.env.PROXY_HEADER] : req.remoteAddress; pool.getConnection().then(conn => { //conn.query("SELECT * FROM routes WHERE apiKey = ? AND block_start <= ? AND block_start + block_length >= ?", [apiKey, ani, ani]).then((rows) => { conn.query("SELECT * FROM routes WHERE apiKey = ?", [apiKey]).then((rows) => { // We'll try this Nick, if it doesn't work we'll go back to the original diff --git a/migrations/011_update_callLogs_add_srcIp.sql b/migrations/011_update_callLogs_add_srcIp.sql new file mode 100644 index 0000000..273365a --- /dev/null +++ b/migrations/011_update_callLogs_add_srcIp.sql @@ -0,0 +1 @@ +ALTER TABLE callLogs ADD COLUMN srcIp VARCHAR(255) NOT NULL DEFAULT 'unknown'; \ No newline at end of file diff --git a/tools/Rotating AstroCom Secret/AstroCom_Rotate.service b/tools/Rotating AstroCom Secret/AstroCom_Rotate.service new file mode 100644 index 0000000..7d1d0d8 --- /dev/null +++ b/tools/Rotating AstroCom Secret/AstroCom_Rotate.service @@ -0,0 +1,5 @@ +[Unit] +Description=Rotate AstroCom Secret +[Service] +ExecStart=/usr/bin/astrocom_rotate.sh +Type=oneshot \ No newline at end of file diff --git a/tools/Rotating AstroCom Secret/AstroCom_Rotate.timer b/tools/Rotating AstroCom Secret/AstroCom_Rotate.timer new file mode 100644 index 0000000..ab2e257 --- /dev/null +++ b/tools/Rotating AstroCom Secret/AstroCom_Rotate.timer @@ -0,0 +1,7 @@ +[Unit] +Description=Rotate AstroCom Secret +[Timer] +# This will run daily at 0200 local time +OnCalendar=*-*-* 02:00:00 +[Install] +WantedBy=timers.target \ No newline at end of file diff --git a/tools/Rotating AstroCom Secret/astrocom_rotate.sh b/tools/Rotating AstroCom Secret/astrocom_rotate.sh new file mode 100644 index 0000000..24367f6 --- /dev/null +++ b/tools/Rotating AstroCom Secret/astrocom_rotate.sh @@ -0,0 +1,69 @@ +#!/bin/bash + +# --- USER CONFIG --- +IAXBLOCK="from-astrocom" +CONF="/etc/asterisk/iax_custom.conf" + +# Astrocom API endpoint info +ASTROCOM_URL="https://astrocom.tel/api/v1/user/update" # Shouldn't need to change this! +ASTROCOM_TOKEN="" +# ------------------- + +# Parse flags +DRYRUN=0 +if [[ "$1" == "--dry-run" || "$1" == "-n" ]]; then + DRYRUN=1 +fi + +# Generate a 32-char alphanumeric secret +NEWSECRET=$(tr -dc 'A-Za-z0-9'