Mini Shell
from pathlib import Path
from flask import current_app as app
from flask import request, render_template, jsonify
from bakmgr.configs import Conf
from bakmgr.dash.dash_helpers import login
@app.route('/config', methods=['GET', 'POST'])
@login
def config_page():
conf = Conf()
if request.method == 'GET':
return render_template("config.html.jinja", conf=conf, page='config')
for task_conf in (conf.files, conf.mysql, conf.pgsql):
task_conf.enabled = bool(request.form[f'{task_conf.task}-enabled'])
interval = int(request.form[f"{task_conf.task}-interval"])
if interval < 1 or interval > 30:
return jsonify(
accepted=False,
text=f"{task_conf.label} interval must be >= 1 and <= 30",
)
task_conf.interval = interval
conf.loglevel = request.form['loglevel']
if conf.loglevel not in ('CRITICAL', 'ERROR', 'WARNING', 'INFO', 'DEBUG'):
return jsonify(accepted=False, text="Invalid loglevel")
conf.files.include = request.form['files-include'].splitlines()
for path in conf.files.include:
if not Path(path).is_absolute():
return jsonify(
accepted=False, text=f'{path} in "Include" is not a full path.'
)
if conf.files.enabled and not conf.files.include:
return jsonify(
accepted=False,
text='No paths supplied in "Include".\n'
'Please either specify paths to backup or disable file backups.',
)
conf.files.exclude = request.form['files-exclude'].splitlines()
for path in conf.files.exclude:
if not Path(path).is_absolute():
return jsonify(
accepted=False, text=f'{path} in "Exclude" is not a full path.'
)
# return jsonify(accepted=False, text=repr(include))
try:
conf.max_cpus = max(int(request.form['max-cpus']), 0)
except ValueError:
return jsonify(accepted=False, text='"Max CPUs" must be an integer')
try:
conf.max_load = max(float(request.form['max-load']), 0.0)
except ValueError:
return jsonify(
accepted=False, text='"Max Load" must be a decimal number'
)
conf.save()
return jsonify(accepted=True, text="Saved successfully")
Zerion Mini Shell 1.0