Commit 8044a822 authored by Ted Trask's avatar Ted Trask

Added code to display short reason from DG log and shorten URI and fixed bug...

Added code to display short reason from DG log and shorten URI and fixed bug with empty reason. Bumped to 0.4.0
Required new shortreason field in several tables which breaks backward compatibility.
Full reason and full URI available by hovering.
parent 138ae855
APP_NAME=weblog
PACKAGE=acf-$(APP_NAME)
VERSION=0.3.2
VERSION=0.4.0
APP_DIST=\
weblog* \
......
......@@ -28,7 +28,7 @@ This form accepts a Postgresql SELECT statement and displays the results. Exampl
</ul>
The available database tables and descriptions are as follows:<br>
<H3>PubWeblog and PubBlocklog</H3>
These tables contain the combined squid access log and dansguardian log for every access and blocked accesses respectively. The definition of the table is as follows:
These tables contain the combined squid access log and dansguardian log for every access and blocked access respectively. The definition of the table is as follows:
<pre>
(
sourcename character varying(40),
......@@ -38,7 +38,8 @@ These tables contain the combined squid access log and dansguardian log for ever
uri text NOT NULL,
bytes integer NOT NULL,
reason text,
score integer
score integer,
shortreason text
)
</pre>
<H3>dbHistLog</H3>
......
......@@ -20,10 +20,10 @@ local config = format.parse_ini_file(configcontent, "") or {}
local database_creation_script = {
"CREATE TABLE dbhistlog (logdatetime timestamp(0) without time zone NOT NULL, msgtext text)",
"CREATE TABLE pubblocklog(sourcename character varying(40), clientip inet NOT NULL, clientuserid character varying(64) NOT NULL, logdatetime timestamp(3) without time zone NOT NULL, uri text NOT NULL, bytes integer NOT NULL, reason text, score integer)",
"CREATE TABLE blocklog(sourcename character varying(40), clientip inet NOT NULL, clientuserid character varying(64) NOT NULL, logdatetime timestamp(0) without time zone NOT NULL, uri text NOT NULL, bytes integer NOT NULL, reason text, score integer)",
"CREATE TABLE pubweblog(sourcename character varying(40), clientip inet NOT NULL, clientuserid character varying(64) NOT NULL, logdatetime timestamp(3) without time zone NOT NULL, uri text NOT NULL, bytes integer NOT NULL, reason text, score integer)",
"CREATE TABLE weblog(sourcename character varying(40), clientip inet NOT NULL, clientuserid character varying(64) NOT NULL, logdatetime timestamp(3) without time zone NOT NULL, uri text NOT NULL, bytes integer NOT NULL, reason text, score integer)",
"CREATE TABLE pubblocklog(sourcename character varying(40), clientip inet NOT NULL, clientuserid character varying(64) NOT NULL, logdatetime timestamp(3) without time zone NOT NULL, uri text NOT NULL, bytes integer NOT NULL, reason text, score integer, shortreason text)",
"CREATE TABLE blocklog(sourcename character varying(40), clientip inet NOT NULL, clientuserid character varying(64) NOT NULL, logdatetime timestamp(0) without time zone NOT NULL, uri text NOT NULL, bytes integer NOT NULL, reason text, score integer, shortreason text)",
"CREATE TABLE pubweblog(sourcename character varying(40), clientip inet NOT NULL, clientuserid character varying(64) NOT NULL, logdatetime timestamp(3) without time zone NOT NULL, uri text NOT NULL, bytes integer NOT NULL, reason text, score integer, shortreason text)",
"CREATE TABLE weblog(sourcename character varying(40), clientip inet NOT NULL, clientuserid character varying(64) NOT NULL, logdatetime timestamp(3) without time zone NOT NULL, uri text NOT NULL, bytes integer NOT NULL, reason text, score integer, shortreason text)",
"CREATE TABLE source (sourcename character varying(40) NOT NULL, method character varying(100) NOT NULL, userid character varying(32), passwd character varying(255), source character varying(255) NOT NULL, tzislocal boolean, enabled boolean)",
"CREATE TABLE usagestat (sourcename character varying(40) NOT NULL, date timestamp(0) without time zone NOT NULL, numrequest integer, numblock integer)",
"CREATE TABLE watchlist (clientuserid character varying(64) NOT NULL, expiredatetime timestamp(0) without time zone NOT NULL)",
......@@ -41,12 +41,12 @@ local database_creation_script = {
"CREATE INDEX weblogclientidx ON weblog USING btree (clientip, clientuserid)",
"CREATE INDEX weblogclientipidx ON weblog USING btree (clientip)",
"CREATE INDEX weblogclientuserididx ON weblog USING btree (clientuserid)",
"GRANT SELECT ON dbhistlog TO webloguser",
"GRANT SELECT ON pubblocklog TO webloguser",
"GRANT SELECT ON pubweblog TO webloguser",
"GRANT SELECT, UPDATE, INSERT, DELETE ON source TO webloguser",
"GRANT SELECT ON usagestat TO webloguser",
"GRANT SELECT, UPDATE, INSERT, DELETE ON watchlist TO webloguser",
"GRANT SELECT ON dbhistlog TO "..DatabaseUser,
"GRANT SELECT ON pubblocklog TO "..DatabaseUser,
"GRANT SELECT ON pubweblog TO "..DatabaseUser,
"GRANT SELECT, UPDATE, INSERT, DELETE ON source TO "..DatabaseUser,
"GRANT SELECT ON usagestat TO "..DatabaseUser,
"GRANT SELECT, UPDATE, INSERT, DELETE ON watchlist TO "..DatabaseUser,
}
-- ################################################################################
......@@ -189,9 +189,9 @@ end
local importdglog = function(logentries, sourcename)
for i,entry in pairs(logentries) do
local sql = string.format("INSERT INTO blocklog VALUES ('%s', '0.0.0.0', '%s', '%s', '%s', '%s', '%s', '%s')",
escape(sourcename), escape(entry.clientuserid:lower()), escape(entry.logdatetime),
escape(entry.URL), escape(entry.bytes), escape(entry.reason), escape(entry.score or "0"))
local sql = string.format("INSERT INTO blocklog VALUES ('%s', '0.0.0.0', '%s', '%s', '%s', '%s', '%s', '%s', '%s')",
escape(sourcename), escape(entry.clientuserid:lower()), escape(entry.logdatetime), escape(entry.URL),
escape(entry.bytes), escape(entry.reason), escape(entry.score or "0"), escape(entry.shortreason))
local res = assert (con:execute(sql))
end
end
......@@ -277,7 +277,7 @@ end
local importpubweblog = function()
-- Merge equal blocks into weblog
sql = "update weblog set reason=blocklog.reason, " ..
"score=blocklog.score from blocklog where " ..
"score=blocklog.score, shortreason=blocklog.shortreason from blocklog where " ..
"blocklog.logdatetime >= date_trunc('second', weblog.logdatetime) and " ..
"blocklog.logdatetime < (weblog.logdatetime + INTERVAL '45' second) and " ..
"blocklog.sourcename=weblog.sourcename and "..
......@@ -436,7 +436,7 @@ local listlogentries = function(logname, clientuserid, starttime, endtime, clien
cur = assert (con:execute(sql))
row = cur:fetch ({}, "a")
while row do
entries[#entries+1] = {sourcename=row.sourcename, clientip=row.clientip, clientuserid=row.clientuserid, logdatetime=row.logdatetime, uri=row.uri, bytes=row.bytes, reason=row.reason, score=row.score}
entries[#entries+1] = {sourcename=row.sourcename, clientip=row.clientip, clientuserid=row.clientuserid, logdatetime=row.logdatetime, uri=row.uri, bytes=row.bytes, reason=row.reason, score=row.score, shortreason=row.shortreason}
row = cur:fetch (row, "a")
end
-- close everything
......@@ -544,15 +544,15 @@ end
local parsedglog = function(logdata)
local logentries = {}
for line in string.gmatch(logdata, "[^\n]+") do
local words = {}
for word in string.gmatch(line, "[^\t]+") do
words[#words+1] = word
local words = format.string_to_table(line, "\t")
local logentry = {logdatetime=words[1], clientuserid=words[2], clientip=words[3], URL=words[4], reason=words[5], method=words[6], bytes=words[7], shortreason=words[9]}
if logentry.reason ~= "" then
if logentry.shortreason == "" then logentry.shortreason = logentry.reason end
logentry.score = string.match(logentry.reason, "^.*: ([0-9]*) ")
logentry.logdatetime = string.gsub(logentry.logdatetime, "%.", "-")
logentries[#logentries+1] = logentry
end
local logentry = {logdatetime=words[1], clientuserid=words[2], clientip=words[3], URL=words[4], reason=words[5], method=words[6], bytes=words[7]}
logentry.score = string.match(logentry.reason, "^.*: ([0-9]*) ")
logentry.logdatetime = string.gsub(logentry.logdatetime, "%.", "-")
logentries[#logentries+1] = logentry
end
return logentries
end
......
......@@ -54,7 +54,8 @@ end
<H1><%= html.html_escape(data.label) %></H1>
<TABLE>
<TR style="background:#eee;font-weight:bold;">
<TD style="padding-right:20px;white-space:nowrap;" class="header" colspan=2>Timestamp</TD>
<TD style="padding-right:20px;white-space:nowrap;" class="header">Timestamp</TD>
<TD style="padding-right:20px;white-space:nowrap;" class="header"></TD>
<TD style="padding-right:20px;white-space:nowrap;" class="header">Client IP</TD>
<TD style="padding-right:20px;white-space:nowrap;" class="header">User ID</TD>
<TD style="white-space:nowrap;" WIDTH="90%" class="header">Size</TD>
......@@ -79,10 +80,19 @@ end
<TD><%= html.html_escape(watch.clientuserid) %></TD>
<TD><%= html.html_escape(watch.bytes) %></TD>
</TR>
<TR><TD></TD><TD <% if string.find(watch.uri, "GBYPASS=") then %> style="background:#ee1" <% end %> colspan=4><%= html.link{value = watch.uri, label=watch.uri} %></TD></TR>
<% if watch.reason and watch.reason ~= "" then %>
<TR><TD></TD><TD style="background:#f33; color:#fff" colspan=4><%= html.html_escape(watch.reason) %></TD></TR>
<% end %>
<TR><TD></TD>
<TD <% if (watch.shortreason and watch.shortreason ~= "") or (watch.reason and watch.reason ~= "") then %>
style="background:#f33; color:#fff" title="<%= html.html_escape(watch.reason) %>"<% end %> colspan=3>
<% if watch.score and watch.score ~= "0" then %><%= html.html_escape(watch.score) %> - <% end %>
<% if (watch.shortreason and watch.shortreason ~= "") then %>
<%= html.html_escape(watch.shortreason) %>
<% elseif (watch.reason and watch.reason ~= "") then %>
<%= html.html_escape(string.gsub(watch.reason, "%(.*", "")) %>
<% end %>
</TD>
<TD <% if string.find(watch.uri, "GBYPASS=") then %> style="background:#ee1" <% end %>
title="<%= html.html_escape(watch.uri) %>" >
<%= html.link{value = watch.uri, label=string.gsub(watch.uri, "[;?].*", "...")} %></TD></TR>
<% end %>
</TABLE>
......
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