formatting

This commit is contained in:
2026-04-23 15:05:06 -05:00
parent 034d05eb81
commit 5768f75f29
2 changed files with 259 additions and 228 deletions
+33 -14
View File
@@ -1,5 +1,6 @@
#!/usr/bin/php -q
<?php
/**
* Generate Polycom-compatible global directory XML (000000000000-directory.xml)
* from PBXact/FreePBX extensions.
@@ -14,11 +15,11 @@
*/
$bootstrap_settings['freepbx_auth'] = false;
require_once('/etc/freepbx.conf');
require_once '/etc/freepbx.conf';
$provision_dir = '/tftpboot'; // <-- adjust if needed
$out_file = $provision_dir . '/000000000000-directory.xml';
$do_notify = in_array('--notify', $argv, true);
$provision_dir = '/tftpboot'; // <-- adjust if needed
$out_file = $provision_dir . '/000000000000-directory.xml';
$do_notify = in_array('--notify', $argv, true);
$db = FreePBX::Database();
$rows = [];
@@ -39,17 +40,18 @@ try {
/** Fall back to PJSIP ps_endpoints (id is ext; parse callerid "Name <1001>") */
if (!$rows) {
$stmt = $db->prepare("
$stmt = $db->prepare('
SELECT id AS extension, callerid
FROM ps_endpoints
ORDER BY CAST(id AS UNSIGNED)
");
');
$stmt->execute();
$tmp = $stmt->fetchAll(PDO::FETCH_ASSOC);
foreach ($tmp as $r) {
$ext = trim((string)$r['extension']);
if (!preg_match('/^[0-9]+$/', $ext)) continue; // only numeric extensions
$cid = trim((string)($r['callerid'] ?? ''));
$ext = trim((string) $r['extension']);
if (!preg_match('/^[0-9]+$/', $ext))
continue; // only numeric extensions
$cid = trim((string) ($r['callerid'] ?? ''));
// Try to parse descriptive name from callerid
$name = 'Ext ' . $ext;
if ($cid !== '') {
@@ -79,9 +81,10 @@ $root = $xml->createElement('directory');
$xml->appendChild($root);
foreach ($rows as $r) {
$name = trim((string)($r['name'] ?? ''));
$ext = trim((string)($r['extension'] ?? ''));
if ($ext === '') continue;
$name = trim((string) ($r['name'] ?? ''));
$ext = trim((string) ($r['extension'] ?? ''));
if ($ext === '')
continue;
// Split name into fn/ln if possible
$fn = $name;
@@ -128,7 +131,23 @@ if ($do_notify) {
$asteriskBin = '/usr/sbin/asterisk';
$excludedEndpoints = [
'101', '102', '103', '104', '105', '106', '107', '108', '109', '110', '111', '112', '113', '114', '900', 'Voyant', '<Endpoint dpma_endpoint'
'101',
'102',
'103',
'104',
'105',
'106',
'107',
'108',
'109',
'110',
'111',
'112',
'113',
'114',
'900',
'Voyant',
'<Endpoint dpma_endpoint',
];
// Get all endpoints from Asterisk CLI
@@ -158,7 +177,7 @@ if ($do_notify) {
$notifyCmd = sprintf(
'%s -rx "pjsip send notify polycom-check-cfg endpoint %s"',
escapeshellarg($asteriskBin),
escapeshellarg($ep)
escapeshellarg($ep),
);
exec($notifyCmd);
}