help->select("sagacity.nessus_plugins", ['plugin_id', 'file_date']); if ($rows = $db->help->execute()) { foreach ($rows as $row) { $nasl_ids[$row['plugin_id']] = DateTime::createFromFormat("U", $row['file_date']); } } chdir(TMP . '/nessus_plugins'); $files = glob("*.nasl"); if (strtolower(substr(PHP_OS, 0, 3)) == 'win') { if (file_exists(getenv("%ProgramData%") . "/Tenable/Nessus/nessus/plugins")) { chdir(getenv("%ProgramData%") . "/Tenable/Nessus/nessus/plugins"); $files = array_merge($files, glob("*.nasl")); } } elseif (strtolower(substr(PHP_OS, 0, 3)) == 'lin') { if (file_exists("/opt/nessus/lib/nessus/plugins") && is_readable("/opt/nessus/lib/nessus/plugins")) { chdir("/opt/nessus/lib/nessus/plugins"); $files = array_merge($files, glob("*.nasl")); } if (file_exists("/opt/sc/data/nasl") && is_readable("/opt/sc/data/nasl")) { chdir("/opt/sc/data/nasl"); $files = array_merge($files, glob("*.nasl")); } } $files = array_unique($files); print "Found " . count($files) . " NASL files\nStarted at {$time->getStartClockTime()}\n"; chdir(DOC_ROOT . "/exec"); // Query database to build an array of existing plugins to compare against on import $existing_plugins = []; $db->help->select("nessus_plugins", ['plugin_id', 'file_date']); $rows = $db->help->execute(); if (is_array($rows) && count($rows)) { foreach ($rows as $row) { $existing_plugins[$row['plugin_id']] = DateTime::createFromFormat("U", $row['file_date']); } } // Sort the files and loop over them natsort($files); $threads = []; $count = 0; $total_complete = 0; foreach ($files as $file) { $db->help->select("nessus_plugins", ['plugin_id', 'file_date'], [ [ 'field' => 'file_name', 'value' => basename($file) ] ]); $row = $db->help->execute(); if (!isset($row['file_name']) || is_null($row['file_date']) || filemtime(TMP . "/nessus_plugins/$file") > $row['file_date']) { $comp = number_format(($x / count($files)) * 100, 2); print "\r$comp%"; $script = realpath(defined('PHP_BIN') ? PHP_BIN : PHP) . " -c " . realpath(PHP_CONF) . " -f " . realpath(DOC_ROOT . "/exec/nessus-plugin-to-database.php") . " --" . " -f=\"" . realpath(TMP . "/nessus_plugins/$file") . "\""; $threads[] = new Cocur\BackgroundProcess\BackgroundProcess($script); end($threads)->run(); //sleep(1); $count++; $total_complete++; if ($count > 1000) { $db->set_Setting("nasl-progress", $comp); foreach ($threads as $k => $t) { if (!$t->isRunning()) { unset($threads[$k]); $count--; } } } } } $db->set_Setting("nasl-dl-progress", 100); $db->set_Setting("nasl-progress", 100); $db->set_Setting("nasl-count", $total_complete); $time->stopClock(); print "\nFinished at {$time->getEndClockTime()}\nTotal Time: {$time->getTotalDiffString()}\n"; function usage() { print <<