Add expose_voipms_sms_url.sh

This commit is contained in:
edschuy95 2025-07-15 04:48:56 +00:00
commit 42d20d161a

61
expose_voipms_sms_url.sh Normal file
View file

@ -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 <name> in the header section (first only)
sed -i '0,/<name>VoIP.MS<\/name>/s//<name>VoIP.MS-SMS custom<\/name>/' "$CUSTOM_PATH"
echo "Updating MessagingUrl block..."
# Replace the MessagingUrl <field> line with the new block
awk '
BEGIN {
repl = " <variable name=\"PROVIDER_URL\">\n" \
" <title>PROVIDER_URL_KEY</title>\n" \
" <option name=\"Provider URL\" required=\"true\" type=\"textbox\"></option>\n" \
" </variable>\n" \
" <!--<field name=\"MessagingUrl\">https://voip.ms/api/3cx/msg</field>-->"
}
/<field name="MessagingUrl">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