function run($category) { global $report; subsys::init(); $lists = preg_split("/[\\n|\\r]/", subsys::$script_cat); $deps = array(); foreach ($lists as $list) { if (strlen($list) === 0) { continue; } $list = explode(":\t", $list, 2); $list[1] = explode("\t", $list[1]); $deps[] = $list; } $dep = array(); foreach ($deps as $tmp) { if ($tmp[0] == $category) { $dep = $tmp; } } $file_list = array(); $d = dir("subsys"); while (false !== ($entry = $d->read())) { foreach ($dep[1] as $cat) { if (!($entry === ".") && !($entry === "..")) { if (preg_match("/^[0-9][0-9]-" . $cat . "---.*\$/", $entry)) { $file_list[] = $entry; } } } } $d->close(); //sort files and process the files foreach ($dep[1] as $cat) { $files = array(); foreach (preg_grep("/^[0-9][0-9]-" . $cat . "---.*\$/", $file_list) as $file) { $files[(int) substr($file, 0, 2)] = $file; } ksort($files); //now process it $report->enter_section($cat); foreach ($files as $file) { $report->enter_section(substr($file, strpos($file, "---") + 3)); $code = rtrim(file_get_contents("subsys/" . $file)); $report->add(shell_exec("/bin/bash subsys/" . $file)); $report->exit_section(substr($file, strpos($file, "---") + 3)); } $report->exit_section($cat); } }
public function go() { cli::init(); $cli_opts = cli::$cli_opts; $mode = -1; foreach ($cli_opts as $opt => $val) { if (in_array($opt, array_keys(data::$elements))) { $mode = $opt; } } if ($mode === -1) { echo "No action!" . PHP_EOL; exit(1); } subsys::run($mode); global $report; file_put_contents("./report.txt", $report->report); }