diff --git a/config.ini b/config.ini deleted file mode 100644 index 1dd87b4..0000000 --- a/config.ini +++ /dev/null @@ -1,4 +0,0 @@ -target_extensions = 334, 338 -list_filter_type = whitelist -extension_filter_list = 404, 911 -blacklisted_terms = vesibule, inpatient diff --git a/config.json b/config.json new file mode 100644 index 0000000..1c388e8 --- /dev/null +++ b/config.json @@ -0,0 +1,46 @@ +{ + "target_extensions": ["334", "338", "227", "228"], + "list_filter_type": "blacklist", + "extension_filter_list": [ + "209", + "214", + "220", + "234", + "254", + "333", + "344", + "348", + "355", + "365", + "370", + "371", + "372", + "373", + "374", + "375", + "377", + "378", + "379", + "383", + "384", + "390", + "391", + "393", + "397", + "398", + "529" + ], + "blacklisted_terms": ["vesibule", "inpatient"], + + "prepend_extensions": [ + {"name": "Night Hours", "extension": "*271"}, + {"name": "Overhead Page", "extension": "900"}, + {"name": "All page", "extension": "300"}, + {"name": "Park 71", "extension": "71"}, + {"name": "Park 72", "extension": "72"}, + {"name": "OR", "extension": "356"}, + {"name": "Lab", "extension": "340"}, + {"name": "Business", "extension": "249"}, + {"name": "OP Nurse", "extension": "336"} + ] +} diff --git a/gen_pc_sidecar.php b/gen_pc_sidecar.php index 70f7a8b..24720e7 100755 --- a/gen_pc_sidecar.php +++ b/gen_pc_sidecar.php @@ -1,16 +1,22 @@ #!/usr/bin/php -q prepare(" + $stmt = $DB->prepare(" SELECT name, extension FROM users WHERE extension REGEXP '^[0-9]+$' @@ -142,23 +147,16 @@ function blacklist_extension_filter(&$pbdb) { } function prepend_contact_list(&$pbdb) { - $pbdb_prepend = [ - [ 'name' => 'Night Hours', 'extension' => '*271', ], - [ 'name' => 'Overhead Page', 'extension' => '900', ], - [ 'name' => 'All page', 'extension' => '300'], - [ 'name' => 'Park 71', 'extension' => '71'], - [ 'name' => 'Park 72', 'extension' => '72'], - ]; - - array_unshift($pbdb, ...$pbdb_prepend); + global $PREPEND_EXTENSIONS; + array_unshift($pbdb, ...$PREPEND_EXTENSIONS); } function pull_mac_list(): array { - $db = FreePBX::Database(); + global $DB; $mac_db = []; try { - $stmt = $db->prepare(" + $stmt = $DB->prepare(" SELECT mac, SUBSTRING_INDEX(ext, '-', 1) AS ext FROM endpoint_extensions ORDER BY CAST(ext AS UNSIGNED) @@ -171,20 +169,54 @@ function pull_mac_list(): array { return array_column($mac_db, 'mac', 'ext'); } -function read_config_ini($CONFIG_KEY): array { - $config = parse_ini_file('config.ini'); - $config_value = preg_split('/\s*,\s*/', $config[$CONFIG_KEY] ?? '', -1, PREG_SPLIT_NO_EMPTY); - $config_value = array_map( - fn($v) => strtolower(trim((string)$v)), - $config_value - ); +function read_config_json_file(string $path): array { + global $COFNIG_PATH; + if (!is_file($path)) { + throw new RuntimeException("Config file not found: {$path}"); + } - $config_value = array_values(array_filter($config_value, fn($v) => $v !== '')); + $raw = file_get_contents($path); + if ($raw === false) { + throw new RuntimeException("Unable to read config file: {$path}"); + } - return $config_value; + $data = json_decode($raw, true); + if (!is_array($data)) { + throw new RuntimeException("Invalid JSON in config file: {$path}"); + } + + return $data; } +function read_config_json($key) { + global $CONFIG; + $value = $CONFIG[$key] ?? []; + + if (is_string($value)) { + $items = preg_split('/\s*,\s*/', $value, -1, PREG_SPLIT_NO_EMPTY); + } elseif (is_array($value)) { + $items = $value; + } else { + $items = []; + } + + $items = array_map( + fn($v) => strtolower(trim((string)$v)), + $items + ); + + $items = array_values(array_filter($items, fn($v) => $v !== '')); + + return $items; +} + +function read_config_json_string(array $config, string $key): string { + $value = $config[$key] ?? ''; + return strtolower(trim((string)$value)); +} + + function pull_xml_file($file): DOMDocument { if (!file_exists($file)) { $file = '/tftpboot/000000000000-features.cfg';