refactor: OS Discovery cleanup (Part 1) (#4335)

* refactor: OS Discovery cleanup (Part 1)
Convert linux.inc.php to use new string functions
Create OS discovery tests
Use glob instead of readdir in os discovery (could change discovery order)
Stop discovering once $os is set

* Remove duplicate file header.
This commit is contained in:
Tony Murray
2016-09-06 05:43:04 -05:00
committed by Neil Lathwood
parent f42406e2b0
commit f6134f429c
5 changed files with 269 additions and 56 deletions

View File

@@ -106,20 +106,15 @@ function getHostOS($device)
d_echo("| $sysDescr | $sysObjectId | ");
$path = $config['install_dir'] . "/includes/discovery/os";
$dir_handle = @opendir($path) or die("Unable to open $path");
while ($file = readdir($dir_handle)) {
if (preg_match("/.php$/", $file)) {
include($config['install_dir'] . "/includes/discovery/os/" . $file);
$pattern = $config['install_dir'] . '/includes/discovery/os/*.inc.php';
foreach (glob($pattern) as $file) {
include $file;
if (isset($os)) {
return $os;
}
}
closedir($dir_handle);
if ($os) {
return $os;
} else {
return "generic";
}
return "generic";
}
function percent_colour($perc)