Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,7 +9,7 @@ def html_to_pdf(html_content):
|
|
| 9 |
HTML(string=html_content).write_pdf(tmp_pdf.name)
|
| 10 |
return tmp_pdf.name
|
| 11 |
|
| 12 |
-
def analyze_email(file_path
|
| 13 |
if file_path is None:
|
| 14 |
return "<p style='color:red;'>Please upload a .eml file to analyze.</p>", None
|
| 15 |
|
|
@@ -52,7 +52,7 @@ def analyze_email(file_path, export_pdf=False):
|
|
| 52 |
else:
|
| 53 |
auth_html = "<p>No auth results found.</p>"
|
| 54 |
|
| 55 |
-
# Tags
|
| 56 |
main_tags_str = summary.get("Main Tags", "")
|
| 57 |
tags = [t.strip() for t in main_tags_str.split(",")] if main_tags_str else []
|
| 58 |
|
|
@@ -70,14 +70,17 @@ def analyze_email(file_path, export_pdf=False):
|
|
| 70 |
<p><b>Final Verdict:</b> <span style="background:{verdict_color}; color:white; padding:4px 10px; border-radius:6px;">
|
| 71 |
{verdict}
|
| 72 |
</span></p>
|
|
|
|
| 73 |
<details style="margin-top:15px;" open>
|
| 74 |
<summary>π Attack Analysis Tags ({len(tags)})</summary>
|
| 75 |
{"<ul>" + "".join(f"<li>{tag}</li>" for tag in tags if tag) + "</ul>" if tags else "<p>No special tags</p>"}
|
| 76 |
</details>
|
|
|
|
| 77 |
<details style="margin-top:15px;" open>
|
| 78 |
<summary>π‘ Authentication Results</summary>
|
| 79 |
{auth_html}
|
| 80 |
</details>
|
|
|
|
| 81 |
<details style="margin-top:15px;" open>
|
| 82 |
<summary>π΅οΈ Detailed Findings</summary>
|
| 83 |
<h4>Headers ({len(header_findings)})</h4>
|
|
@@ -87,6 +90,7 @@ def analyze_email(file_path, export_pdf=False):
|
|
| 87 |
<h4>URLs ({len(url_findings)})</h4>
|
| 88 |
{"<ul>" + "".join(f"<li>{f}</li>" for f in url_findings) + "</ul>" if url_findings else "<p>No URL findings.</p>"}
|
| 89 |
</details>
|
|
|
|
| 90 |
<details style="margin-top:15px;">
|
| 91 |
<summary>π© Highlighted Email Body</summary>
|
| 92 |
<div style='border:1px solid #ccc; padding:15px; background:#fdfdfd; border-radius:8px; white-space:pre-wrap;'>
|
|
@@ -96,29 +100,27 @@ def analyze_email(file_path, export_pdf=False):
|
|
| 96 |
</div>
|
| 97 |
"""
|
| 98 |
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
|
| 106 |
return html, pdf_path
|
| 107 |
|
| 108 |
-
# Gradio Interface
|
| 109 |
demo = gr.Interface(
|
| 110 |
fn=analyze_email,
|
| 111 |
inputs=[
|
| 112 |
-
gr.File(label="Upload .eml File", type="filepath")
|
| 113 |
-
gr.Checkbox(label="Export PDF Report")
|
| 114 |
],
|
| 115 |
outputs=[
|
| 116 |
gr.HTML(label="Analysis Report"),
|
| 117 |
gr.File(label="Download PDF Report")
|
| 118 |
],
|
| 119 |
title="π§ Email Security Analyzer",
|
| 120 |
-
description="Upload an .eml file to detect phishing, spam, or malicious emails. "
|
| 121 |
-
"Check 'Export PDF Report' to download a professional PDF report."
|
| 122 |
)
|
| 123 |
|
| 124 |
demo.launch()
|
|
|
|
| 9 |
HTML(string=html_content).write_pdf(tmp_pdf.name)
|
| 10 |
return tmp_pdf.name
|
| 11 |
|
| 12 |
+
def analyze_email(file_path):
|
| 13 |
if file_path is None:
|
| 14 |
return "<p style='color:red;'>Please upload a .eml file to analyze.</p>", None
|
| 15 |
|
|
|
|
| 52 |
else:
|
| 53 |
auth_html = "<p>No auth results found.</p>"
|
| 54 |
|
| 55 |
+
# Tags
|
| 56 |
main_tags_str = summary.get("Main Tags", "")
|
| 57 |
tags = [t.strip() for t in main_tags_str.split(",")] if main_tags_str else []
|
| 58 |
|
|
|
|
| 70 |
<p><b>Final Verdict:</b> <span style="background:{verdict_color}; color:white; padding:4px 10px; border-radius:6px;">
|
| 71 |
{verdict}
|
| 72 |
</span></p>
|
| 73 |
+
|
| 74 |
<details style="margin-top:15px;" open>
|
| 75 |
<summary>π Attack Analysis Tags ({len(tags)})</summary>
|
| 76 |
{"<ul>" + "".join(f"<li>{tag}</li>" for tag in tags if tag) + "</ul>" if tags else "<p>No special tags</p>"}
|
| 77 |
</details>
|
| 78 |
+
|
| 79 |
<details style="margin-top:15px;" open>
|
| 80 |
<summary>π‘ Authentication Results</summary>
|
| 81 |
{auth_html}
|
| 82 |
</details>
|
| 83 |
+
|
| 84 |
<details style="margin-top:15px;" open>
|
| 85 |
<summary>π΅οΈ Detailed Findings</summary>
|
| 86 |
<h4>Headers ({len(header_findings)})</h4>
|
|
|
|
| 90 |
<h4>URLs ({len(url_findings)})</h4>
|
| 91 |
{"<ul>" + "".join(f"<li>{f}</li>" for f in url_findings) + "</ul>" if url_findings else "<p>No URL findings.</p>"}
|
| 92 |
</details>
|
| 93 |
+
|
| 94 |
<details style="margin-top:15px;">
|
| 95 |
<summary>π© Highlighted Email Body</summary>
|
| 96 |
<div style='border:1px solid #ccc; padding:15px; background:#fdfdfd; border-radius:8px; white-space:pre-wrap;'>
|
|
|
|
| 100 |
</div>
|
| 101 |
"""
|
| 102 |
|
| 103 |
+
# ALWAYS generate PDF
|
| 104 |
+
try:
|
| 105 |
+
pdf_path = html_to_pdf(html)
|
| 106 |
+
except Exception as e:
|
| 107 |
+
pdf_path = None
|
| 108 |
+
html += f"<p style='color:#c0392b;'><b>PDF export failed:</b> {e}</p>"
|
| 109 |
|
| 110 |
return html, pdf_path
|
| 111 |
|
| 112 |
+
# Gradio Interface (checkbox removed)
|
| 113 |
demo = gr.Interface(
|
| 114 |
fn=analyze_email,
|
| 115 |
inputs=[
|
| 116 |
+
gr.File(label="Upload .eml File", type="filepath")
|
|
|
|
| 117 |
],
|
| 118 |
outputs=[
|
| 119 |
gr.HTML(label="Analysis Report"),
|
| 120 |
gr.File(label="Download PDF Report")
|
| 121 |
],
|
| 122 |
title="π§ Email Security Analyzer",
|
| 123 |
+
description="Upload an .eml file to detect phishing, spam, or malicious emails. A PDF report will be generated automatically."
|
|
|
|
| 124 |
)
|
| 125 |
|
| 126 |
demo.launch()
|