From 88bd43593a46edc9c2ef98964f7722df2cf7d806 Mon Sep 17 00:00:00 2001 From: poslop Date: Wed, 22 Apr 2026 10:39:58 -0500 Subject: [PATCH 1/5] redo notify to exclude sangoma --- gen_polycom_directory.php | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) 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 } From be8f9b5ba4c299db572cb1e3489e181f3918c011 Mon Sep 17 00:00:00 2001 From: poslop Date: Wed, 22 Apr 2026 10:50:09 -0500 Subject: [PATCH 2/5] fixed syntax --- gen_polycom_directory.php | 47 +++++++++++++++++++++++++++++++-------- 1 file changed, 38 insertions(+), 9 deletions(-) diff --git a/gen_polycom_directory.php b/gen_polycom_directory.php index 052472a..e899a70 100755 --- a/gen_polycom_directory.php +++ b/gen_polycom_directory.php @@ -125,14 +125,43 @@ echo "Wrote $out_file with " . $root->childNodes->length . " contacts\n"; /** Optional: push check-sync to re-download directory without reboot */ if ($do_notify) { - 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) + $asteriskBin = '/usr/sbin/asterisk'; - for ep in $endpoints; do - echo "Sending check-sync to $ep" - $asterisk_bin -rx "pjsip send notify polycom-check-cfg endpoint $ep" - done + $excludedEndpoints = [ + '101', '102', '103', '104', '105', '106', '107', '108', '109', '110', '111', '112', '113', '114', '900', 'Voyant', ' Date: Wed, 22 Apr 2026 12:03:37 -0500 Subject: [PATCH 3/5] changed provision_dir to /tftboot --- gen_polycom_directory.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gen_polycom_directory.php b/gen_polycom_directory.php index e899a70..7358f8b 100755 --- a/gen_polycom_directory.php +++ b/gen_polycom_directory.php @@ -16,7 +16,7 @@ $bootstrap_settings['freepbx_auth'] = false; require_once('/etc/freepbx.conf'); -$provision_dir = '/tftpboot/directory'; // <-- adjust if needed +$provision_dir = '/tftpboot'; // <-- adjust if needed $out_file = $provision_dir . '/000000000000-directory.xml'; $do_notify = in_array('--notify', $argv, true); From ff1f8f618e48e59db75400d2467048ded2efd31d Mon Sep 17 00:00:00 2001 From: poslop Date: Wed, 22 Apr 2026 12:06:04 -0500 Subject: [PATCH 4/5] Update readme.md --- readme.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/readme.md b/readme.md index a5d4b57..942c9b8 100644 --- a/readme.md +++ b/readme.md @@ -34,10 +34,10 @@ prepend_extensions ``` # Run Polycom directory sync every 4 hours at :00 -0 */4 * * * /usr/bin/php /var/lib/asterisk/PC-Contact-Sync/gen_polycom_directory.php >> /var/log/gen_polycom_directory.log 2>&1 +0 */4 * * * /usr/bin/php /var/lib/asterisk/PC-Contact-Sync/gen_polycom_directory.php --notify >> /var/log/gen_polycom_directory.log 2>&1 # Run PC sidecar sync every 4 hours at :05 (5 mins after) -5 */4 * * * /usr/bin/php /var/lib/asterisk/PC-Contact-Sync/gen_pc_sidecar.php >> /var/log/gen_pc_sidecar.log 2>&1 +10 */4 * * * /usr/bin/php /var/lib/asterisk/PC-Contact-Sync/gen_pc_sidecar.php >> /var/log/gen_pc_sidecar.log 2>&1 ```
From a15c767684ade9eaae7f303c7fc19da0bf58c8d3 Mon Sep 17 00:00:00 2001 From: poslop Date: Wed, 22 Apr 2026 12:28:42 -0500 Subject: [PATCH 5/5] Update readme.md --- readme.md | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 942c9b8..cce8ce2 100644 --- a/readme.md +++ b/readme.md @@ -1,12 +1,16 @@ ## Gen PC Sidecar Script The files are stored typically inside of `/var/lib/asterisk/PC-Contact-Sync` and the scripts should be run every 6 hours by a cron job. +Make sure that all files are owned by asterisk user including the output files and the cronjob. +
## Quickstart #### Config Fields `config.json` has several fields. The config file needs to be next to the script in order to be read. +See the example [config.json](./config.json) included. +
⚠️ Warning: Make sure the config follows proper json syntax. @@ -31,13 +35,20 @@ prepend_extensions
#### Cronjob Example +Create the cronjob as asterisk user. + +``` +EDITOR=vim crontab -e -u asterisk +``` + +Append this to the crontab ``` # Run Polycom directory sync every 4 hours at :00 0 */4 * * * /usr/bin/php /var/lib/asterisk/PC-Contact-Sync/gen_polycom_directory.php --notify >> /var/log/gen_polycom_directory.log 2>&1 # Run PC sidecar sync every 4 hours at :05 (5 mins after) -10 */4 * * * /usr/bin/php /var/lib/asterisk/PC-Contact-Sync/gen_pc_sidecar.php >> /var/log/gen_pc_sidecar.log 2>&1 +5 */4 * * * /usr/bin/php /var/lib/asterisk/PC-Contact-Sync/gen_pc_sidecar.php >> /var/log/gen_pc_sidecar.log 2>&1 ```