2021-10-01 21:14:10 +00:00
|
|
|
import flask; from flask import request
|
|
|
|
|
|
|
|
from voussoirkit import flasktools
|
|
|
|
|
2022-07-16 06:35:35 +00:00
|
|
|
import etiquette
|
|
|
|
|
2021-10-01 21:14:10 +00:00
|
|
|
from .. import common
|
|
|
|
|
|
|
|
site = common.site
|
|
|
|
session_manager = common.session_manager
|
|
|
|
|
|
|
|
####################################################################################################
|
|
|
|
|
|
|
|
@site.route('/admin')
|
|
|
|
def get_admin():
|
|
|
|
if not request.is_localhost:
|
|
|
|
flask.abort(403)
|
|
|
|
|
|
|
|
return common.render_template(request, 'admin.html')
|
|
|
|
|
|
|
|
@site.route('/admin/reload_config', methods=['POST'])
|
|
|
|
def post_reload_config():
|
|
|
|
if not request.is_localhost:
|
2021-10-02 06:05:46 +00:00
|
|
|
return flasktools.json_response({}, status=403)
|
2021-10-01 21:14:10 +00:00
|
|
|
|
|
|
|
common.P.load_config()
|
2021-10-02 06:05:46 +00:00
|
|
|
return flasktools.json_response({})
|
2022-07-16 06:35:35 +00:00
|
|
|
|
|
|
|
@site.route('/admin/dbdownload')
|
|
|
|
def get_dbdump():
|
|
|
|
if not request.is_localhost:
|
|
|
|
flask.abort(403)
|
|
|
|
|
|
|
|
with common.P.transaction:
|
|
|
|
binary = common.P.database_filepath.read('rb')
|
|
|
|
|
2022-07-20 03:03:43 +00:00
|
|
|
now = etiquette.helpers.now().strftime('%Y-%m-%d_%H-%M-%S')
|
2022-07-16 06:35:35 +00:00
|
|
|
download_as = f'etiquette {now}.db'
|
|
|
|
outgoing_headers = {
|
|
|
|
'Content-Type': 'application/octet-stream',
|
|
|
|
'Content-Disposition': f'attachment; filename*=UTF-8\'\'{download_as}',
|
|
|
|
}
|
|
|
|
return flask.Response(binary, headers=outgoing_headers)
|