huge commit for webfront facelift
This commit is contained in:
@ -130,7 +130,7 @@ namespace SharedLibraryCore
|
||||
new Claim(ClaimTypes.NameIdentifier, Client.CurrentAlias.Name),
|
||||
new Claim(ClaimTypes.Role, Client.Level.ToString()),
|
||||
new Claim(ClaimTypes.Sid, Client.ClientId.ToString()),
|
||||
new Claim(ClaimTypes.PrimarySid, Client.NetworkId.ToString("X"))
|
||||
new Claim(ClaimTypes.PrimarySid, Client.NetworkId.ToString("X")),
|
||||
};
|
||||
var claimsIdentity = new ClaimsIdentity(claims, "login");
|
||||
SignInAsync(new ClaimsPrincipal(claimsIdentity)).Wait();
|
||||
@ -161,6 +161,14 @@ namespace SharedLibraryCore
|
||||
ViewBag.EnablePrivilegedUserPrivacy = AppConfig.EnablePrivilegedUserPrivacy;
|
||||
ViewBag.Configuration = AppConfig;
|
||||
ViewBag.ScriptInjection = AppConfig.Webfront?.ScriptInjection;
|
||||
ViewBag.CommunityInformation = AppConfig.CommunityInformation;
|
||||
ViewBag.ClientCount = Manager.GetServers().Sum(server => server.ClientNum);
|
||||
ViewBag.AdminCount = Manager.GetServers().Sum(server =>
|
||||
server.GetClientsAsList()
|
||||
.Count(client => client.Level >= Data.Models.Client.EFClient.Permission.Trusted));
|
||||
ViewBag.ReportCount = Manager.GetServers().Sum(server =>
|
||||
server.Reports.Count(report => DateTime.UtcNow - report.ReportedOn <= TimeSpan.FromHours(24)));
|
||||
ViewBag.PermissionsSet = PermissionsSet;
|
||||
|
||||
base.OnActionExecuting(context);
|
||||
}
|
||||
|
@ -1,12 +1,14 @@
|
||||
using Data.Models.Client;
|
||||
using System;
|
||||
using Data.Models.Client;
|
||||
|
||||
namespace SharedLibraryCore.Dtos
|
||||
{
|
||||
public class ClientInfo
|
||||
public class ClientInfo
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public int ClientId { get; set; }
|
||||
public int LinkId { get; set; }
|
||||
public EFClient.Permission Level { get; set; }
|
||||
public DateTime LastConnection { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -15,8 +15,8 @@ namespace SharedLibraryCore.Dtos
|
||||
public int LevelInt { get; set; }
|
||||
public string IPAddress { get; set; }
|
||||
public long NetworkId { get; set; }
|
||||
public List<string> Aliases { get; set; }
|
||||
public List<string> IPs { get; set; }
|
||||
public List<(string, DateTime)> Aliases { get; set; }
|
||||
public List<(string, DateTime)> IPs { get; set; }
|
||||
public bool HasActivePenalty { get; set; }
|
||||
public string ActivePenaltyType { get; set; }
|
||||
public bool Authenticated { get; set; }
|
||||
@ -29,5 +29,8 @@ namespace SharedLibraryCore.Dtos
|
||||
public IDictionary<int, long> LinkedAccounts { get; set; }
|
||||
public MetaType? MetaFilterType { get; set; }
|
||||
public double? ZScore { get; set; }
|
||||
public string ConnectProtocolUrl { get;set; }
|
||||
public string CurrentServerName { get; set; }
|
||||
public IGeoLocationResult GeoLocationInfo { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -20,6 +20,7 @@ namespace SharedLibraryCore.Dtos
|
||||
public bool Online { get; set; }
|
||||
public string ConnectProtocolUrl { get; set; }
|
||||
public string IPAddress { get; set; }
|
||||
public string ExternalIPAddress { get; set; }
|
||||
public bool IsPasswordProtected { get; set; }
|
||||
public string Endpoint => $"{IPAddress}:{Port}";
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
using SharedLibraryCore.Database.Models;
|
||||
using System;
|
||||
using SharedLibraryCore.Database.Models;
|
||||
|
||||
namespace SharedLibraryCore.Helpers
|
||||
{
|
||||
@ -7,5 +8,6 @@ namespace SharedLibraryCore.Helpers
|
||||
public EFClient Target { get; set; }
|
||||
public EFClient Origin { get; set; }
|
||||
public string Reason { get; set; }
|
||||
public DateTime ReportedOn { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
11
SharedLibraryCore/Interfaces/IGeoLocationResult.cs
Normal file
11
SharedLibraryCore/Interfaces/IGeoLocationResult.cs
Normal file
@ -0,0 +1,11 @@
|
||||
namespace SharedLibraryCore.Interfaces;
|
||||
|
||||
public interface IGeoLocationResult
|
||||
{
|
||||
string Country { get; set; }
|
||||
string CountryCode { get; set; }
|
||||
string Region { get; set; }
|
||||
string ASN { get; set; }
|
||||
string Timezone { get; set; }
|
||||
string Organization { get; set; }
|
||||
}
|
8
SharedLibraryCore/Interfaces/IGeoLocationService.cs
Normal file
8
SharedLibraryCore/Interfaces/IGeoLocationService.cs
Normal file
@ -0,0 +1,8 @@
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SharedLibraryCore.Interfaces;
|
||||
|
||||
public interface IGeoLocationService
|
||||
{
|
||||
Task<IGeoLocationResult> Locate(string address);
|
||||
}
|
@ -117,7 +117,7 @@ namespace SharedLibraryCore
|
||||
|
||||
public int ClientNum
|
||||
{
|
||||
get { return Clients.ToArray().Count(p => p != null && !p.IsBot); }
|
||||
get { return Clients.ToArray().Count(p => p != null && Utilities.IsDevelopment || (!p?.IsBot ?? false)); }
|
||||
}
|
||||
|
||||
public int MaxClients { get; protected set; }
|
||||
|
@ -529,32 +529,36 @@ namespace SharedLibraryCore
|
||||
public static bool HasPermission<TEntity, TPermission>(this IEnumerable<string> permissionsSet, TEntity entity,
|
||||
TPermission permission) where TEntity : Enum where TPermission : Enum
|
||||
{
|
||||
return permissionsSet?.Any(raw =>
|
||||
if (permissionsSet == null)
|
||||
{
|
||||
if (raw == "*")
|
||||
return false;
|
||||
}
|
||||
|
||||
var requiredPermission = $"{entity.ToString()}.{permission.ToString()}";
|
||||
var hasAllPermissions = permissionsSet.Any(p => p.Equals("*"));
|
||||
var permissionCheckResult = permissionsSet.Select(p =>
|
||||
{
|
||||
if (p.Equals(requiredPermission, StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
var split = raw.Split(".");
|
||||
|
||||
if (split.Length != 2)
|
||||
if (p.Equals($"-{requiredPermission}", StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!Enum.TryParse(typeof(TEntity), split[0], out var e))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return (bool?)null;
|
||||
}).ToList();
|
||||
|
||||
if (!Enum.TryParse(typeof(TPermission), split[1], out var p))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
var permissionNegated = permissionCheckResult.Any(result => result.HasValue && !result.Value);
|
||||
|
||||
return (e?.Equals(entity) ?? false) && (p?.Equals(permission) ?? false);
|
||||
}) ?? false;
|
||||
if (permissionNegated)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return hasAllPermissions || permissionCheckResult.Any(result => result.HasValue && result.Value);
|
||||
}
|
||||
|
||||
public static bool HasPermission<TEntity, TPermission>(this ApplicationConfiguration appConfig,
|
||||
|
Reference in New Issue
Block a user