diff --git a/ProjectLighthouse/Controllers/MatchController.cs b/ProjectLighthouse/Controllers/MatchController.cs index dc62e6c9..900107f8 100644 --- a/ProjectLighthouse/Controllers/MatchController.cs +++ b/ProjectLighthouse/Controllers/MatchController.cs @@ -6,6 +6,7 @@ using System.Text.Json; using System.Threading.Tasks; using Kettu; using LBPUnion.ProjectLighthouse.Helpers; +using LBPUnion.ProjectLighthouse.Logging; using LBPUnion.ProjectLighthouse.Types; using LBPUnion.ProjectLighthouse.Types.Match; using LBPUnion.ProjectLighthouse.Types.Profiles; @@ -53,8 +54,8 @@ namespace LBPUnion.ProjectLighthouse.Controllers } catch(Exception e) { - Logger.Log("Exception while parsing MatchData: " + e); - Logger.Log("Data: " + bodyString); + Logger.Log("Exception while parsing MatchData: " + e, LoggerLevelMatch.Instance); + Logger.Log("Data: " + bodyString, LoggerLevelMatch.Instance); return this.BadRequest(); } diff --git a/ProjectLighthouse/Controllers/PhotosController.cs b/ProjectLighthouse/Controllers/PhotosController.cs index d5559365..c853aedf 100644 --- a/ProjectLighthouse/Controllers/PhotosController.cs +++ b/ProjectLighthouse/Controllers/PhotosController.cs @@ -6,6 +6,7 @@ using System.Linq; using System.Threading.Tasks; using System.Xml.Serialization; using Kettu; +using LBPUnion.ProjectLighthouse.Logging; using LBPUnion.ProjectLighthouse.Serialization; using LBPUnion.ProjectLighthouse.Types; using Microsoft.AspNetCore.Mvc; @@ -48,7 +49,7 @@ namespace LBPUnion.ProjectLighthouse.Controllers if (subject.User == null) continue; subject.UserId = subject.User.UserId; - Logger.Log($"Adding PhotoSubject (userid {subject.UserId}) to db"); + Logger.Log($"Adding PhotoSubject (userid {subject.UserId}) to db", LoggerLevelPhotos.Instance); this.database.PhotoSubjects.Add(subject); } @@ -59,7 +60,7 @@ namespace LBPUnion.ProjectLighthouse.Controllers // photo.Slot = await this.database.Slots.FirstOrDefaultAsync(s => s.SlotId == photo.SlotId); - Logger.Log($"Adding PhotoSubjectCollection ({photo.PhotoSubjectCollection}) to photo"); + Logger.Log($"Adding PhotoSubjectCollection ({photo.PhotoSubjectCollection}) to photo", LoggerLevelPhotos.Instance); this.database.Photos.Add(photo); diff --git a/ProjectLighthouse/Controllers/ResourcesController.cs b/ProjectLighthouse/Controllers/ResourcesController.cs index dcb1a4d8..3680bbfd 100644 --- a/ProjectLighthouse/Controllers/ResourcesController.cs +++ b/ProjectLighthouse/Controllers/ResourcesController.cs @@ -4,6 +4,7 @@ using System.Threading.Tasks; using System.Xml.Serialization; using Kettu; using LBPUnion.ProjectLighthouse.Helpers; +using LBPUnion.ProjectLighthouse.Logging; using LBPUnion.ProjectLighthouse.Serialization; using LBPUnion.ProjectLighthouse.Types; using LBPUnion.ProjectLighthouse.Types.Files; @@ -60,11 +61,16 @@ namespace LBPUnion.ProjectLighthouse.Controllers FileHelper.EnsureDirectoryCreated(assetsDirectory); if (FileHelper.ResourceExists(hash)) this.Ok(); // no reason to fail if it's already uploaded - Logger.Log($"Processing resource upload (hash: {hash})"); + Logger.Log($"Processing resource upload (hash: {hash})", LoggerLevelResources.Instance); LbpFile file = new(await BinaryHelper.ReadFromPipeReader(this.Request.BodyReader)); - if (!FileHelper.IsFileSafe(file)) return this.UnprocessableEntity(); + if (!FileHelper.IsFileSafe(file)) + { + Logger.Log($"File is unsafe (hash: {hash}, type: {file.FileType})", LoggerLevelResources.Instance); + return this.UnprocessableEntity(); + } + Logger.Log($"File is OK! (hash: {hash}, type: {file.FileType})", LoggerLevelResources.Instance); await IOFile.WriteAllBytesAsync(path, file.Data); return this.Ok(); } diff --git a/ProjectLighthouse/Logging/LoggerLevels.cs b/ProjectLighthouse/Logging/LoggerLevels.cs index 0b304a1a..2fb28109 100644 --- a/ProjectLighthouse/Logging/LoggerLevels.cs +++ b/ProjectLighthouse/Logging/LoggerLevels.cs @@ -33,6 +33,24 @@ namespace LBPUnion.ProjectLighthouse.Logging public override string Name => "Login"; } + public class LoggerLevelResources : LoggerLevel + { + public static readonly LoggerLevelResources Instance = new(); + public override string Name => "Resources"; + } + + public class LoggerLevelMatch : LoggerLevel + { + public static readonly LoggerLevelMatch Instance = new(); + public override string Name => "Match"; + } + + public class LoggerLevelPhotos : LoggerLevel + { + public static readonly LoggerLevelPhotos Instance = new(); + public override string Name => "Photos"; + } + public class LoggerLevelAspNet : LoggerLevel { diff --git a/ProjectLighthouse/Startup.cs b/ProjectLighthouse/Startup.cs index fe0cdd4a..106b27da 100644 --- a/ProjectLighthouse/Startup.cs +++ b/ProjectLighthouse/Startup.cs @@ -60,7 +60,8 @@ namespace LBPUnion.ProjectLighthouse Logger.Log ( "The SERVER_DIGEST_KEY environment variable wasn't set, so digest headers won't be set or verified. This will prevent LBP 1 and LBP 3 from working. " + - "To increase security, it is recommended that you find and set this variable." + "To increase security, it is recommended that you find and set this variable.", + LoggerLevelStartup.Instance ); computeDigests = false; }