Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 21 additions & 16 deletions src/components/views/dialogs/devtools/ServerInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -33,28 +34,32 @@ interface IServerWellKnown {
};
}

export async function getServerVersionFromFederationApi(client: MatrixClient): Promise<IServerWellKnown> {
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<IDevtoolsProps> = ({ 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<IServerWellKnown | symbol> => {
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);
}
Expand Down
39 changes: 39 additions & 0 deletions src/rageshake/submit-rageshake.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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[];
Expand Down Expand Up @@ -122,6 +124,43 @@ async function collectBugReport(opts: IOpts = {}, gzipLogs = true): Promise<Form
body.append("session_backup_key_cached", String(!!sessionBackupKeyFromCache));
body.append("session_backup_key_well_formed", String(sessionBackupKeyFromCache instanceof Uint8Array));
}

try {
// XXX: This is synapse-specific but better than nothing until MSC support for a server version endpoint
const data = await client.http.request<Record<string, any>>(
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) {
Expand Down