2022-01-03 10:33:02 +00:00
|
|
|
import json
|
|
|
|
|
|
|
|
import flask
|
|
|
|
import flask_login
|
|
|
|
|
|
|
|
from . import db
|
|
|
|
from . import system
|
|
|
|
|
2023-12-04 08:46:37 +00:00
|
|
|
blueprint = flask.Blueprint('config', __name__)
|
2022-01-03 10:33:02 +00:00
|
|
|
|
|
|
|
@blueprint.route('/', methods=('GET', 'POST'))
|
|
|
|
@flask_login.login_required
|
|
|
|
def index():
|
2023-07-12 12:18:31 +00:00
|
|
|
if not flask_login.current_user.is_admin:
|
|
|
|
return flask.Response('forbidden', status=403, mimetype='text/plain')
|
2023-07-07 11:23:51 +00:00
|
|
|
|
2023-07-12 12:18:31 +00:00
|
|
|
with db.locked():
|
|
|
|
settings = db.read('settings')
|
|
|
|
if flask.request.method == 'POST':
|
|
|
|
form = flask.request.form
|
|
|
|
for name, value in form.items():
|
|
|
|
if name in settings:
|
|
|
|
settings[name] = value
|
|
|
|
db.write('settings', settings)
|
|
|
|
system.run(system.save_config)
|
|
|
|
return flask.redirect(flask.url_for('config.index'))
|
|
|
|
return flask.render_template('config/index.html', settings=settings)
|
2022-01-03 10:33:02 +00:00
|
|
|
|
|
|
|
@blueprint.route('/edit/<name>', methods=('GET', 'POST'))
|
|
|
|
@flask_login.login_required
|
|
|
|
def edit(name):
|
2023-07-12 12:18:31 +00:00
|
|
|
if not flask_login.current_user.is_admin:
|
|
|
|
return flask.Response('forbidden', status=403, mimetype='text/plain')
|
|
|
|
if flask.request.method == 'POST':
|
|
|
|
form = flask.request.form
|
|
|
|
db.save(name, json.loads(form.get('text').replace('\r\n', '\n')))
|
|
|
|
system.run(system.save_config)
|
|
|
|
content = json.dumps(db.load(name), indent=2)
|
|
|
|
return flask.render_template('config/edit.html', **locals())
|