commit 42d20d161af9e3db9d2e5294ff06e94def2671c8 Author: edschuy95 Date: Tue Jul 15 04:48:56 2025 +0000 Add expose_voipms_sms_url.sh diff --git a/expose_voipms_sms_url.sh b/expose_voipms_sms_url.sh new file mode 100644 index 0000000..d04fb53 --- /dev/null +++ b/expose_voipms_sms_url.sh @@ -0,0 +1,61 @@ +#!/usr/bin/env bash + +# === CONFIG === +# Path to the provider templates directory +TEMPLATE_DIR="/var/lib/3cxpbx/Instance1/Data/Http/Templates/provider" + +# Filenames +ORIGINAL="voipms.pv.xml" +CUSTOM="voipms-smscustom.pv.xml" + +# DB config +DB_NAME="database_single" +DB_USER="postgres" + +# === SCRIPT === + +# Full paths +ORIGINAL_PATH="$TEMPLATE_DIR/$ORIGINAL" +CUSTOM_PATH="$TEMPLATE_DIR/$CUSTOM" + +echo "Using template directory: $TEMPLATE_DIR" + +# Safety check +if [ ! -f "$ORIGINAL_PATH" ]; then + echo "Error: Original template $ORIGINAL_PATH not found!" + exit 1 +fi + +echo "Copying $ORIGINAL_PATH to $CUSTOM_PATH..." +cp "$ORIGINAL_PATH" "$CUSTOM_PATH" + +echo "Updating template header name..." +# Replace the in the header section (first only) +sed -i '0,/VoIP.MS<\/name>/s//VoIP.MS-SMS custom<\/name>/' "$CUSTOM_PATH" + +echo "Updating MessagingUrl block..." +# Replace the MessagingUrl line with the new block +awk ' +BEGIN { + repl = " \n" \ + " PROVIDER_URL_KEY\n" \ + " \n" \ + " \n" \ + " " +} +/https:\/\/voip\.ms\/api\/3cx\/msg<\/field>/ { + print repl + next +} +{ print } +' "$CUSTOM_PATH" > "${CUSTOM_PATH}.tmp" && mv "${CUSTOM_PATH}.tmp" "$CUSTOM_PATH" + +echo "Custom template created at: $CUSTOM_PATH" + +echo "Updating trunk model in database..." +# Run the psql update — using sudo for the postgres user +sudo -u postgres psql -d "$DB_NAME" -c "UPDATE gateway SET model = '$CUSTOM' WHERE model = '$ORIGINAL';" + +echo "Database model updated for all matching trunks!" +3CXStopServices +3CXStartServices \ No newline at end of file