diff --git a/Teknik/Areas/API/V1/Controllers/AccountAPIv1Controller.cs b/Teknik/Areas/API/V1/Controllers/AccountAPIv1Controller.cs index 47c3a7e..126d947 100644 --- a/Teknik/Areas/API/V1/Controllers/AccountAPIv1Controller.cs +++ b/Teknik/Areas/API/V1/Controllers/AccountAPIv1Controller.cs @@ -19,7 +19,7 @@ namespace Teknik.Areas.API.V1.Controllers public AccountAPIv1Controller(ILogger logger, Config config, TeknikEntities dbContext) : base(logger, config, dbContext) { } [HttpGet] - [ServiceFilter(typeof(TrackPageView))] + [TrackPageView] public IActionResult GetClaims() { return new JsonResult(from c in User.Claims select new { c.Type, c.Value }); diff --git a/Teknik/Areas/API/V1/Controllers/PasteAPIv1Controller.cs b/Teknik/Areas/API/V1/Controllers/PasteAPIv1Controller.cs index e008be2..8596bcf 100644 --- a/Teknik/Areas/API/V1/Controllers/PasteAPIv1Controller.cs +++ b/Teknik/Areas/API/V1/Controllers/PasteAPIv1Controller.cs @@ -25,7 +25,7 @@ namespace Teknik.Areas.API.V1.Controllers [HttpPost] [AllowAnonymous] - [ServiceFilter(typeof(TrackPageView))] + [TrackPageView] public IActionResult Paste(PasteAPIv1Model model) { try diff --git a/Teknik/Areas/API/V1/Controllers/ShortenAPIv1Controller.cs b/Teknik/Areas/API/V1/Controllers/ShortenAPIv1Controller.cs index e566855..85d5bb3 100644 --- a/Teknik/Areas/API/V1/Controllers/ShortenAPIv1Controller.cs +++ b/Teknik/Areas/API/V1/Controllers/ShortenAPIv1Controller.cs @@ -26,7 +26,7 @@ namespace Teknik.Areas.API.V1.Controllers [HttpPost] [AllowAnonymous] - [ServiceFilter(typeof(TrackPageView))] + [TrackPageView] public IActionResult Shorten(ShortenAPIv1Model model) { try diff --git a/Teknik/Areas/API/V1/Controllers/UploadAPIv1Controller.cs b/Teknik/Areas/API/V1/Controllers/UploadAPIv1Controller.cs index 908f7a0..4f8f212 100644 --- a/Teknik/Areas/API/V1/Controllers/UploadAPIv1Controller.cs +++ b/Teknik/Areas/API/V1/Controllers/UploadAPIv1Controller.cs @@ -30,7 +30,7 @@ namespace Teknik.Areas.API.V1.Controllers [HttpPost] [AllowAnonymous] - [ServiceFilter(typeof(TrackPageView))] + [TrackPageView] public async Task Upload(UploadAPIv1Model model) { try diff --git a/Teknik/Areas/About/Controllers/AboutController.cs b/Teknik/Areas/About/Controllers/AboutController.cs index 633ccc4..5a86901 100644 --- a/Teknik/Areas/About/Controllers/AboutController.cs +++ b/Teknik/Areas/About/Controllers/AboutController.cs @@ -22,7 +22,7 @@ namespace Teknik.Areas.About.Controllers public AboutController(ILogger logger, Config config, TeknikEntities dbContext) : base(logger, config, dbContext) { } [AllowAnonymous] - [ServiceFilter(typeof(TrackPageView))] + [TrackPageView] public IActionResult Index([FromServices] Config config) { ViewBag.Title = "About"; diff --git a/Teknik/Areas/Abuse/Controllers/AbuseController.cs b/Teknik/Areas/Abuse/Controllers/AbuseController.cs index c1d927a..34852fb 100644 --- a/Teknik/Areas/Abuse/Controllers/AbuseController.cs +++ b/Teknik/Areas/Abuse/Controllers/AbuseController.cs @@ -22,7 +22,7 @@ namespace Teknik.Areas.Abuse.Controllers public AbuseController(ILogger logger, Config config, TeknikEntities dbContext) : base(logger, config, dbContext) { } [AllowAnonymous] - [ServiceFilter(typeof(TrackPageView))] + [TrackPageView] public IActionResult Index() { ViewBag.Title = "Abuse Reporting"; diff --git a/Teknik/Areas/Admin/Controllers/AdminController.cs b/Teknik/Areas/Admin/Controllers/AdminController.cs index 2323b76..a9e64ff 100644 --- a/Teknik/Areas/Admin/Controllers/AdminController.cs +++ b/Teknik/Areas/Admin/Controllers/AdminController.cs @@ -29,7 +29,7 @@ namespace Teknik.Areas.Admin.Controllers public AdminController(ILogger logger, Config config, TeknikEntities dbContext) : base (logger, config, dbContext) { } [HttpGet] - [ServiceFilter(typeof(TrackPageView))] + [TrackPageView] public IActionResult Dashboard() { DashboardViewModel model = new DashboardViewModel(); @@ -37,7 +37,7 @@ namespace Teknik.Areas.Admin.Controllers } [HttpGet] - [ServiceFilter(typeof(TrackPageView))] + [TrackPageView] public IActionResult UserSearch() { UserSearchViewModel model = new UserSearchViewModel(); @@ -45,7 +45,7 @@ namespace Teknik.Areas.Admin.Controllers } [HttpGet] - [ServiceFilter(typeof(TrackPageView))] + [TrackPageView] public async Task UserInfo(string username) { if (UserHelper.UserExists(_dbContext, username)) @@ -66,7 +66,7 @@ namespace Teknik.Areas.Admin.Controllers } [HttpGet] - [ServiceFilter(typeof(TrackPageView))] + [TrackPageView] public IActionResult UploadSearch() { UploadSearchViewModel model = new UploadSearchViewModel(); diff --git a/Teknik/Areas/Blog/Controllers/BlogController.cs b/Teknik/Areas/Blog/Controllers/BlogController.cs index be44033..10d5482 100644 --- a/Teknik/Areas/Blog/Controllers/BlogController.cs +++ b/Teknik/Areas/Blog/Controllers/BlogController.cs @@ -30,7 +30,7 @@ namespace Teknik.Areas.Blog.Controllers public BlogController(ILogger logger, Config config, TeknikEntities dbContext) : base(logger, config, dbContext) { } [AllowAnonymous] - [ServiceFilter(typeof(TrackPageView))] + [TrackPageView] public IActionResult Blog(string username) { BlogViewModel model = new BlogViewModel(); @@ -120,7 +120,7 @@ namespace Teknik.Areas.Blog.Controllers #region Posts [AllowAnonymous] - [ServiceFilter(typeof(TrackPageView))] + [TrackPageView] public IActionResult Post(string username, int id) { if (string.IsNullOrEmpty(username)) @@ -163,7 +163,7 @@ namespace Teknik.Areas.Blog.Controllers return View("~/Areas/Blog/Views/Blog/ViewPost.cshtml", model); } - [ServiceFilter(typeof(TrackPageView))] + [TrackPageView] public IActionResult NewPost(string username, int blogID) { if (string.IsNullOrEmpty(username)) @@ -203,7 +203,7 @@ namespace Teknik.Areas.Blog.Controllers return View("~/Areas/Blog/Views/Blog/Blog.cshtml", model); } - [ServiceFilter(typeof(TrackPageView))] + [TrackPageView] public IActionResult EditPost(string username, int id) { if (string.IsNullOrEmpty(username)) diff --git a/Teknik/Areas/Contact/Controllers/ContactController.cs b/Teknik/Areas/Contact/Controllers/ContactController.cs index f33b887..2296d82 100644 --- a/Teknik/Areas/Contact/Controllers/ContactController.cs +++ b/Teknik/Areas/Contact/Controllers/ContactController.cs @@ -26,7 +26,7 @@ namespace Teknik.Areas.Contact.Controllers public ContactController(ILogger logger, Config config, TeknikEntities dbContext) : base(logger, config, dbContext) { } [AllowAnonymous] - [ServiceFilter(typeof(TrackPageView))] + [TrackPageView] public IActionResult Index() { ViewBag.Title = "Contact Us"; diff --git a/Teknik/Areas/Error/Controllers/ErrorController.cs b/Teknik/Areas/Error/Controllers/ErrorController.cs index 587a098..877c0a9 100644 --- a/Teknik/Areas/Error/Controllers/ErrorController.cs +++ b/Teknik/Areas/Error/Controllers/ErrorController.cs @@ -28,7 +28,7 @@ namespace Teknik.Areas.Error.Controllers public ErrorController(ILogger logger, Config config, TeknikEntities dbContext) : base(logger, config, dbContext) { } [AllowAnonymous] - [ServiceFilter(typeof(TrackPageView))] + [TrackPageView] public IActionResult HttpError(int statusCode) { switch (statusCode) @@ -45,7 +45,7 @@ namespace Teknik.Areas.Error.Controllers } [AllowAnonymous] - [ServiceFilter(typeof(TrackPageView))] + [TrackPageView] public IActionResult HttpGeneral(int statusCode) { ViewBag.Title = statusCode; @@ -59,7 +59,7 @@ namespace Teknik.Areas.Error.Controllers } [AllowAnonymous] - [ServiceFilter(typeof(TrackPageView))] + [TrackPageView] public IActionResult Http401() { Response.StatusCode = StatusCodes.Status401Unauthorized; @@ -76,7 +76,7 @@ namespace Teknik.Areas.Error.Controllers } [AllowAnonymous] - [ServiceFilter(typeof(TrackPageView))] + [TrackPageView] public IActionResult Http403() { Response.StatusCode = StatusCodes.Status403Forbidden; @@ -93,7 +93,7 @@ namespace Teknik.Areas.Error.Controllers } [AllowAnonymous] - [ServiceFilter(typeof(TrackPageView))] + [TrackPageView] public IActionResult Http404() { Response.StatusCode = StatusCodes.Status404NotFound; @@ -110,7 +110,7 @@ namespace Teknik.Areas.Error.Controllers } [AllowAnonymous] - [ServiceFilter(typeof(TrackPageView))] + [TrackPageView] public IActionResult Http500(Exception exception) { try diff --git a/Teknik/Areas/FAQ/Controllers/FAQController.cs b/Teknik/Areas/FAQ/Controllers/FAQController.cs index 700f459..03c835d 100644 --- a/Teknik/Areas/FAQ/Controllers/FAQController.cs +++ b/Teknik/Areas/FAQ/Controllers/FAQController.cs @@ -18,7 +18,7 @@ namespace Teknik.Areas.FAQ.Controllers public FAQController(ILogger logger, Config config, TeknikEntities dbContext) : base(logger, config, dbContext) { } [AllowAnonymous] - [ServiceFilter(typeof(TrackPageView))] + [TrackPageView] public IActionResult Index() { ViewBag.Title = "Frequently Asked Questions"; diff --git a/Teknik/Areas/Help/Controllers/HelpController.cs b/Teknik/Areas/Help/Controllers/HelpController.cs index 37a0ade..c234964 100644 --- a/Teknik/Areas/Help/Controllers/HelpController.cs +++ b/Teknik/Areas/Help/Controllers/HelpController.cs @@ -14,7 +14,7 @@ namespace Teknik.Areas.Help.Controllers { [Authorize] [Area("Help")] - [ServiceFilter(typeof(TrackPageView))] + [TrackPageView] public class HelpController : DefaultController { public HelpController(ILogger logger, Config config, TeknikEntities dbContext) : base(logger, config, dbContext) { } diff --git a/Teknik/Areas/Home/Controllers/HomeController.cs b/Teknik/Areas/Home/Controllers/HomeController.cs index 53d1030..9f169c0 100644 --- a/Teknik/Areas/Home/Controllers/HomeController.cs +++ b/Teknik/Areas/Home/Controllers/HomeController.cs @@ -23,7 +23,7 @@ namespace Teknik.Areas.Home.Controllers public HomeController(ILogger logger, Config config, TeknikEntities dbContext) : base(logger, config, dbContext) { } [AllowAnonymous] - [ServiceFilter(typeof(TrackPageView))] + [TrackPageView] public IActionResult Index() { HomeViewModel model = new HomeViewModel(); diff --git a/Teknik/Areas/Paste/Controllers/PasteController.cs b/Teknik/Areas/Paste/Controllers/PasteController.cs index 95c381f..1ebadd1 100644 --- a/Teknik/Areas/Paste/Controllers/PasteController.cs +++ b/Teknik/Areas/Paste/Controllers/PasteController.cs @@ -31,7 +31,7 @@ namespace Teknik.Areas.Paste.Controllers public PasteController(ILogger logger, Config config, TeknikEntities dbContext) : base(logger, config, dbContext) { } [AllowAnonymous] - [ServiceFilter(typeof(TrackPageView))] + [TrackPageView] public IActionResult Index() { ViewBag.Title = "Pastebin"; @@ -41,7 +41,7 @@ namespace Teknik.Areas.Paste.Controllers } [AllowAnonymous] - [ServiceFilter(typeof(TrackPageView))] + [TrackPageView] public async Task ViewPaste(string type, string url, string password) { Models.Paste paste = _dbContext.Pastes.Where(p => p.Url == url).FirstOrDefault(); @@ -205,7 +205,7 @@ namespace Teknik.Areas.Paste.Controllers return View("~/Areas/Paste/Views/Paste/Index.cshtml", model); } - [ServiceFilter(typeof(TrackPageView))] + [TrackPageView] public async Task Edit(string url, string password) { Models.Paste paste = _dbContext.Pastes.Where(p => p.Url == url).FirstOrDefault(); diff --git a/Teknik/Areas/Podcast/Controllers/PodcastController.cs b/Teknik/Areas/Podcast/Controllers/PodcastController.cs index 2410652..280ec3e 100644 --- a/Teknik/Areas/Podcast/Controllers/PodcastController.cs +++ b/Teknik/Areas/Podcast/Controllers/PodcastController.cs @@ -29,7 +29,7 @@ namespace Teknik.Areas.Podcast.Controllers public PodcastController(ILogger logger, Config config, TeknikEntities dbContext) : base(logger, config, dbContext) { } [AllowAnonymous] - [ServiceFilter(typeof(TrackPageView))] + [TrackPageView] public IActionResult Index() { MainViewModel model = new MainViewModel(); @@ -64,7 +64,7 @@ namespace Teknik.Areas.Podcast.Controllers #region Podcasts [AllowAnonymous] - [ServiceFilter(typeof(TrackPageView))] + [TrackPageView] public IActionResult View(int episode) { PodcastViewModel model = new PodcastViewModel(); @@ -86,7 +86,7 @@ namespace Teknik.Areas.Podcast.Controllers [HttpGet] [AllowAnonymous] [ResponseCache(Duration = 31536000, Location = ResponseCacheLocation.Any)] - [ServiceFilter(typeof(TrackDownload))] + [TrackDownload] public IActionResult Download(int episode, string fileName) { string path = string.Empty; diff --git a/Teknik/Areas/Privacy/Controllers/PrivacyController.cs b/Teknik/Areas/Privacy/Controllers/PrivacyController.cs index 51e7c2b..d66da40 100644 --- a/Teknik/Areas/Privacy/Controllers/PrivacyController.cs +++ b/Teknik/Areas/Privacy/Controllers/PrivacyController.cs @@ -18,7 +18,7 @@ namespace Teknik.Areas.Privacy.Controllers public PrivacyController(ILogger logger, Config config, TeknikEntities dbContext) : base(logger, config, dbContext) { } [AllowAnonymous] - [ServiceFilter(typeof(TrackPageView))] + [TrackPageView] public IActionResult Index() { ViewBag.Title = "Privacy Policy"; diff --git a/Teknik/Areas/RSS/Controllers/RSSController.cs b/Teknik/Areas/RSS/Controllers/RSSController.cs index a0e3b7d..8225bcc 100644 --- a/Teknik/Areas/RSS/Controllers/RSSController.cs +++ b/Teknik/Areas/RSS/Controllers/RSSController.cs @@ -32,7 +32,7 @@ namespace Teknik.Areas.RSS.Controllers public RSSController(ILogger logger, Config config, TeknikEntities dbContext) : base(logger, config, dbContext) { } [AllowAnonymous] - [ServiceFilter(typeof(TrackPageView))] + [TrackPageView] public async Task Index() { Response.ContentType = "application/rss+xml"; @@ -50,7 +50,7 @@ namespace Teknik.Areas.RSS.Controllers } [AllowAnonymous] - [ServiceFilter(typeof(TrackPageView))] + [TrackPageView] public async Task Blog(string username) { Response.ContentType = "application/rss+xml"; @@ -156,7 +156,7 @@ namespace Teknik.Areas.RSS.Controllers } [AllowAnonymous] - [ServiceFilter(typeof(TrackPageView))] + [TrackPageView] public async Task Podcast() { Response.ContentType = "application/rss+xml"; diff --git a/Teknik/Areas/Shortener/Controllers/ShortenerController.cs b/Teknik/Areas/Shortener/Controllers/ShortenerController.cs index 9ea3bad..bff35ef 100644 --- a/Teknik/Areas/Shortener/Controllers/ShortenerController.cs +++ b/Teknik/Areas/Shortener/Controllers/ShortenerController.cs @@ -24,7 +24,7 @@ namespace Teknik.Areas.Shortener.Controllers public ShortenerController(ILogger logger, Config config, TeknikEntities dbContext) : base(logger, config, dbContext) { } [AllowAnonymous] - [ServiceFilter(typeof(TrackPageView))] + [TrackPageView] public IActionResult Index() { ViewBag.Title = "Url Shortener"; @@ -33,7 +33,7 @@ namespace Teknik.Areas.Shortener.Controllers } [AllowAnonymous] - [ServiceFilter(typeof(TrackPageView))] + [TrackPageView] public IActionResult RedirectToUrl(string url) { ShortenedUrl shortUrl = _dbContext.ShortenedUrls.Where(s => s.ShortUrl == url).FirstOrDefault(); diff --git a/Teknik/Areas/Stats/Controllers/StatsController.cs b/Teknik/Areas/Stats/Controllers/StatsController.cs index 656aaa3..c6bd3a3 100644 --- a/Teknik/Areas/Stats/Controllers/StatsController.cs +++ b/Teknik/Areas/Stats/Controllers/StatsController.cs @@ -24,7 +24,7 @@ namespace Teknik.Areas.Stats.Controllers public StatsController(ILogger logger, Config config, TeknikEntities dbContext) : base(logger, config, dbContext) { } [AllowAnonymous] - [ServiceFilter(typeof(TrackPageView))] + [TrackPageView] public IActionResult Index() { ViewBag.Title = "System Statistics"; diff --git a/Teknik/Areas/TOS/Controllers/TOSController.cs b/Teknik/Areas/TOS/Controllers/TOSController.cs index 068ea9e..f7bfed4 100644 --- a/Teknik/Areas/TOS/Controllers/TOSController.cs +++ b/Teknik/Areas/TOS/Controllers/TOSController.cs @@ -18,7 +18,7 @@ namespace Teknik.Areas.TOS.Controllers public TOSController(ILogger logger, Config config, TeknikEntities dbContext) : base(logger, config, dbContext) { } [AllowAnonymous] - [ServiceFilter(typeof(TrackPageView))] + [TrackPageView] public IActionResult Index() { ViewBag.Title = "Terms of Service"; diff --git a/Teknik/Areas/Upload/Controllers/UploadController.cs b/Teknik/Areas/Upload/Controllers/UploadController.cs index c1c2269..3cff732 100644 --- a/Teknik/Areas/Upload/Controllers/UploadController.cs +++ b/Teknik/Areas/Upload/Controllers/UploadController.cs @@ -33,7 +33,7 @@ namespace Teknik.Areas.Upload.Controllers [HttpGet] [AllowAnonymous] - [ServiceFilter(typeof(TrackPageView))] + [TrackPageView] public async Task Index() { ViewBag.Title = "Upload Files"; @@ -181,8 +181,8 @@ namespace Teknik.Areas.Upload.Controllers [HttpGet] [AllowAnonymous] - [ServiceFilter(typeof(TrackDownload))] - [ServiceFilter(typeof(TrackPageView))] + [TrackDownload] + [TrackPageView] [ResponseCache(Duration = 31536000, Location = ResponseCacheLocation.Any)] public async Task Download(string file) { diff --git a/Teknik/Areas/User/Controllers/UserController.cs b/Teknik/Areas/User/Controllers/UserController.cs index 3d40e10..305d314 100644 --- a/Teknik/Areas/User/Controllers/UserController.cs +++ b/Teknik/Areas/User/Controllers/UserController.cs @@ -62,7 +62,7 @@ namespace Teknik.Areas.Users.Controllers } [HttpGet] - [ServiceFilter(typeof(TrackPageView))] + [TrackPageView] public IActionResult Login(string returnUrl) { // Let's double check their email and git accounts to make sure they exist @@ -86,7 +86,7 @@ namespace Teknik.Areas.Users.Controllers } [HttpGet] - [ServiceFilter(typeof(TrackPageView))] + [TrackPageView] public async Task Logout() { // these are the sub & sid to signout @@ -100,7 +100,7 @@ namespace Teknik.Areas.Users.Controllers } [AllowAnonymous] - [ServiceFilter(typeof(TrackPageView))] + [TrackPageView] public IActionResult GetPremium() { ViewBag.Title = "Get a Premium Account"; @@ -112,7 +112,7 @@ namespace Teknik.Areas.Users.Controllers [HttpGet] [AllowAnonymous] - [ServiceFilter(typeof(TrackPageView))] + [TrackPageView] public IActionResult Register(string inviteCode, string ReturnUrl) { RegisterViewModel model = new RegisterViewModel(); @@ -206,7 +206,7 @@ namespace Teknik.Areas.Users.Controllers // GET: Profile/Profile [AllowAnonymous] - [ServiceFilter(typeof(TrackPageView))] + [TrackPageView] public async Task ViewProfile(string username) { if (string.IsNullOrEmpty(username)) @@ -264,7 +264,7 @@ namespace Teknik.Areas.Users.Controllers return View(model); } - [ServiceFilter(typeof(TrackPageView))] + [TrackPageView] public IActionResult ViewServiceData() { string username = User.Identity.Name; @@ -303,13 +303,13 @@ namespace Teknik.Areas.Users.Controllers return View(model); } - [ServiceFilter(typeof(TrackPageView))] + [TrackPageView] public IActionResult Settings() { return Redirect(Url.SubRouteUrl("account", "User.ProfileSettings")); } - [ServiceFilter(typeof(TrackPageView))] + [TrackPageView] public IActionResult ProfileSettings() { string username = User.Identity.Name; @@ -334,7 +334,7 @@ namespace Teknik.Areas.Users.Controllers return new StatusCodeResult(StatusCodes.Status403Forbidden); } - [ServiceFilter(typeof(TrackPageView))] + [TrackPageView] public IActionResult AccountSettings() { string username = User.Identity.Name; @@ -356,7 +356,7 @@ namespace Teknik.Areas.Users.Controllers return new StatusCodeResult(StatusCodes.Status403Forbidden); } - [ServiceFilter(typeof(TrackPageView))] + [TrackPageView] public async Task SecuritySettings() { string username = User.Identity.Name; @@ -399,7 +399,7 @@ namespace Teknik.Areas.Users.Controllers return new StatusCodeResult(StatusCodes.Status403Forbidden); } - [ServiceFilter(typeof(TrackPageView))] + [TrackPageView] public async Task DeveloperSettings() { string username = User.Identity.Name; @@ -447,7 +447,7 @@ namespace Teknik.Areas.Users.Controllers return new StatusCodeResult(StatusCodes.Status403Forbidden); } - [ServiceFilter(typeof(TrackPageView))] + [TrackPageView] public IActionResult InviteSettings() { string username = User.Identity.Name; @@ -493,7 +493,7 @@ namespace Teknik.Areas.Users.Controllers return new StatusCodeResult(StatusCodes.Status403Forbidden); } - [ServiceFilter(typeof(TrackPageView))] + [TrackPageView] public IActionResult BlogSettings() { string username = User.Identity.Name; @@ -517,7 +517,7 @@ namespace Teknik.Areas.Users.Controllers return new StatusCodeResult(StatusCodes.Status403Forbidden); } - [ServiceFilter(typeof(TrackPageView))] + [TrackPageView] public IActionResult UploadSettings() { string username = User.Identity.Name; @@ -544,7 +544,7 @@ namespace Teknik.Areas.Users.Controllers [HttpGet] [AllowAnonymous] - [ServiceFilter(typeof(TrackPageView))] + [TrackPageView] public async Task ViewRawPGP(string username) { ViewBag.Title = username + "'s Public Key"; @@ -839,7 +839,7 @@ namespace Teknik.Areas.Users.Controllers [HttpGet] [AllowAnonymous] - [ServiceFilter(typeof(TrackPageView))] + [TrackPageView] public IActionResult ResetPassword(string username) { ResetPasswordViewModel model = new ResetPasswordViewModel(); @@ -883,7 +883,7 @@ namespace Teknik.Areas.Users.Controllers [HttpGet] [AllowAnonymous] - [ServiceFilter(typeof(TrackPageView))] + [TrackPageView] public async Task VerifyResetPassword(string username, string code) { bool verified = true; diff --git a/Teknik/Areas/Vault/Controllers/VaultController.cs b/Teknik/Areas/Vault/Controllers/VaultController.cs index 2c81143..22fc9de 100644 --- a/Teknik/Areas/Vault/Controllers/VaultController.cs +++ b/Teknik/Areas/Vault/Controllers/VaultController.cs @@ -34,7 +34,7 @@ namespace Teknik.Areas.Vault.Controllers public VaultController(ILogger logger, Config config, TeknikEntities dbContext) : base(logger, config, dbContext) { } [AllowAnonymous] - [ServiceFilter(typeof(TrackPageView))] + [TrackPageView] public async Task ViewVault(string id) { Models.Vault foundVault = _dbContext.Vaults.Where(v => v.Url == id).FirstOrDefault(); @@ -136,7 +136,7 @@ namespace Teknik.Areas.Vault.Controllers [HttpGet] [AllowAnonymous] - [ServiceFilter(typeof(TrackPageView))] + [TrackPageView] public IActionResult NewVault() { ViewBag.Title = "Create Vault"; @@ -147,7 +147,7 @@ namespace Teknik.Areas.Vault.Controllers [HttpGet] [AllowAnonymous] - [ServiceFilter(typeof(TrackPageView))] + [TrackPageView] public IActionResult NewVaultFromService(string type, string items) { ViewBag.Title = "Create Vault"; @@ -184,7 +184,7 @@ namespace Teknik.Areas.Vault.Controllers } [HttpGet] - [ServiceFilter(typeof(TrackPageView))] + [TrackPageView] public IActionResult EditVault(string url, string type, string items) { ViewBag.Title = "Edit Vault"; diff --git a/Teknik/Filters/TrackDownload.cs b/Teknik/Filters/TrackDownload.cs index 3d9d197..b6801b1 100644 --- a/Teknik/Filters/TrackDownload.cs +++ b/Teknik/Filters/TrackDownload.cs @@ -10,39 +10,52 @@ using Teknik.Tracking; using Microsoft.AspNetCore.Mvc.Filters; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Extensions; +using Microsoft.AspNetCore.Mvc; namespace Teknik.Filters { - public class TrackDownload : ActionFilterAttribute + public class TrackDownloadAttribute : TypeFilterAttribute { - private readonly Config _config; - - public TrackDownload(Config config) - { - _config = config; - } - - public override void OnActionExecuting(ActionExecutingContext filterContext) + public TrackDownloadAttribute() : base(typeof(TrackDownload)) { } - public override void OnActionExecuted(ActionExecutedContext filterContext) + public class TrackDownload : ActionFilterAttribute { - HttpRequest request = filterContext.HttpContext.Request; + private readonly IBackgroundTaskQueue _queue; + private readonly Config _config; - string doNotTrack = request.Headers["DNT"]; - if (string.IsNullOrEmpty(doNotTrack) || doNotTrack != "1") + public TrackDownload(IBackgroundTaskQueue queue, Config config) { - string userAgent = request.Headers["User-Agent"].ToString(); + _queue = queue; + _config = config; + } - string clientIp = request.ClientIPFromRequest(true); + public override void OnActionExecuting(ActionExecutingContext filterContext) + { + } - string urlReferrer = request.Headers["Referer"].ToString(); + public override void OnActionExecuted(ActionExecutedContext filterContext) + { + HttpRequest request = filterContext.HttpContext.Request; - string url = UriHelper.GetEncodedUrl(request); + string doNotTrack = request.Headers["DNT"]; + if (string.IsNullOrEmpty(doNotTrack) || doNotTrack != "1") + { + string userAgent = request.Headers["User-Agent"].ToString(); - // Fire and forget. Don't need to wait for it. - Tracking.Tracking.TrackDownload(filterContext.HttpContext, _config, userAgent, clientIp, url, urlReferrer); + string clientIp = request.ClientIPFromRequest(true); + + string urlReferrer = request.Headers["Referer"].ToString(); + + string url = UriHelper.GetEncodedUrl(request); + + // Fire and forget. Don't need to wait for it. + _queue.QueueBackgroundWorkItem(async token => + { + Tracking.Tracking.TrackDownload(filterContext.HttpContext, _config, userAgent, clientIp, url, urlReferrer); + }); + } } } } diff --git a/Teknik/Filters/TrackPageView.cs b/Teknik/Filters/TrackPageView.cs index 0a54c54..0385ed8 100644 --- a/Teknik/Filters/TrackPageView.cs +++ b/Teknik/Filters/TrackPageView.cs @@ -14,53 +14,64 @@ using Microsoft.AspNetCore.Mvc; namespace Teknik.Filters { - public class TrackPageView : ActionFilterAttribute + public class TrackPageViewAttribute : TypeFilterAttribute { - private readonly Config _config; - - public TrackPageView(Config config) - { - _config = config; - } - - public override void OnActionExecuting(ActionExecutingContext filterContext) + public TrackPageViewAttribute() : base(typeof(TrackPageView)) { } - - public override void OnActionExecuted(ActionExecutedContext filterContext) + public class TrackPageView : ActionFilterAttribute { - HttpRequest request = filterContext.HttpContext.Request; + private readonly IBackgroundTaskQueue _queue; + private readonly Config _config; - string doNotTrack = request.Headers["DNT"]; - if (string.IsNullOrEmpty(doNotTrack) || doNotTrack != "1") + public TrackPageView(IBackgroundTaskQueue queue, Config config) { - string title = (filterContext.Controller as Controller)?.ViewBag?.Title; + _queue = queue; + _config = config; + } - string sub = filterContext.RouteData.Values["sub"].ToString(); - if (string.IsNullOrEmpty(sub)) + public override void OnActionExecuting(ActionExecutingContext filterContext) + { + } + + public override void OnActionExecuted(ActionExecutedContext filterContext) + { + HttpRequest request = filterContext.HttpContext.Request; + + string doNotTrack = request.Headers["DNT"]; + if (string.IsNullOrEmpty(doNotTrack) || doNotTrack != "1") { - sub = request.Host.ToUriComponent().GetSubdomain(); + string title = (filterContext.Controller as Controller)?.ViewBag?.Title; + + string sub = filterContext.RouteData.Values["sub"].ToString(); + if (string.IsNullOrEmpty(sub)) + { + sub = request.Host.ToUriComponent().GetSubdomain(); + } + + string clientIp = request.ClientIPFromRequest(true); + + string url = UriHelper.GetEncodedUrl(request); + + string urlReferrer = request.Headers["Referer"].ToString(); + + string userAgent = request.Headers["User-Agent"].ToString(); + + int pixelWidth = 0; + int pixelHeight = 0; + + bool hasCookies = false; + + string acceptLang = request.Headers["Accept-Language"]; + + bool hasJava = false; + + // Fire and forget. Don't need to wait for it. + _queue.QueueBackgroundWorkItem(async token => + { + Tracking.Tracking.TrackPageView(filterContext.HttpContext, _config, title, sub, clientIp, url, urlReferrer, userAgent, pixelWidth, pixelHeight, hasCookies, acceptLang, hasJava); + }); } - - string clientIp = request.ClientIPFromRequest(true); - - string url = UriHelper.GetEncodedUrl(request); - - string urlReferrer = request.Headers["Referer"].ToString(); - - string userAgent = request.Headers["User-Agent"].ToString(); - - int pixelWidth = 0; - int pixelHeight = 0; - - bool hasCookies = false; - - string acceptLang = request.Headers["Accept-Language"]; - - bool hasJava = false; - - // Fire and forget. Don't need to wait for it. - Tracking.Tracking.TrackPageView(filterContext.HttpContext, _config, title, sub, clientIp, url, urlReferrer, userAgent, pixelWidth, pixelHeight, hasCookies, acceptLang, hasJava); } } } diff --git a/Teknik/Startup.cs b/Teknik/Startup.cs index 02be972..fa1c256 100644 --- a/Teknik/Startup.cs +++ b/Teknik/Startup.cs @@ -39,6 +39,7 @@ using Microsoft.AspNetCore.Routing; using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.AspNetCore.Authorization; using System.Text.Encodings.Web; +using Teknik.Tracking; namespace Teknik { @@ -96,10 +97,13 @@ namespace Teknik #endif }); + services.AddHostedService(); + services.AddSingleton(); + // Add Tracking Filter scopes - services.AddScoped(); + //services.AddScoped(); //services.AddScoped(); - services.AddScoped(); + //services.AddScoped(); // Create the Database Context services.AddDbContext(options => options diff --git a/Tracking/Tracking.csproj b/Tracking/Tracking.csproj index 0513e9a..abc18ba 100644 --- a/Tracking/Tracking.csproj +++ b/Tracking/Tracking.csproj @@ -13,6 +13,8 @@ + + diff --git a/Tracking/TrackingService.cs b/Tracking/TrackingService.cs new file mode 100644 index 0000000..fe81f0d --- /dev/null +++ b/Tracking/TrackingService.cs @@ -0,0 +1,48 @@ +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using Teknik.Logging; +using Teknik.Utilities; + +namespace Teknik.Tracking +{ + public class TrackingService : BackgroundService + { + private readonly ILogger _logger; + + public TrackingService(IBackgroundTaskQueue taskQueue, + ILogger logger) + { + TaskQueue = taskQueue; + _logger = logger; + } + + public IBackgroundTaskQueue TaskQueue { get; } + + protected async override Task ExecuteAsync(CancellationToken cancellationToken) + { + _logger.LogInformation("Queued Hosted Service is starting."); + + while (!cancellationToken.IsCancellationRequested) + { + var workItem = await TaskQueue.DequeueAsync(cancellationToken); + + try + { + await workItem(cancellationToken); + } + catch (Exception ex) + { + _logger.LogError(ex, + $"Error occurred executing {nameof(workItem)}."); + } + } + + _logger.LogInformation("Queued Hosted Service is stopping."); + } + } +} diff --git a/Utilities/BackgroundTaskQueue.cs b/Utilities/BackgroundTaskQueue.cs new file mode 100644 index 0000000..9c2907e --- /dev/null +++ b/Utilities/BackgroundTaskQueue.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Concurrent; +using System.Collections.Generic; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace Teknik.Utilities +{ + public class BackgroundTaskQueue : IBackgroundTaskQueue + { + private ConcurrentQueue> _workItems = + new ConcurrentQueue>(); + + private SemaphoreSlim _signal = new SemaphoreSlim(0); + + public void QueueBackgroundWorkItem( + Func workItem) + { + if (workItem == null) + { + throw new ArgumentNullException(nameof(workItem)); + } + + _workItems.Enqueue(workItem); + _signal.Release(); + } + + public async Task> DequeueAsync( + CancellationToken cancellationToken) + { + await _signal.WaitAsync(cancellationToken); + _workItems.TryDequeue(out var workItem); + + return workItem; + } + } +} diff --git a/Utilities/HostedService.cs b/Utilities/HostedService.cs new file mode 100644 index 0000000..0c0a839 --- /dev/null +++ b/Utilities/HostedService.cs @@ -0,0 +1,49 @@ +using Microsoft.Extensions.Hosting; +using System; +using System.Collections.Generic; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace Teknik.Utilities +{ + public abstract class HostedService : IHostedService + { + private Task _executingTask; + private CancellationTokenSource _cts; + + public Task StartAsync(CancellationToken cancellationToken) + { + // Create a linked token so we can trigger cancellation outside of this token's cancellation + _cts = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken); + + // Store the task we're executing + _executingTask = ExecuteAsync(_cts.Token); + + // If the task is completed then return it, otherwise it's running + return _executingTask.IsCompleted ? _executingTask : Task.CompletedTask; + } + + public async Task StopAsync(CancellationToken cancellationToken) + { + // Stop called without start + if (_executingTask == null) + { + return; + } + + // Signal cancellation to the executing method + _cts.Cancel(); + + // Wait until the task completes or the stop token triggers + await Task.WhenAny(_executingTask, Task.Delay(-1, cancellationToken)); + + // Throw if cancellation triggered + cancellationToken.ThrowIfCancellationRequested(); + } + + // Derived classes should override this and execute a long running method until + // cancellation is requested + protected abstract Task ExecuteAsync(CancellationToken cancellationToken); + } +} diff --git a/Utilities/IBackgroundTaskQueue.cs b/Utilities/IBackgroundTaskQueue.cs new file mode 100644 index 0000000..1aa7e57 --- /dev/null +++ b/Utilities/IBackgroundTaskQueue.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace Teknik.Utilities +{ + public interface IBackgroundTaskQueue + { + void QueueBackgroundWorkItem(Func workItem); + + Task> DequeueAsync( + CancellationToken cancellationToken); + } +}