|
19 | 19 | import sys |
20 | 20 | from colorama import Fore, Style |
21 | 21 | import webbrowser |
| 22 | + import sqlite3 |
22 | 23 | except ImportError: |
23 | 24 | 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) |
24 | 25 | sys.exit() |
25 | 26 |
|
| 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 | + |
26 | 52 | def find_files(filename): |
27 | 53 | """ |
28 | 54 | Function which will find wkhtmltopdf executable file |
@@ -80,7 +106,7 @@ def report_encoding_config(): |
80 | 106 | } |
81 | 107 |
|
82 | 108 | search_query = [] |
83 | | -def create_report(short_domain, url, n): |
| 109 | +def create_report(short_domain, url, n, case_comment): |
84 | 110 | """ |
85 | 111 | Functions which calls all the functions from crawl_processor module and compiles them into PDF report. |
86 | 112 | PDF report will be saved in main script directory |
@@ -108,6 +134,9 @@ def create_report(short_domain, url, n): |
108 | 134 |
|
109 | 135 | ctime = datetime.now().strftime('%Y-%m-%d, %Hh%Mm%Ss') |
110 | 136 | 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) |
111 | 140 |
|
112 | 141 | try: |
113 | 142 | 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): |
136 | 165 | config = pdfkit.configuration(wkhtmltopdf=file_path) |
137 | 166 | pdfkit.from_string(output_text, casename, configuration=config, options=report_encoding_config()) |
138 | 167 | 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) |
139 | 169 | except: |
140 | 170 | print(Fore.RED + 'Unable to create PDF report. Closing scan...') |
0 commit comments