Commit 18ce55cc authored by Ted Trask's avatar Ted Trask

Added groupby option to allow to view audit by clientuserid or clientip.

parent 290d71b1
APP_NAME=weblog
PACKAGE=acf-$(APP_NAME)
VERSION=0.1.0
VERSION=0.2.0
APP_DIST=\
weblog* \
......
......@@ -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 {}
......
......@@ -6,7 +6,7 @@
<script type="text/javascript" src="/js/jquery.tablesorter.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#audit").tablesorter();
$("#audit").tablesorter({headers: {1:{sorter:'digit'}, 2:{sorter:'digit'}}});
});
</script>
......@@ -21,13 +21,13 @@
<H1><%= html.html_escape(data.label) %></H1>
<TABLE id="audit" class="tablesorter"><THEAD>
<TR style="background:#eee;font-weight:bold;">
<TH>User ID</TH>
<TH><% if data.value.groupby.value == "clientip" then %>Client IP<% else %>User ID<% end %></TH>
<TH>Blocks</TH>
<TH>Maximum Score</TH>
</TR>
</THEAD><TBODY>
<% for i,stat in ipairs(data.value.stats.value) do %>
<TR><TD><%= html.link{value = "viewblocklog?clientuserid="..stat.clientuserid, label=stat.clientuserid} %></TD>
<TR><TD><%= html.link{value = "viewblocklog?"..data.value.groupby.value.."="..stat[data.value.groupby.value], label=stat[data.value.groupby.value]} %></TD>
<TD><%= html.html_escape(stat.numblock) %></TD>
<TD><%= html.html_escape(stat.maxscore) %></TD></TR>
<% end %>
......
......@@ -35,6 +35,16 @@
</DL>
</FORM>
<%
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
%>
<H1><%= html.html_escape(data.label) %></H1>
<TABLE>
<TR style="background:#eee;font-weight:bold;">
......@@ -54,8 +64,8 @@
<% else %>
<TR style="background:#eee">
<% end %>
<TD colspan=2><%= html.link{value = "viewweblog?clientuserid="..watch.clientuserid..
"&starttime="..os.date("%Y-%m-%d %H:%M:%S", time - 60*(tonumber(data.value.window.value)))..
<TD colspan=2><%= 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} %></TD>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment