From a65e35fbc2668c2db77e7c312da1b1fb778e09e4 Mon Sep 17 00:00:00 2001 From: Rory& Date: Mon, 15 Jan 2024 02:12:26 +0100 Subject: LibMatrix update, refactor login page, add web manifest --- LibMatrix | 2 +- MatrixRoomUtils.Web/Pages/About.razor | 20 ++--- MatrixRoomUtils.Web/Pages/HSAdmin/HSAdmin.razor | 2 +- MatrixRoomUtils.Web/Pages/Index.razor | 4 +- MatrixRoomUtils.Web/Pages/LoginPage.razor | 109 ++++++++++++++++-------- MatrixRoomUtils.Web/Pages/ServerInfo.razor | 2 +- MatrixRoomUtils.Web/wwwroot/index.html | 1 + MatrixRoomUtils.Web/wwwroot/mru.webmanifest | 16 ++++ reset-submodules.sh | 9 ++ 9 files changed, 114 insertions(+), 51 deletions(-) create mode 100644 MatrixRoomUtils.Web/wwwroot/mru.webmanifest create mode 100755 reset-submodules.sh diff --git a/LibMatrix b/LibMatrix index a481bea..cb92b26 160000 --- a/LibMatrix +++ b/LibMatrix @@ -1 +1 @@ -Subproject commit a481bead16d904da8ad4d6de8d1a8ab006460b31 +Subproject commit cb92b267f46113f3c0a6138729ac584be6ae9399 diff --git a/MatrixRoomUtils.Web/Pages/About.razor b/MatrixRoomUtils.Web/Pages/About.razor index a5864ab..59368af 100644 --- a/MatrixRoomUtils.Web/Pages/About.razor +++ b/MatrixRoomUtils.Web/Pages/About.razor @@ -7,29 +7,29 @@

Rory&::MatrixUtils - About


-

Rory&::MatrixRoomUtils is a "small" collection of tools to do not-so-everyday things.

+

Rory&::MatrixUtils is a "small" collection of tools to do not-so-everyday things.

These range from joining rooms on dead homeservers, to managing your accounts and rooms, and creating rooms based on templates.



-

You can find the source code on my git server.

+

You can find the source code on cgit.rory.gay.

You can also join the Matrix room for this project.

