-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebapp.py
More file actions
50 lines (40 loc) · 1.4 KB
/
Copy pathwebapp.py
File metadata and controls
50 lines (40 loc) · 1.4 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
import io
import csv
import json
import os
from flask import Flask, request, render_template, send_file, session
from scanner.core import scan_url
from dotenv import load_dotenv
load_dotenv()
app = Flask(__name__)
app.secret_key = os.getenv("SECRET_KEY")
@app.route("/", methods=["GET", "POST"])
def index():
result = None
if request.method == "POST":
url = request.form.get("url", "").strip()
result = scan_url(url)
session["last_result"] = result
return render_template("index.html", result=result)
@app.route("/export/csv")
def export_csv():
scan = session.get("last_result")
if not scan:
return "No data to export.", 400
output = io.StringIO()
writer = csv.writer(output)
writer.writerow(scan.keys())
writer.writerow([json.dumps(v) if isinstance(v, (dict, list)) else v for v in scan.values()])
output.seek(0)
return send_file(io.BytesIO(output.getvalue().encode()), download_name="scan_result.csv", as_attachment=True)
@app.route("/export/json")
def export_json():
scan = session.get("last_result")
if not scan:
return "No data to export.", 400
output = io.StringIO()
json.dump(scan, output, indent=2)
output.seek(0)
return send_file(io.BytesIO(output.getvalue().encode()), download_name="scan_result.json", as_attachment=True)
if __name__ == "__main__":
app.run(debug=True, host="0.0.0.0", port=5000)