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,4 +1,4 @@
target_extensions = 334, 338 target_extensions = 334, 338
list_filter_type = whitelist list_filter_type = whitelist
extension_list = 404,911 extension_filter_list = 404, 911
blacklisted_terms = vestibule, inpatient blacklisted_terms = vesibule, inpatient

View File

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