2025-07-15 04:48:56 +00:00
|
|
|
#!/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>-->"
|
|
|
|
|
}
|
2025-07-15 14:07:35 +00:00
|
|
|
/<field[[:space:]]+name="MessagingUrl"[^>]*>https:\/\/voip\.ms\/api\/3cx\/msg<\/field>/ {
|
2025-07-15 04:48:56 +00:00
|
|
|
print repl
|
|
|
|
|
next
|
|
|
|
|
}
|
|
|
|
|
{ print }
|
|
|
|
|
' "$CUSTOM_PATH" > "${CUSTOM_PATH}.tmp" && mv "${CUSTOM_PATH}.tmp" "$CUSTOM_PATH"
|
|
|
|
|
|
2025-07-15 14:07:35 +00:00
|
|
|
|
2025-07-15 13:54:02 +00:00
|
|
|
chown phonesystem:phonesystem $CUSTOM_PATH
|
|
|
|
|
|
2025-07-15 04:48:56 +00:00
|
|
|
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
|