aboutsummaryrefslogtreecommitdiffstats
path: root/src/slskd/Messaging/API/Controllers/PublicChatController.cs
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2022-11-18 11:18:44 -0600
committerGitHub <noreply@github.com>2022-11-18 11:18:44 -0600
commit43c3a052796fbd490677de931c2b6925efa0fa5e (patch)
tree79d4b6a810d1fe591baafc720d5dd0c0cfb14b4c /src/slskd/Messaging/API/Controllers/PublicChatController.cs
parentf959a86d865eee5a8a1f353afdc34560067ba544 (diff)
parent7b129b69211909a3af9bbeddf0acc1dc3d84e20c (diff)
downloadslskd-43c3a052796fbd490677de931c2b6925efa0fa5e.tar.gz
Merge pull request #757 from slskd/agent-apis
Forbid server API calls in Agent mode
Diffstat (limited to 'src/slskd/Messaging/API/Controllers/PublicChatController.cs')
-rw-r--r--src/slskd/Messaging/API/Controllers/PublicChatController.cs18
1 files changed, 17 insertions, 1 deletions
diff --git a/src/slskd/Messaging/API/Controllers/PublicChatController.cs b/src/slskd/Messaging/API/Controllers/PublicChatController.cs
index 83f7ede7..66f0951d 100644
--- a/src/slskd/Messaging/API/Controllers/PublicChatController.cs
+++ b/src/slskd/Messaging/API/Controllers/PublicChatController.cs
@@ -15,12 +15,15 @@
// along with this program. If not, see https://www.gnu.org/licenses/.
// </copyright>
+using Microsoft.Extensions.Options;
+
namespace slskd.Messaging.API
{
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
+ using slskd.Relay;
using Soulseek;
/// <summary>
@@ -33,12 +36,15 @@ namespace slskd.Messaging.API
[Consumes("application/json")]
public class PublicChatController : ControllerBase
{
- public PublicChatController(ISoulseekClient soulseekClient)
+ public PublicChatController(ISoulseekClient soulseekClient, IOptionsSnapshot<Options> optionsSnapshot)
{
Client = soulseekClient;
+ OptionsSnapshot = optionsSnapshot;
}
private ISoulseekClient Client { get; }
+ private IOptionsSnapshot<Options> OptionsSnapshot { get; }
+ private bool IsAgent => OptionsSnapshot.Value.Relay.Mode.ToEnum<OperationMode>() == OperationMode.Agent;
/// <summary>
/// Starts public chat.
@@ -48,6 +54,11 @@ namespace slskd.Messaging.API
[Authorize(Policy = AuthPolicy.Any)]
public async Task<IActionResult> Start()
{
+ if (IsAgent)
+ {
+ return Forbid();
+ }
+
await Client.StartPublicChatAsync();
return StatusCode(StatusCodes.Status201Created);
}
@@ -60,6 +71,11 @@ namespace slskd.Messaging.API
[Authorize(Policy = AuthPolicy.Any)]
public async Task<IActionResult> Stop()
{
+ if (IsAgent)
+ {
+ return Forbid();
+ }
+
await Client.StopPublicChatAsync();
return StatusCode(StatusCodes.Status204NoContent);
}