setup for multiple settings sections

This commit is contained in:
Jakob Ketterl 2020-04-25 21:42:00 +02:00
parent 2f011ea249
commit b874583931
6 changed files with 41 additions and 9 deletions

26
htdocs/settings.html Normal file
View File

@ -0,0 +1,26 @@
<!DOCTYPE HTML>
<html>
<head>
<title>OpenWebRX Settings</title>
<link rel="shortcut icon" type="image/x-icon" href="static/favicon.ico" />
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<link rel="stylesheet" type="text/css" href="static/css/admin.css" />
<script src="static/lib/jquery-3.2.1.min.js"></script>
<script src="https://unpkg.com/location-picker/dist/location-picker.min.js"></script>
<script src="static/settings.js"></script>
<meta charset="utf-8">
</head>
<body>
${header}
<div class="container">
<div class="col-12">
<h1>Settings</h1>
</div>
<div class="col-12">
<a href="generalsettings">General settings</a>
</div>
<div class="col-12">
<a href="sdrsettings">SDR device settings</a>
</div>
</div>
</body>

View File

@ -46,12 +46,12 @@ class SessionController(WebpageController):
if data["user"] in userlist:
user = userlist[data["user"]]
if user.password.is_valid(data["password"]):
# TODO pass the final destination
# TODO evaluate password force_change and redirect to password change
key = SessionStorage.getSharedInstance().startSession({"user": user.name})
cookie = SimpleCookie()
cookie["owrx-session"] = key
self.send_redirect("/admin", cookies=cookie)
# TODO pass the final destination
self.send_redirect("/settings", cookies=cookie)
return
self.send_redirect("/login")

View File

@ -44,6 +44,11 @@ class Section(object):
class SettingsController(AdminController):
def indexAction(self):
self.serve_template("settings.html", **self.template_variables())
class GeneralSettingsController(AdminController):
sections = [
Section(
"General settings",
@ -222,7 +227,7 @@ class SettingsController(AdminController):
]
def render_sections(self):
sections = "".join(section.render() for section in SettingsController.sections)
sections = "".join(section.render() for section in GeneralSettingsController.sections)
return """
<form class="settings-body" method="POST">
{sections}
@ -235,7 +240,7 @@ class SettingsController(AdminController):
)
def indexAction(self):
self.serve_template("admin.html", **self.template_variables())
self.serve_template("generalsettings.html", **self.template_variables())
def template_variables(self):
variables = super().template_variables()
@ -245,7 +250,7 @@ class SettingsController(AdminController):
def processFormData(self):
data = parse_qs(self.get_body().decode("utf-8"))
data = {
k: v for i in SettingsController.sections for k, v in i.parse(data).items()
k: v for i in GeneralSettingsController.sections for k, v in i.parse(data).items()
}
config = Config.get()
for k, v in data.items():

View File

@ -23,7 +23,7 @@ class WebpageController(TemplateController):
settingslink = ""
pm = Config.get()
if "webadmin_enabled" in pm and pm["webadmin_enabled"]:
settingslink = """<a class="button" href="admin" target="_blank"><img src="static/gfx/openwebrx-panel-settings.png" /><br/>Settings</a>"""
settingslink = """<a class="button" href="settings" target="_blank"><img src="static/gfx/openwebrx-panel-settings.png" /><br/>Settings</a>"""
header = self.render_template("include/header.include.html", settingslink=settingslink)
return {"header": header}

View File

@ -11,7 +11,7 @@ from owrx.controllers.assets import (
from owrx.controllers.websocket import WebSocketController
from owrx.controllers.api import ApiController
from owrx.controllers.metrics import MetricsController
from owrx.controllers.settings import SettingsController
from owrx.controllers.settings import SettingsController, GeneralSettingsController
from owrx.controllers.session import SessionController
from http.server import BaseHTTPRequestHandler
from urllib.parse import urlparse, parse_qs
@ -100,8 +100,9 @@ class Router(object):
StaticRoute("/features", FeatureController),
StaticRoute("/api/features", ApiController),
StaticRoute("/metrics", MetricsController),
StaticRoute("/admin", SettingsController),
StaticRoute("/admin", SettingsController, method="POST", options={"action": "processFormData"}),
StaticRoute("/settings", SettingsController),
StaticRoute("/generalsettings", GeneralSettingsController),
StaticRoute("/generalsettings", GeneralSettingsController, method="POST", options={"action": "processFormData"}),
StaticRoute("/login", SessionController, options={"action": "loginAction"}),
StaticRoute("/login", SessionController, method="POST", options={"action": "processLoginAction"}),
StaticRoute("/logout", SessionController, options={"action": "logoutAction"}),