diff options
| author | JP Dillingham <jp@dillingham.me> | 2022-11-18 11:18:44 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-11-18 11:18:44 -0600 |
| commit | 43c3a052796fbd490677de931c2b6925efa0fa5e (patch) | |
| tree | 79d4b6a810d1fe591baafc720d5dd0c0cfb14b4c /src/slskd/Core/API | |
| parent | f959a86d865eee5a8a1f353afdc34560067ba544 (diff) | |
| parent | 7b129b69211909a3af9bbeddf0acc1dc3d84e20c (diff) | |
| download | slskd-43c3a052796fbd490677de931c2b6925efa0fa5e.tar.gz | |
Merge pull request #757 from slskd/agent-apis
Forbid server API calls in Agent mode
Diffstat (limited to 'src/slskd/Core/API')
| -rw-r--r-- | src/slskd/Core/API/Controllers/ServerController.cs | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/slskd/Core/API/Controllers/ServerController.cs b/src/slskd/Core/API/Controllers/ServerController.cs index a725c978..b1e36b1a 100644 --- a/src/slskd/Core/API/Controllers/ServerController.cs +++ b/src/slskd/Core/API/Controllers/ServerController.cs @@ -22,6 +22,7 @@ namespace slskd.Core.API using System.Threading.Tasks; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; + using slskd.Relay; using Soulseek; /// <summary> @@ -47,6 +48,7 @@ namespace slskd.Core.API private ISoulseekClient Client { get; } private IOptionsSnapshot<Options> OptionsSnapshot { get; } private IStateSnapshot<State> StateSnapshot { get; } + private bool IsAgent => OptionsSnapshot.Value.Relay.Mode.ToEnum<OperationMode>() == OperationMode.Agent; /// <summary> /// Connects the client. @@ -59,6 +61,11 @@ namespace slskd.Core.API [ProducesResponseType(403)] public async Task<IActionResult> Connect() { + if (IsAgent) + { + return Forbid(); + } + if (!Client.State.HasFlag(SoulseekClientStates.Connected)) { await Client.ConnectAsync(OptionsSnapshot.Value.Soulseek.Username, OptionsSnapshot.Value.Soulseek.Password); @@ -79,6 +86,11 @@ namespace slskd.Core.API [ProducesResponseType(403)] public IActionResult Disconnect([FromBody] string message) { + if (IsAgent) + { + return Forbid(); + } + if (Client.State.HasFlag(SoulseekClientStates.Connected)) { Client.Disconnect(message, new IntentionalDisconnectException(message)); |
