Fix chan_sip intercepting registrations and pjsip.conf corruption after import

Three fixes:
- Always regenerate modules.conf on startup to ensure chan_sip stays disabled.
  Previously it was only written if missing, so a persisted Docker volume with
  an old modules.conf would load chan_sip, causing all pjsip registrations to
  fail with "Wrong password".
- Add pjsip.conf sanitization on startup to remove endpoint-only options
  (like direct_media) that end up in aor sections after a corrupted import.
- Fix dialplan rebuild to skip room extensions that conflict with device
  extensions, preventing duplicate extension registration warnings.
- Fix import merge to not write orphaned device comment headers for skipped
  (conflicting) devices.

https://claude.ai/code/session_01Vm6NLaQuzM4VosAotqS1q8
This commit is contained in:
Claude
2026-02-24 14:10:49 +00:00
parent 61b9235f60
commit 06c75371d0
2 changed files with 53 additions and 6 deletions
+17 -3
View File
@@ -3174,6 +3174,7 @@ exten => _X.,1,Hangup()
EOF
local dev_name="" dev_cat="" dev_auto="" dev_aa_override=""
local -A device_extensions=()
while IFS= read -r line; do
if [[ "$line" == *"; === Device:"* ]]; then
dev_aa_override=""
@@ -3198,6 +3199,7 @@ EOF
if [[ "$line" =~ ^\[([0-9]+)\] ]]; then
local ext="${BASH_REMATCH[1]}"
if [[ -n "$dev_name" ]]; then
device_extensions[$ext]=1
if [[ "$dev_auto" == "yes" ]]; then
cat >> "$conf_file" << EOF
exten => ${ext},1,NoOp(Auto-Answer ${ext})
@@ -3220,11 +3222,15 @@ EOF
fi
done < /etc/asterisk/pjsip.conf
# Add rooms
# Add rooms (skip if extension already used by a device)
if [[ -f "$ROOMS_FILE" ]]; then
while IFS='|' read -r rext rname rmem rtime rtype; do
[[ "$rext" =~ ^# ]] && continue
[[ -z "$rext" ]] && continue
if [[ -n "${device_extensions[$rext]:-}" ]]; then
[[ "$quiet" != "quiet" ]] && print_warn "Room '$rname' ext $rext conflicts with device — skipping"
continue
fi
local dial_list=""
IFS=',' read -ra EXTS <<< "$rmem"
for ext in "${EXTS[@]}"; do
@@ -6663,17 +6669,25 @@ import_clients() {
echo "Importing non-conflicting devices..."
local temp_import="/tmp/import_filtered_${timestamp}.conf"
local skip_device=0
local pending_header=""
while IFS= read -r line; do
if [[ "$line" == "; === Device:"* ]]; then
skip_device=0
echo "$line" >> "$temp_import"
pending_header="$line"
elif [[ "$line" =~ ^\[([0-9]+)\]$ ]]; then
local ext="${BASH_REMATCH[1]}"
if grep -q "^\[${ext}\]" /etc/asterisk/pjsip.conf 2>/dev/null; then
skip_device=1
echo " Skipping extension $ext (already exists)"
if [[ -n "$pending_header" ]]; then
echo " Skipping extension $ext (already exists)"
pending_header=""
fi
else
if [[ -n "$pending_header" ]]; then
echo "$pending_header" >> "$temp_import"
pending_header=""
fi
echo "$line" >> "$temp_import"
fi
elif [[ $skip_device -eq 0 ]]; then