# 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
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:
</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 %}