diff options
Diffstat (limited to 'bin/common/srtool_common.py')
-rwxr-xr-x | bin/common/srtool_common.py | 89 |
1 files changed, 11 insertions, 78 deletions
diff --git a/bin/common/srtool_common.py b/bin/common/srtool_common.py index 6518aee7..62cc95dc 100755 --- a/bin/common/srtool_common.py +++ b/bin/common/srtool_common.py @@ -373,81 +373,6 @@ def score_new_cves(cve_filter): print("\nUpdated CVEs=%d, Added alternate sources=%d" % (write_count,ds_count)) ################################# -# preset_new -# - -def preset_new(): - global cmd_skip - - conn = sqlite3.connect(srtDbName) - cur = conn.cursor() - cur_write = conn.cursor() - cur_ds = conn.cursor() - date_delta = timedelta(days=30) - init_new_date = datetime.now(pytz.utc) - date_delta - print("\nPreset new data = %s" % init_new_date.strftime("%Y%m%d")) - init_new_date = init_new_date.strftime("%Y%m%d") - - sql = '''SELECT * FROM orm_cve;''' - cve = cur.execute(sql).fetchone() - i = 0 - while cve: - cve_name = cve[ORM.CVE_NAME] - cve_status = cve[ORM.CVE_STATUS] - publishedDate = cve[ORM.CVE_PUBLISHEDDATE].replace('-','') - lastModifiedDate = cve[ORM.CVE_LASTMODIFIEDDATE].replace('-','') - - newer = publishedDate > init_new_date - #print("%s = [%s] %s,%s" % (cve_name,cve_status,lastModifiedDate,newer)) - - if (ORM.STATUS_HISTORICAL == cve_status) and newer: - # Progress indicator support - i += 1 - if 0 == i % 10: - print('%04d: %20s %30s\r' % (i,cve_name,lastModifiedDate), end='') - if (0 == i % 200) and not cmd_skip: - conn.commit() - print('') - # Development/debug support - if cmd_skip: - if i < cmd_skip: - continue - else: - cmd_skip = 0 - if cmd_count: - if record_count < cmd_count: - record_count += 1 - else: - print("Count return: %s,%s,%s" % (i,record_count,cmd_count)) - break - - # Mark CVE as "New", or "New_Reserved" if no NIST source (e.g. only MITRE) - status = ORM.STATUS_NEW_RESERVED - sql = "SELECT * FROM orm_datasource WHERE data = ? AND source = ?" - cur_ds.execute(sql, ('cve','nist', )) - for ds in cur_ds: - if ds[ORM.DATASOURCE_CVE_FILTER] and cve[ORM.CVE_NAME].startswith(ds[ORM.DATASOURCE_CVE_FILTER]): - sql = ''' SELECT * FROM orm_cvesource WHERE cve_id = ? AND datasource_id = ?''' - if cur_write.execute(sql, (cve[ORM.CVE_ID],ds[ORM.DATASOURCE_ID],)).fetchone(): - print("STATUS_NEW: found NIST data source parent") - status = ORM.STATUS_NEW - break - else: - print("STATUS_NEW_RESERVED: no NIST data source parent") - sql = ''' UPDATE orm_cve - SET status = ? - WHERE id = ?''' - cur_write.execute(sql, (status, cve[ORM.CVE_ID])) - print("%s = HISTORICAL to NEW " % (cve_name)) - - # Next Record - cve = cur.fetchone() - conn.commit() - cur.close() - conn.close() - - -################################# # init_notify_categories # @@ -551,6 +476,17 @@ def gen_schema_header(): fd.write(" %s_%s = %d\n" % ('DEFECT','REPLACED_BY_REQUIREMENT' ,8)) fd.write(" %s_%s = %d\n" % ('DEFECT','CANNOT_REPRODUCE' ,9)) fd.write(" %s_%s = %d\n" % ('DEFECT','DONE' ,10)) + + fd.write(" %s_%s = %d\n" % ('PACKAGE','FOR' ,0)) + fd.write(" %s_%s = %d\n" % ('PACKAGE','AGAINST' ,1)) + + fd.write(" %s_%s = %d\n" % ('DATASOURCE','MINUTELY' ,0)) + fd.write(" %s_%s = %d\n" % ('DATASOURCE','HOURLY' ,1)) + fd.write(" %s_%s = %d\n" % ('DATASOURCE','DAILY' ,2)) + fd.write(" %s_%s = %d\n" % ('DATASOURCE','WEEKLY' ,3)) + fd.write(" %s_%s = %d\n" % ('DATASOURCE','MONTHLY' ,4)) + fd.write(" %s_%s = %d\n" % ('DATASOURCE','ONDEMAND' ,5)) + fd.write("\n") ################################# @@ -594,7 +530,6 @@ def main(argv): parser.add_argument('--init-notify-categories', '-n', action='store_const', const='init_notify_categories', dest='command', help='Initialize notify categories') parser.add_argument('--score-new-cves', '-s', dest='score_new_cves', help='Score CVEs for triage [NEW|CVE-1234]') parser.add_argument('--generate-schema-header', action='store_const', const='gen_schema_header', dest='command', help='Generate database schema header') - parser.add_argument('--preset-new', action='store_const', const='preset_new', dest='command', help='Preset historical to new CVEs') parser.add_argument('--verbose', '-v', action='store_true', dest='verbose', help='Debugging: verbose output') parser.add_argument('--skip', dest='skip', help='Debugging: skip record count') parser.add_argument('--count', dest='count', help='Debugging: short run record count') @@ -619,8 +554,6 @@ def main(argv): score_new_cves(args.score_new_cves) elif 'gen_schema_header' == args.command: gen_schema_header() - elif 'preset_new' == args.command: - preset_new() elif 'fix_name_sort' == args.command: fix_name_sort() else: |