From 0652771ef9c31e580dad987ac106b4b1717e0e38 Mon Sep 17 00:00:00 2001 From: Agnibho Mondal Date: Thu, 14 Mar 2024 23:58:35 +0530 Subject: [PATCH] Database dump --- librevax.py | 16 +++++++++++++++- templates/admin.html | 15 +++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/librevax.py b/librevax.py index d1580ed..a9ce250 100644 --- a/librevax.py +++ b/librevax.py @@ -5,7 +5,7 @@ # LibreVax is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. # You should have received a copy of the GNU General Public License along with LibreVax. If not, see . -from flask import Flask, render_template, request, session, redirect, g +from flask import Flask, render_template, request, session, redirect, send_file, g from urllib.parse import urlencode from datetime import datetime import json, sqlite3 @@ -843,6 +843,20 @@ def report(mid): raise(e) return render_template("error.html", data=e) +@app.get("/dump") +def dump(msg=None): + if((ret:=problem())!="go"): + return ret + try: + if(g.user!="admin"): + raise PermissionError + return send_file("data/database.db", as_attachment=True, download_name="backup-"+str(datetime.now())+".db") + except PermissionError as e: + return render_template("error.html", data="Access Denied") + except Exception as e: + raise(e) + return render_template("error.html", data=e) + def get_db(): db=getattr(g, "_database", None) if db is None: diff --git a/templates/admin.html b/templates/admin.html index 4f4e898..e6e0fc4 100644 --- a/templates/admin.html +++ b/templates/admin.html @@ -130,6 +130,21 @@ You should have received a copy of the GNU General Public License along with Lib +
+

+
+
+
+
+
Database Dump
+
+
+ Download +
+
+
+
+
{% endblock %} -- 2.39.5