added console page back

This commit is contained in:
RaidMax 2018-02-23 01:06:13 -06:00
parent 20994f693c
commit 9ee39b5260
16 changed files with 195 additions and 34 deletions

View File

@ -581,7 +581,7 @@ namespace IW4MAdmin
#endif #endif
Logger.WriteInfo($"Log file is {logPath}"); Logger.WriteInfo($"Log file is {logPath}");
#if !DEBUG #if !DEBUG
Broadcast("IW4M Admin is now ^2ONLINE"); await Broadcast("IW4M Admin is now ^2ONLINE");
} }
#endif #endif
} }

View File

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SharedLibrary.Dtos
{
public class CommandResponseInfo
{
public string Response { get; set; }
public int ClientId { get; set; }
}
}

View File

@ -1,14 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SharedLibrary.Helpers
{
public class CommandResult
{
public string Message { get; set; }
public int Clientd { get; set; }
}
}

View File

@ -10,6 +10,7 @@ using SharedLibrary.Commands;
using System.Threading.Tasks; using System.Threading.Tasks;
using SharedLibrary.Helpers; using SharedLibrary.Helpers;
using SharedLibrary.Objects; using SharedLibrary.Objects;
using SharedLibrary.Dtos;
namespace SharedLibrary namespace SharedLibrary
{ {
@ -171,12 +172,12 @@ namespace SharedLibrary
Console.WriteLine(Utilities.StripColors(Message)); Console.WriteLine(Utilities.StripColors(Message));
Console.ForegroundColor = ConsoleColor.Gray; Console.ForegroundColor = ConsoleColor.Gray;
} }
if (commandResult.Count > 15) if (CommandResult.Count > 15)
commandResult.RemoveAt(0); CommandResult.RemoveAt(0);
commandResult.Add(new CommandResult() CommandResult.Add(new CommandResponseInfo()
{ {
Message = Utilities.StripColors(Message), Response = Utilities.StripColors(Message),
Clientd = Target.ClientId ClientId = Target.ClientId
}); });
} }
@ -398,6 +399,6 @@ namespace SharedLibrary
protected DateTime LastPoll; protected DateTime LastPoll;
//Remote //Remote
public IList<CommandResult> commandResult = new List<CommandResult>(); public IList<CommandResponseInfo> CommandResult = new List<CommandResponseInfo>();
} }
} }

View File

