diff --git a/SS14.Admin/Admins/AdminFlags.cs b/SS14.Admin/Admins/AdminFlags.cs index 69465b4..a5745f8 100644 --- a/SS14.Admin/Admins/AdminFlags.cs +++ b/SS14.Admin/Admins/AdminFlags.cs @@ -25,6 +25,7 @@ public enum AdminFlags : uint /// /// !!FUN!! + /// This is stuff that trial administrators shouldn't quite have access to yet, e.g. for running events. /// Fun = 1 << 3, @@ -58,9 +59,74 @@ public enum AdminFlags : uint /// //Piss = 1 << 9, + /// + /// Lets you view admin logs. + /// + Logs = 1 << 9, + + /// + /// Lets you modify the round (forcemap, loadgamemap, etc) + /// + Round = 1 << 10, + + /// + /// Lets you use BQL queries. + /// + Query = 1 << 11, + + /// + /// Lets you use the admin help system. + /// + Adminhelp = 1 << 12, + + /// + /// Lets you view admin notes. + /// + ViewNotes = 1 << 13, + + /// + /// Lets you create, edit and delete admin notes. + /// + EditNotes = 1 << 14, + + /// + /// Lets you Massban, on SS14.Admin + /// + MassBan = 1 << 15, + + /// + /// Allows you to remain hidden from adminwho except to other admins with this flag. + /// + Stealth = 1 << 16, + + /// + /// Allows you to use Admin chat + /// + Adminchat = 1 << 17, + + /// + /// Permits the visibility of Pii in game and on SS14 Admin + /// + Pii = 1 << 18, + + /// + /// Lets you take moderator actions on the game server. + /// + Moderator = 1 << 19, + + /// + /// Lets you check currently online admins. + /// + AdminWho = 1 << 20, + + /// + /// Lets you set the color of your OOC name. + /// + NameColor = 1 << 21, + /// /// Dangerous host permissions like scsi. /// Host = 1u << 31, } -} \ No newline at end of file +} diff --git a/SS14.Admin/Constants.cs b/SS14.Admin/Constants.cs index 010d81b..626e4f4 100644 --- a/SS14.Admin/Constants.cs +++ b/SS14.Admin/Constants.cs @@ -3,4 +3,6 @@ public static class Constants { public const int HwidLength = 32; + + public const string PIIRole = "PII"; } diff --git a/SS14.Admin/Helpers/SearchHelper.cs b/SS14.Admin/Helpers/SearchHelper.cs index e64d2db..1030eb1 100644 --- a/SS14.Admin/Helpers/SearchHelper.cs +++ b/SS14.Admin/Helpers/SearchHelper.cs @@ -1,5 +1,6 @@ using System.Linq.Expressions; using System.Net; +using System.Security.Claims; using Content.Server.Database; using Microsoft.EntityFrameworkCore; using WhitelistJoin = SS14.Admin.Helpers.WhitelistHelper.WhitelistJoin; @@ -8,7 +9,7 @@ namespace SS14.Admin.Helpers; public static class SearchHelper { - public static IQueryable SearchConnectionLog(IQueryable query, string? search) + public static IQueryable SearchConnectionLog(IQueryable query, string? search, ClaimsPrincipal user) { if (string.IsNullOrEmpty(search)) return query; @@ -21,21 +22,21 @@ public static IQueryable SearchConnectionLog(IQueryable u.UserId == guid); - if (IPHelper.TryParseCidr(search, out var cidr)) + if (user.IsInRole(Constants.PIIRole) && IPHelper.TryParseCidr(search, out var cidr)) CombineSearch(ref expr, u => EF.Functions.Contains(cidr, u.Address)); - if (IPAddress.TryParse(search, out var ip)) + if (user.IsInRole(Constants.PIIRole) && IPAddress.TryParse(search, out var ip)) CombineSearch(ref expr, u => u.Address.Equals(ip)); var hwid = new byte[Constants.HwidLength]; - if (Convert.TryFromBase64String(search, hwid, out var len) && len == Constants.HwidLength) + if (user.IsInRole(Constants.PIIRole) && Convert.TryFromBase64String(search, hwid, out var len) && len == Constants.HwidLength) CombineSearch(ref expr, u => u.HWId == hwid); return query.Where(expr); } private static Expression, bool>> MakeCommonBanSearchExpression( - string search) + string search, ClaimsPrincipal user) where TBan : IBanCommon where TUnban : IUnbanCommon { @@ -48,14 +49,14 @@ public static IQueryable SearchConnectionLog(IQueryable b.Ban.PlayerUserId == guid); - if (IPHelper.TryParseCidr(search, out var cidr)) + if (user.IsInRole(Constants.PIIRole) && IPHelper.TryParseCidr(search, out var cidr)) CombineSearch(ref expr, b => EF.Functions.ContainsOrEqual(cidr, b.Ban.Address!.Value)); - if (IPAddress.TryParse(search, out var ip)) + if (user.IsInRole(Constants.PIIRole) && IPAddress.TryParse(search, out var ip)) CombineSearch(ref expr, u => EF.Functions.ContainsOrEqual(u.Ban.Address!.Value, ip)); var hwid = new byte[Constants.HwidLength]; - if (Convert.TryFromBase64String(search, hwid, out var len) && len == Constants.HwidLength) + if (user.IsInRole(Constants.PIIRole) && Convert.TryFromBase64String(search, hwid, out var len) && len == Constants.HwidLength) CombineSearch(ref expr, u => u.Ban.HWId == hwid); return expr; @@ -63,28 +64,28 @@ public static IQueryable SearchConnectionLog(IQueryable> SearchServerBans( IQueryable> query, - string? search) + string? search, ClaimsPrincipal user) { if (string.IsNullOrEmpty(search)) return query; search = search.Trim(); - var expr = MakeCommonBanSearchExpression(search); + var expr = MakeCommonBanSearchExpression(search, user); return query.Where(expr); } public static IQueryable> SearchRoleBans( IQueryable> query, - string? search) + string? search, ClaimsPrincipal user) { if (string.IsNullOrEmpty(search)) return query; search = search.Trim(); - var expr = MakeCommonBanSearchExpression(search); + var expr = MakeCommonBanSearchExpression(search, user); // Match role name exactly. CombineSearch(ref expr, u => u.Ban.RoleId == search); @@ -92,7 +93,7 @@ public static IQueryable SearchConnectionLog(IQueryable SearchPlayers(IQueryable query, string? search) + public static IQueryable SearchPlayers(IQueryable query, string? search, ClaimsPrincipal user) { if (string.IsNullOrEmpty(search)) return query; @@ -105,14 +106,14 @@ public static IQueryable SearchPlayers(IQueryable query, string? if (Guid.TryParse(search, out var guid)) CombineSearch(ref expr, u => u.UserId == guid); - if (IPHelper.TryParseCidr(search, out var cidr)) + if (user.IsInRole(Constants.PIIRole) && IPHelper.TryParseCidr(search, out var cidr)) CombineSearch(ref expr, u => EF.Functions.Contains(cidr, u.LastSeenAddress)); - if (IPAddress.TryParse(search, out var ip)) + if (user.IsInRole(Constants.PIIRole) && IPAddress.TryParse(search, out var ip)) CombineSearch(ref expr, u => u.LastSeenAddress.Equals(ip)); var hwid = new byte[Constants.HwidLength]; - if (Convert.TryFromBase64String(search, hwid, out var len) && len == Constants.HwidLength) + if (user.IsInRole(Constants.PIIRole) && Convert.TryFromBase64String(search, hwid, out var len) && len == Constants.HwidLength) CombineSearch(ref expr, u => u.LastSeenHWId == hwid); return query.Where(expr); diff --git a/SS14.Admin/Pages/Bans/Create.cshtml b/SS14.Admin/Pages/Bans/Create.cshtml index 937bcd3..50f7f78 100644 --- a/SS14.Admin/Pages/Bans/Create.cshtml +++ b/SS14.Admin/Pages/Bans/Create.cshtml @@ -21,8 +21,9 @@
-
- +
+ +
@@ -34,8 +35,9 @@
-
- +
+ +
diff --git a/SS14.Admin/Pages/Bans/Create.cshtml.cs b/SS14.Admin/Pages/Bans/Create.cshtml.cs index bc0501a..538e67e 100644 --- a/SS14.Admin/Pages/Bans/Create.cshtml.cs +++ b/SS14.Admin/Pages/Bans/Create.cshtml.cs @@ -27,38 +27,43 @@ public sealed class InputModel public string? NameOrUid { get; set; } public string? IP { get; set; } public string? HWid { get; set; } + public bool UseLatestIp {get; set; } + public bool UseLatestHwid { get; set; } public int LengthMinutes { get; set; } [Required] public string Reason { get; set; } = ""; } - public async Task OnPostFillAsync() + public async Task OnPostCreateAsync() { - if (string.IsNullOrWhiteSpace(Input.NameOrUid)) - { - TempData.SetStatusError("Must provide name/UID."); - return; - } + var ban = new ServerBan(); + + var ipAddr = Input.IP; + var hwid = Input.HWid; - var lastInfo = await _banHelper.GetLastPlayerInfo(Input.NameOrUid); - if (lastInfo == null) + if (Input.UseLatestHwid || Input.UseLatestIp) { - TempData.SetStatusError("Unable to find player"); - return; - } + if (string.IsNullOrWhiteSpace(Input.NameOrUid)) + { + TempData.SetStatusError("Must provide name/UID."); + return Page(); + } - Input.IP = lastInfo.Value.address.ToString(); - Input.HWid = lastInfo.Value.hwid is { } h ? Convert.ToBase64String(h) : null; - } + var lastInfo = await _banHelper.GetLastPlayerInfo(Input.NameOrUid); + if (lastInfo == null) + { + TempData.SetStatusError("Unable to find player"); + return Page(); + } - public async Task OnPostCreateAsync() - { - var ban = new ServerBan(); + ipAddr = Input.UseLatestIp ? lastInfo.Value.address.ToString() : Input.IP; + hwid = Input.UseLatestHwid ? (lastInfo.Value.hwid is { } h ? Convert.ToBase64String(h) : null) : Input.HWid; + } var error = await _banHelper.FillBanCommon( ban, Input.NameOrUid, - Input.IP, - Input.HWid, + ipAddr, + hwid, Input.LengthMinutes, Input.Reason); diff --git a/SS14.Admin/Pages/Bans/Hits.cshtml.cs b/SS14.Admin/Pages/Bans/Hits.cshtml.cs index 267c217..2611920 100644 --- a/SS14.Admin/Pages/Bans/Hits.cshtml.cs +++ b/SS14.Admin/Pages/Bans/Hits.cshtml.cs @@ -53,7 +53,7 @@ public async Task OnGetAsync( .Where(bh => bh.BanId == banEntry.Ban.Id) .Select(bh => bh.Connection); - logQuery = SearchHelper.SearchConnectionLog(logQuery, search); + logQuery = SearchHelper.SearchConnectionLog(logQuery, search, User); SortState = await ConnectionsIndexModel.LoadSortConnectionsTableData( Pagination, diff --git a/SS14.Admin/Pages/Bans/Index.cshtml.cs b/SS14.Admin/Pages/Bans/Index.cshtml.cs index 88f4a19..7630cff 100644 --- a/SS14.Admin/Pages/Bans/Index.cshtml.cs +++ b/SS14.Admin/Pages/Bans/Index.cshtml.cs @@ -35,7 +35,7 @@ public async Task OnGetAsync( { Pagination.Init(pageIndex, perPage, AllRouteData); - var bans = SearchHelper.SearchServerBans(_banHelper.CreateServerBanJoin(), search); + var bans = SearchHelper.SearchServerBans(_banHelper.CreateServerBanJoin(), search, User); bans = show switch { diff --git a/SS14.Admin/Pages/Connections/Hits.cshtml b/SS14.Admin/Pages/Connections/Hits.cshtml index 572052f..7de059f 100644 --- a/SS14.Admin/Pages/Connections/Hits.cshtml +++ b/SS14.Admin/Pages/Connections/Hits.cshtml @@ -15,7 +15,7 @@
@Model.Log.UserName
User ID:
@Model.Log.UserId
- @if (User.IsInRole("ADMIN")) + @if (User.IsInRole(Constants.PIIRole)) {
IP:
@Model.Log.Address
diff --git a/SS14.Admin/Pages/Connections/Hits.cshtml.cs b/SS14.Admin/Pages/Connections/Hits.cshtml.cs index 1436d2e..74564ec 100644 --- a/SS14.Admin/Pages/Connections/Hits.cshtml.cs +++ b/SS14.Admin/Pages/Connections/Hits.cshtml.cs @@ -47,7 +47,7 @@ public async Task OnGetAsync( Pagination.Init(pageIndex, perPage, AllRouteData); - var banQuery = SearchHelper.SearchServerBans(_banHelper.CreateServerBanJoin(), search) + var banQuery = SearchHelper.SearchServerBans(_banHelper.CreateServerBanJoin(), search, User) .Join(_dbContext.ServerBanHit, bj => bj.Ban.Id, bh => bh.BanId, (join, hit) => new { join, hit diff --git a/SS14.Admin/Pages/Connections/Index.cshtml.cs b/SS14.Admin/Pages/Connections/Index.cshtml.cs index 3e9e056..cab3a75 100644 --- a/SS14.Admin/Pages/Connections/Index.cshtml.cs +++ b/SS14.Admin/Pages/Connections/Index.cshtml.cs @@ -72,7 +72,7 @@ public async Task OnGetAsync( AllRouteData.Add("showSet", "true"); IQueryable logQuery = _dbContext.ConnectionLog; - logQuery = SearchHelper.SearchConnectionLog(logQuery, search); + logQuery = SearchHelper.SearchConnectionLog(logQuery, search, User); var acceptableDenies = new List(); if (showAccepted) diff --git a/SS14.Admin/Pages/Players/Index.cshtml b/SS14.Admin/Pages/Players/Index.cshtml index bcb148c..06ee8fa 100644 --- a/SS14.Admin/Pages/Players/Index.cshtml +++ b/SS14.Admin/Pages/Players/Index.cshtml @@ -43,8 +43,16 @@ @player.UserId @player.LastSeenTime.ToString("yyyy-MM-dd HH:mm:ss") - @player.LastSeenAddress - @BanHelper.FormatHwid(player.LastSeenHWId) + @if (User.IsInRole(Constants.PIIRole)) + { + @player.LastSeenAddress + @BanHelper.FormatHwid(player.LastSeenHWId) + } + else + { + Hidden + Hidden + } @player.FirstSeenTime.ToString("yyyy-MM-dd HH:mm:ss") Player Info diff --git a/SS14.Admin/Pages/Players/Index.cshtml.cs b/SS14.Admin/Pages/Players/Index.cshtml.cs index 23264dc..37c8034 100644 --- a/SS14.Admin/Pages/Players/Index.cshtml.cs +++ b/SS14.Admin/Pages/Players/Index.cshtml.cs @@ -40,7 +40,7 @@ public async Task OnGetAsync( AllRouteData.Add("search", CurrentFilter); IQueryable userQuery = _dbContext.Player; - userQuery = SearchHelper.SearchPlayers(userQuery, search); + userQuery = SearchHelper.SearchPlayers(userQuery, search, User); userQuery = SortState.ApplyToQuery(userQuery); diff --git a/SS14.Admin/Pages/Players/Info.cshtml b/SS14.Admin/Pages/Players/Info.cshtml index 3219fda..395dcaa 100644 --- a/SS14.Admin/Pages/Players/Info.cshtml +++ b/SS14.Admin/Pages/Players/Info.cshtml @@ -22,18 +22,21 @@
@Model.Player.FirstSeenTime.ToString("yyyy-MM-dd HH:mm:ss")
Last seen time:
@Model.Player.LastSeenTime.ToString("yyyy-MM-dd HH:mm:ss")
-
Last seen address:
-
- - @Model.Player.LastSeenAddress - -
-
Last seen HWID:
-
- - @BanHelper.FormatHwid(Model.Player.LastSeenHWId) - -
+ @if (User.IsInRole(Constants.PIIRole)) + { +
Last seen address:
+
+ + @Model.Player.LastSeenAddress + +
+
Last seen HWID:
+
+ + @BanHelper.FormatHwid(Model.Player.LastSeenHWId) + +
+ }
Whitelisted:
@if (Model.Whitelisted) diff --git a/SS14.Admin/Pages/Players/Info.cshtml.cs b/SS14.Admin/Pages/Players/Info.cshtml.cs index 12db6e9..82a3ab3 100644 --- a/SS14.Admin/Pages/Players/Info.cshtml.cs +++ b/SS14.Admin/Pages/Players/Info.cshtml.cs @@ -39,8 +39,8 @@ public async Task OnGetAsync( GameBanPagination.Init(pageIndex, perPage, GameBanRouteData); RoleBanPagination.Init(pageIndex, perPage, RoleBanRouteData); - var gameBans = SearchHelper.SearchServerBans(_banHelper.CreateServerBanJoin(), userId.ToString()); - var roleBans = SearchHelper.SearchRoleBans(_banHelper.CreateRoleBanJoin(), userId.ToString()); + var gameBans = SearchHelper.SearchServerBans(_banHelper.CreateServerBanJoin(), userId.ToString(), User); + var roleBans = SearchHelper.SearchRoleBans(_banHelper.CreateRoleBanJoin(), userId.ToString(), User); GameBanRouteData.Add("search", userId.ToString()); GameBanRouteData.Add("show", "all"); diff --git a/SS14.Admin/Pages/RoleBans/Index.cshtml.cs b/SS14.Admin/Pages/RoleBans/Index.cshtml.cs index 38cc18f..cf04137 100644 --- a/SS14.Admin/Pages/RoleBans/Index.cshtml.cs +++ b/SS14.Admin/Pages/RoleBans/Index.cshtml.cs @@ -35,7 +35,7 @@ public async Task OnGetAsync( { Pagination.Init(pageIndex, perPage, AllRouteData); - var bans = SearchHelper.SearchRoleBans(_banHelper.CreateRoleBanJoin(), search); + var bans = SearchHelper.SearchRoleBans(_banHelper.CreateRoleBanJoin(), search, User); bans = show switch { diff --git a/SS14.Admin/Pages/Tables/BansTable.cshtml b/SS14.Admin/Pages/Tables/BansTable.cshtml index 4ce355f..354a850 100644 --- a/SS14.Admin/Pages/Tables/BansTable.cshtml +++ b/SS14.Admin/Pages/Tables/BansTable.cshtml @@ -52,7 +52,7 @@
} - @if (User.IsInRole("ADMIN")) + @if (User.IsInRole(Constants.PIIRole)) { if (ban.Address != null) { diff --git a/SS14.Admin/Pages/Tables/ConnectionsTable.cshtml b/SS14.Admin/Pages/Tables/ConnectionsTable.cshtml index 1bde37b..9a93211 100644 --- a/SS14.Admin/Pages/Tables/ConnectionsTable.cshtml +++ b/SS14.Admin/Pages/Tables/ConnectionsTable.cshtml @@ -34,8 +34,16 @@ @log.UserId @log.Time.ToString("yyyy-MM-dd HH:mm:ss") - @log.Address - @(log.HWId is { } hwid ? Convert.ToBase64String(hwid) : null) + @if (User.IsInRole(Constants.PIIRole)) + { + @log.Address + @(log.HWId is { } hwid ? Convert.ToBase64String(hwid) : null) + } + else + { + Hidden + Hidden + } @switch (log.Denied) {