strtolower and permission updates

This commit is contained in:
poslop
2025-12-22 16:13:20 -06:00
parent f21f4c2bbf
commit fd9ce292b3

View File

@@ -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++;