summary refs log tree commit diff
path: root/MxApiExtensions/Controllers/Extensions
diff options
context:
space:
mode:
authorTheArcaneBrony <myrainbowdash949@gmail.com>2023-11-05 17:59:38 +0100
committerTheArcaneBrony <myrainbowdash949@gmail.com>2023-11-05 17:59:38 +0100
commit2abb132234546e61bb0aff3897dc49e72ea84f5d (patch)
treec885c03d35e7a0a6b8fc21bd0b259216c61c877c /MxApiExtensions/Controllers/Extensions
parentUpdate (diff)
downloadMxApiExtensions-2abb132234546e61bb0aff3897dc49e72ea84f5d.tar.xz
Working sync proxy
Diffstat (limited to 'MxApiExtensions/Controllers/Extensions')
-rw-r--r--MxApiExtensions/Controllers/Extensions/DebugController.cs45
1 files changed, 45 insertions, 0 deletions
diff --git a/MxApiExtensions/Controllers/Extensions/DebugController.cs b/MxApiExtensions/Controllers/Extensions/DebugController.cs
new file mode 100644

index 0000000..79ed2f0 --- /dev/null +++ b/MxApiExtensions/Controllers/Extensions/DebugController.cs
@@ -0,0 +1,45 @@ +using System.Collections.Concurrent; +using Microsoft.AspNetCore.Mvc; +using MxApiExtensions.Classes.LibMatrix; +using MxApiExtensions.Services; + +namespace MxApiExtensions.Controllers.Extensions; + +[ApiController] +[Route("/")] +public class DebugController : ControllerBase { + private readonly ILogger _logger; + private readonly MxApiExtensionsConfiguration _config; + private readonly AuthenticationService _authenticationService; + + private static ConcurrentDictionary<string, RoomInfoEntry> _roomInfoCache = new(); + + public DebugController(ILogger<ProxyConfigurationController> logger, MxApiExtensionsConfiguration config, AuthenticationService authenticationService, + AuthenticatedHomeserverProviderService authenticatedHomeserverProviderService) { + _logger = logger; + _config = config; + _authenticationService = authenticationService; + } + + [HttpGet("debug")] + public async Task<object?> GetDebug() { + var mxid = await _authenticationService.GetMxidFromToken(); + if(!_config.Admins.Contains(mxid)) { + _logger.LogWarning("Got debug 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 debug request for {user}", mxid); + return new { + SyncStates = SyncController._syncStates + }; + } +}