From f1934028a11ccfa7d4cc587917f98c35af0d5018 Mon Sep 17 00:00:00 2001 From: sbwalker Date: Fri, 27 Feb 2026 14:15:03 -0500 Subject: [PATCH] use visitor tracking filter with url mapping --- Oqtane.Server/Components/App.razor | 58 +++++++++++++++++++++--------- 1 file changed, 41 insertions(+), 17 deletions(-) diff --git a/Oqtane.Server/Components/App.razor b/Oqtane.Server/Components/App.razor index a55b28a1..e9d09249 100644 --- a/Oqtane.Server/Components/App.razor +++ b/Oqtane.Server/Components/App.razor @@ -266,6 +266,30 @@ private void HandlePageNotFound(Site site, Page page, Route route) { + string useragent = (Context.Request.Headers[HeaderNames.UserAgent] != StringValues.Empty) ? Context.Request.Headers[HeaderNames.UserAgent] : "(none)"; + useragent = (useragent.Length > 256) ? useragent.Substring(0, 256) : useragent; + + // filter + var settings = Context.GetSiteSettings(); + var filter = settings.GetValue("VisitorFilter", Constants.DefaultVisitorFilter); + foreach (string term in filter.ToLower().Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(sValue => sValue.Trim()).ToArray()) + { + if (_remoteIPAddress.ToLower().Contains(term) || useragent.ToLower().Contains(term)) + { + // handle not found request in static mode + if (_renderMode == RenderModes.Static) + { + NavigationManager.NotFound(); + } + else + { + // redirect to 404 page + NavigationManager.NavigateTo(route.SiteUrl + "/404", true); + } + return; + } + } + // referrer will only be set if the link originated externally string referrer = (Context.Request.Headers[HeaderNames.Referer] != StringValues.Empty) ? Context.Request.Headers[HeaderNames.Referer] : ""; @@ -564,23 +588,6 @@ } } - private void SetLocalizationCookie(string cookieValue) - { - var cookieOptions = new Microsoft.AspNetCore.Http.CookieOptions - { - Expires = DateTimeOffset.UtcNow.AddYears(1), - SameSite = Microsoft.AspNetCore.Http.SameSiteMode.Lax, // Set SameSite attribute - Secure = true, // Ensure the cookie is only sent over HTTPS - HttpOnly = false // cookie is updated using JS Interop in Interactive render mode - }; - - Context.Response.Cookies.Append( - Shared.CookieRequestCultureProvider.DefaultCookieName, - cookieValue, - cookieOptions - ); - } - private async Task> GetPageResources(Alias alias, Site site, Page page, List modules, int moduleid, string action) { var resources = new List(); @@ -852,4 +859,21 @@ SetLocalizationCookie(cultureCookie); } } + + private void SetLocalizationCookie(string cookieValue) + { + var cookieOptions = new Microsoft.AspNetCore.Http.CookieOptions + { + Expires = DateTimeOffset.UtcNow.AddYears(1), + SameSite = Microsoft.AspNetCore.Http.SameSiteMode.Lax, // Set SameSite attribute + Secure = true, // Ensure the cookie is only sent over HTTPS + HttpOnly = false // cookie is updated using JS Interop in Interactive render mode + }; + + Context.Response.Cookies.Append( + Shared.CookieRequestCultureProvider.DefaultCookieName, + cookieValue, + cookieOptions + ); + } }