global values

This commit is contained in:
2026-01-30 12:00:05 -06:00
parent 792998334f
commit 8421f5d374
2 changed files with 23 additions and 16 deletions

View File

@@ -1,32 +1,38 @@
#!/usr/bin/php -q
<?php
$TARGET_EXTENSIONS = read_config_ini("target_extensions");
$LIST_FILTER_TYPE = read_config_ini("list_filter_type");
$EXTENSION_FILTER_LIST = read_config_ini("extension_filter_list");
$BLACKLISTED_TERMS = read_config_ini("blacklisted_terms");
$PROVISION_DIR = '/tftpboot';
$bootstrap_settings['freepbx_auth'] = false;
require_once('/etc/freepbx.conf');
function main(): void {
$TARGET_EXTENSIONS = "target_extensions";
global $TARGET_EXTENSIONS;
global $PROVISION_DIR;
$provision_dir = '/tftpboot';
$argv = $_SERVER['argv'] ?? [];
$do_notify = in_array('--notify', $argv, true);
$pbdb = trim_db(pull_db());
$ext_list = read_config_ini($TARGET_EXTENSIONS);
$mac_list = pull_mac_list();
foreach ($ext_list as $ext) {
foreach ($TARGET_EXTENSIONS as $ext) {
$mac = strtolower($mac_list[$ext]) ?? null;
if (!$mac) { echo "Mac for $ext not found\n"; continue; }
$file = $provision_dir . '/' . $mac . '-features.cfg';
$file = $PROVISION_DIR . '/' . $mac . '-features.cfg';
$xml = pull_xml_file($file);
$attendant = remove_attendants($xml);
write_attendants($attendant, $pbdb);
write_to_file($provision_dir, $file, $xml);
write_to_file($file, $xml);
}
if ($do_notify) {
@@ -64,7 +70,7 @@ function pull_db(): array {
}
function trim_db($pbdb): array {
$BLACKLISTED_TERMS = "blacklisted_terms";
global $BLACKLISTED_TERMS;
$pbdb_prepend = [
[ 'name' => 'Night Hours', 'extension' => '*271', ],
@@ -114,10 +120,10 @@ function pull_mac_list(): array {
}
function read_config_ini($CONFIG_KEY): array {
$extensions = parse_ini_file('config.ini');
$ext_list = array_map('intval', explode(',', $extensions[$CONFIG_KEY]));
$config = parse_ini_file('config.ini');
$config_value = preg_split('/\s*,\s*/', $config[$CONFIG_KEY] ?? '', -1, PREG_SPLIT_NO_EMPTY);
return $ext_list;
return $config_value;
}
function pull_xml_file($file): DOMDocument {
@@ -191,9 +197,10 @@ function write_attendants($attendant, $pbdb): void {
}
}
function write_to_file($provision_dir, $file, $xml): void {
if (!is_dir($provision_dir)) {
fwrite(STDERR, "Provisioning directory not found: $provision_dir\n");
function write_to_file($file, $xml): void {
global $PROVISION_DIR;
if (!is_dir($PROVISION_DIR)) {
fwrite(STDERR, "Provisioning directory not found: $PROVISION_DIR\n");
exit(2);
}