Moved NVD CVE parse progress to update_db and changed download progress to update overall instead of each file progress (bug #6)
Added include for autoload in helper.inc (bug #7) Removed a few unnecessary variables
This commit is contained in:
parent
082ccd5381
commit
d41c1f9e21
@ -80,8 +80,6 @@ $dbh = new db();
|
||||
|
||||
$files = glob("*.*");
|
||||
$stack = [];
|
||||
$running = [];
|
||||
$time = 0;
|
||||
$threads = [];
|
||||
|
||||
foreach ($files as $file) {
|
||||
|
@ -65,7 +65,6 @@ print "Currently " . count($existing_cves) . " in DB" . PHP_EOL . "Parsing: " .
|
||||
$db_cpes = [];
|
||||
$new_cves = [];
|
||||
$new_cve_refs = [];
|
||||
$new_cve_web = [];
|
||||
$sw_rows = [];
|
||||
$new = 0;
|
||||
$existing = 0;
|
||||
@ -82,9 +81,6 @@ $cve_fields = [
|
||||
$ref_fields = [
|
||||
'cve_seq', 'source', 'url', 'val'
|
||||
];
|
||||
$web_fields = [
|
||||
'cve_id', 'xml'
|
||||
];
|
||||
|
||||
foreach ($json->CVE_Items as $cve) {
|
||||
if (!isset($existing_cves["{$cve->cve->CVE_data_meta->ID}"])) {
|
||||
@ -168,18 +164,9 @@ foreach ($json->CVE_Items as $cve) {
|
||||
|
||||
$new_cves = [];
|
||||
$new_cve_refs = [];
|
||||
$new_cve_web = [];
|
||||
$sw_rows = [];
|
||||
|
||||
print "\t" . ($existing + $new) . " completed" . PHP_EOL;
|
||||
|
||||
$db->help->update("settings", ['meta_value' => number_format((($existing + $new) / count($json->CVE_Items)) * 100, 2)], [
|
||||
[
|
||||
'field' => 'meta_key',
|
||||
'value' => 'nvd-cve-progress'
|
||||
]
|
||||
]);
|
||||
$db->help->execute();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -361,9 +361,10 @@ if (isset($cmd['nvd'])) {
|
||||
$load_date = new DateTime($db->get_Settings("nvd-cve-load-date"));
|
||||
if ($load_date < $too_old) {
|
||||
// More than 7 days old so have to do a full load
|
||||
foreach ($nvd_years as $yr) {
|
||||
foreach ($nvd_years as $x => $yr) {
|
||||
$db->set_Setting('nvd-year', $yr);
|
||||
download_file("https://static.nvd.nist.gov/feeds/json/cve/1.0/nvdcve-1.0-{$yr}.json.zip", TMP . "/nvd/nvdcve-{$yr}.json.zip", $db->help, 'nvd-cve-dl-progress');
|
||||
$db->set_Setting('nvd-cve-dl-progress', (($x + 1) / count($nvd_years)) * 100);
|
||||
download_file("https://static.nvd.nist.gov/feeds/json/cve/1.0/nvdcve-1.0-{$yr}.json.zip", TMP . "/nvd/nvdcve-{$yr}.json.zip");
|
||||
$zip = new ZipArchive();
|
||||
$zip->open(TMP . "/nvd/nvdcve-{$yr}.json.zip");
|
||||
$zip->extractTo(TMP . "/nvd");
|
||||
@ -392,7 +393,7 @@ if (isset($cmd['nvd'])) {
|
||||
chdir(DOC_ROOT . "/exec");
|
||||
if (isset($cmd['po']) || !isset($cmd['do'])) {
|
||||
$json_files = glob(TMP . "/nvd/*.json");
|
||||
foreach ($json_files as $j) {
|
||||
foreach ($json_files as $x => $j) {
|
||||
$match = [];
|
||||
if (preg_match("/(\d{4}|recent|modified)/", basename($j), $match)) {
|
||||
$db->set_Setting('nvd-year', $match[1]);
|
||||
@ -407,6 +408,7 @@ if (isset($cmd['nvd'])) {
|
||||
|
||||
$log->debug("Running NVD CVE parsing script on file: $j");
|
||||
passthru($script);
|
||||
$db->set_Setting('nvd-cve-progress', (($x + 1) / count($json_files)) * 100);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -42,6 +42,9 @@
|
||||
*/
|
||||
include_once 'error.inc';
|
||||
include_once 'validation.inc';
|
||||
include_once 'vendor/autoload.php';
|
||||
|
||||
use Monolog\Logger;
|
||||
|
||||
/**
|
||||
* Function to get element or value from XML document using XPath
|
||||
@ -720,9 +723,9 @@ function url_exists($url)
|
||||
|
||||
/**
|
||||
*
|
||||
* @param type $start
|
||||
* @param type $end
|
||||
* @return type
|
||||
* @param float $start
|
||||
* @param float $end
|
||||
* @return float
|
||||
*/
|
||||
function microtime_diff($start, $end = null)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user