update default permissions for guest webfront users

This commit is contained in:
RaidMax 2022-10-16 16:25:09 -05:00
parent 76925a78d4
commit 3295315339
3 changed files with 27 additions and 3 deletions

View File

@ -1,21 +1,25 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using SharedLibraryCore;
using SharedLibraryCore.Configuration;
using SharedLibraryCore.Dtos;
using SharedLibraryCore.Interfaces;
using SharedLibraryCore.Services;
using ILogger = Microsoft.Extensions.Logging.ILogger;
namespace IW4MAdmin.Application.Misc;
public class RemoteCommandService : IRemoteCommandService
{
private readonly ILogger _logger;
private readonly ApplicationConfiguration _appConfig;
private readonly ClientService _clientService;
public RemoteCommandService(ApplicationConfiguration appConfig, ClientService clientService)
public RemoteCommandService(ILogger<RemoteCommandService> logger, ApplicationConfiguration appConfig, ClientService clientService)
{
_logger = logger;
_appConfig = appConfig;
_clientService = clientService;
}
@ -23,6 +27,13 @@ public class RemoteCommandService : IRemoteCommandService
public async Task<IEnumerable<CommandResponseInfo>> Execute(int originId, int? targetId, string command,
IEnumerable<string> arguments, Server server)
{
if (originId < 1)
{
_logger.LogWarning("Not executing command {Command} for {Originid} because origin id is invalid", command,
originId);
return Enumerable.Empty<CommandResponseInfo>();
}
var client = await _clientService.Get(originId);
client.CurrentServer = server;

View File

@ -67,7 +67,7 @@ namespace SharedLibraryCore
Client = new EFClient
{
ClientId = -1,
Level = Data.Models.Client.EFClient.Permission.Banned,
Level = Data.Models.Client.EFClient.Permission.User,
CurrentAlias = new EFAlias { Name = "Webfront Guest" }
};
}

View File

@ -10,10 +10,12 @@ namespace WebfrontCore.Controllers
public class ConsoleController : BaseController
{
private readonly IRemoteCommandService _remoteCommandService;
private readonly ITranslationLookup _translationLookup;
public ConsoleController(IManager manager, IRemoteCommandService remoteCommandService) : base(manager)
public ConsoleController(IManager manager, IRemoteCommandService remoteCommandService, ITranslationLookup translationLookup) : base(manager)
{
_remoteCommandService = remoteCommandService;
_translationLookup = translationLookup;
}
public IActionResult Index()
@ -33,6 +35,17 @@ namespace WebfrontCore.Controllers
public async Task<IActionResult> Execute(long serverId, string command)
{
if (Client.ClientId < 1)
{
return Ok(new[]
{
new CommandResponseInfo
{
Response = _translationLookup["SERVER_COMMANDS_INTERCEPTED"]
}
});
}
var server = Manager.GetServers().First(s => s.EndPoint == serverId);
var response = await _remoteCommandService.Execute(Client.ClientId, null, command, Enumerable.Empty<string>(), server);
return !response.Any() ? StatusCode(400, response) : Ok(response);