-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate_report.py
104 lines (90 loc) · 3.86 KB
/
generate_report.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import streamlit as st
import os
import pandas as pd
from sms_data import display_sms_data
from call_logs_data import display_call_logs_data
from contacts_data import display_contacts_data
from logs_data import display_log_data
from browser_history_data import display_browser_history_data
from calander_data import display_calendar_data
if "case_dir" not in st.session_state:
st.session_state.case_dir = None
# Generate HTML Report
def generate_html_report(case_directory, extracted_data):
try:
report_path = os.path.join(case_directory, "Android_Forensic_Report.html")
# Generate HTML sections for each data type
sections_html = ""
for section_name, data in extracted_data.items():
if isinstance(data, pd.DataFrame):
if not data.empty:
section_html = data.to_html(index=False, classes="table table-striped", justify="center")
else:
section_html = f"<p>No {section_name} data available</p>"
else:
section_html = f"<p>Invalid or unsupported data format for {section_name}</p>"
sections_html += f"""
<h2>{section_name}</h2>
{section_html}
<hr>
"""
# Read the case_info.txt file and replace \n with <br>
case_info_path = os.path.join(case_directory, "case_info.txt")
if os.path.exists(case_info_path):
with open(case_info_path, "r", encoding="utf-8") as f:
case_info_content = f.read().replace("\n", "<br>")
else:
case_info_content = "No case information available."
# Add case info to the HTML report
sections_html = f"""
<h2>Case Information</h2>
<p>{case_info_content}</p>
<hr>
""" + sections_html
# Create the HTML report with UTF-8 encoding
with open(report_path, "w", encoding="utf-8") as report_file:
report_file.write(f"""
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Android Forensic Toolkit Report</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css">
</head>
<body>
<div class="container mt-4">
<h1 class="text-center">Android Forensic Toolkit Report</h1>
<hr>
{sections_html}
</div>
</body>
</html>
""")
# To Create a clickable link
formatted_report_path = report_path.replace('\\', '/')
report_url = f"file://{formatted_report_path}"
st.caption(report_url)
st.success(f"HTML report generated successfully! [Click here to open the report]({report_url})")
except Exception as e:
st.error(f"Failed to generate HTML report: {e}")
# Update the "Report" section in the sidebar navigation
def display_report_section():
st.title("Generate Report")
df_sms, df_mms = display_sms_data()
df_call_logs = display_call_logs_data()
df_contacts = display_contacts_data()
df_log = display_log_data()
df_browser_history = display_browser_history_data()
df_calendar = display_calendar_data()
extracted_data = {
"SMS": df_sms,
"MMS": df_mms,
"Call Logss": df_call_logs,
"Contacts": df_contacts,
"Logs": df_log,
"Browser History": df_browser_history ,
"Calendar": df_calendar,
}
if st.button("Generate HTML Report"):
generate_html_report(st.session_state["case_dir"], extracted_data)