@ -57,7 +57,7 @@ namespace SharedLibrary.Services
// set the level to the level of the existing client if they have the same IP + Name but new NetworkId // set the level to the level of the existing client if they have the same IP + Name but new NetworkId
// fixme: issues? // fixme: issues?
Level = hasExistingAlias ? Level = hasExistingAlias ?
context.Clients.First(c => c.AliasLinkId== existingAlias.LinkId).Level : context.Clients.First(c => c.AliasLinkId == existingAlias.LinkId).Level :
Player.Permission.User, Player.Permission.User,
FirstConnection = DateTime.UtcNow, FirstConnection = DateTime.UtcNow,
Connections = 1, Connections = 1,
@ -240,14 +240,39 @@ namespace SharedLibrary.Services
var iqClients = (from alias in context.Aliases var iqClients = (from alias in context.Aliases
.AsNoTracking() .AsNoTracking()
where alias.Name where alias.Name
.Contains(name) .Contains(name)
join link in context.AliasLinks join link in context.AliasLinks
on alias.LinkId equals link.AliasLinkId on alias.LinkId equals link.AliasLinkId
join client in context.Clients join client in context.Clients
.AsNoTracking()
on alias.LinkId equals client.AliasLinkId
select client)
.Distinct()
.Include(c => c.CurrentAlias)
.Include(c => c.AliasLink.Children);
return await iqClients.ToListAsync();
}
}
public async Task<IList<EFClient>> GetClientByIP(int ipAddress)
{
using (var context = new DatabaseContext())
{
context.Configuration.LazyLoadingEnabled = false;
context.Configuration.ProxyCreationEnabled = false;
context.Configuration.AutoDetectChangesEnabled = false;
var iqClients = (from alias in context.Aliases
.AsNoTracking() .AsNoTracking()
on alias.LinkId equals client.AliasLinkId where alias.IPAddress == ipAddress
select client) join link in context.AliasLinks
on alias.LinkId equals link.AliasLinkId
join client in context.Clients
.AsNoTracking()
on alias.LinkId equals client.AliasLinkId
select client)
.Distinct() .Distinct()
.Include(c => c.CurrentAlias) .Include(c => c.CurrentAlias)
.Include(c => c.AliasLink.Children); .Include(c => c.AliasLink.Children);

View File

@ -151,6 +151,7 @@
<Compile Include="Database\Models\EFClient.cs" /> <Compile Include="Database\Models\EFClient.cs" />
<Compile Include="Database\Models\EFPenalty.cs" /> <Compile Include="Database\Models\EFPenalty.cs" />
<Compile Include="Database\Models\SharedEntity.cs" /> <Compile Include="Database\Models\SharedEntity.cs" />
<Compile Include="Dtos\CommandResponseInfo.cs" />
<Compile Include="Dtos\PlayerInfo.cs" /> <Compile Include="Dtos\PlayerInfo.cs" />
<Compile Include="Dtos\ClientInfo.cs" /> <Compile Include="Dtos\ClientInfo.cs" />
<Compile Include="Dtos\ProfileMeta.cs" /> <Compile Include="Dtos\ProfileMeta.cs" />
@ -164,7 +165,6 @@
<Compile Include="Exceptions\NetworkException.cs" /> <Compile Include="Exceptions\NetworkException.cs" />
<Compile Include="Exceptions\SerializationException.cs" /> <Compile Include="Exceptions\SerializationException.cs" />
<Compile Include="Exceptions\ServerException.cs" /> <Compile Include="Exceptions\ServerException.cs" />
<Compile Include="Helpers\CommandResult.cs" />
<Compile Include="Helpers\ConfigurationManager.cs" /> <Compile Include="Helpers\ConfigurationManager.cs" />
<Compile Include="Helpers\ParseEnum.cs" /> <Compile Include="Helpers\ParseEnum.cs" />
<Compile Include="Helpers\Vector3.cs" /> <Compile Include="Helpers\Vector3.cs" />

View File

@ -96,7 +96,8 @@ namespace SharedLibrary
{ {
if (str == null) if (str == null)
return ""; return "";
return Regex.Replace(str, @"(\^+((?![a-z]|[A-Z]).){0,1})+", ""); return Regex.Replace(str, @"(\^+((?![a-z]|[A-Z]).){0,1})+", "")
.Replace("/", " /");
} }
/// <summary> /// <summary>
@ -346,7 +347,7 @@ namespace SharedLibrary
AliasLink = client.AliasLink, AliasLink = client.AliasLink,
AliasLinkId = client.AliasLinkId, AliasLinkId = client.AliasLinkId,
ClientId = client.ClientId, ClientId = client.ClientId,
ClientNumber = 0, ClientNumber = -1,
FirstConnection = client.FirstConnection, FirstConnection = client.FirstConnection,
Connections = client.Connections, Connections = client.Connections,
NetworkId = client.NetworkId, NetworkId = client.NetworkId,

View File

@ -0,0 +1,55 @@
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
{
public class ConsoleController : Controller
{
public IActionResult Index()
{
var activeServers = IW4MAdmin.ApplicationManager.GetInstance().Servers.Select(s => new ServerInfo()
{
Name = s.Hostname,
ID = s.GetHashCode(),
});
ViewBag.Title = "Web Console";
return View(activeServers);
}
public async Task<IActionResult> ExecuteAsync(int serverId, string command)
{
var requestIPAddress = Request.HttpContext.Connection.RemoteIpAddress;
var intIP = requestIPAddress.ToString().ConvertToIP();
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
};
var server = IW4MAdmin.ApplicationManager.GetInstance().Servers.First(s => s.GetHashCode() == serverId);
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);
}
}
}

View File

@ -14,6 +14,8 @@ by editing this MSBuild file. In order to learn more about this please visit htt
<ExcludeApp_Data>False</ExcludeApp_Data> <ExcludeApp_Data>False</ExcludeApp_Data>
<ProjectGuid>65340d7d-5831-406c-acad-b13ba634bde2</ProjectGuid> <ProjectGuid>65340d7d-5831-406c-acad-b13ba634bde2</ProjectGuid>
<publishUrl>bin\Release\PublishOutput</publishUrl> <publishUrl>bin\Release\PublishOutput</publishUrl>
<DeleteExistingFiles>False</DeleteExistingFiles> <DeleteExistingFiles>True</DeleteExistingFiles>
<TargetFramework>net452</TargetFramework>
<RuntimeIdentifier>win7-x86</RuntimeIdentifier>
</PropertyGroup> </PropertyGroup>
</Project> </Project>

