From 8edbc53ffe54bae97d0108bf8b96b384804f28b0 Mon Sep 17 00:00:00 2001 From: poslop Date: Mon, 22 Dec 2025 14:26:53 -0600 Subject: [PATCH] mac list --- gen_pc_sidecar.php | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/gen_pc_sidecar.php b/gen_pc_sidecar.php index 2912bd2..0b52f3d 100755 --- a/gen_pc_sidecar.php +++ b/gen_pc_sidecar.php @@ -19,21 +19,21 @@ require_once('/etc/freepbx.conf'); function main(): void { $provision_dir = '/tftpboot'; - $file = $provision_dir . '/482567bcdeff-features.cfg'; $argv = $_SERVER['argv'] ?? []; $do_notify = in_array('--notify', $argv, true); + $mac_list = ['482567bcdeff', '482567bcd8f0'] $pbdb = pull_db(); - $pbdb = trim_db($pbdb); - $xml = pull_xml_file($file); - - $attendant = remove_attendants($xml); + foreach ($mac_list as $mac) { + $file = $provision_dir . '/' . $mac . '-features.cfg'; - write_attendants($attendant, $pbdb); - - write_to_file($provision_dir, $file, $xml); + $xml = pull_xml_file($file); + $attendant = remove_attendants($xml); + write_attendants($attendant, $pbdb); + write_to_file($provision_dir, $file, $xml); + } if ($do_notify) { notify($pbdb); @@ -118,6 +118,24 @@ function trim_db($pbdb): array { return $filtered; } +function pull_mac_db(): array { + $db = FreePBX::Database(); + $mac_db = []; + + try { + $stmt = $db->prepare(" + SELECT mac, ext + FROM endpoint_extensions + WHERE ext REGEXP '^[0-9]+$' + ORDER BY CAST(extension AS UNSIGNED) + "); + $stmt->execute(); + $mac_db = $stmt->fetchAll(PDO::FETCH_ASSOC); + } catch (Exception $e) { + } + return $mac_db; +} + function pull_xml_file($file): DOMDocument { $xmlString = file_get_contents($file); if ($xmlString === false) {