Commit 000e4471 authored by Jan Čermák's avatar Jan Čermák

system password handler (for setting root's PW), main page of config interface - refs #2813, #2786

parent ef36c22a
from bottle import Bottle, request, template
import bottle
from config_handlers import PasswordHandler, WanHandler, LanHandler, WifiHandler
from config_handlers import *
import logging
from utils import login_required
......@@ -11,11 +11,14 @@ logger = logging.getLogger("admin")
app = Bottle()
# names of handlers used in their URL
# use dash-separated names, underscores in URL are ugly
handler_map = {
'password': PasswordHandler,
'wan': WanHandler,
'lan': LanHandler,
'wifi': WifiHandler,
'system-password': SystemPasswordHandler,
}
......@@ -34,6 +37,12 @@ def render_form(form, **kwargs):
return template("config/main", form=form, title=title, description=description, **kwargs)
@app.route("/")
@login_required
def index():
return template("config/index", handlers=handler_map.keys())
@app.route("/<handler_name:re:.+>/")
@login_required
def config_get(handler_name):
......@@ -56,7 +65,7 @@ def config_post(handler_name):
try:
if handler.save():
logger.info("saved")
bottle.redirect(request.fullpath)
except TypeError:
# raised by Validator - could happen when the form is posted with wrong fields
pass
......
from base import BaseConfigHandler, LanHandler, PasswordHandler, TimeHandler,\
WanHandler, WifiHandler
WanHandler, WifiHandler, SystemPasswordHandler
__all__ = ['BaseConfigHandler', 'LanHandler', 'PasswordHandler', 'TimeHandler',
'WanHandler', 'WifiHandler']
\ No newline at end of file
'WanHandler', 'WifiHandler', 'SystemPasswordHandler']
\ No newline at end of file
......@@ -307,4 +307,27 @@ class WifiHandler(BaseConfigHandler):
wifi_form.add_callback(wifi_form_cb)
return wifi_form
\ No newline at end of file
return wifi_form
class SystemPasswordHandler(BaseConfigHandler):
"""
Setting the password of a system user (currently only root's pw).
"""
def get_form(self):
system_pw_form = fapi.ForisForm("system_password", self.data)
system_pw_main = system_pw_form.add_section(name="set_password", title=_("Advanced administration"),
description=_(
"To access the advanced administraion, you must set root user's password. "
"When the password is set, follow the link below."))
system_pw_main.add_field(Password, name="password", label=_("Password"), required=True)
system_pw_main.add_field(Password, name="password_validation", label=_("Password (repeat)"))
system_pw_form.add_validator(validators.FieldsEqual("password", "password_validation",
_("Passwords are not equal.")))
def system_pw_form_cb(data):
client.set_password("root", data["password"])
return "none", None
system_pw_form.add_callback(system_pw_form_cb)
return system_pw_form
\ No newline at end of file
%rebase _layout **locals()
<h1>Foris</h1>
<a href="/logout">odhlásit</a>
<ul>
%for handler in handlers:
<a href="/config/{{ handler }}/">{{ handler }}</a>
%end
</ul>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment