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