From fd9ce292b38409f2a5daff70bf3f7fa66f84838c Mon Sep 17 00:00:00 2001 From: poslop Date: Mon, 22 Dec 2025 16:13:20 -0600 Subject: [PATCH] strtolower and permission updates --- gen_pc_sidecar.php | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/gen_pc_sidecar.php b/gen_pc_sidecar.php index 90d146e..dbb00aa 100755 --- a/gen_pc_sidecar.php +++ b/gen_pc_sidecar.php @@ -29,7 +29,7 @@ function main(): void { $mac_list = pull_mac_list(); foreach ($ext_list as $ext) { - $mac = $mac_list[$ext] ?? null; + $mac = strtolower($mac_list[$ext]) ?? null; if (!$mac) { echo "Mac for $ext not found\n"; continue; } @@ -224,34 +224,38 @@ function write_attendants($attendant, $pbdb): void { } } -function write_to_file($provision_dir, $out_file, $xml): void { +function write_to_file($provision_dir, $file, $xml): void { if (!is_dir($provision_dir)) { fwrite(STDERR, "Provisioning directory not found: $provision_dir\n"); exit(2); } - $tmpfile = $out_file . '.tmp'; + $tmpfile = $file . '.tmp'; if ($xml->save($tmpfile) === false) { fwrite(STDERR, "Failed to write temporary file $tmpfile\n"); exit(3); } - if (!@rename($tmpfile, $out_file)) { + if (!@rename($tmpfile, $file)) { @unlink($tmpfile); - fwrite(STDERR, "Failed to move $tmpfile to $out_file (permissions?)\n"); + fwrite(STDERR, "Failed to move $tmpfile to $file (permissions?)\n"); exit(4); } - echo "Wrote $out_file \n"; + if (!chown($file, 'asterisk')) { + error_log("chown failed for $file"); + } + if (!chgrp($file, 'asterisk')) { + error_log("chgrp failed for $file"); + } + + echo "Wrote $file \n"; } function notify($pbdb): void { - /** Optional: push check-sync to re-download directory without reboot */ - // Use the extension list we already built $notified = 0; foreach ($pbdb 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++;