]> Softwares of Agnibho - librevax.git/commitdiff
Database dump master
authorAgnibho Mondal <mondal@agnibho.com>
Thu, 14 Mar 2024 18:28:35 +0000 (23:58 +0530)
committerAgnibho Mondal <mondal@agnibho.com>
Thu, 14 Mar 2024 18:28:35 +0000 (23:58 +0530)
librevax.py
templates/admin.html

index d1580ed5c2bb4da701a94fad14eca04042f7f4fe..a9ce25019fcc910104957b7545d84eb217933dfb 100644 (file)
@@ -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 <https://www.gnu.org/licenses/>.
 
-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:
index 4f4e8987e7aabdb1b6807490eb58ce13afe75459..e6e0fc4814d9e2d5176ede330a604d6605fbd6a6 100644 (file)
@@ -130,6 +130,21 @@ You should have received a copy of the GNU General Public License along with Lib
         </div>
       </div>
     </div>
+    <div class="accordion-item">
+      <h2 class="accordion-header"><button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#sec-4" aria-expanded="false" aria-controls="sec-4">Data</button></h2>
+      <div id="sec-4" class="accordion-collapse collapse" data-bs-parent="#admin">
+        <div class="accordion-body">
+          <div class="card">
+            <div class="card-header">
+              <h6>Database Dump</h6>
+            </div>
+            <div class="card-body">
+              <a href="/dump" class="btn btn-danger">Download</a>
+            </div>
+          </div>
+        </div>
+      </div>
+    </div>
   </div>
 </div>
 {% endblock %}