diff --git a/exec/background_results.php b/exec/background_results.php index 45c7e64..292602c 100644 --- a/exec/background_results.php +++ b/exec/background_results.php @@ -80,8 +80,6 @@ $dbh = new db(); $files = glob("*.*"); $stack = []; -$running = []; -$time = 0; $threads = []; foreach ($files as $file) { diff --git a/exec/parse_nvd_json_cve.php b/exec/parse_nvd_json_cve.php index 7cbb8c3..4d8d06f 100644 --- a/exec/parse_nvd_json_cve.php +++ b/exec/parse_nvd_json_cve.php @@ -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(); } } diff --git a/exec/update_db.php b/exec/update_db.php index 7cfeb61..11674e3 100644 --- a/exec/update_db.php +++ b/exec/update_db.php @@ -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); } } diff --git a/inc/helper.inc b/inc/helper.inc index 78f652f..ce3c589 100644 --- a/inc/helper.inc +++ b/inc/helper.inc @@ -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) { @@ -815,7 +818,7 @@ function add_intervals($i1, $i2) /** * Helper method to convert a file name to a .log file - * + * * @param string $fname * * @return string New filename with the prepended LOG_PATH