hide logout botton when auth is disabled

This commit is contained in:
Maxim Devaev
2022-03-26 00:54:16 +03:00
parent ed23fef512
commit 3a878baac8
3 changed files with 41 additions and 3 deletions

View File

@@ -25,6 +25,7 @@ from typing import Set
from ....yamlconf import Section from ....yamlconf import Section
from .base import BaseInfoSubmanager from .base import BaseInfoSubmanager
from .auth import AuthInfoSubmanager
from .system import SystemInfoSubmanager from .system import SystemInfoSubmanager
from .meta import MetaInfoSubmanager from .meta import MetaInfoSubmanager
from .extras import ExtrasInfoSubmanager from .extras import ExtrasInfoSubmanager
@@ -37,6 +38,7 @@ class InfoManager:
def __init__(self, config: Section) -> None: def __init__(self, config: Section) -> None:
self.__subs = { self.__subs = {
"system": SystemInfoSubmanager(config.kvmd.streamer.cmd), "system": SystemInfoSubmanager(config.kvmd.streamer.cmd),
"auth": AuthInfoSubmanager(config.kvmd.auth.enabled),
"meta": MetaInfoSubmanager(config.kvmd.info.meta), "meta": MetaInfoSubmanager(config.kvmd.info.meta),
"extras": ExtrasInfoSubmanager(config), "extras": ExtrasInfoSubmanager(config),
"hw": HwInfoSubmanager(**config.kvmd.info.hw._unpack()), "hw": HwInfoSubmanager(**config.kvmd.info.hw._unpack()),

View File

@@ -0,0 +1,34 @@
# ========================================================================== #
# #
# KVMD - The main PiKVM daemon. #
# #
# Copyright (C) 2018-2022 Maxim Devaev <mdevaev@gmail.com> #
# #
# 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}

View File

@@ -51,7 +51,7 @@ function __setAppText() {
} }
function __loadKvmdInfo() { 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.readyState === 4) {
if (http.status === 200) { if (http.status === 200) {
let info = JSON.parse(http.responseText).result; let info = JSON.parse(http.responseText).result;
@@ -85,8 +85,10 @@ function __loadKvmdInfo() {
} }
} }
$("apps").innerHTML += __makeApp("logout-button", "#", "share/svg/logout.svg", "Logout"); if (info.auth.enabled) {
tools.el.setOnClick($("logout-button"), __logout); $("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) { if (info.meta !== null && info.meta.server && info.meta.server.host) {
$("kvmd-meta-server-host").innerHTML = info.meta.server.host; $("kvmd-meta-server-host").innerHTML = info.meta.server.host;