From 18ff3cb05de253383dfde74b7ba3156972f361dc Mon Sep 17 00:00:00 2001 From: Janos Zold Date: Wed, 19 Dec 2018 10:15:46 +0000 Subject: [PATCH] bugfix: fix issue with reporting for previous scan results when theHarvester runs the first time/day --- lib/statichtmlgenerator.py | 6 +--- stash.py | 69 +++++++++++++++++++++----------------- 2 files changed, 40 insertions(+), 35 deletions(-) diff --git a/lib/statichtmlgenerator.py b/lib/statichtmlgenerator.py index f07a7074..f71b404c 100644 --- a/lib/statichtmlgenerator.py +++ b/lib/statichtmlgenerator.py @@ -135,11 +135,7 @@ def generatepluginscanstatistics(self, scanstatistics): ''' for i in scanstatistics: - html += '' + str(i[0]) + "" - html += '' + str(i[1]) + "" - html += '' + str(i[2]) + "" - html += '' + str(i[3]) + "" - html += '' + str(i[4]) + "" + html += '' + str(i) + "" html +='' html +=''' diff --git a/stash.py b/stash.py index a19922c7..825f536f 100644 --- a/stash.py +++ b/stash.py @@ -104,38 +104,47 @@ def getlatestscanresults(self,domain,previousday=False): try: conn = sqlite3.connect(self.db) if previousday: - c = conn.cursor() - c.execute(''' - SELECT DISTINCT(find_date) - FROM results - WHERE find_date=date('now', '-1 day') and domain=?''',(domain,)) - previousscandate = c.fetchone() - c = conn.cursor() - c.execute(''' - SELECT find_date, domain, source,type,resource - FROM results - WHERE find_date=? and domain=? - ORDER BY source,type - ''',(previousscandate[0],domain,)) - results = c.fetchall() - self.previousscanresults = results - return self.previousscanresults + try: + c = conn.cursor() + c.execute(''' + SELECT DISTINCT(find_date) + FROM results + WHERE find_date=date('now', '-1 day') and domain=?''',(domain,)) + previousscandate = c.fetchone() + if not previousscandate: #when theHarvester runs first time/day this query will return + self.previousscanresults = ["No results","No results","No results","No results","No results"] + else: + c = conn.cursor() + c.execute(''' + SELECT find_date, domain, source,type,resource + FROM results + WHERE find_date=? and domain=? + ORDER BY source,type + ''',(previousscandate[0],domain,)) + results = c.fetchall() + self.previousscanresults = results + return self.previousscanresults + except Exception as e: + print("Error in getting the previous scan results from the database: " + str(e)) else: - c = conn.cursor() - c.execute('''SELECT MAX(find_date) FROM results WHERE domain=?''',(domain,)) - latestscandate = c.fetchone() - c = conn.cursor() - c.execute(''' - SELECT find_date, domain, source,type,resource - FROM results - WHERE find_date=? and domain=? - ORDER BY source,type - ''',(latestscandate[0],domain,)) - results = c.fetchall() - self.latestscanresults = results - return self.latestscanresults + try: + c = conn.cursor() + c.execute('''SELECT MAX(find_date) FROM results WHERE domain=?''',(domain,)) + latestscandate = c.fetchone() + c = conn.cursor() + c.execute(''' + SELECT find_date, domain, source,type,resource + FROM results + WHERE find_date=? and domain=? + ORDER BY source,type + ''',(latestscandate[0],domain,)) + results = c.fetchall() + self.latestscanresults = results + return self.latestscanresults + except Exception as e: + print("Error in getting the latest scan results from the database: " + str(e)) except Exception as e: - print("Error in getting the latest scan results from the database: " + str(e)) + print("Error connecting to theHarvester database: " + str(e)) finally: conn.close()