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("*.*");
|
$files = glob("*.*");
|
||||||
$stack = [];
|
$stack = [];
|
||||||
$running = [];
|
|
||||||
$time = 0;
|
|
||||||
$threads = [];
|
$threads = [];
|
||||||
|
|
||||||
foreach ($files as $file) {
|
foreach ($files as $file) {
|
||||||
|
@ -65,7 +65,6 @@ print "Currently " . count($existing_cves) . " in DB" . PHP_EOL . "Parsing: " .
|
|||||||
$db_cpes = [];
|
$db_cpes = [];
|
||||||
$new_cves = [];
|
$new_cves = [];
|
||||||
$new_cve_refs = [];
|
$new_cve_refs = [];
|
||||||
$new_cve_web = [];
|
|
||||||
$sw_rows = [];
|
$sw_rows = [];
|
||||||
$new = 0;
|
$new = 0;
|
||||||
$existing = 0;
|
$existing = 0;
|
||||||
@ -82,9 +81,6 @@ $cve_fields = [
|
|||||||
$ref_fields = [
|
$ref_fields = [
|
||||||
'cve_seq', 'source', 'url', 'val'
|
'cve_seq', 'source', 'url', 'val'
|
||||||
];
|
];
|
||||||
$web_fields = [
|
|
||||||
'cve_id', 'xml'
|
|
||||||
];
|
|
||||||
|
|
||||||
foreach ($json->CVE_Items as $cve) {
|
foreach ($json->CVE_Items as $cve) {
|
||||||
if (!isset($existing_cves["{$cve->cve->CVE_data_meta->ID}"])) {
|
if (!isset($existing_cves["{$cve->cve->CVE_data_meta->ID}"])) {
|
||||||
@ -168,18 +164,9 @@ foreach ($json->CVE_Items as $cve) {
|
|||||||
|
|
||||||
$new_cves = [];
|
$new_cves = [];
|
||||||
$new_cve_refs = [];
|
$new_cve_refs = [];
|
||||||
$new_cve_web = [];
|
|
||||||
$sw_rows = [];
|
$sw_rows = [];
|
||||||
|
|
||||||
print "\t" . ($existing + $new) . " completed" . PHP_EOL;
|
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"));
|
$load_date = new DateTime($db->get_Settings("nvd-cve-load-date"));
|
||||||
if ($load_date < $too_old) {
|
if ($load_date < $too_old) {
|
||||||
// More than 7 days old so have to do a full load
|
// 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);
|
$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 = new ZipArchive();
|
||||||
$zip->open(TMP . "/nvd/nvdcve-{$yr}.json.zip");
|
$zip->open(TMP . "/nvd/nvdcve-{$yr}.json.zip");
|
||||||
$zip->extractTo(TMP . "/nvd");
|
$zip->extractTo(TMP . "/nvd");
|
||||||
@ -392,7 +393,7 @@ if (isset($cmd['nvd'])) {
|
|||||||
chdir(DOC_ROOT . "/exec");
|
chdir(DOC_ROOT . "/exec");
|
||||||
if (isset($cmd['po']) || !isset($cmd['do'])) {
|
if (isset($cmd['po']) || !isset($cmd['do'])) {
|
||||||
$json_files = glob(TMP . "/nvd/*.json");
|
$json_files = glob(TMP . "/nvd/*.json");
|
||||||
foreach ($json_files as $j) {
|
foreach ($json_files as $x => $j) {
|
||||||
$match = [];
|
$match = [];
|
||||||
if (preg_match("/(\d{4}|recent|modified)/", basename($j), $match)) {
|
if (preg_match("/(\d{4}|recent|modified)/", basename($j), $match)) {
|
||||||
$db->set_Setting('nvd-year', $match[1]);
|
$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");
|
$log->debug("Running NVD CVE parsing script on file: $j");
|
||||||
passthru($script);
|
passthru($script);
|
||||||
|
$db->set_Setting('nvd-cve-progress', (($x + 1) / count($json_files)) * 100);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,6 +42,9 @@
|
|||||||
*/
|
*/
|
||||||
include_once 'error.inc';
|
include_once 'error.inc';
|
||||||
include_once 'validation.inc';
|
include_once 'validation.inc';
|
||||||
|
include_once 'vendor/autoload.php';
|
||||||
|
|
||||||
|
use Monolog\Logger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function to get element or value from XML document using XPath
|
* Function to get element or value from XML document using XPath
|
||||||
@ -720,9 +723,9 @@ function url_exists($url)
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param type $start
|
* @param float $start
|
||||||
* @param type $end
|
* @param float $end
|
||||||
* @return type
|
* @return float
|
||||||
*/
|
*/
|
||||||
function microtime_diff($start, $end = null)
|
function microtime_diff($start, $end = null)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user