Inline media stream for DM attachments. We only allow inline rendering for safe media types; active content (HTML/SVG/XML) is forced to download to prevent stored XSS.
(fid: int)
| 12930 | with open(path, "r", encoding="utf-8", errors="replace") as f: |
| 12931 | selected_content = f.read()[-200000:] |
| 12932 | except Exception as e: |
| 12933 | selected_content = f"Could not read log: {e}" |
| 12934 | return render_template("admin_logs.html", title="Admin logs", files=files, selected_name=selected_name, selected_content=selected_content) |
| 12935 | |
| 12936 | |
| 12937 | |
| 12938 | |
| 12939 | @app.route("/admin/device_approve", methods=["POST"]) |
| 12940 | @login_required |
| 12941 | def admin_device_approve(): |
| 12942 | require_admin() |
| 12943 | try: |
| 12944 | log_security_event("admin_action", detail="approve_device_request", username=current_user(), level="info") |
| 12945 | except Exception: |
| 12946 | pass |
| 12947 | rid = (request.form.get("req_id") or "").strip() |
| 12948 | if not rid.isdigit(): |
| 12949 | return redirect(url_for("admin_panel")) |
| 12950 | conn = db_connect() |
| 12951 | row = conn.execute("SELECT id, username, device_fp, status FROM device_access_requests WHERE id=?", (int(rid),)).fetchone() |
| 12952 | if not row: |
| 12953 | conn.close() |
| 12954 | flash("Request not found.") |
| 12955 | return redirect(url_for("admin_panel")) |
| 12956 | if row["status"] != "pending": |
| 12957 | conn.close() |
| 12958 | flash("Request already handled.") |
| 12959 | return redirect(url_for("admin_panel")) |
| 12960 | conn.execute( |
| 12961 | "UPDATE device_access_requests SET status='approved', approved_by=?, approved_at=? WHERE id=?", |
| 12962 | (current_user(), now_z(), int(rid)) |
| 12963 | ) |
| 12964 | conn.commit() |
| 12965 | conn.close() |
| 12966 | flash(f"Approved device request for @{row['username']}.") |
| 12967 | return redirect(url_for("admin_panel")) |
| 12968 | |
| 12969 | @app.route("/admin/device_deny", methods=["POST"]) |
| 12970 | @login_required |
| 12971 | def admin_device_deny(): |
| 12972 | require_admin() |
| 12973 | try: |
| 12974 | log_security_event("admin_action", detail="deny_device_request", username=current_user(), level="info") |
| 12975 | except Exception: |
| 12976 | pass |
| 12977 | rid = (request.form.get("req_id") or "").strip() |
| 12978 | if not rid.isdigit(): |
| 12979 | return redirect(url_for("admin_panel")) |
| 12980 | conn = db_connect() |
| 12981 | row = conn.execute("SELECT id, username, status FROM device_access_requests WHERE id=?", (int(rid),)).fetchone() |
| 12982 | if not row: |
nothing calls this directly
no test coverage detected