diff --git a/.gitignore b/.gitignore index 19ed2b6..a15c178 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ config/usr/* !.gitkeep +.*.swp diff --git a/api/v1/config/get/index.php b/api/v1/config/get/index.php index 65d20b3..7e0de73 100644 --- a/api/v1/config/get/index.php +++ b/api/v1/config/get/index.php @@ -3,22 +3,28 @@ []]; -foreach (scandir('config/usr') as $file) { - $file = trim($file); - if (strrpos($file,'.php') !== false) { - if (strpos($file, '-') === false) + +$instances_path = $appconf['data_dir'].'/instances'; +if (!file_exists($instances_path)) { + mkdir($instances_path); + apiresult($json); +} + +foreach ($supported_ap_software as $apsoft) { + $json['hosts'][$apsoft] = []; + $apsoft_path = $instances_path.'/'.$apsoft; + if (!file_exists($apsoft_path)) { + mkdir($apsoft_path); + continue; + } + foreach (scandir($apsoft_path) as $file) { + if (in_array($file,['.','..'])) continue; - $name = substr($file, 0, -4); - $hostn = substr($name, strpos($name, '-')+1); - $apsoft = strtolower(substr($name, 0, strpos($name, '-'))); - if (!in_array($apsoft, $supported_ap_software)) - continue; - if (!isset($json['hosts'][$apsoft])) - $json['hosts'][$apsoft] = []; - require "config/usr/$file"; - $json['hosts'][$apsoft] []= [ - 'instance' => $hostn, - 'config' => $config, + $instance_path = $apsoft_path.'/'.$file; + $json['hosts'][$apsoft] [] = [ + 'instance' => $file, + 'config' => trim( + file_get_contents($instance_path.'/config')), ]; } }