-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLogServer.py
More file actions
26 lines (20 loc) · 758 Bytes
/
LogServer.py
File metadata and controls
26 lines (20 loc) · 758 Bytes
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
from flask import Flask, request, jsonify
import datetime
app = Flask(__name__)
def write_log(entry: str):
timestamp = datetime.datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S UTC")
with open("infractions.log", "a") as f:
f.write(f"[{timestamp}] {entry}\n")
@app.route("/api/logs", methods=["POST"])
def receive_log():
# Simple API key check
api_key = request.headers.get("X-API-KEY")
if api_key != "#h}=))r7az6P1Q5:^LK6]b5.*.c~jY.3":
return jsonify({"error": "Unauthorized"}), 401
data = request.get_json()
log_entry = data["log"]
write_log(log_entry)
print(f"Log received: {log_entry}")
return jsonify({"status": "success"}), 200
if __name__ == "__main__":
app.run(host="0.0.0.0", port=5000)