RCon error handling is clearer

Show chat on mobile view of server overview
basic authentication
switched to extreme-ip-lookup for ip lookups (SSL)
This commit is contained in:
RaidMax
2018-04-04 14:38:34 -05:00
parent a0c1d9b1bc
commit c0865b82a0
27 changed files with 476 additions and 123 deletions

View File

@ -0,0 +1,40 @@
using Microsoft.AspNetCore.Mvc;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authentication.Cookies;
using System.Security.Claims;
namespace WebfrontCore.Controllers
{
public class AccountController : BaseController
{
[HttpGet]
public async Task<IActionResult> Login(int userId, string password)
{
if (userId == 0 || string.IsNullOrEmpty(password))
{
return Unauthorized();
}
var client = IW4MAdmin.Program.ServerManager.PrivilegedClients[userId];
string[] hashedPassword = await Task.FromResult(SharedLibrary.Helpers.Hashing.Hash(password, client.PasswordSalt));
if (hashedPassword[0] == client.Password)
{
var claims = new[]
{
new Claim(ClaimTypes.NameIdentifier, client.Name),
new Claim(ClaimTypes.Role, client.Level.ToString()),
new Claim(ClaimTypes.Sid, client.ClientId.ToString())
};
var claimsIdentity = new ClaimsIdentity(claims, "login");
var claimsPrinciple = new ClaimsPrincipal(claimsIdentity);
await HttpContext.Authentication.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, claimsPrinciple);
return Ok();
}
return Unauthorized();
}
}
}

View File

@ -71,5 +71,34 @@ namespace WebfrontCore.Controllers
command = $"!unban @{targetId} {Reason}"
}));
}
public IActionResult LoginForm()
{
var login = new ActionInfo()
{
ActionButtonLabel = "Login",
Name = "Login",
Inputs = new List<InputInfo>()
{
new InputInfo()
{
Name = "UserID"
},
new InputInfo()
{
Name = "Password",
Type = "password",
}
},
Action = "Login"
};
return View("_ActionForm", login);
}
public IActionResult Login(int userId, string password)
{
return RedirectToAction("Login", "Account", new { userId, password });
}
}
}

View File

@ -3,7 +3,11 @@ using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using SharedLibrary;
using SharedLibrary.Database.Models;
using SharedLibrary.Objects;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
namespace WebfrontCore.Controllers
{
@ -24,18 +28,17 @@ namespace WebfrontCore.Controllers
try
{
var client = Manager.PrivilegedClients[context.HttpContext.Connection.RemoteIpAddress.ToString().ConvertToIP()];
User.ClientId = client.ClientId;
User.Level = client.Level;
User.ClientId = Convert.ToInt32(base.User.Claims.First(c => c.Type == ClaimTypes.Sid).Value);
User.Level = (Player.Permission)Enum.Parse(typeof(Player.Permission), base.User.Claims.First(c => c.Type == ClaimTypes.Role).Value);
User.CurrentAlias = new EFAlias() { Name = base.User.Claims.First(c => c.Type == ClaimTypes.NameIdentifier).Value };
}
catch (KeyNotFoundException)
catch (InvalidOperationException)
{
}
Authorized = context.HttpContext.Connection.RemoteIpAddress.ToString() == "127.0.0.1" ||
User.ClientId >= 0;
Authorized = User.ClientId >= 0;
ViewBag.Authorized = Authorized;
ViewBag.Url = Startup.Configuration["Web:Address"];
ViewBag.User = User;

View File

@ -63,7 +63,7 @@ namespace WebfrontCore.Controllers
.Select(a => new ProfileMeta()
{
Key = "AliasEvent",
Value = $"Connected with name {a.Name}",
Value = $"Joined with alias {a.Name}",
Sensitive = true,
When = a.DateAdded
}));

View File

@ -28,29 +28,16 @@ namespace WebfrontCore.Controllers
public async Task<IActionResult> ExecuteAsync(int serverId, string command)
{
var requestIPAddress = Request.HttpContext.Connection.RemoteIpAddress;
var intIP = requestIPAddress.ToString().ConvertToIP();
#if !DEBUG
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
};
#else
var origin = (await Manager.GetClientService().GetUnique(0)).AsPlayer();
#endif
var server = Manager.Servers.First(s => s.GetHashCode() == serverId);
origin.CurrentServer = server;
var remoteEvent = new Event(Event.GType.Say, command, origin, null, server);
var client = User.AsPlayer();
client.CurrentServer = server;
var remoteEvent = new Event(Event.GType.Say, command, client, null, server);
await server.ExecuteEvent(remoteEvent);
var response = server.CommandResult.Where(c => c.ClientId == origin.ClientId).ToList();
var response = server.CommandResult.Where(c => c.ClientId == client.ClientId).ToList();
// remove the added command response
for (int i = 0; i < response.Count; i++)

View File

@ -21,7 +21,7 @@ namespace WebfrontCore.Controllers
public IActionResult Error()
{
ViewBag.Description = "IW4MAdmin encountered and error";
ViewBag.Description = "IW4MAdmin encountered an error";
ViewBag.Title = "Error!";
return View();
}