Compare commits
2 Commits
d8ff7cc641
...
f96abcbb4e
| Author | SHA1 | Date | |
|---|---|---|---|
| f96abcbb4e | |||
| c89e1da002 |
@@ -1,4 +0,0 @@
|
||||
target_extensions = 334, 338
|
||||
list_filter_type = whitelist
|
||||
extension_filter_list = 404, 911
|
||||
blacklisted_terms = vesibule, inpatient
|
||||
46
config.json
Normal file
46
config.json
Normal file
@@ -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"}
|
||||
]
|
||||
}
|
||||
@@ -1,16 +1,22 @@
|
||||
#!/usr/bin/php -q
|
||||
<?php
|
||||
|
||||
$TARGET_EXTENSIONS = read_config_ini("target_extensions");
|
||||
$LIST_FILTER_TYPE = read_config_ini("list_filter_type")[0];
|
||||
$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');
|
||||
|
||||
$DB = FreePBX::Database();
|
||||
|
||||
$CONFIG_PATH = "./config.json";
|
||||
$CONFIG = read_config_json_file($CONFIG_PATH);
|
||||
|
||||
$TARGET_EXTENSIONS = read_config_json("target_extensions");
|
||||
$LIST_FILTER_TYPE = read_config_json_string("list_filter_type");
|
||||
$EXTENSION_FILTER_LIST = read_config_json("extension_filter_list");
|
||||
$BLACKLISTED_TERMS = read_config_json("blacklisted_terms");
|
||||
$PREPEND_EXTENSIONS = read_config_json("prepend_extensions");
|
||||
|
||||
function main(): void {
|
||||
global $TARGET_EXTENSIONS;
|
||||
global $PROVISION_DIR;
|
||||
@@ -45,13 +51,12 @@ function main(): void {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function pull_db(): array {
|
||||
$db = FreePBX::Database();
|
||||
global $DB;
|
||||
$pbdb = [];
|
||||
|
||||
try {
|
||||
$stmt = $db->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($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($key) {
|
||||
global $CONFIG;
|
||||
$value = $CONFIG[$key] ?? '';
|
||||
return strtolower(trim((string)$value));
|
||||
}
|
||||
|
||||
|
||||
function pull_xml_file($file): DOMDocument {
|
||||
if (!file_exists($file)) {
|
||||
$file = '/tftpboot/000000000000-features.cfg';
|
||||
|
||||
Reference in New Issue
Block a user