-@if (ShowBinDownload) { -

This deployment also serves a copy of the compiled, hosting-ready binaries at /MRU-BIN.tar.xz!

+@if (BinDownloadAvailable) { +

This deployment also serves a copy of the compiled, hosting-ready binaries at /MRU-BIN.tar.xz!

} -@if (ShowSrcDownload) { -

This deployment also serves a copy of the compiled, hosting-ready binaries at /MRU-SRC.tar.xz!

+@if (SrcDownloadAvailable) { +

This deployment also serves a copy of the source code at /MRU-SRC.tar.xz!

} @code { - private bool ShowBinDownload { get; set; } - private bool ShowSrcDownload { get; set; } + private bool BinDownloadAvailable { get; set; } + private bool SrcDownloadAvailable { get; set; } protected override async Task OnInitializedAsync() { using var hc = new HttpClient(); var hr = await hc.SendAsync(new HttpRequestMessage(HttpMethod.Head, NavigationManager.ToAbsoluteUri("/MRU-BIN.tar.xz").AbsoluteUri)); - ShowBinDownload = hr.StatusCode == HttpStatusCode.OK; + BinDownloadAvailable = hr.StatusCode == HttpStatusCode.OK; hr = await hc.SendAsync(new HttpRequestMessage(HttpMethod.Head, NavigationManager.ToAbsoluteUri("/MRU-SRC.tar.xz").AbsoluteUri)); - ShowSrcDownload = hr.StatusCode == HttpStatusCode.OK; + SrcDownloadAvailable = hr.StatusCode == HttpStatusCode.OK; await base.OnInitializedAsync(); } diff --git a/MatrixRoomUtils.Web/Pages/HSAdmin/HSAdmin.razor b/MatrixRoomUtils.Web/Pages/HSAdmin/HSAdmin.razor index c605e7a..d1a2df5 100644 --- a/MatrixRoomUtils.Web/Pages/HSAdmin/HSAdmin.razor +++ b/MatrixRoomUtils.Web/Pages/HSAdmin/HSAdmin.razor @@ -27,7 +27,7 @@ else { protected override async Task OnInitializedAsync() { Homeserver = await MRUStorage.GetCurrentSessionOrNavigate(); if (Homeserver is null) return; - ServerVersionResponse = await Homeserver.GetServerVersionAsync(); + ServerVersionResponse = await (Homeserver.FederationClient?.GetServerVersionAsync() ?? Task.FromResult(null)); await base.OnInitializedAsync(); } diff --git a/MatrixRoomUtils.Web/Pages/Index.razor b/MatrixRoomUtils.Web/Pages/Index.razor index ebb0ebb..250dc2d 100644 --- a/MatrixRoomUtils.Web/Pages/Index.razor +++ b/MatrixRoomUtils.Web/Pages/Index.razor @@ -121,7 +121,7 @@ Small collection of tools to do not-so-everyday things. return; } - catch (HttpRequestException e) { + catch (Exception e) { logger.LogError(e, $"Failed to instantiate AuthenticatedHomeserver for {token.ToJson()}, homeserver may be offline?", token.UserId); _offlineSessions.Add(token); return; @@ -140,7 +140,7 @@ Small collection of tools to do not-so-everyday things. DisplayName = profile.DisplayName ?? hs.WhoAmI.UserId }, UserAuth = token, - ServerVersion = await hs.GetServerVersionAsync(), + ServerVersion = await (hs.FederationClient?.GetServerVersionAsync() ?? Task.FromResult(null)), Homeserver = hs }); }); diff --git a/MatrixRoomUtils.Web/Pages/LoginPage.razor b/MatrixRoomUtils.Web/Pages/LoginPage.razor index c926a93..b6f244d 100644 --- a/MatrixRoomUtils.Web/Pages/LoginPage.razor +++ b/MatrixRoomUtils.Web/Pages/LoginPage.razor @@ -1,36 +1,50 @@ @page "/Login" @using System.Text.Json +@using System.Text.Json.Serialization +@using LibMatrix @inject ILocalStorageService LocalStorage @inject IJSRuntime JsRuntime

Login


- + + @@: - via - - + + + + +
+Add account to queue +Log in +

+

Import from TSV

+
+Import credentials from a TSV (Tab Separated Values) file
+Columns: username, homeserver, password, proxy
+Keep in mind there is no column header!
+

-

-

Parsed records

-
+
+ - - - - - + + + + + + @foreach (var record in records) { var r = record; @@ -47,16 +61,28 @@ - + @if (r.Exception is MatrixException me) { + + + + + + } + else if (r.Exception is { } e) { + + + + + } }
UsernameHomeserverPasswordProxy
UsernameHomeserverPasswordProxyActions
+ Remove
Exception:@me.ErrorCode@me.Error
Exception:@e.Message

