From 7e40421d0eaee613be5b807502eb25fafebde5b1 Mon Sep 17 00:00:00 2001 From: TheArcaneBrony Date: Mon, 4 Sep 2023 02:18:47 +0200 Subject: Added a lot of utilities --- .../Extensions/ProxyConfigurationController.cs | 43 ++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 MxApiExtensions/Controllers/Extensions/ProxyConfigurationController.cs (limited to 'MxApiExtensions/Controllers/Extensions/ProxyConfigurationController.cs') diff --git a/MxApiExtensions/Controllers/Extensions/ProxyConfigurationController.cs b/MxApiExtensions/Controllers/Extensions/ProxyConfigurationController.cs new file mode 100644 index 0000000..71bf167 --- /dev/null +++ b/MxApiExtensions/Controllers/Extensions/ProxyConfigurationController.cs @@ -0,0 +1,43 @@ +using System.Collections.Concurrent; +using LibMatrix.MxApiExtensions; +using Microsoft.AspNetCore.Mvc; +using MxApiExtensions.Services; + +namespace MxApiExtensions.Controllers.Extensions; + +[ApiController] +[Route("/_matrix/client/unstable/gay.rory.mxapiextensions")] +public class ProxyConfigurationController : ControllerBase { + private readonly ILogger _logger; + private readonly MxApiExtensionsConfiguration _config; + private readonly AuthenticationService _authenticationService; + + private static ConcurrentDictionary _roomInfoCache = new(); + + public ProxyConfigurationController(ILogger logger, MxApiExtensionsConfiguration config, AuthenticationService authenticationService, + AuthenticatedHomeserverProviderService authenticatedHomeserverProviderService) { + _logger = logger; + _config = config; + _authenticationService = authenticationService; + } + + [HttpGet("proxy_config")] + public async Task GetConfig() { + var mxid = await _authenticationService.GetMxidFromToken(); + if(!_config.Admins.Contains(mxid)) { + _logger.LogWarning("Got proxy config request for {user}, but they are not an admin", mxid); + Response.StatusCode = StatusCodes.Status403Forbidden; + Response.ContentType = "application/json"; + + await Response.WriteAsJsonAsync(new { + ErrorCode = "M_FORBIDDEN", + Error = "You are not an admin" + }); + await Response.CompleteAsync(); + return null; + } + + _logger.LogInformation("Got proxy config request for {user}", mxid); + return _config; + } +} -- cgit 1.5.1