From 18ce55cc3fc0c6d1295b067d8b7ec6dd4a3461e3 Mon Sep 17 00:00:00 2001 From: Ted Trask Date: Thu, 18 Jun 2009 14:43:25 +0000 Subject: Added groupby option to allow to view audit by clientuserid or clientip. --- Makefile | 2 +- weblog-model.lua | 17 +++++++++++------ weblog-viewauditstats-html.lsp | 6 +++--- weblog-viewblocklog-html.lsp | 14 ++++++++++++-- 4 files changed, 27 insertions(+), 12 deletions(-) diff --git a/Makefile b/Makefile index b2e1be4..7829923 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ APP_NAME=weblog PACKAGE=acf-$(APP_NAME) -VERSION=0.1.0 +VERSION=0.2.0 APP_DIST=\ weblog* \ diff --git a/weblog-model.lua b/weblog-model.lua index aeb401e..1311d1a 100644 --- a/weblog-model.lua +++ b/weblog-model.lua @@ -452,16 +452,18 @@ local listpubweblogentries = function(...) return listlogentries("pubweblog", ...) end -local grouppubblocklogentries = function(starttime, endtime) +local grouppubblocklogentries = function(starttime, endtime, groupby) + groupby = groupby or "clientuserid" local entries = {} -- retrieve a cursor - local sql = "SELECT clientuserid, count(*) AS numblock, max(score) AS maxscore FROM pubblocklog" + local sql = "SELECT "..groupby..", count(*) AS numblock, max(score) AS maxscore FROM pubblocklog" sql = sql .. generatewhereclause(nil, starttime, endtime) - sql = sql .. " GROUP BY clientuserid ORDER BY numblock DESC" + sql = sql .. " GROUP BY "..groupby.. " ORDER BY numblock DESC" cur = assert (con:execute(sql)) row = cur:fetch ({}, "a") while row do - entries[#entries+1] = {clientuserid=row.clientuserid, numblock=row.numblock, maxscore=row.maxscore} + entries[#entries+1] = {numblock=row.numblock, maxscore=row.maxscore} + entries[#entries][groupby] = row[groupby] row = cur:fetch (row, "a") end -- close everything @@ -992,11 +994,12 @@ function getauditstats() local result = {} result.auditstart = cfe({ value=config.auditstart or "", label="Audit Start Time" }) result.auditend = cfe({ value=config.auditend or "", label="Audit End Time" }) + result.groupby = cfe({ value=config.groupby or "clientuserid", label="Group By" }) result.stats = cfe({ type="list", value={}, label="Audit Block Statistics" }) local res, err = pcall(function() if config.auditstart ~= "" and config.auditend ~= "" then databaseconnect(DatabaseUser) - result.stats.value = grouppubblocklogentries(config.auditstart, config.auditend) or {} + result.stats.value = grouppubblocklogentries(config.auditstart, config.auditend, result.groupby.value) or {} databasedisconnect() end end) @@ -1025,11 +1028,12 @@ function getconfig() result.watchdays = cfe({ value=config.watchdays or "14", label="Days to Watch", descr="Number of additional days to keep history for users in watchlist" }) result.purgedays = cfe({ value=config.purgedays or "30", label="Days before Purge", descr="Days to keep history, regardless of audit" }) result.historydays = cfe({ value=config.historydays or "14", label="Days to keep History", descr="Days beyond Audit Start Time to keep complete log history" }) + result.groupby = cfe({ type="select", value=config.groupby or "clientuserid", label="Group results by", option={"clientuserid", "clientip"} }) return cfe({ type="group", value=result, label="Weblog Config" }) end function updateconfig(newconfig) - local success = true + local success = modelfunctions.validateselect(newconfig.value.groupby) -- Validating a timestamp is going to be tricky, how about using postgres? if newconfig.value.window.value == "" then newconfig.value.window.errtxt = "Cannot be blank" @@ -1057,6 +1061,7 @@ function updateconfig(newconfig) configcontent = format.update_ini_file(configcontent, "", "watchdays", newconfig.value.watchdays.value) configcontent = format.update_ini_file(configcontent, "", "purgedays", newconfig.value.purgedays.value) configcontent = format.update_ini_file(configcontent, "", "historydays", newconfig.value.historydays.value) + configcontent = format.update_ini_file(configcontent, "", "groupby", newconfig.value.groupby.value) fs.write_file(configfile, configcontent) config = format.parse_ini_file(configcontent, "") or {} diff --git a/weblog-viewauditstats-html.lsp b/weblog-viewauditstats-html.lsp index 2b5d380..97d1f38 100644 --- a/weblog-viewauditstats-html.lsp +++ b/weblog-viewauditstats-html.lsp @@ -6,7 +6,7 @@ @@ -21,13 +21,13 @@

<%= html.html_escape(data.label) %>

- + <% for i,stat in ipairs(data.value.stats.value) do %> - + <% end %> diff --git a/weblog-viewblocklog-html.lsp b/weblog-viewblocklog-html.lsp index 1bbeda2..bff6667 100644 --- a/weblog-viewblocklog-html.lsp +++ b/weblog-viewblocklog-html.lsp @@ -35,6 +35,16 @@ +<% +local clientinfo = "" +if data.value.clientuserid.value ~= "" then + clientinfo = clientinfo .. "clientuserid="..data.value.clientuserid.value.."&" +end +if data.value.clientip.value ~= "" then + clientinfo = clientinfo .. "clientip="..data.value.clientip.value.."&" +end +%> +

<%= html.html_escape(data.label) %>

User ID<% if data.value.groupby.value == "clientip" then %>Client IP<% else %>User ID<% end %> Blocks Maximum Score
<%= html.link{value = "viewblocklog?clientuserid="..stat.clientuserid, label=stat.clientuserid} %>
<%= html.link{value = "viewblocklog?"..data.value.groupby.value.."="..stat[data.value.groupby.value], label=stat[data.value.groupby.value]} %> <%= html.html_escape(stat.numblock) %> <%= html.html_escape(stat.maxscore) %>
@@ -54,8 +64,8 @@ <% else %> <% end %> - -- cgit v1.2.3
<%= html.link{value = "viewweblog?clientuserid="..watch.clientuserid.. - "&starttime="..os.date("%Y-%m-%d %H:%M:%S", time - 60*(tonumber(data.value.window.value))).. + <%= html.link{value = "viewweblog?"..clientinfo.. + "starttime="..os.date("%Y-%m-%d %H:%M:%S", time - 60*(tonumber(data.value.window.value))).. "&endtime="..os.date("%Y-%m-%d %H:%M:%S", time + 60*(tonumber(data.value.window.value))).. "&focus="..watch.logdatetime, label=watch.logdatetime} %>