formatting
This commit is contained in:
+33
-14
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user