config reading
This commit is contained in:
4
config.ini
Normal file
4
config.ini
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
target_extensions = 334,338
|
||||||
|
list_filter_type = whitelist
|
||||||
|
extension_list = 404,911
|
||||||
|
blacklisted_terms = vestibule, inpatient
|
||||||
@@ -1 +0,0 @@
|
|||||||
extensions = 334,338
|
|
||||||
@@ -5,15 +5,15 @@ $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";
|
||||||
|
|
||||||
$provision_dir = '/tftpboot';
|
$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_extension_ini();
|
$ext_list = read_config_ini($TARGET_EXTENSIONS);
|
||||||
$mac_list = pull_mac_list();
|
$mac_list = pull_mac_list();
|
||||||
|
|
||||||
foreach ($ext_list as $ext) {
|
foreach ($ext_list as $ext) {
|
||||||
@@ -64,6 +64,8 @@ function pull_db(): array {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function trim_db($pbdb): array {
|
function trim_db($pbdb): array {
|
||||||
|
$BLACKLISTED_TERMS = "blacklisted_terms";
|
||||||
|
|
||||||
$pbdb_prepend = [
|
$pbdb_prepend = [
|
||||||
[ 'name' => 'Night Hours', 'extension' => '*271', ],
|
[ 'name' => 'Night Hours', 'extension' => '*271', ],
|
||||||
[ 'name' => 'Overhead Page', 'extension' => '900', ],
|
[ 'name' => 'Overhead Page', 'extension' => '900', ],
|
||||||
@@ -74,10 +76,7 @@ function trim_db($pbdb): array {
|
|||||||
|
|
||||||
array_unshift($pbdb, ...$pbdb_prepend);
|
array_unshift($pbdb, ...$pbdb_prepend);
|
||||||
|
|
||||||
$remove_names = [
|
$remove_names = read_config_ini($BLACKLISTED_TERMS);
|
||||||
'inpatient',
|
|
||||||
'vestibule'
|
|
||||||
];
|
|
||||||
|
|
||||||
$filtered = array_filter($pbdb, function ($item) use ($remove_names) {
|
$filtered = array_filter($pbdb, function ($item) use ($remove_names) {
|
||||||
if (!is_array($item) || !isset($item['name'])) {
|
if (!is_array($item) || !isset($item['name'])) {
|
||||||
@@ -114,9 +113,9 @@ function pull_mac_list(): array {
|
|||||||
return array_column($mac_db, 'mac', 'ext');
|
return array_column($mac_db, 'mac', 'ext');
|
||||||
}
|
}
|
||||||
|
|
||||||
function read_extension_ini(): array {
|
function read_config_ini($CONFIG_KEY): array {
|
||||||
$extensions = parse_ini_file('extensions.ini');
|
$extensions = parse_ini_file('config.ini');
|
||||||
$ext_list = array_map('intval', explode(',', $extensions['extensions']));
|
$ext_list = array_map('intval', explode(',', $extensions[$CONFIG_KEY]));
|
||||||
|
|
||||||
return $ext_list;
|
return $ext_list;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user