Repository navigation
Expand file tree
/
Copy pathapp.py
More file actions
54 lines (35 loc) · 1.32 KB
/
Copy pathapp.py
File metadata and controls
54 lines (35 loc) · 1.32 KB
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
"""Flask entrypoint for the PhishTix phishing analysis web app."""
from __future__ import annotations
from datetime import datetime, timezone
from flask import Flask, jsonify, render_template, request
from backend.analyzer import analyze_message
app = Flask(__name__)
ANALYSIS_HISTORY: list[dict] = []
def _add_to_history(message: str, analysis: dict) -> None:
"""Store an analysis record in memory and retain only the newest entries."""
ANALYSIS_HISTORY.append(
{
"message": message,
"analysis": analysis,
"timestamp": datetime.now(timezone.utc).isoformat(),
}
)
if len(ANALYSIS_HISTORY) > 10:
del ANALYSIS_HISTORY[:-10]
@app.get("/")
def index() -> str:
"""Render the main PhishTix dashboard page."""
return render_template("index.html")
@app.post("/analyze")
def analyze() -> tuple:
"""Analyze submitted message text and return phishing risk details."""
message = request.form.get("message", "").strip()
analysis = analyze_message(message)
_add_to_history(message, analysis)
return jsonify(analysis), 200
@app.get("/history")
def history() -> tuple:
"""Return the latest ten phishing analyses as JSON."""
return jsonify(ANALYSIS_HISTORY[-10:]), 200
if __name__ == "__main__":
app.run(host="127.0.0.1", port=5000)