From b44f7bc157daf8b31f1aed35565845826f8862d7 Mon Sep 17 00:00:00 2001 From: Azareal Date: Sat, 18 May 2019 10:33:35 +1000 Subject: [PATCH] Hide spammy referrers by default. Added the panel_statistics_spam_hide phrase. Added the panel_statistics_spam_show phrase. --- common/pages.go | 7 +++ langs/english.json | 3 + public/global.js | 16 +++++- routes/panel/analytics.go | 55 ++++++++++++------- templates/panel_analytics_referrers.html | 4 ++ templates/panel_analytics_time_range.html | 2 +- .../panel_analytics_time_range_month.html | 2 +- themes/cosora/public/panel.css | 8 +-- themes/nox/public/panel.css | 4 ++ themes/shadow/public/panel.css | 8 +-- themes/tempra_simple/public/panel.css | 9 +-- 11 files changed, 84 insertions(+), 34 deletions(-) diff --git a/common/pages.go b/common/pages.go index c27a5da7..c991ae5a 100644 --- a/common/pages.go +++ b/common/pages.go @@ -424,6 +424,13 @@ type PanelAnalyticsAgentsPage struct { TimeRange string } +type PanelAnalyticsReferrersPage struct { + *BasePanelPage + ItemList []PanelAnalyticsAgentsItem + TimeRange string + ShowSpam bool +} + type PanelAnalyticsRoutePage struct { *BasePanelPage Route string diff --git a/langs/english.json b/langs/english.json index 3e48ea91..89d28371 100644 --- a/langs/english.json +++ b/langs/english.json @@ -887,6 +887,9 @@ "panel_statistics_memory_head":"Memory Usage", "panel_statistics_active_memory_head":"Active Memory", + "panel_statistics_spam_hide":"Hide Spam", + "panel_statistics_spam_show":"Show Spam", + "panel_statistics_time_range_one_year":"1 year", "panel_statistics_time_range_three_months":"3 months", "panel_statistics_time_range_one_month":"1 month", diff --git a/public/global.js b/public/global.js index a4f06788..bb2cd9c3 100644 --- a/public/global.js +++ b/public/global.js @@ -885,9 +885,23 @@ function mainInit(){ }); // The time range selector for the time graphs in the Control Panel - $(".timeRangeSelector").change(function(){ + /*$(".timeRangeSelector").change(function(){ console.log("Changed the time range to " + this.options[this.selectedIndex].getAttribute("val")); window.location = this.form.getAttribute("action")+"?timeRange=" + this.options[this.selectedIndex].getAttribute("val"); // Do a redirect as a form submission refuses to work properly + });*/ + $(".autoSubmitRedirect").change(function(){ + let elems = this.form.elements; + let s = ""; + for(let i = 0; i < elems.length; i++) { + let elem = elems[i]; + if(elem.nodeName=="SELECT") { + s += elem.name + "=" + elem.options[elem.selectedIndex].getAttribute("val") + "&"; + } + // TODO: Implement other element types... + } + if(s.length > 0) s = "?" + s.substr(0, s.length-1); + + window.location = this.form.getAttribute("action") + s; // Do a redirect as a form submission refuses to work properly }); $(".unix_to_24_hour_time").each(function(){ diff --git a/routes/panel/analytics.go b/routes/panel/analytics.go index 6d3293e6..cd495dfa 100644 --- a/routes/panel/analytics.go +++ b/routes/panel/analytics.go @@ -6,6 +6,7 @@ import ( "log" "net/http" "strconv" + "strings" "time" c "github.com/Azareal/Gosora/common" @@ -238,7 +239,7 @@ func AnalyticsViews(w http.ResponseWriter, r *http.Request, user c.User) c.Route } pi := c.PanelAnalyticsStd{graph, viewItems, timeRange.Range, timeRange.Unit, ttime} - return renderTemplate("panel", w, r, basePage.Header, c.Panel{basePage, "panel_analytics_right","analytics","panel_analytics_views", pi}) + return renderTemplate("panel", w, r, basePage.Header, c.Panel{basePage, "panel_analytics_right", "analytics", "panel_analytics_views", pi}) } func AnalyticsRouteViews(w http.ResponseWriter, r *http.Request, user c.User, route string) c.RouteError { @@ -273,7 +274,7 @@ func AnalyticsRouteViews(w http.ResponseWriter, r *http.Request, user c.User, ro c.DebugLogf("graph: %+v\n", graph) pi := c.PanelAnalyticsRoutePage{basePage, c.SanitiseSingleLine(route), graph, viewItems, timeRange.Range} - return renderTemplate("panel", w, r, basePage.Header, c.Panel{basePage, "panel_analytics_right","analytics","panel_analytics_route_views", pi}) + return renderTemplate("panel", w, r, basePage.Header, c.Panel{basePage, "panel_analytics_right", "analytics", "panel_analytics_route_views", pi}) } func AnalyticsAgentViews(w http.ResponseWriter, r *http.Request, user c.User, agent string) c.RouteError { @@ -313,7 +314,7 @@ func AnalyticsAgentViews(w http.ResponseWriter, r *http.Request, user c.User, ag } pi := c.PanelAnalyticsAgentPage{basePage, agent, friendlyAgent, graph, timeRange.Range} - return renderTemplate("panel", w, r, basePage.Header, c.Panel{basePage, "panel_analytics_right","analytics","panel_analytics_agent_views", pi}) + return renderTemplate("panel", w, r, basePage.Header, c.Panel{basePage, "panel_analytics_right", "analytics", "panel_analytics_agent_views", pi}) } func AnalyticsForumViews(w http.ResponseWriter, r *http.Request, user c.User, sfid string) c.RouteError { @@ -356,7 +357,7 @@ func AnalyticsForumViews(w http.ResponseWriter, r *http.Request, user c.User, sf } pi := c.PanelAnalyticsAgentPage{basePage, sfid, forum.Name, graph, timeRange.Range} - return renderTemplate("panel", w, r, basePage.Header, c.Panel{basePage, "panel_analytics_right","analytics","panel_analytics_forum_views", pi}) + return renderTemplate("panel", w, r, basePage.Header, c.Panel{basePage, "panel_analytics_right", "analytics", "panel_analytics_forum_views", pi}) } func AnalyticsSystemViews(w http.ResponseWriter, r *http.Request, user c.User, system string) c.RouteError { @@ -395,7 +396,7 @@ func AnalyticsSystemViews(w http.ResponseWriter, r *http.Request, user c.User, s } pi := c.PanelAnalyticsAgentPage{basePage, system, friendlySystem, graph, timeRange.Range} - return renderTemplate("panel", w, r, basePage.Header, c.Panel{basePage, "panel_analytics_right","analytics","panel_analytics_system_views", pi}) + return renderTemplate("panel", w, r, basePage.Header, c.Panel{basePage, "panel_analytics_right", "analytics", "panel_analytics_system_views", pi}) } func AnalyticsLanguageViews(w http.ResponseWriter, r *http.Request, user c.User, lang string) c.RouteError { @@ -435,7 +436,7 @@ func AnalyticsLanguageViews(w http.ResponseWriter, r *http.Request, user c.User, } pi := c.PanelAnalyticsAgentPage{basePage, lang, friendlyLang, graph, timeRange.Range} - return renderTemplate("panel", w, r, basePage.Header, c.Panel{basePage, "panel_analytics_right","analytics","panel_analytics_lang_views", pi}) + return renderTemplate("panel", w, r, basePage.Header, c.Panel{basePage, "panel_analytics_right", "analytics", "panel_analytics_lang_views", pi}) } func AnalyticsReferrerViews(w http.ResponseWriter, r *http.Request, user c.User, domain string) c.RouteError { @@ -467,7 +468,7 @@ func AnalyticsReferrerViews(w http.ResponseWriter, r *http.Request, user c.User, graph := c.PanelTimeGraph{Series: [][]int64{viewList}, Labels: labelList} c.DebugLogf("graph: %+v\n", graph) pi := c.PanelAnalyticsAgentPage{basePage, c.SanitiseSingleLine(domain), "", graph, timeRange.Range} - return renderTemplate("panel", w, r, basePage.Header, c.Panel{basePage, "panel_analytics_right","analytics","panel_analytics_referrer_views", pi}) + return renderTemplate("panel", w, r, basePage.Header, c.Panel{basePage, "panel_analytics_right", "analytics", "panel_analytics_referrer_views", pi}) } func AnalyticsTopics(w http.ResponseWriter, r *http.Request, user c.User) c.RouteError { @@ -500,7 +501,7 @@ func AnalyticsTopics(w http.ResponseWriter, r *http.Request, user c.User) c.Rout graph := c.PanelTimeGraph{Series: [][]int64{viewList}, Labels: labelList} c.DebugLogf("graph: %+v\n", graph) pi := c.PanelAnalyticsStd{graph, viewItems, timeRange.Range, timeRange.Unit, "time"} - return renderTemplate("panel", w, r, basePage.Header, c.Panel{basePage, "panel_analytics_right","analytics","panel_analytics_topics", pi}) + return renderTemplate("panel", w, r, basePage.Header, c.Panel{basePage, "panel_analytics_right", "analytics", "panel_analytics_topics", pi}) } func AnalyticsPosts(w http.ResponseWriter, r *http.Request, user c.User) c.RouteError { @@ -533,7 +534,7 @@ func AnalyticsPosts(w http.ResponseWriter, r *http.Request, user c.User) c.Route graph := c.PanelTimeGraph{Series: [][]int64{viewList}, Labels: labelList} c.DebugLogf("graph: %+v\n", graph) pi := c.PanelAnalyticsStd{graph, viewItems, timeRange.Range, timeRange.Unit, "time"} - return renderTemplate("panel", w, r, basePage.Header, c.Panel{basePage, "panel_analytics_right","analytics","panel_analytics_posts", pi}) + return renderTemplate("panel", w, r, basePage.Header, c.Panel{basePage, "panel_analytics_right", "analytics", "panel_analytics_posts", pi}) } func AnalyticsMemory(w http.ResponseWriter, r *http.Request, user c.User) c.RouteError { @@ -568,7 +569,7 @@ func AnalyticsMemory(w http.ResponseWriter, r *http.Request, user c.User) c.Rout graph := c.PanelTimeGraph{Series: [][]int64{avgList}, Labels: labelList} c.DebugLogf("graph: %+v\n", graph) pi := c.PanelAnalyticsStdUnit{graph, avgItems, timeRange.Range, timeRange.Unit, "time"} - return renderTemplate("panel", w, r, basePage.Header, c.Panel{basePage, "panel_analytics_right","analytics","panel_analytics_memory", pi}) + return renderTemplate("panel", w, r, basePage.Header, c.Panel{basePage, "panel_analytics_right", "analytics", "panel_analytics_memory", pi}) } // TODO: Show stack and heap memory separately on the chart @@ -604,7 +605,7 @@ func AnalyticsActiveMemory(w http.ResponseWriter, r *http.Request, user c.User) graph := c.PanelTimeGraph{Series: [][]int64{avgList}, Labels: labelList} c.DebugLogf("graph: %+v\n", graph) pi := c.PanelAnalyticsStdUnit{graph, avgItems, timeRange.Range, timeRange.Unit, "time"} - return renderTemplate("panel", w, r, basePage.Header, c.Panel{basePage, "panel_analytics_right","analytics","panel_analytics_active_memory", pi}) + return renderTemplate("panel", w, r, basePage.Header, c.Panel{basePage, "panel_analytics_right", "analytics", "panel_analytics_active_memory", pi}) } func analyticsRowsToNameMap(rows *sql.Rows) (map[string]int, error) { @@ -784,7 +785,7 @@ func AnalyticsForums(w http.ResponseWriter, r *http.Request, user c.User) c.Rout } pi := c.PanelAnalyticsDuoPage{basePage, forumItems, graph, timeRange.Range} - return renderTemplate("panel", w, r, basePage.Header, c.Panel{basePage, "panel_analytics_right","analytics","panel_analytics_forums", pi}) + return renderTemplate("panel", w, r, basePage.Header, c.Panel{basePage, "panel_analytics_right", "analytics", "panel_analytics_forums", pi}) } func AnalyticsRoutes(w http.ResponseWriter, r *http.Request, user c.User) c.RouteError { @@ -839,7 +840,7 @@ func AnalyticsRoutes(w http.ResponseWriter, r *http.Request, user c.User) c.Rout } pi := c.PanelAnalyticsRoutesPage{basePage, routeItems, graph, timeRange.Range} - return renderTemplate("panel", w, r, basePage.Header, c.Panel{basePage, "panel_analytics_right","analytics","panel_analytics_routes", pi}) + return renderTemplate("panel", w, r, basePage.Header, c.Panel{basePage, "panel_analytics_right", "analytics", "panel_analytics_routes", pi}) } // Trialling multi-series charts @@ -904,7 +905,7 @@ func AnalyticsAgents(w http.ResponseWriter, r *http.Request, user c.User) c.Rout } pi := c.PanelAnalyticsDuoPage{basePage, agentItems, graph, timeRange.Range} - return renderTemplate("panel", w, r, basePage.Header, c.Panel{basePage, "panel_analytics_right","analytics","panel_analytics_agents", pi}) + return renderTemplate("panel", w, r, basePage.Header, c.Panel{basePage, "panel_analytics_right", "analytics", "panel_analytics_agents", pi}) } func AnalyticsSystems(w http.ResponseWriter, r *http.Request, user c.User) c.RouteError { @@ -968,7 +969,7 @@ func AnalyticsSystems(w http.ResponseWriter, r *http.Request, user c.User) c.Rou } pi := c.PanelAnalyticsDuoPage{basePage, systemItems, graph, timeRange.Range} - return renderTemplate("panel", w, r, basePage.Header, c.Panel{basePage, "panel_analytics_right","analytics","panel_analytics_systems", pi}) + return renderTemplate("panel", w, r, basePage.Header, c.Panel{basePage, "panel_analytics_right", "analytics", "panel_analytics_systems", pi}) } func AnalyticsLanguages(w http.ResponseWriter, r *http.Request, user c.User) c.RouteError { @@ -1033,9 +1034,11 @@ func AnalyticsLanguages(w http.ResponseWriter, r *http.Request, user c.User) c.R } pi := c.PanelAnalyticsDuoPage{basePage, langItems, graph, timeRange.Range} - return renderTemplate("panel", w, r, basePage.Header, c.Panel{basePage, "panel_analytics_right","analytics","panel_analytics_langs", pi}) + return renderTemplate("panel", w, r, basePage.Header, c.Panel{basePage, "panel_analytics_right", "analytics", "panel_analytics_langs", pi}) } +var spamDomains = []string{"porn", "sexy"} + func AnalyticsReferrers(w http.ResponseWriter, r *http.Request, user c.User) c.RouteError { basePage, ferr := buildBasePage(w, r, &user, "analytics", "analytics") if ferr != nil { @@ -1054,16 +1057,30 @@ func AnalyticsReferrers(w http.ResponseWriter, r *http.Request, user c.User) c.R if err != nil { return c.InternalError(err, w, r) } + showSpam := r.FormValue("spam") == "1" + + var isSpammy = func(domain string) bool { + for _, substr := range spamDomains { + if strings.Contains(domain, substr) { + return true + } + } + return false + } // TODO: Sort this slice var refItems []c.PanelAnalyticsAgentsItem for domain, count := range refMap { + sdomain := c.SanitiseSingleLine(domain) + if !showSpam && isSpammy(sdomain) { + continue + } refItems = append(refItems, c.PanelAnalyticsAgentsItem{ - Agent: c.SanitiseSingleLine(domain), + Agent: sdomain, Count: count, }) } - pi := c.PanelAnalyticsAgentsPage{basePage, refItems, timeRange.Range} - return renderTemplate("panel", w, r, basePage.Header, c.Panel{basePage, "panel_analytics_right","analytics","panel_analytics_referrers", pi}) + pi := c.PanelAnalyticsReferrersPage{basePage, refItems, timeRange.Range, showSpam} + return renderTemplate("panel", w, r, basePage.Header, c.Panel{basePage, "panel_analytics_right", "analytics", "panel_analytics_referrers", pi}) } diff --git a/templates/panel_analytics_referrers.html b/templates/panel_analytics_referrers.html index 24cc9381..400108fa 100644 --- a/templates/panel_analytics_referrers.html +++ b/templates/panel_analytics_referrers.html @@ -1,6 +1,10 @@

