diff options
Diffstat (limited to 'lib/orm/management/commands/lsupdates.py')
-rw-r--r-- | lib/orm/management/commands/lsupdates.py | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/lib/orm/management/commands/lsupdates.py b/lib/orm/management/commands/lsupdates.py index ccb98074..7bbcb066 100644 --- a/lib/orm/management/commands/lsupdates.py +++ b/lib/orm/management/commands/lsupdates.py @@ -473,6 +473,105 @@ class Command(BaseCommand): # print("[%d]cpe23Uri=%s,%s" % (i,company,product)) + def cve_keywords_old(self, csvfile_name): + # mode,type,keyword,weight + # y,key,abiword, + + KEY_MODE=0 + KEY_TYPE=1 + KEY_KEY=2 + KEY_WEIGHT=3 + + i_index=0 + is_header = True + with open(csvfile_name, newline='') as csvfile: + CPE_reader = csv.reader(csvfile, delimiter=',', quotechar='"') + for row in CPE_reader: + if is_header or not len(row): + is_header = False + continue + + if (KEY_WEIGHT+1) != len(row): + print("KEY_ROWLEN_ERROR:'%s'" % row) + continue + + i_index += 1 + if 0 == i_index % 100: + print('%04d: %20s\r' % (i_index,row[KEY_KEY]), end='') + +# # DEBUG ### TODO +# if 0 < Command.debug_jira_limit: +# if i_index > Command.debug_jira_limit: +# return + + k, created = Keywords.objects.get_or_create(keyword=row[KEY_KEY]) + if 'y' == row[KEY_MODE]: + k.key_mode = Keywords.FOR + else: + k.key_mode = Keywords.AGAINST + if 'keyword' == row[KEY_KEY]: + k.key_type = Keywords.KEYWORD + else: + k.key_type = Keywords.CPE + if row[KEY_WEIGHT]: + k.weight = int(row[KEY_WEIGHT]) + else: + if Keywords.FOR == k.key_mode: + k.weight = 1 + else: + k.weight = -1 + k.save() + + def cve_keywords(self, csvfile_name): + # mode,type,keyword,weight + # y,key,abiword, + + KEY_MODE=0 + KEY_TYPE=1 + KEY_KEY=2 + KEY_WEIGHT=3 + + keywords_for = '' + keywords_against = '' + + i_index=0 + is_header = True + with open(csvfile_name, newline='') as csvfile: + CPE_reader = csv.reader(csvfile, delimiter=',', quotechar='"') + for row in CPE_reader: + if is_header or not len(row): + is_header = False + continue + + if (KEY_WEIGHT+1) != len(row): + print("KEY_ROWLEN_ERROR:'%s'" % row) + continue + + i_index += 1 + if 0 == i_index % 100: + print('%04d: %20s\r' % (i_index,row[KEY_KEY]), end='') + + key = row[KEY_MODE] + if '#' == key[0]: + key = key[1:] + + if 'y' == key: + keywords_for += "|%s,%s" % (row[KEY_KEY],row[KEY_WEIGHT]) + elif 'n' == key: + keywords_against += "|%s,%s" % (row[KEY_KEY],row[KEY_WEIGHT]) + + setting = SrtSetting.objects.get_or_create(name='keywords_for')[0] + setting.value = keywords_for[1:] + setting.save() + setting = SrtSetting.objects.get_or_create(name='keywords_against')[0] + setting.value = keywords_against[1:] + setting.save() + + S = SrtSetting.objects.get(name='keywords_for') + #print("FOO_FOR:[%s]='%s'" % (S.name,S.value[0:30])) + S = SrtSetting.objects.get(name='keywords_against') + #print("FOO_NOT:[%s]='%s'" % (S.name,S.value[0:30])) + def debug_set_cve(self,key,public,vulnerability,wr_comments,wr_comments_private): try: @@ -557,9 +656,18 @@ class Command(BaseCommand): logger.error("Unknown data source path for '%s' (%s,%s) " % (source.source.description,source.file_path,source.url)) continue + # testing shortcut if ('nist' == source.source) and ('yes' == SrtSetting.objects.get(name='TEST_SKIP_NIST_IMPORT').value): continue + + # Common data sources + if 'common' == source.source: + if 'triage_keywords' == source.data: + self.cve_keywords(csvfile_name) + source.loaded = True + source.save() + continue # Common Vulnerabilities and Exposures if 'cve' == source.data: @@ -587,6 +695,7 @@ class Command(BaseCommand): source.loaded = True source.save() continue + # data source not handled logger.error("Unknown data source type for '%s' (%s,%s,%s) " % (source.file_path,source.data,source.source,source.type)) |