Add IP logging for genCall
This commit is contained in:
parent
da5a029161
commit
86fd430d46
7
index.js
7
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
|
||||
|
|
|
|||
1
migrations/011_update_callLogs_add_srcIp.sql
Normal file
1
migrations/011_update_callLogs_add_srcIp.sql
Normal file
|
|
@ -0,0 +1 @@
|
|||
ALTER TABLE callLogs ADD COLUMN srcIp VARCHAR(255) NOT NULL DEFAULT 'unknown';
|
||||
5
tools/Rotating AstroCom Secret/AstroCom_Rotate.service
Normal file
5
tools/Rotating AstroCom Secret/AstroCom_Rotate.service
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
[Unit]
|
||||
Description=Rotate AstroCom Secret
|
||||
[Service]
|
||||
ExecStart=/usr/bin/astrocom_rotate.sh
|
||||
Type=oneshot
|
||||
7
tools/Rotating AstroCom Secret/AstroCom_Rotate.timer
Normal file
7
tools/Rotating AstroCom Secret/AstroCom_Rotate.timer
Normal file
|
|
@ -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
|
||||
69
tools/Rotating AstroCom Secret/astrocom_rotate.sh
Normal file
69
tools/Rotating AstroCom Secret/astrocom_rotate.sh
Normal file
|
|
@ -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' </dev/urandom | head -c 32)
|
||||
|
||||
# Escape block name for sed search
|
||||
ESC_BLOCK=$(printf '%s\n' "$IAXBLOCK" | sed 's/[]\/$*.^[]/\\&/g')
|
||||
|
||||
# Sed script to modify only the first secret= inside the block
|
||||
SED_SCRIPT="
|
||||
/^\[$ESC_BLOCK\]/,/^\[/{
|
||||
/^\[/!{
|
||||
s/^secret=.*/secret=$NEWSECRET/
|
||||
t done
|
||||
}
|
||||
}
|
||||
: done
|
||||
"
|
||||
|
||||
if [[ $DRYRUN -eq 1 ]]; then
|
||||
echo "=== DRY RUN: Showing updated output only ==="
|
||||
sed "$SED_SCRIPT" "$CONF"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
#
|
||||
# REAL UPDATE EXECUTION
|
||||
#
|
||||
|
||||
echo "Updating secret in file..."
|
||||
sed -i "$SED_SCRIPT" "$CONF" || { echo "Error updating $CONF"; exit 1; }
|
||||
|
||||
echo "New secret: $NEWSECRET"
|
||||
|
||||
#
|
||||
# ASTROCOM API REQUEST
|
||||
#
|
||||
echo "Sending updated secret to Astrocom..."
|
||||
|
||||
# ----- EDIT THIS TO MATCH YOUR REAL API FORMAT -----
|
||||
curl -X PATCH "$ASTROCOM_URL" \
|
||||
-H "Authorization: Bearer $ASTROCOM_TOKEN" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "{\"secret\": \"$NEWSECRET\"}" \
|
||||
|| echo "Warning: Astrocom API call failed"
|
||||
# ---------------------------------------------------
|
||||
|
||||
#
|
||||
# RELOAD ASTERISK
|
||||
#
|
||||
echo "Reloading Asterisk..."
|
||||
asterisk -x "core reload"
|
||||
|
||||
echo "Update complete."
|
||||
Loading…
Reference in a new issue