2019-01-03 14:39:22 -06:00
|
|
|
|
using Microsoft.AspNetCore.Authentication;
|
2018-03-06 01:22:19 -06:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc.Filters;
|
2019-01-03 14:39:22 -06:00
|
|
|
|
using SharedLibraryCore;
|
2018-04-08 01:44:42 -05:00
|
|
|
|
using SharedLibraryCore.Database;
|
|
|
|
|
using SharedLibraryCore.Database.Models;
|
2018-04-08 13:48:40 -05:00
|
|
|
|
using SharedLibraryCore.Interfaces;
|
2019-01-03 14:39:22 -06:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Security.Claims;
|
2018-08-03 17:10:20 -05:00
|
|
|
|
using WebfrontCore.ViewModels;
|
2018-03-06 01:22:19 -06:00
|
|
|
|
|
|
|
|
|
namespace WebfrontCore.Controllers
|
|
|
|
|
{
|
|
|
|
|
public class BaseController : Controller
|
|
|
|
|
{
|
2018-04-08 13:48:40 -05:00
|
|
|
|
protected IManager Manager;
|
2018-04-08 01:44:42 -05:00
|
|
|
|
protected readonly DatabaseContext Context;
|
2018-06-26 20:17:24 -05:00
|
|
|
|
protected bool Authorized { get; set; }
|
2018-05-05 15:36:26 -05:00
|
|
|
|
protected SharedLibraryCore.Localization.Index Localization { get; private set; }
|
2018-04-26 01:13:04 -05:00
|
|
|
|
protected EFClient Client { get; private set; }
|
2018-08-03 17:10:20 -05:00
|
|
|
|
private static readonly byte[] LocalHost = { 127, 0, 0, 1 };
|
2018-05-05 17:52:04 -05:00
|
|
|
|
private static string SocialLink;
|
|
|
|
|
private static string SocialTitle;
|
2019-01-03 14:39:22 -06:00
|
|
|
|
protected List<Page> Pages;
|
2018-03-06 01:22:19 -06:00
|
|
|
|
|
2018-04-26 01:13:04 -05:00
|
|
|
|
public BaseController()
|
2018-03-06 01:22:19 -06:00
|
|
|
|
{
|
2018-05-05 17:52:04 -05:00
|
|
|
|
if (Manager == null)
|
2019-01-03 14:39:22 -06:00
|
|
|
|
{
|
2018-05-05 17:52:04 -05:00
|
|
|
|
Manager = Program.Manager;
|
2019-01-03 14:39:22 -06:00
|
|
|
|
}
|
2018-05-05 17:52:04 -05:00
|
|
|
|
|
|
|
|
|
if (Localization == null)
|
2019-01-03 14:39:22 -06:00
|
|
|
|
{
|
|
|
|
|
Localization = Utilities.CurrentLocalization.LocalizationIndex;
|
|
|
|
|
}
|
2018-05-05 17:52:04 -05:00
|
|
|
|
|
2018-05-07 23:58:46 -05:00
|
|
|
|
if (Manager.GetApplicationSettings().Configuration().EnableSocialLink && SocialLink == null)
|
2018-04-26 01:13:04 -05:00
|
|
|
|
{
|
2018-05-07 23:58:46 -05:00
|
|
|
|
SocialLink = Manager.GetApplicationSettings().Configuration().SocialLinkAddress;
|
2018-05-05 17:52:04 -05:00
|
|
|
|
SocialTitle = Manager.GetApplicationSettings().Configuration().SocialLinkTitle;
|
2018-04-26 01:13:04 -05:00
|
|
|
|
}
|
2018-09-16 15:34:16 -05:00
|
|
|
|
|
2019-01-03 14:39:22 -06:00
|
|
|
|
Pages = Manager.GetPageList().Pages
|
|
|
|
|
.Select(page => new Page
|
|
|
|
|
{
|
|
|
|
|
Name = page.Key,
|
|
|
|
|
Location = page.Value
|
|
|
|
|
}).ToList();
|
|
|
|
|
|
2018-09-16 15:34:16 -05:00
|
|
|
|
ViewBag.Version = Manager.Version;
|
2018-04-26 01:13:04 -05:00
|
|
|
|
}
|
2018-03-26 23:54:20 -05:00
|
|
|
|
|
2018-04-26 01:13:04 -05:00
|
|
|
|
public override void OnActionExecuting(ActionExecutingContext context)
|
|
|
|
|
{
|
|
|
|
|
Client = Client ?? new EFClient()
|
2018-03-26 23:54:20 -05:00
|
|
|
|
{
|
2018-04-28 20:11:13 -05:00
|
|
|
|
ClientId = -1,
|
2018-11-05 21:01:29 -06:00
|
|
|
|
Level = EFClient.Permission.User,
|
2018-04-28 20:11:13 -05:00
|
|
|
|
CurrentAlias = new EFAlias() { Name = "Web Console Guest" }
|
2018-03-26 23:54:20 -05:00
|
|
|
|
};
|
|
|
|
|
|
2018-04-26 01:13:04 -05:00
|
|
|
|
if (!HttpContext.Connection.RemoteIpAddress.GetAddressBytes().SequenceEqual(LocalHost))
|
2018-03-26 23:54:20 -05:00
|
|
|
|
{
|
2018-04-09 22:33:42 -05:00
|
|
|
|
try
|
|
|
|
|
{
|
2018-04-26 01:13:04 -05:00
|
|
|
|
Client.ClientId = Convert.ToInt32(base.User.Claims.First(c => c.Type == ClaimTypes.Sid).Value);
|
2019-01-03 14:39:22 -06:00
|
|
|
|
Client.NetworkId = User.Claims.First(_claim => _claim.Type == ClaimTypes.PrimarySid).Value.ConvertLong();
|
2018-11-05 21:01:29 -06:00
|
|
|
|
Client.Level = (EFClient.Permission)Enum.Parse(typeof(EFClient.Permission), User.Claims.First(c => c.Type == ClaimTypes.Role).Value);
|
2018-04-26 01:13:04 -05:00
|
|
|
|
Client.CurrentAlias = new EFAlias() { Name = User.Claims.First(c => c.Type == ClaimTypes.NameIdentifier).Value };
|
2018-04-09 22:33:42 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
catch (InvalidOperationException)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
2018-04-28 16:39:45 -05:00
|
|
|
|
|
|
|
|
|
catch (System.Collections.Generic.KeyNotFoundException)
|
|
|
|
|
{
|
|
|
|
|
// force the "banned" client to be signed out
|
2018-05-14 12:55:10 -05:00
|
|
|
|
HttpContext.SignOutAsync().Wait(5000);
|
2018-04-28 16:39:45 -05:00
|
|
|
|
}
|
2018-03-26 23:54:20 -05:00
|
|
|
|
}
|
|
|
|
|
|
2018-11-25 20:00:36 -06:00
|
|
|
|
// give the local host full access
|
2018-04-09 22:33:42 -05:00
|
|
|
|
else
|
2018-03-26 23:54:20 -05:00
|
|
|
|
{
|
2018-04-26 01:13:04 -05:00
|
|
|
|
Client.ClientId = 1;
|
2018-11-05 21:01:29 -06:00
|
|
|
|
Client.Level = EFClient.Permission.Console;
|
2018-04-26 01:13:04 -05:00
|
|
|
|
Client.CurrentAlias = new EFAlias() { Name = "IW4MAdmin" };
|
2018-11-25 20:00:36 -06:00
|
|
|
|
Authorized = true;
|
2018-03-26 23:54:20 -05:00
|
|
|
|
}
|
|
|
|
|
|
2018-04-26 01:13:04 -05:00
|
|
|
|
Authorized = Client.ClientId >= 0;
|
2018-03-09 02:01:12 -06:00
|
|
|
|
ViewBag.Authorized = Authorized;
|
2019-01-03 14:39:22 -06:00
|
|
|
|
ViewBag.Url = Manager.GetApplicationSettings().Configuration().WebfrontUrl;
|
2018-04-26 01:13:04 -05:00
|
|
|
|
ViewBag.User = Client;
|
2018-05-05 17:52:04 -05:00
|
|
|
|
ViewBag.SocialLink = SocialLink ?? "";
|
|
|
|
|
ViewBag.SocialTitle = SocialTitle;
|
2019-01-03 14:39:22 -06:00
|
|
|
|
ViewBag.Pages = Pages;
|
2018-08-03 17:10:20 -05:00
|
|
|
|
|
2018-03-06 01:22:19 -06:00
|
|
|
|
base.OnActionExecuting(context);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|