def search(keyword): db = DB(Config.dbOpts) sql = 'SELECT * FROM cve WHERE `desc` like "%%%s%%"' % keyword ret = db.select(sql) for kd in ret: print(kd[0]) print(highlight(kd[1], keyword))
def search(opts): keyword = opts.search exclude = opts.exclude # excludes = exclude.split(",") # exclude = exclude.replace(",", "|") # print("exclude %s" % exclude) keywords = keyword.split(",") if keyword != "raw": sql = "SELECT `number`, `desc` FROM cve WHERE" for key in keywords: sql += '`desc` like "%%%s%%" and' % key sql = sql[:-4] else: sql = input("input your sql here:") # print(sql) db = DB(Config.dbOpts) ret = db.select(sql) for kd in ret: # for ex in excludes: # print(re.search(exclude, kd[1], re.IGNORECASE)) if len(exclude) > 0 and re.search(exclude.replace(",", "|"), kd[1], re.IGNORECASE) is not None: continue # if ex in kd[1]: if opts.colorful: print(colored(kd[0], "yellow")) print(highlight(kd[1], keywords)) else: print(kd[0]) print(kd[1]) print("\ntotal %d results with keywords: %s" % (len(ret), keyword))
def searchDB(keyword): db = DB(Config.dbOpts) sql = 'SELECT * FROM cve WHERE `desc` like "%%%s%%"' % keyword ret = db.select(sql) s = Statistics() for kd in ret: if 'field' in kd[1]: s.update(kd[1]) # print(kd[0], highlight(kd[1], ['field', keyword])) print(len(ret)) return s
def search(keyword, exclude): # excludes = exclude.split(",") # exclude = exclude.replace(",", "|") # print("exclude %s" % exclude) keywords = keyword.split(",") db = DB(Config.dbOpts) sql = 'SELECT `number`, `desc` FROM cve WHERE' for key in keywords: sql += '`desc` like "%%%s%%" and' % key sql = sql[:-4] # print(sql) ret = db.select(sql) for kd in ret: # for ex in excludes: # print(re.search(exclude, kd[1], re.IGNORECASE)) if len(exclude) > 0 and re.search(exclude.replace(",", "|"), kd[1], re.IGNORECASE) is not None: continue # if ex in kd[1]: print(colored(kd[0], "yellow")) print(highlight(kd[1], keywords)) print("\ntotal %d results with keywords: %s" % (len(ret), keyword))