From 577aa7ba79ffdb65a7047446fb7e95d4704e66b5 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Mon, 26 Jul 2021 19:58:26 +0200 Subject: [PATCH] web/admin: add status card for https and timedrift Signed-off-by: Jens Langhammer --- web/src/locales/en.po | 18 ++++++++ web/src/locales/pseudo-LOCALE.po | 18 ++++++++ .../pages/admin-overview/AdminOverviewPage.ts | 9 +++- .../admin-overview/cards/SystemStatusCard.ts | 46 +++++++++++++++++++ 4 files changed, 89 insertions(+), 2 deletions(-) create mode 100644 web/src/pages/admin-overview/cards/SystemStatusCard.ts diff --git a/web/src/locales/en.po b/web/src/locales/en.po index 74a33f435..9db36b6e3 100644 --- a/web/src/locales/en.po +++ b/web/src/locales/en.po @@ -1424,6 +1424,10 @@ msgstr "Event {0}" msgid "Events" msgstr "Events" +#: src/pages/admin-overview/cards/SystemStatusCard.ts +msgid "Everything is ok." +msgstr "Everything is ok." + #: src/pages/events/EventInfo.ts #: src/pages/events/EventInfo.ts #: src/pages/events/EventInfo.ts @@ -1773,6 +1777,10 @@ msgstr "HTTP-Basic Password Key" msgid "HTTP-Basic Username Key" msgstr "HTTP-Basic Username Key" +#: src/pages/admin-overview/cards/SystemStatusCard.ts +msgid "HTTPS is not detected correctly" +msgstr "HTTPS is not detected correctly" + #: src/pages/outposts/OutpostListPage.ts msgid "Health and Version" msgstr "Health and Version" @@ -3320,6 +3328,10 @@ msgstr "Separator: Static Separator Line" msgid "Server URI" msgstr "Server URI" +#: src/pages/admin-overview/cards/SystemStatusCard.ts +msgid "Server and client are further than 5 seconds apart." +msgstr "Server and client are further than 5 seconds apart." + #: src/pages/providers/ldap/LDAPProviderForm.ts msgid "Server name for which this provider's certificate is valid for." msgstr "Server name for which this provider's certificate is valid for." @@ -3897,6 +3909,10 @@ msgstr "System Overview" msgid "System Tasks" msgstr "System Tasks" +#: src/pages/admin-overview/AdminOverviewPage.ts +msgid "System status" +msgstr "System status" + #: src/pages/events/utils.ts msgid "System task exception" msgstr "System task exception" @@ -4612,6 +4628,8 @@ msgstr "Wait (max)" msgid "Wait (min)" msgstr "Wait (min)" +#: src/pages/admin-overview/cards/SystemStatusCard.ts +#: src/pages/admin-overview/cards/SystemStatusCard.ts #: src/pages/events/RuleForm.ts #: src/pages/system-tasks/SystemTaskListPage.ts msgid "Warning" diff --git a/web/src/locales/pseudo-LOCALE.po b/web/src/locales/pseudo-LOCALE.po index cbaa9dbea..88e11913e 100644 --- a/web/src/locales/pseudo-LOCALE.po +++ b/web/src/locales/pseudo-LOCALE.po @@ -1416,6 +1416,10 @@ msgstr "" msgid "Events" msgstr "" +#: src/pages/admin-overview/cards/SystemStatusCard.ts +msgid "Everything is ok." +msgstr "" + #: src/pages/events/EventInfo.ts #: src/pages/events/EventInfo.ts #: src/pages/events/EventInfo.ts @@ -1765,6 +1769,10 @@ msgstr "" msgid "HTTP-Basic Username Key" msgstr "" +#: src/pages/admin-overview/cards/SystemStatusCard.ts +msgid "HTTPS is not detected correctly" +msgstr "" + #: src/pages/outposts/OutpostListPage.ts msgid "Health and Version" msgstr "" @@ -3312,6 +3320,10 @@ msgstr "" msgid "Server URI" msgstr "" +#: src/pages/admin-overview/cards/SystemStatusCard.ts +msgid "Server and client are further than 5 seconds apart." +msgstr "" + #: src/pages/providers/ldap/LDAPProviderForm.ts msgid "Server name for which this provider's certificate is valid for." msgstr "" @@ -3889,6 +3901,10 @@ msgstr "" msgid "System Tasks" msgstr "" +#: src/pages/admin-overview/AdminOverviewPage.ts +msgid "System status" +msgstr "" + #: src/pages/events/utils.ts msgid "System task exception" msgstr "" @@ -4597,6 +4613,8 @@ msgstr "" msgid "Wait (min)" msgstr "" +#: src/pages/admin-overview/cards/SystemStatusCard.ts +#: src/pages/admin-overview/cards/SystemStatusCard.ts #: src/pages/events/RuleForm.ts #: src/pages/system-tasks/SystemTaskListPage.ts msgid "Warning" diff --git a/web/src/pages/admin-overview/AdminOverviewPage.ts b/web/src/pages/admin-overview/AdminOverviewPage.ts index f629d2181..87869ae2e 100644 --- a/web/src/pages/admin-overview/AdminOverviewPage.ts +++ b/web/src/pages/admin-overview/AdminOverviewPage.ts @@ -9,6 +9,7 @@ import "./cards/AdminStatusCard"; import "./cards/BackupStatusCard"; import "./cards/VersionStatusCard"; import "./cards/WorkerStatusCard"; +import "./cards/SystemStatusCard"; import "./charts/FlowStatusChart"; import "./charts/LDAPSyncStatusChart"; @@ -92,14 +93,18 @@ export class AdminOverviewPage extends LitElement { -
+
-
+
+
+ + +

diff --git a/web/src/pages/admin-overview/cards/SystemStatusCard.ts b/web/src/pages/admin-overview/cards/SystemStatusCard.ts new file mode 100644 index 000000000..301ea8965 --- /dev/null +++ b/web/src/pages/admin-overview/cards/SystemStatusCard.ts @@ -0,0 +1,46 @@ +import { t } from "@lingui/macro"; +import { customElement, html, TemplateResult } from "lit-element"; +import { AdminApi, System } from "authentik-api"; +import { DEFAULT_CONFIG } from "../../../api/Config"; +import { AdminStatusCard, AdminStatus } from "./AdminStatusCard"; + +@customElement("ak-admin-status-system") +export class SystemStatusCard extends AdminStatusCard { + + now?: Date; + + header = "OK"; + + getPrimaryValue(): Promise { + this.now = new Date(); + return new AdminApi(DEFAULT_CONFIG).adminSystemRetrieve(); + } + + getStatus(value: System): Promise { + if (!value.httpIsSecure && document.location.protocol === "https:") { + this.header = t`Warning`; + return Promise.resolve({ + icon: "fa fa-exclamation-triangle pf-m-warning", + message: t`HTTPS is not detected correctly`, + }); + } + const timeDiff = value.serverTime.getTime() - (this.now || new Date()).getTime(); + console.log(`authentik/: timediff ${timeDiff}`); + if (timeDiff > 5000 || timeDiff < -5000) { + this.header = t`Warning`; + return Promise.resolve({ + icon: "fa fa-exclamation-triangle pf-m-warning", + message: t`Server and client are further than 5 seconds apart.`, + }); + } + return Promise.resolve({ + icon: "fa fa-check-circle pf-m-success", + message: t`Everything is ok.` + }); + } + + renderValue(): TemplateResult { + return html`${this.header}`; + } + +}