From 0ada5287d7257c930e5c0f422d0ad48f2fc1aba9 Mon Sep 17 00:00:00 2001 From: Manuel Stahl Date: Tue, 5 May 2020 19:07:07 +0200 Subject: [PATCH] Show Synapse server version on login page Change-Id: Id9b0d2adf83590524069d308f4fe9e5d14147295 --- src/components/LoginPage.js | 34 +++++++++++++++++++++++++++++++++- src/i18n/de.js | 1 + 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/components/LoginPage.js b/src/components/LoginPage.js index a5bcec8..3058b45 100644 --- a/src/components/LoginPage.js +++ b/src/components/LoginPage.js @@ -1,4 +1,4 @@ -import React, { useState } from "react"; +import React, { useState, useEffect } from "react"; import { fetchUtils, FormDataConsumer, @@ -65,6 +65,12 @@ const useStyles = makeStyles(theme => ({ actions: { padding: "0 1em 1em 1em", }, + serverVersion: { + color: "#9e9e9e", + fontFamily: "Roboto, Helvetica, Arial, sans-serif", + marginBottom: "1em", + marginLeft: "0.5em", + }, })); const LoginPage = ({ theme }) => { @@ -138,6 +144,7 @@ const LoginPage = ({ theme }) => { const UserData = ({ formData }) => { const form = useForm(); + const [serverVersion, setServerVersion] = useState(""); const handleUsernameChange = _ => { if (formData.base_url) return; @@ -158,6 +165,30 @@ const LoginPage = ({ theme }) => { } }; + useEffect( + _ => { + if ( + !formData.base_url || + !formData.base_url.match(/^(http|https):\/\/[a-zA-Z0-9\-.]+$/) + ) + return; + const versionUrl = `${formData.base_url}/_synapse/admin/v1/server_version`; + fetchUtils + .fetchJson(versionUrl, { method: "GET" }) + .then(({ json }) => { + setServerVersion( + `${translate("synapseadmin.auth.server_version")} ${ + json["server_version"] + }` + ); + }) + .catch(_ => { + setServerVersion(""); + }); + }, + [formData.base_url] + ); + return (
@@ -190,6 +221,7 @@ const LoginPage = ({ theme }) => { fullWidth />
+
{serverVersion}
); }; diff --git a/src/i18n/de.js b/src/i18n/de.js index a467c1a..05d9a6e 100644 --- a/src/i18n/de.js +++ b/src/i18n/de.js @@ -6,6 +6,7 @@ export default { auth: { base_url: "Heimserver URL", welcome: "Willkommen bei Synapse-admin", + server_version: "Synapse Version", username_error: "Bitte vollständigen Nutzernamen angeben: '@user:domain'", protocol_error: "Die URL muss mit 'http://' oder 'https://' beginnen", url_error: "Keine gültige Matrix Server URL",