diff options
author | Maxim Devaev <[email protected]> | 2022-03-26 00:54:16 +0300 |
---|---|---|
committer | Maxim Devaev <[email protected]> | 2022-03-26 00:54:16 +0300 |
commit | 3a878baac812958fd27ca5d82ef4bb4463de4654 (patch) | |
tree | 20b91c821e03e9df108ac29a0b9bad632ac441c1 | |
parent | ed23fef5121f8f71b47b3e6aefe409a7e36fd9a7 (diff) |
hide logout botton when auth is disabled
-rw-r--r-- | kvmd/apps/kvmd/info/__init__.py | 2 | ||||
-rw-r--r-- | kvmd/apps/kvmd/info/auth.py | 34 | ||||
-rw-r--r-- | web/share/js/index/main.js | 8 |
3 files changed, 41 insertions, 3 deletions
diff --git a/kvmd/apps/kvmd/info/__init__.py b/kvmd/apps/kvmd/info/__init__.py index 53a02f88..f8871d72 100644 --- a/kvmd/apps/kvmd/info/__init__.py +++ b/kvmd/apps/kvmd/info/__init__.py @@ -25,6 +25,7 @@ from typing import Set from ....yamlconf import Section from .base import BaseInfoSubmanager +from .auth import AuthInfoSubmanager from .system import SystemInfoSubmanager from .meta import MetaInfoSubmanager from .extras import ExtrasInfoSubmanager @@ -37,6 +38,7 @@ class InfoManager: def __init__(self, config: Section) -> None: self.__subs = { "system": SystemInfoSubmanager(config.kvmd.streamer.cmd), + "auth": AuthInfoSubmanager(config.kvmd.auth.enabled), "meta": MetaInfoSubmanager(config.kvmd.info.meta), "extras": ExtrasInfoSubmanager(config), "hw": HwInfoSubmanager(**config.kvmd.info.hw._unpack()), diff --git a/kvmd/apps/kvmd/info/auth.py b/kvmd/apps/kvmd/info/auth.py new file mode 100644 index 00000000..bf1c6160 --- /dev/null +++ b/kvmd/apps/kvmd/info/auth.py @@ -0,0 +1,34 @@ +# ========================================================================== # +# # +# KVMD - The main PiKVM daemon. # +# # +# Copyright (C) 2018-2022 Maxim Devaev <[email protected]> # +# # +# This program is free software: you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation, either version 3 of the License, or # +# (at your option) any later version. # +# # +# This program is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program. If not, see <https://www.gnu.org/licenses/>. # +# # +# ========================================================================== # + + +from typing import Dict + +from .base import BaseInfoSubmanager + + +# ===== +class AuthInfoSubmanager(BaseInfoSubmanager): + def __init__(self, enabled: bool) -> None: + self.__enabled = enabled + + async def get_state(self) -> Dict: + return {"enabled": self.__enabled} diff --git a/web/share/js/index/main.js b/web/share/js/index/main.js index f153e2fa..b34fa099 100644 --- a/web/share/js/index/main.js +++ b/web/share/js/index/main.js @@ -51,7 +51,7 @@ function __setAppText() { } function __loadKvmdInfo() { - let http = tools.makeRequest("GET", "/api/info?fields=meta,extras", function() { + let http = tools.makeRequest("GET", "/api/info?fields=auth,meta,extras", function() { if (http.readyState === 4) { if (http.status === 200) { let info = JSON.parse(http.responseText).result; @@ -85,8 +85,10 @@ function __loadKvmdInfo() { } } - $("apps").innerHTML += __makeApp("logout-button", "#", "share/svg/logout.svg", "Logout"); - tools.el.setOnClick($("logout-button"), __logout); + if (info.auth.enabled) { + $("apps").innerHTML += __makeApp("logout-button", "#", "share/svg/logout.svg", "Logout"); + tools.el.setOnClick($("logout-button"), __logout); + } if (info.meta !== null && info.meta.server && info.meta.server.host) { $("kvmd-meta-server-host").innerHTML = info.meta.server.host; |