2018-02-23 02:06:13 -05:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2018-04-08 02:44:42 -04:00
|
|
|
|
using SharedLibraryCore;
|
|
|
|
|
using SharedLibraryCore.Dtos;
|
2019-12-02 16:52:36 -05:00
|
|
|
|
using SharedLibraryCore.Interfaces;
|
2018-02-23 02:06:13 -05:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace WebfrontCore.Controllers
|
|
|
|
|
{
|
2018-03-06 02:22:19 -05:00
|
|
|
|
public class ConsoleController : BaseController
|
2018-02-23 02:06:13 -05:00
|
|
|
|
{
|
2022-10-12 22:06:18 -04:00
|
|
|
|
private readonly IRemoteCommandService _remoteCommandService;
|
2022-10-16 17:25:09 -04:00
|
|
|
|
private readonly ITranslationLookup _translationLookup;
|
2020-07-31 21:40:03 -04:00
|
|
|
|
|
2022-10-16 17:25:09 -04:00
|
|
|
|
public ConsoleController(IManager manager, IRemoteCommandService remoteCommandService, ITranslationLookup translationLookup) : base(manager)
|
2019-12-02 16:52:36 -05:00
|
|
|
|
{
|
2022-10-12 22:06:18 -04:00
|
|
|
|
_remoteCommandService = remoteCommandService;
|
2022-10-16 17:25:09 -04:00
|
|
|
|
_translationLookup = translationLookup;
|
2019-12-02 16:52:36 -05:00
|
|
|
|
}
|
|
|
|
|
|
2018-02-23 02:06:13 -05:00
|
|
|
|
public IActionResult Index()
|
|
|
|
|
{
|
2018-04-08 14:48:40 -04:00
|
|
|
|
var activeServers = Manager.GetServers().Select(s => new ServerInfo()
|
2018-02-23 02:06:13 -05:00
|
|
|
|
{
|
|
|
|
|
Name = s.Hostname,
|
2018-11-27 19:31:48 -05:00
|
|
|
|
ID = s.EndPoint,
|
2018-02-23 02:06:13 -05:00
|
|
|
|
});
|
|
|
|
|
|
2021-01-08 20:21:23 -05:00
|
|
|
|
ViewBag.Description = Localization["WEFBRONT_DESCRIPTION_CONSOLE"];
|
2018-05-05 18:52:04 -04:00
|
|
|
|
ViewBag.Title = Localization["WEBFRONT_CONSOLE_TITLE"];
|
2021-01-08 20:21:23 -05:00
|
|
|
|
ViewBag.Keywords = Localization["WEBFRONT_KEYWORDS_CONSOLE"];
|
2018-03-13 17:30:22 -04:00
|
|
|
|
|
2018-02-23 02:06:13 -05:00
|
|
|
|
return View(activeServers);
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-19 19:43:58 -04:00
|
|
|
|
public async Task<IActionResult> Execute(long serverId, string command)
|
2018-02-23 02:06:13 -05:00
|
|
|
|
{
|
2022-10-16 17:25:09 -04:00
|
|
|
|
if (Client.ClientId < 1)
|
|
|
|
|
{
|
|
|
|
|
return Ok(new[]
|
|
|
|
|
{
|
|
|
|
|
new CommandResponseInfo
|
|
|
|
|
{
|
|
|
|
|
Response = _translationLookup["SERVER_COMMANDS_INTERCEPTED"]
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-27 19:31:48 -05:00
|
|
|
|
var server = Manager.GetServers().First(s => s.EndPoint == serverId);
|
2022-10-12 22:06:18 -04:00
|
|
|
|
var response = await _remoteCommandService.Execute(Client.ClientId, null, command, Enumerable.Empty<string>(), server);
|
2022-10-13 14:29:17 -04:00
|
|
|
|
return !response.Any() ? StatusCode(400, response) : Ok(response);
|
2018-02-23 02:06:13 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
2022-04-19 19:43:58 -04:00
|
|
|
|
}
|