This commit is contained in:
2026-04-22 13:23:14 -05:00
2 changed files with 51 additions and 12 deletions
+39 -11
View File
@@ -16,7 +16,7 @@
$bootstrap_settings['freepbx_auth'] = false; $bootstrap_settings['freepbx_auth'] = false;
require_once('/etc/freepbx.conf'); 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'; $out_file = $provision_dir . '/000000000000-directory.xml';
$do_notify = in_array('--notify', $argv, true); $do_notify = in_array('--notify', $argv, true);
@@ -125,15 +125,43 @@ echo "Wrote $out_file with " . $root->childNodes->length . " contacts\n";
/** Optional: push check-sync to re-download directory without reboot */ /** Optional: push check-sync to re-download directory without reboot */
if ($do_notify) { if ($do_notify) {
// Use the extension list we already built $asteriskBin = '/usr/sbin/asterisk';
$notified = 0;
foreach ($rows as $r) { $excludedEndpoints = [
$ext = trim((string)$r['extension']); '101', '102', '103', '104', '105', '106', '107', '108', '109', '110', '111', '112', '113', '114', '900', 'Voyant', '<Endpoint dpma_endpoint'
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) . "\""; // Get all endpoints from Asterisk CLI
exec($cmd, $o, $rc); $cmd = escapeshellcmd($asteriskBin) . ' -rx "pjsip show endpoints"';
if ($rc === 0) $notified++; exec($cmd, $output, $returnCode);
if ($returnCode !== 0) {
die("Failed to connect to Asterisk CLI.\n");
} }
echo "Sent check-sync to $notified endpoints\n";
// Parse endpoint names (mirror sed: capture until space or slash)
$endpoints = [];
foreach ($output as $line) {
if (preg_match('/^\s*Endpoint:\s+([^\/\s]+)/', $line, $matches)) {
$ep = trim($matches[1]);
if (!in_array($ep, ['anonymous', 'system']) && !in_array($ep, $excludedEndpoints)) {
$endpoints[] = $ep;
}
}
}
$endpoints = array_unique($endpoints);
// Send check-sync NOTIFY to each endpoint
foreach ($endpoints as $ep) {
echo "Sending check-sync to $ep\n";
$notifyCmd = sprintf(
'%s -rx "pjsip send notify polycom-check-cfg endpoint %s"',
escapeshellarg($asteriskBin),
escapeshellarg($ep)
);
exec($notifyCmd);
}
echo "Done.\n";
} }
+12 -1
View File
@@ -1,12 +1,16 @@
## Gen PC Sidecar Script ## 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. 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.
<br> <br>
## Quickstart ## Quickstart
#### Config Fields #### Config Fields
`config.json` has several fields. The config file needs to be next to the script in order to be read. `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.
<br> <br>
<div style="border-left: 6px solid #FFA500; padding: 10px;"> <div style="border-left: 6px solid #FFA500; padding: 10px;">
<strong>⚠️ Warning:</strong> Make sure the config follows proper json syntax. <strong>⚠️ Warning:</strong> Make sure the config follows proper json syntax.
@@ -31,10 +35,17 @@ prepend_extensions
<br> <br>
#### Cronjob Example #### 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 # 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) # 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 5 */4 * * * /usr/bin/php /var/lib/asterisk/PC-Contact-Sync/gen_pc_sidecar.php >> /var/log/gen_pc_sidecar.log 2>&1