help->select("sagacity.nessus_plugins", array('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"); $start_time = new DateTime(); print "Found " . count($files) . " NASL files\nStarted at {$start_time->format("Y-m-d H:i:s")}\n"; chdir(DOC_ROOT . '/exec'); $x = 0; foreach ($files as $file) { $db->help->select("nessus_plugins", array('plugin_id', 'file_date'), [ [ 'field' => 'file_name', 'op' => '=', '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") . "\""; if (substr(strtolower(PHP_OS), 0, 3) == "win") { $shell = new COM("WScript.Shell"); $shell->CurrentDirectory = DOC_ROOT . "/exec"; $shell->run($script, 0, false); } elseif (substr(strtolower(PHP_OS), 0, 3) == 'lin') { exec("$script > /dev/null &"); $output = array(); exec("netstat -an | grep TIME_WAIT | wc -l", $output); if ($output[0] > 1200) { do { sleep(1); exec("netstat -an | grep TIME_WAIT | wc -l", $output); } while ($output[0] > 100); } } $x++; } } $db->help->update("settings", ['meta_value' => 100], [ [ 'field' => 'meta_key', 'op' => IN, 'value' => ['nasl-dl-progress', 'nasl-progress'] ] ]); $db->help->execute(); $end_time = new DateTime(); $diff = $end_time->diff($start_time); print "\nFinished at {$end_time->format("Y-m-d H:i:s")}\nTotal Time: {$diff->format("%H:%I:%S")}\n"; function usage() { print <<