Simplify internal Sentinel dashboard
This commit is contained in:
@@ -2,10 +2,9 @@ import hashlib
|
||||
import hmac
|
||||
import json
|
||||
import os
|
||||
from functools import wraps
|
||||
|
||||
import psycopg
|
||||
from flask import Flask, Response, abort, redirect, render_template, request, url_for
|
||||
from flask import Flask, abort, redirect, render_template, request, url_for
|
||||
|
||||
|
||||
app = Flask(__name__)
|
||||
@@ -22,20 +21,6 @@ def db_connection():
|
||||
)
|
||||
|
||||
|
||||
def requires_auth(view):
|
||||
@wraps(view)
|
||||
def wrapped(*args, **kwargs):
|
||||
auth = __import__("flask").request.authorization
|
||||
expected_user = os.environ["DASHBOARD_USER"]
|
||||
expected_password = os.environ["DASHBOARD_PASSWORD"]
|
||||
valid = auth and hmac.compare_digest(auth.username or "", expected_user) and hmac.compare_digest(auth.password or "", expected_password)
|
||||
if not valid:
|
||||
return Response("Authentication required", 401, {"WWW-Authenticate": 'Basic realm="OCSentinel Debug"'})
|
||||
return view(*args, **kwargs)
|
||||
|
||||
return wrapped
|
||||
|
||||
|
||||
def csrf_token():
|
||||
secret = os.environ["DASHBOARD_CSRF_SECRET"].encode("utf-8")
|
||||
return hmac.new(secret, b"recipient-rules", hashlib.sha256).hexdigest()
|
||||
@@ -48,7 +33,6 @@ def require_csrf():
|
||||
|
||||
|
||||
@app.get("/")
|
||||
@requires_auth
|
||||
def overview():
|
||||
with db_connection() as connection, connection.cursor() as cursor:
|
||||
cursor.execute("SELECT * FROM ocsentinel.organization_summary")
|
||||
@@ -85,7 +69,6 @@ def overview():
|
||||
|
||||
|
||||
@app.get("/device/<machine_name>")
|
||||
@requires_auth
|
||||
def device(machine_name):
|
||||
with db_connection() as connection, connection.cursor() as cursor:
|
||||
cursor.execute(
|
||||
@@ -108,7 +91,6 @@ def device(machine_name):
|
||||
|
||||
|
||||
@app.get("/reports")
|
||||
@requires_auth
|
||||
def reports():
|
||||
with db_connection() as connection, connection.cursor() as cursor:
|
||||
cursor.execute(
|
||||
@@ -126,7 +108,6 @@ def reports():
|
||||
|
||||
|
||||
@app.get("/reports/<int:report_id>")
|
||||
@requires_auth
|
||||
def weekly_report(report_id):
|
||||
with db_connection() as connection, connection.cursor() as cursor:
|
||||
cursor.execute(
|
||||
@@ -147,7 +128,6 @@ def weekly_report(report_id):
|
||||
|
||||
|
||||
@app.get("/recipients")
|
||||
@requires_auth
|
||||
def recipients():
|
||||
with db_connection() as connection, connection.cursor() as cursor:
|
||||
cursor.execute(
|
||||
@@ -173,7 +153,6 @@ def recipients():
|
||||
|
||||
|
||||
@app.post("/recipients")
|
||||
@requires_auth
|
||||
def add_recipient():
|
||||
require_csrf()
|
||||
organization_id = request.form.get("organization_id", "").strip()
|
||||
@@ -198,7 +177,6 @@ def add_recipient():
|
||||
|
||||
|
||||
@app.post("/recipients/<int:rule_id>/toggle")
|
||||
@requires_auth
|
||||
def toggle_recipient(rule_id):
|
||||
require_csrf()
|
||||
with db_connection() as connection, connection.cursor() as cursor:
|
||||
@@ -211,7 +189,6 @@ def toggle_recipient(rule_id):
|
||||
|
||||
|
||||
@app.post("/recipients/<int:rule_id>/delete")
|
||||
@requires_auth
|
||||
def delete_recipient(rule_id):
|
||||
require_csrf()
|
||||
with db_connection() as connection, connection.cursor() as cursor:
|
||||
|
||||
Reference in New Issue
Block a user