chat_with. Route handler or application helper. This docstring was expanded to make future maintenance easier. Args: username: Parameter. Returns: Varies.
(username: str)
| 13179 | return redirect(url_for("admin_panel")) |
| 13180 | |
| 13181 | # Remove login + public profile + memberships (DO NOT delete files on disk) |
| 13182 | conn.execute("DELETE FROM profiles WHERE username=?", (me,)) |
| 13183 | conn.execute("DELETE FROM group_members WHERE username=?", (me,)) |
| 13184 | conn.execute("DELETE FROM users WHERE username=?", (me,)) |
| 13185 | conn.commit() |
| 13186 | conn.close() |
| 13187 | |
| 13188 | session.clear() |
| 13189 | flash("Admin account deleted. If no admins remain, restart to create a new admin.") |
| 13190 | return redirect(url_for("login")) |
| 13191 | |
| 13192 | @app.route("/admin/self_destruct", methods=["POST"]) |
| 13193 | @login_required |
| 13194 | def admin_self_destruct(): |
| 13195 | """Delete all ButSystem data from storage. Admin-only, requires creds.""" |
| 13196 | require_admin() |
| 13197 | try: |
| 13198 | log_security_event("admin_action", detail="self_destruct_attempt", username=current_user(), level="info") |
| 13199 | except Exception: |
| 13200 | pass |
| 13201 | u = (request.form.get("username") or "").strip() |
| 13202 | p = request.form.get("password") or "" |
| 13203 | me = current_user() |
| 13204 | |
| 13205 | if not u or u != me: |
| 13206 | flash("Username must match your current session.") |
| 13207 | return redirect(url_for("admin_panel")) |
| 13208 | |
| 13209 | conn = db_connect() |
| 13210 | row = conn.execute("SELECT pw_hash, is_admin FROM users WHERE username=?", (u,)).fetchone() |
| 13211 | conn.close() |
| 13212 | if not row or not int(row["is_admin"]) or not check_password_hash(row["pw_hash"], p): |
| 13213 | flash("Invalid credentials.") |
| 13214 | return redirect(url_for("admin_panel")) |
| 13215 | |
| 13216 | # Safety: only delete our own app folder |
| 13217 | target = os.path.abspath(BASE_DIR) |
| 13218 | if os.path.basename(target) != "ButSystem" or target in ("/", "/storage", "/storage/emulated", "/storage/emulated/0", os.path.abspath(HOMEWORK_ROOT)): |
| 13219 | flash("Refusing to delete an unsafe path.") |
| 13220 | return redirect(url_for("admin_panel")) |
| 13221 | |
| 13222 | try: |
| 13223 | shutil.rmtree(target, ignore_errors=True) |
| 13224 | try: |
| 13225 | shutil.rmtree(os.path.abspath(TOR_DIR), ignore_errors=True) |
| 13226 | except Exception: |
| 13227 | pass |
| 13228 | |
| 13229 | except Exception: |
| 13230 | pass |
| 13231 | |
| 13232 | session.clear() |
| 13233 | flash("ButSystem deleted from storage. Server shutting down.") |
| 13234 | |
| 13235 | # Best-effort shutdown (Werkzeug) |
| 13236 | try: |
| 13237 | func = request.environ.get("werkzeug.server.shutdown") |
| 13238 | if func: |
nothing calls this directly
no test coverage detected