Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from flask import Flask, request, jsonify
|
| 2 |
+
from flask_cors import CORS
|
| 3 |
+
import sqlite3
|
| 4 |
+
from urllib.parse import urlparse
|
| 5 |
+
|
| 6 |
+
app = Flask(__name__)
|
| 7 |
+
CORS(app)
|
| 8 |
+
|
| 9 |
+
# Open whitelist DB
|
| 10 |
+
db_conn = sqlite3.connect("whitelist.db", check_same_thread=False)
|
| 11 |
+
|
| 12 |
+
def is_whitelisted(url):
|
| 13 |
+
cursor = db_conn.cursor()
|
| 14 |
+
domain = urlparse(url).netloc.lower()
|
| 15 |
+
if domain.startswith("www."):
|
| 16 |
+
domain = domain[4:]
|
| 17 |
+
cursor.execute("SELECT 1 FROM whitelist WHERE domain = ?", (domain,))
|
| 18 |
+
return cursor.fetchone() is not None
|
| 19 |
+
|
| 20 |
+
@app.route("/scan", methods=["POST"])
|
| 21 |
+
def scan():
|
| 22 |
+
data = request.get_json()
|
| 23 |
+
url = data.get("text", "")
|
| 24 |
+
|
| 25 |
+
if is_whitelisted(url):
|
| 26 |
+
return jsonify({
|
| 27 |
+
"label": "Safe (Whitelisted)",
|
| 28 |
+
"confidence": 1.0
|
| 29 |
+
})
|
| 30 |
+
|
| 31 |
+
# Fake model response for testing
|
| 32 |
+
return jsonify({
|
| 33 |
+
"label": "Phishing",
|
| 34 |
+
"confidence": 0.75
|
| 35 |
+
})
|
| 36 |
+
|
| 37 |
+
if __name__ == "__main__":
|
| 38 |
+
app.run(host="0.0.0.0", port=7860)
|