diff --git a/src/components/views/dialogs/devtools/ServerInfo.tsx b/src/components/views/dialogs/devtools/ServerInfo.tsx index 32f6a072e2..3f48aadb5b 100644 --- a/src/components/views/dialogs/devtools/ServerInfo.tsx +++ b/src/components/views/dialogs/devtools/ServerInfo.tsx @@ -15,6 +15,7 @@ limitations under the License. */ import React, { useContext } from "react"; +import { MatrixClient } from "matrix-js-sdk/src/matrix"; import BaseTool, { IDevtoolsProps } from "./BaseTool"; import { _t } from "../../../../languageHandler"; @@ -33,28 +34,32 @@ interface IServerWellKnown { }; } +export async function getServerVersionFromFederationApi(client: MatrixClient): Promise { + let baseUrl = client.getHomeserverUrl(); + + try { + const hsName = MatrixClientPeg.getHomeserverName(); + // We don't use the js-sdk Autodiscovery module here as it only support client well-known, not server ones. + const response = await fetch(`https://${hsName}/.well-known/matrix/server`); + const json = await response.json(); + if (json["m.server"]) { + baseUrl = `https://${json["m.server"]}`; + } + } catch (e) { + console.warn(e); + } + + const response = await fetch(`${baseUrl}/_matrix/federation/v1/version`); + return response.json(); +} + const ServerInfo: React.FC = ({ onBack }) => { const cli = useContext(MatrixClientContext); const capabilities = useAsyncMemo(() => cli.getCapabilities(true).catch(() => FAILED_TO_LOAD), [cli]); const clientVersions = useAsyncMemo(() => cli.getVersions().catch(() => FAILED_TO_LOAD), [cli]); const serverVersions = useAsyncMemo(async (): Promise => { - let baseUrl = cli.getHomeserverUrl(); - try { - const hsName = MatrixClientPeg.getHomeserverName(); - // We don't use the js-sdk Autodiscovery module here as it only support client well-known, not server ones. - const response = await fetch(`https://${hsName}/.well-known/matrix/server`); - const json = await response.json(); - if (json["m.server"]) { - baseUrl = `https://${json["m.server"]}`; - } - } catch (e) { - console.warn(e); - } - - try { - const response = await fetch(`${baseUrl}/_matrix/federation/v1/version`); - return response.json(); + return await getServerVersionFromFederationApi(cli); } catch (e) { console.warn(e); } diff --git a/src/rageshake/submit-rageshake.ts b/src/rageshake/submit-rageshake.ts index afc02037ad..4abaafdc64 100644 --- a/src/rageshake/submit-rageshake.ts +++ b/src/rageshake/submit-rageshake.ts @@ -17,6 +17,7 @@ limitations under the License. */ import { logger } from "matrix-js-sdk/src/logger"; +import { Method } from "matrix-js-sdk/src/http-api"; import type * as Pako from "pako"; import { MatrixClientPeg } from "../MatrixClientPeg"; @@ -25,6 +26,7 @@ import { _t } from "../languageHandler"; import * as rageshake from "./rageshake"; import SettingsStore from "../settings/SettingsStore"; import SdkConfig from "../SdkConfig"; +import { getServerVersionFromFederationApi } from "../components/views/dialogs/devtools/ServerInfo"; interface IOpts { labels?: string[]; @@ -122,6 +124,43 @@ async function collectBugReport(opts: IOpts = {}, gzipLogs = true): Promise
>( + Method.Get, + "/server_version", + undefined, + undefined, + { + prefix: "/_synapse/admin/v1", + }, + ); + Object.keys(data).forEach((key) => { + body.append(`matrix_hs_${key}`, data[key]); + }); + } catch { + try { + // XXX: This relies on the federation listener being delegated via well-known + // or at the same place as the client server endpoint + const data = await getServerVersionFromFederationApi(client); + body.append("matrix_hs_name", data.server.name); + body.append("matrix_hs_version", data.server.version); + } catch { + try { + // If that fails we'll hit any endpoint and look at the server response header + const res = await window.fetch(client.http.getUrl("/login"), { + method: "GET", + mode: "cors", + }); + if (res.headers.has("server")) { + body.append("matrix_hs_server", res.headers.get("server")!); + } + } catch { + // Could not determine server version + } + } + } } if (opts.labels) {