View File

@ -0,0 +1,20 @@
@model IEnumerable<SharedLibrary.Dtos.ServerInfo>
<div class="row justify-content-center">
<div id="console" class="col-md-8">
@Html.DropDownList("Server", Model.Select(s => new SelectListItem() { Text = s.Name, Value = s.ID.ToString() }).ToList(), new { @class = "form-control bg-dark text-light", id="console_server_select" })
<div id="console_command_response" class="bg-dark p-3">
</div>
<div class="form-row">
<div class="col-12 col-sm-9 pr-1 pr-md-0">
<input id="console_command_value" class="form-control m-0 bg-dark text-light" type="text" />
</div>
<div class="col pl-1 pl-md-0">
<button id="console_command_button" class="btn btn-primary btn-block m-0">Execute</button>
</div>
</div>
</div>
</div>
@section scripts {
<script type="text/javascript" src="~/js/console.js"></script>
}

View File

@ -0,0 +1,11 @@
@model List<SharedLibrary.Dtos.CommandResponseInfo>
@{
Layout = null;
}
@{
foreach (var response in Model)
{
<span class="text-success">@response.Response</span><br />
}
}

View File

@ -26,6 +26,7 @@
<li class="nav-item text-center text-md-left">@Html.ActionLink("Home", "Index", "Home", new { area = "" }, new { @class = "nav-link" })</li> <li class="nav-item text-center text-md-left">@Html.ActionLink("Home", "Index", "Home", new { area = "" }, new { @class = "nav-link" })</li>
<li class="nav-item text-center text-md-left">@Html.ActionLink("Penalties", "List", "Penalty", new { area = "" }, new { @class = "nav-link" })</li> <li class="nav-item text-center text-md-left">@Html.ActionLink("Penalties", "List", "Penalty", new { area = "" }, new { @class = "nav-link" })</li>
<li class="nav-item text-center text-md-left">@Html.ActionLink("Admins", "PrivilegedAsync", "Client", new { area = "" }, new { @class = "nav-link" })</li> <li class="nav-item text-center text-md-left">@Html.ActionLink("Admins", "PrivilegedAsync", "Client", new { area = "" }, new { @class = "nav-link" })</li>
<li class="nav-item text-center text-md-left">@Html.ActionLink("Console", "Index", "Console", new { area = "" }, new { @class = "nav-link" })</li>
</ul> </ul>
<form class="form-inline text-primary pt-3 pb-3" method="get" action="/Client/FindAsync"> <form class="form-inline text-primary pt-3 pb-3" method="get" action="/Client/FindAsync">
<input id="client_search" name="clientName" class="form-control mr-auto ml-auto mr-md-2" type="text" placeholder="Find Player" /> <input id="client_search" name="clientName" class="form-control mr-auto ml-auto mr-md-2" type="text" placeholder="Find Player" />

View File

@ -65,3 +65,14 @@ a.link-inverse:hover {
display: table-header-group !important display: table-header-group !important
} }
} }
#console_command_response {
min-height: 20rem;
}
#console .form-control, #console button {
border-radius: 0;
border-color: $primary;
border-left: 0;
border-right: 0;
}

View File

@ -0,0 +1,25 @@
function executeCommand() {
const serverId = $('#console_server_select').val();
const command = $('#console_command_value').val();
$.get('/Console/ExecuteAsync', { serverId: serverId, command: command })
.done(function (response) {
$('#console_command_response').html(response);
$('#console_command_value').val("");
})
.fail(function (jqxhr, textStatus, error) {
$('#console_command_response').text('Could not execute command: ' + error).addClass('text-danger');
});
}
$(document).ready(function () {
$('#console_command_button').click(function (e) {
executeCommand();
});
$(document).keydown(function (event) {
const keyCode = (event.keyCode ? event.keyCode : event.which);
if (keyCode === 13) {
executeCommand();
}
});
});

View File

@ -6076,3 +6076,12 @@ a.link-inverse:hover {
.d-md-table-header-group { .d-md-table-header-group {
display: table-header-group !important; } } display: table-header-group !important; } }
#console_command_response {
min-height: 20rem; }
#console .form-control, #console button {
border-radius: 0;
border-color: #007ACC;
border-left: 0;
border-right: 0; }

File diff suppressed because one or more lines are too long