diff --git a/gen_polycom_directory.php b/gen_polycom_directory.php index 5216a01..052472a 100755 --- a/gen_polycom_directory.php +++ b/gen_polycom_directory.php @@ -125,15 +125,14 @@ echo "Wrote $out_file with " . $root->childNodes->length . " contacts\n"; /** Optional: push check-sync to re-download directory without reboot */ if ($do_notify) { - // Use the extension list we already built - $notified = 0; - foreach ($rows as $r) { - $ext = trim((string)$r['extension']); - if ($ext === '') continue; - // In FreePBX, PJSIP endpoint id is typically the extension number - $cmd = "asterisk -rx \"pjsip send notify polycom-check-cfg endpoint " . escapeshellarg($ext) . "\""; - exec($cmd, $o, $rc); - if ($rc === 0) $notified++; - } - echo "Sent check-sync to $notified endpoints\n"; + asterisk_bin=/usr/sbin/asterisk + endpoints=$($asterisk_bin -rx "pjsip show endpoints" \ + | sed -n 's/^[[:space:]]*Endpoint:[[:space:]]\+\([^[:space:]/]\+\).*/\1/p' \ + | grep -vE '^(anonymous|system)$' \ + | sort -u) + + for ep in $endpoints; do + echo "Sending check-sync to $ep" + $asterisk_bin -rx "pjsip send notify polycom-check-cfg endpoint $ep" + done }