- -
- +Log in + @code { readonly List records = new(); @@ -64,29 +90,37 @@ List? LoggedInSessions { get; set; } = new(); - async Task Login() { - var loginTasks = records.Select(async record => { - if (LoggedInSessions.Any(x => x.UserId == $"@{record.Username}:{record.Homeserver}" && x.Proxy == record.Proxy)) return; - try { - var result = new UserAuth(await hsProvider.Login(record.Homeserver, record.Username, record.Password, record.Proxy)) { - Proxy = record.Proxy - }; - if (result == null) { - Console.WriteLine($"Failed to login to {record.Homeserver} as {record.Username}!"); - return; - } - Console.WriteLine($"Obtained access token for {result.UserId}!"); + async Task LoginAll() { + var loginTasks = records.Select(Login); + await Task.WhenAll(loginTasks); + } - await MRUStorage.AddToken(result); - LoggedInSessions = await MRUStorage.GetAllTokens(); - } - catch (Exception e) { + async Task Login(LoginStruct record) { + if (!records.Contains(record)) + records.Add(record); + if (LoggedInSessions.Any(x => x.UserId == $"@{record.Username}:{record.Homeserver}" && x.Proxy == record.Proxy)) return; + StateHasChanged(); + try { + var result = new UserAuth(await hsProvider.Login(record.Homeserver, record.Username, record.Password, record.Proxy)) { + Proxy = record.Proxy + }; + if (result == null) { Console.WriteLine($"Failed to login to {record.Homeserver} as {record.Username}!"); - Console.WriteLine(e); + return; } - StateHasChanged(); - }); - await Task.WhenAll(loginTasks); + + Console.WriteLine($"Obtained access token for {result.UserId}!"); + + await MRUStorage.AddToken(result); + LoggedInSessions = await MRUStorage.GetAllTokens(); + } + catch (Exception e) { + Console.WriteLine($"Failed to login to {record.Homeserver} as {record.Username}!"); + Console.WriteLine(e); + record.Exception = e; + } + + StateHasChanged(); } private async Task FileChanged(InputFileChangeEventArgs obj) { @@ -118,6 +152,9 @@ public string? Username { get; set; } = ""; public string? Password { get; set; } = ""; public string? Proxy { get; set; } + + [JsonIgnore] + internal Exception? Exception { get; set; } } } \ No newline at end of file diff --git a/MatrixRoomUtils.Web/Pages/ServerInfo.razor b/MatrixRoomUtils.Web/Pages/ServerInfo.razor index 5b3f1c1..71a1980 100644 --- a/MatrixRoomUtils.Web/Pages/ServerInfo.razor +++ b/MatrixRoomUtils.Web/Pages/ServerInfo.razor @@ -80,7 +80,7 @@ protected override async Task OnParametersSetAsync() { if (Homeserver is not null) { var rhs = await hsProvider.GetRemoteHomeserver(Homeserver); - ServerVersionResponse = await rhs.GetServerVersionAsync(); + ServerVersionResponse = await (rhs.FederationClient?.GetServerVersionAsync() ?? Task.FromResult(null)); ClientVersionsResponse = await rhs.GetClientVersionsAsync(); } base.OnParametersSetAsync(); diff --git a/MatrixRoomUtils.Web/wwwroot/index.html b/MatrixRoomUtils.Web/wwwroot/index.html index 3fc740a..7eef159 100644 --- a/MatrixRoomUtils.Web/wwwroot/index.html +++ b/MatrixRoomUtils.Web/wwwroot/index.html @@ -10,6 +10,7 @@ + diff --git a/MatrixRoomUtils.Web/wwwroot/mru.webmanifest b/MatrixRoomUtils.Web/wwwroot/mru.webmanifest new file mode 100644 index 0000000..ef1ee66 --- /dev/null +++ b/MatrixRoomUtils.Web/wwwroot/mru.webmanifest @@ -0,0 +1,16 @@ +{ + "name": "Rory&::MatrixUtils", + "short_name": "MRU", + "description": "A collection of Matrix utilities.", + "icons": [ + { + "src": "icon-192.png", + "sizes": "192x192", + "type": "image/png" + } + ], + "start_url": "/index.html", + "display": "fullscreen", + "theme_color": "#052767", + "background_color": "#3A0647" +} diff --git a/reset-submodules.sh b/reset-submodules.sh new file mode 100755 index 0000000..60f2267 --- /dev/null +++ b/reset-submodules.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env bash + +find . -type d | grep --invert '\.git' | while read dir +do + ( + (git -C $dir submodule init 2>/dev/null) \ + && (git -C $dir submodule update 2>/dev/null) + ) || echo $dir does not contain submodules +done -- cgit 1.4.1