{{lang "panel_statistics_referrers_head"}}

+ {{template "panel_analytics_time_range.html" . }}
diff --git a/templates/panel_analytics_time_range.html b/templates/panel_analytics_time_range.html index a08d6ea8..7294040c 100644 --- a/templates/panel_analytics_time_range.html +++ b/templates/panel_analytics_time_range.html @@ -1,4 +1,4 @@ - diff --git a/templates/panel_analytics_time_range_month.html b/templates/panel_analytics_time_range_month.html index e448432e..50833a9b 100644 --- a/templates/panel_analytics_time_range_month.html +++ b/templates/panel_analytics_time_range_month.html @@ -1,4 +1,4 @@ - diff --git a/themes/cosora/public/panel.css b/themes/cosora/public/panel.css index 0690f59f..44a1eda8 100644 --- a/themes/cosora/public/panel.css +++ b/themes/cosora/public/panel.css @@ -353,6 +353,9 @@ .analytics .colstack_head h1 { margin-top: 2px; } +.spamSelector + .timeRangeSelector { + margin-left: 8px; +} /* Experimental header tweaks */ .colstack_head a { @@ -369,10 +372,7 @@ display: flex; width: 100%; } -#widgetTmpl { - display: none; -} -.widget_disabled { +#widgetTmpl, .widget_disabled { display: none; } .bg_red .widget_disabled { diff --git a/themes/nox/public/panel.css b/themes/nox/public/panel.css index 47f072c0..4e84b114 100644 --- a/themes/nox/public/panel.css +++ b/themes/nox/public/panel.css @@ -172,6 +172,10 @@ button, .formbutton, .panel_right_button:not(.has_inner_button), #panel_users .p color: rgb(200,200,200); }*/ +.spamSelector + .timeRangeSelector { + margin-left: 8px; +} + .colstack_graph_holder { background-color: #444444; border-radius: 3px; diff --git a/themes/shadow/public/panel.css b/themes/shadow/public/panel.css index e5a5c27f..47725998 100644 --- a/themes/shadow/public/panel.css +++ b/themes/shadow/public/panel.css @@ -129,11 +129,11 @@ .ct-series-a .ct-bar, .ct-series-a .ct-line, .ct-series-a .ct-point, .ct-series-a .ct-slice-donut { stroke: hsl(359,98%,43%) !important; } - -#widgetTmpl { - display: none; +.spamSelector + .timeRangeSelector { + margin-left: 8px; } -.widget_disabled { + +#widgetTmpl, .widget_disabled { display: none; } .bg_red .widget_disabled { diff --git a/themes/tempra_simple/public/panel.css b/themes/tempra_simple/public/panel.css index ccf7fb3d..ae981722 100644 --- a/themes/tempra_simple/public/panel.css +++ b/themes/tempra_simple/public/panel.css @@ -162,6 +162,7 @@ padding-left: 2px; padding-right: 2px; } + .ct_chart { padding-left: 10px; padding-top: 14px; @@ -172,11 +173,11 @@ background-color: white; border: 1px solid hsl(0,0%,85%); } - -#widgetTmpl { - display: none; +.spamSelector + .timeRangeSelector { + margin-left: 8px; } -.widget_disabled { + +#widgetTmpl, .widget_disabled { display: none; } .bg_red .widget_disabled {