Skip to content

Commit 8a0bf86

Browse files
Updated report_creation.py to 0.5b
1 parent 5d6c247 commit 8a0bf86

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

report_creation.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,36 @@
1919
import sys
2020
from colorama import Fore, Style
2121
import webbrowser
22+
import sqlite3
2223
except ImportError:
2324
print(Fore.RED + "Can't import some requirements that are necessary to start DPULSE. Please check that all necessary requirements are installed!" + Style.RESET_ALL)
2425
sys.exit()
2526

27+
def insert_pdf(file):
28+
with open(file, 'rb') as pdf_file:
29+
blob_data = pdf_file.read()
30+
return blob_data
31+
def insert_blob(pdf_blob, db_casename, creation_date, case_comment):
32+
try:
33+
sqlite_connection = sqlite3.connect('report_storage.db')
34+
cursor = sqlite_connection.cursor()
35+
print(Fore.GREEN + "Connected to report storage database")
36+
37+
sqlite_insert_blob_query = """INSERT INTO report_storage
38+
(report_content, creation_date, target, comment) VALUES (?, ?, ?, ?)"""
39+
40+
data_tuple = (pdf_blob, creation_date, db_casename, case_comment)
41+
cursor.execute(sqlite_insert_blob_query, data_tuple)
42+
sqlite_connection.commit()
43+
print(Fore.GREEN + "Scanning results are successfully saved in report storage database")
44+
cursor.close()
45+
except sqlite3.Error as error:
46+
print(Fore.RED + "Failed to insert scanning results in report storage database", error)
47+
finally:
48+
if sqlite_connection:
49+
sqlite_connection.close()
50+
print(Fore.RED + "Database connection is closed")
51+
2652
def find_files(filename):
2753
"""
2854
Function which will find wkhtmltopdf executable file
@@ -80,7 +106,7 @@ def report_encoding_config():
80106
}
81107

82108
search_query = []
83-
def create_report(short_domain, url, n):
109+
def create_report(short_domain, url, n, case_comment):
84110
"""
85111
Functions which calls all the functions from crawl_processor module and compiles them into PDF report.
86112
PDF report will be saved in main script directory
@@ -108,6 +134,9 @@ def create_report(short_domain, url, n):
108134

109135
ctime = datetime.now().strftime('%Y-%m-%d, %Hh%Mm%Ss')
110136
casename = short_domain.replace(".", "") + '~' + ctime + '.pdf'
137+
db_casename = short_domain.replace(".", "")
138+
now = datetime.now()
139+
db_creation_date = str(now.year) + str(now.month) + str(now.day)
111140

112141
try:
113142
context = {'sh_domain': short_domain, 'full_url': url, 'ip_address': cp.ip_gather(short_domain),'registrar': res['registrar'],
@@ -136,5 +165,6 @@ def create_report(short_domain, url, n):
136165
config = pdfkit.configuration(wkhtmltopdf=file_path)
137166
pdfkit.from_string(output_text, casename, configuration=config, options=report_encoding_config())
138167
print(Fore.GREEN + "Report for {} case was created at {}".format(''.join(short_domain), ctime) + Style.RESET_ALL)
168+
insert_blob(insert_pdf(casename), db_casename, db_creation_date, case_comment)
139169
except:
140170
print(Fore.RED + 'Unable to create PDF report. Closing scan...')

0 commit comments

Comments
 (0)