setup for multiple settings sections
This commit is contained in:
parent
2f011ea249
commit
b874583931
26
htdocs/settings.html
Normal file
26
htdocs/settings.html
Normal 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>
|
@ -46,12 +46,12 @@ class SessionController(WebpageController):
|
|||||||
if data["user"] in userlist:
|
if data["user"] in userlist:
|
||||||
user = userlist[data["user"]]
|
user = userlist[data["user"]]
|
||||||
if user.password.is_valid(data["password"]):
|
if user.password.is_valid(data["password"]):
|
||||||
# TODO pass the final destination
|
|
||||||
# TODO evaluate password force_change and redirect to password change
|
# TODO evaluate password force_change and redirect to password change
|
||||||
key = SessionStorage.getSharedInstance().startSession({"user": user.name})
|
key = SessionStorage.getSharedInstance().startSession({"user": user.name})
|
||||||
cookie = SimpleCookie()
|
cookie = SimpleCookie()
|
||||||
cookie["owrx-session"] = key
|
cookie["owrx-session"] = key
|
||||||
self.send_redirect("/admin", cookies=cookie)
|
# TODO pass the final destination
|
||||||
|
self.send_redirect("/settings", cookies=cookie)
|
||||||
return
|
return
|
||||||
self.send_redirect("/login")
|
self.send_redirect("/login")
|
||||||
|
|
||||||
|
@ -44,6 +44,11 @@ class Section(object):
|
|||||||
|
|
||||||
|
|
||||||
class SettingsController(AdminController):
|
class SettingsController(AdminController):
|
||||||
|
def indexAction(self):
|
||||||
|
self.serve_template("settings.html", **self.template_variables())
|
||||||
|
|
||||||
|
|
||||||
|
class GeneralSettingsController(AdminController):
|
||||||
sections = [
|
sections = [
|
||||||
Section(
|
Section(
|
||||||
"General settings",
|
"General settings",
|
||||||
@ -222,7 +227,7 @@ class SettingsController(AdminController):
|
|||||||
]
|
]
|
||||||
|
|
||||||
def render_sections(self):
|
def render_sections(self):
|
||||||
sections = "".join(section.render() for section in SettingsController.sections)
|
sections = "".join(section.render() for section in GeneralSettingsController.sections)
|
||||||
return """
|
return """
|
||||||
<form class="settings-body" method="POST">
|
<form class="settings-body" method="POST">
|
||||||
{sections}
|
{sections}
|
||||||
@ -235,7 +240,7 @@ class SettingsController(AdminController):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def indexAction(self):
|
def indexAction(self):
|
||||||
self.serve_template("admin.html", **self.template_variables())
|
self.serve_template("generalsettings.html", **self.template_variables())
|
||||||
|
|
||||||
def template_variables(self):
|
def template_variables(self):
|
||||||
variables = super().template_variables()
|
variables = super().template_variables()
|
||||||
@ -245,7 +250,7 @@ class SettingsController(AdminController):
|
|||||||
def processFormData(self):
|
def processFormData(self):
|
||||||
data = parse_qs(self.get_body().decode("utf-8"))
|
data = parse_qs(self.get_body().decode("utf-8"))
|
||||||
data = {
|
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()
|
config = Config.get()
|
||||||
for k, v in data.items():
|
for k, v in data.items():
|
||||||
|
@ -23,7 +23,7 @@ class WebpageController(TemplateController):
|
|||||||
settingslink = ""
|
settingslink = ""
|
||||||
pm = Config.get()
|
pm = Config.get()
|
||||||
if "webadmin_enabled" in pm and pm["webadmin_enabled"]:
|
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)
|
header = self.render_template("include/header.include.html", settingslink=settingslink)
|
||||||
return {"header": header}
|
return {"header": header}
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@ from owrx.controllers.assets import (
|
|||||||
from owrx.controllers.websocket import WebSocketController
|
from owrx.controllers.websocket import WebSocketController
|
||||||
from owrx.controllers.api import ApiController
|
from owrx.controllers.api import ApiController
|
||||||
from owrx.controllers.metrics import MetricsController
|
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 owrx.controllers.session import SessionController
|
||||||
from http.server import BaseHTTPRequestHandler
|
from http.server import BaseHTTPRequestHandler
|
||||||
from urllib.parse import urlparse, parse_qs
|
from urllib.parse import urlparse, parse_qs
|
||||||
@ -100,8 +100,9 @@ class Router(object):
|
|||||||
StaticRoute("/features", FeatureController),
|
StaticRoute("/features", FeatureController),
|
||||||
StaticRoute("/api/features", ApiController),
|
StaticRoute("/api/features", ApiController),
|
||||||
StaticRoute("/metrics", MetricsController),
|
StaticRoute("/metrics", MetricsController),
|
||||||
StaticRoute("/admin", SettingsController),
|
StaticRoute("/settings", SettingsController),
|
||||||
StaticRoute("/admin", SettingsController, method="POST", options={"action": "processFormData"}),
|
StaticRoute("/generalsettings", GeneralSettingsController),
|
||||||
|
StaticRoute("/generalsettings", GeneralSettingsController, method="POST", options={"action": "processFormData"}),
|
||||||
StaticRoute("/login", SessionController, options={"action": "loginAction"}),
|
StaticRoute("/login", SessionController, options={"action": "loginAction"}),
|
||||||
StaticRoute("/login", SessionController, method="POST", options={"action": "processLoginAction"}),
|
StaticRoute("/login", SessionController, method="POST", options={"action": "processLoginAction"}),
|
||||||
StaticRoute("/logout", SessionController, options={"action": "logoutAction"}),
|
StaticRoute("/logout", SessionController, options={"action": "logoutAction"}),
|
||||||
|
Loading…
Reference in New Issue
Block a user