2018-02-23 02:06:13 -05:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using SharedLibrary;
|
|
|
|
|
using SharedLibrary.Dtos;
|
|
|
|
|
using SharedLibrary.Objects;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
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
|
|
|
|
{
|
|
|
|
|
public IActionResult Index()
|
|
|
|
|
{
|
2018-03-06 02:22:19 -05:00
|
|
|
|
var activeServers = Manager.Servers.Select(s => new ServerInfo()
|
2018-02-23 02:06:13 -05:00
|
|
|
|
{
|
|
|
|
|
Name = s.Hostname,
|
|
|
|
|
ID = s.GetHashCode(),
|
|
|
|
|
});
|
|
|
|
|
|
2018-03-13 17:30:22 -04:00
|
|
|
|
ViewBag.Description = "Use the IW4MAdmin web console to execute commands";
|
2018-02-23 02:06:13 -05:00
|
|
|
|
ViewBag.Title = "Web Console";
|
2018-03-13 17:30:22 -04:00
|
|
|
|
ViewBag.Keywords = "IW4MAdmin, console, execute, commands";
|
|
|
|
|
|
2018-02-23 02:06:13 -05:00
|
|
|
|
return View(activeServers);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<IActionResult> ExecuteAsync(int serverId, string command)
|
|
|
|
|
{
|
|
|
|
|
var requestIPAddress = Request.HttpContext.Connection.RemoteIpAddress;
|
|
|
|
|
var intIP = requestIPAddress.ToString().ConvertToIP();
|
|
|
|
|
|
2018-02-24 00:56:03 -05:00
|
|
|
|
#if !DEBUG
|
2018-02-23 02:06:13 -05:00
|
|
|
|
var origin = (await IW4MAdmin.ApplicationManager.GetInstance().GetClientService().GetClientByIP(intIP))
|
|
|
|
|
.OrderByDescending(c => c.Level)
|
|
|
|
|
.FirstOrDefault()?.AsPlayer() ?? new Player()
|
|
|
|
|
{
|
|
|
|
|
Name = "WebConsoleUser",
|
|
|
|
|
Level = Player.Permission.User,
|
|
|
|
|
IPAddress = intIP
|
|
|
|
|
};
|
2018-02-24 00:56:03 -05:00
|
|
|
|
#else
|
2018-03-27 00:54:20 -04:00
|
|
|
|
var origin = (await Manager.GetClientService().GetUnique(0)).AsPlayer();
|
2018-02-24 00:56:03 -05:00
|
|
|
|
#endif
|
2018-02-23 02:06:13 -05:00
|
|
|
|
|
2018-03-06 02:22:19 -05:00
|
|
|
|
var server = Manager.Servers.First(s => s.GetHashCode() == serverId);
|
2018-02-23 02:06:13 -05:00
|
|
|
|
origin.CurrentServer = server;
|
|
|
|
|
var remoteEvent = new Event(Event.GType.Say, command, origin, null, server);
|
|
|
|
|
|
|
|
|
|
await server.ExecuteEvent(remoteEvent);
|
|
|
|
|
|
|
|
|
|
var response = server.CommandResult.Where(c => c.ClientId == origin.ClientId).ToList();
|
|
|
|
|
|
|
|
|
|
// remove the added command response
|
|
|
|
|
for (int i = 0; i < response.Count; i++)
|
|
|
|
|
server.CommandResult.Remove(response[i]);
|
|
|
|
|
|
|
|
|
|
return View("_Response", response);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|