Commit bd9bd196 authored by Ted Trask's avatar Ted Trask

Removed watchlist functionality

parent 70aa9017
......@@ -108,13 +108,3 @@ This table contains a historical record of pages requested and blocked by hour.
numblock integer
)
</pre></DL>
<H3>Watchlist</H3>
<DL>
This table contains the user watch list. The definition of the table is as follows:
<pre>
(
clientuserid character varying(64) NOT NULL,
expiredatetime timestamp(0) without time zone NOT NULL
)
</pre></DL>
......@@ -37,18 +37,6 @@ function viewactivitylog(self)
return self.model.getactivitylog()
end
function viewwatchlist(self)
return self.model.getwatchlist()
end
function createwatchlistentry(self)
return controllerfunctions.handle_form(self, self.model.getnewwatchlistentry, self.model.createwatchlistentry, self.clientdata, "Create", "Create new watchlist entry", "New watchlist entry created")
end
function deletewatchlistentry(self)
return self:redirect_to_referrer(self.model.deletewatchlistent(self.clientdata.clientuserid))
end
function viewweblog(self)
return self.model.getweblog(self.clientdata.activelog, self.clientdata.clientuserid, self.clientdata.starttime, self.clientdata.endtime, self.clientdata.clientip, self.clientdata.badyesno, self.clientdata.deniedyesno, self.clientdata.bypassyesno, self.clientdata.score, self.clientdata.urisearch, self.clientdata.sortby, self.clientdata.selected, clientdata.focus)
end
......
......@@ -32,7 +32,6 @@ local database_creation_script = {
"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 bigint NOT NULL, reason text, score integer, shortreason text, badyesno int, deniedyesno int, bypassyesno int, wordloc text, goodwordloc text, selected boolean, id serial)",
"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)",
"ALTER TABLE ONLY source ADD CONSTRAINT source_pkey PRIMARY KEY (sourcename)",
"CREATE INDEX dbhistlogdatetimeidx ON dbhistlog USING btree (logdatetime)",
"CREATE INDEX pubweblogclientdateidx ON pubweblog USING btree (logdatetime, clientuserid)",
......@@ -46,7 +45,6 @@ local database_creation_script = {
"GRANT SELECT ON pubweblog_history 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,
}
-- ################################################################################
......@@ -231,20 +229,6 @@ local deletesourceentry = function(sourcename)
return res
end
-- Add blocked users (from blocklog) to the watchlist, removing old entries if updated.
local addtowatchlist = function()
local watchdays = config.watchdays or 14
local sql = "insert into watchlist select clientuserid, " ..
"(max(logdatetime) + INTERVAL '"..watchdays.." days') as expiredatetime " ..
"from weblog where deniedyesno > '0' group by clientuserid"
local res1 = assert (con:execute(sql))
sql = "delete from watchlist where exists " ..
"(select * from watchlist w where w.clientuserid = watchlist.clientuserid " ..
"and w.expiredatetime > watchlist.expiredatetime)"
local res2 = assert (con:execute(sql))
logme("There are now " .. (res1-res2) .. " new names in the watchlist")
end
-- Generate usage statistics from weblog and blocklog
local updateusagestats = function()
-- update the usagestat table from weblog
......@@ -270,12 +254,6 @@ local importpubweblog = function()
logme("truncated staging table")
end
-- Delete people from the watchlist when they have expired out
local groomwatchlist = function()
local res = assert (con:execute("delete from watchlist where expiredatetime < now()"))
logme("removed " .. res .. " names from watchlist")
end
-- Delete useage stats from more than a year ago
local groomusagestat = function()
local res = assert (con:execute("delete from usagestat where " ..
......@@ -293,7 +271,6 @@ end
-- Delete old junk from pub tables
local groompublogs = function()
local purgedays = config.purgedays or 30
--local watchdays = config.watchdays or 14
local now = os.time()
......@@ -310,33 +287,6 @@ local groompublogs = function()
logme("Deleted " .. res .. " old records to from pubweblog")
end
local listwatchlistentries = function()
local entries = {}
-- retrieve a cursor
cur = assert (con:execute("SELECT * from watchlist ORDER BY clientuserid"))
row = cur:fetch ({}, "a")
while row do
entries[#entries+1] = {clientuserid = row.clientuserid, expiredatetime= row.expiredatetime}
row = cur:fetch (row, "a")
end
-- close everything
cur:close()
return entries
end
local importwatchlistentry = function(clientuserid, expiredatetime)
local sql = string.format("INSERT INTO watchlist VALUES ('%s', '%s')",
escape(clientuserid), escape(expiredatetime))
local res = assert (con:execute(sql))
return res
end
local deletewatchlistentry = function(clientuserid)
local sql = string.format("DELETE FROM watchlist WHERE clientuserid='%s'", escape(clientuserid))
local res = assert (con:execute(sql))
return res
end
local generatewhereclause = function(clientuserid, starttime, endtime, clientip, badyesno, deniedyesno, bypassyesno, score, urisearch, selected)
local sql = ""
local where = {}
......@@ -1002,10 +952,8 @@ function importlogs()
-- Process the logs
if success then
addtowatchlist()
updateusagestats()
importpubweblog()
groomwatchlist()
end
-- Purge old database entries
groomusagestat()
......@@ -1042,102 +990,6 @@ function getactivitylog()
return retval
end
function getwatchlist()
local retval = cfe({ type="list", value={}, label="Weblog Watchlist" })
local res, err = pcall(function()
databaseconnect(DatabaseUser)
retval.value = listwatchlistentries() or {}
databasedisconnect()
end)
if not res then
retval.errtxt = err
end
return retval
end
function getnewwatchlistentry()
local watch = {}
watch.clientuserid = cfe({ label="User ID" })
local watchdays = config.watchdays or 14
watch.expiredatetime = cfe({ value=os.date("%Y-%m-%d %H:%M:%S", os.time() + watchdays*86400), label="Expiration Date" })
return cfe({ type="group", value=watch, label="Watchlist Entry" })
end
local function validatewatchlistentry(watch)
local success = true
for i,name in ipairs({"clientuserid", "expiredatetime"}) do
if watch.value[name].value == "" then
watch.value[name].errtxt = "Cannot be empty"
success = false
end
end
if not watch.value.expiredatetime.errtxt then
local res, err = pcall(function()
databaseconnect(DatabaseUser)
local s
s,watch.value.expiredatetime.errtxt = testdatabaseentry("TIMESTAMP", watch.value.expiredatetime.value)
databasedisconnect()
success = success and s
end)
if not res and err then
watch.value.expiredatetime.errtxt = err
success = false
end
end
return success
end
function createwatchlistentry(watch)
watch.value.clientuserid.value = watch.value.clientuserid.value:lower()
watch.errtxt = "Failed to create watchlist entry"
local success = validatewatchlistentry(watch)
if success then
local res, err = pcall(function()
databaseconnect(DatabaseUser)
local watchlist = listwatchlistentries() or {}
for i,w in ipairs(watchlist) do
if w.clientuserid == watch.value.clientuserid.value then
watch.value.clientuserid.errtxt = "User ID already exists"
success = false
break
end
end
if success then
local count = importwatchlistentry(watch.value.clientuserid.value, watch.value.expiredatetime.value)
if count > 0 then
watch.errtxt = nil
end
end
databasedisconnect()
end)
if not res and err then
watch.errtxt = watch.errtxt .. "\n" .. err
end
end
return watch
end
function deletewatchlistent(clientuserid)
local result = cfe({ errtxt="Failed to delete watchlist entry", label="Delete watchlist entry result" })
local res, err = pcall(function()
databaseconnect(DatabaseUser)
local number = deletewatchlistentry(clientuserid)
databasedisconnect()
if number > 0 then
result.value = "Watchlist entry deleted"
result.errtxt = nil
end
end)
if not res and err then
result.errtxt = result.errtxt .. "\n" .. err
end
return result
end
local validateparameters = function(params)
local success = true
if params.clientip.value ~= "" and string.find(params.clientip.value, "[^%d%.]") then
......@@ -1323,7 +1175,6 @@ function getconfig()
result.sortby = cfe({ type="select", value=config.sortby or "logdatetime", label="Sort By field", option={"logdatetime", "logdatetime DESC", "clientuserid", "clientuserid DESC", "clientip", "clientip DESC", "bytes", "bytes DESC", "score", "score DESC", "reason"}, seq=4 })
result.minimumscore = cfe({ value=config.minimumscore or "0", label="Minimum Score", descr="Minimum Score to search for", seq=5 })
result.window = cfe({ value=config.window or "5", label="Time Window", descr="Minutes of activity to display before and after selected block", seq=6 })
result.watchdays = cfe({ value=config.watchdays or "14", label="Days to Watch", descr="Number of additional days to keep history for users in watchlist", seq=9 })
result.purgedays = cfe({ value=config.purgedays or "30", label="Days before Purge", descr="Days to keep history, regardless of audit", seq=10 })
result.shorturi = cfe({ type="boolean", value=(config.shorturi == "true"), label="Truncate URLs", descr="You can limit the length of displayed URLs by enabling this option", seq=7 })
result.shortreason = cfe({ type="boolean", value=(config.shortreason == "true"), label="Short Reason", descr="Display a short reason (dansguardian only)", seq=8 })
......@@ -1340,10 +1191,6 @@ local function validateconfig(newconfig)
newconfig.value.window.errtxt = "Must be a number"
success = false
end
if not validator.is_integer(newconfig.value.watchdays.value) then
newconfig.value.watchdays.errtxt = "Must be a number"
success = false
end
if not validator.is_integer(newconfig.value.purgedays.value) then
newconfig.value.purgedays.errtxt = "Must be a number"
success = false
......@@ -1375,7 +1222,6 @@ function updateconfig(newconfig)
configcontent = format.update_ini_file(configcontent, "", "auditstart", newconfig.value.auditstart.value)
configcontent = format.update_ini_file(configcontent, "", "auditend", newconfig.value.auditend.value)
configcontent = format.update_ini_file(configcontent, "", "window", newconfig.value.window.value)
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, "", "groupby", newconfig.value.groupby.value)
configcontent = format.update_ini_file(configcontent, "", "shorturi", tostring(newconfig.value.shorturi.value))
......
<% local data, viewlibrary, page_info, session = ... %>
<% require("viewfunctions") %>
<script type="text/javascript" src="<%= html.html_escape(page_info.wwwprefix) %>/js/jquery-latest.js"></script>
<script type="text/javascript" src="<%= html.html_escape(page_info.wwwprefix) %>/js/jquery.tablesorter.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#watchlist").tablesorter({headers: {0:{sorter: false}}});
});
</script>
<% displaycommandresults({"deletewatchlistentry"}, session) %>
<% displaycommandresults({"createwatchlistentry"}, session, true) %>
<H1><%= html.html_escape(data.label) %></H1>
<DL>
<TABLE id="watchlist" class="tablesorter"><THEAD>
<TR style="background:#eee;font-weight:bold;">
<TH>Delete</TH>
<TH>User ID</TH>
<TH>Expiration Date</TH>
</TR>
</THEAD><TBODY>
<% for i,watch in ipairs(data.value) do %>
<TR>
<TD><%= html.link{value = "deletewatchlistentry?clientuserid="..watch.clientuserid, label="Delete "} %></TD>
<TD><%= html.link{value = "viewweblog?clientuserid="..watch.clientuserid, label=watch.clientuserid} %></TD>
<TD><%= html.html_escape(watch.expiredatetime) %></TD>
</TR>
<% end %>
</TBODY></TABLE>
<% if data.errtxt then %>
<p class='error'><%= html.html_escape(data.errtxt) %></p>
<% end %>
<% if #data.value == 0 then %>
<p>No watchlist entries found</p>
<% end %>
</DL>
<% if viewlibrary and viewlibrary.dispatch_component and viewlibrary.check_permission("createwatchlistentry") then
viewlibrary.dispatch_component("createwatchlistentry")
end %>
......@@ -4,7 +4,6 @@ Applications 41Weblog Audit viewauditstats
Applications 41Weblog View_Log viewweblog
Applications 41Weblog Config config
Applications 41Weblog File_List listfiles
Applications 41Weblog Watch_List viewwatchlist
Applications 41Weblog Sources listsources
Applications 41Weblog Usage viewusagestats
Applications 41Weblog History viewactivitylog
......
USER=weblog:viewauditstats,weblog:completeaudit,weblog:viewactivitylog,weblog:viewwatchlist,weblog:viewweblog,weblog:downloadweblog,weblog:viewusagestats,weblog:deletewatchlistentry,weblog:createwatchlistentry,weblog:adhocquery,weblog:downloadadhocquery,weblog:updateselected,weblog:clearselected
USER=weblog:viewauditstats,weblog:completeaudit,weblog:viewactivitylog,weblog:viewweblog,weblog:downloadweblog,weblog:viewusagestats,weblog:adhocquery,weblog:downloadadhocquery,weblog:updateselected,weblog:clearselected
EXPERT=weblog:config,weblog:listsources,weblog:createsource,weblog:deletesource,weblog:editsource,weblog:testsource,weblog:importlogs,weblog:status,weblog:createdatabase,weblog:listfiles,weblog:editfile
ADMIN=weblog:config,weblog:viewauditstats,weblog:completeaudit,weblog:viewactivitylog,weblog:viewwatchlist,weblog:viewweblog,weblog:downloadweblog,weblog:updateselected,weblog:clearselected,weblog:viewusagestats,weblog:listsources,weblog:createsource,weblog:deletesource,weblog:editsource,weblog:testsource,weblog:importlogs,weblog:deletewatchlistentry,weblog:createwatchlistentry,weblog:adhocquery,weblog:downloadadhocquery,weblog:status,weblog:createdatabase,weblog:listfiles,weblog:editfile
ADMIN=weblog:config,weblog:viewauditstats,weblog:completeaudit,weblog:viewactivitylog,weblog:viewweblog,weblog:downloadweblog,weblog:updateselected,weblog:clearselected,weblog:viewusagestats,weblog:listsources,weblog:createsource,weblog:deletesource,weblog:editsource,weblog:testsource,weblog:importlogs,weblog:adhocquery,weblog:downloadadhocquery,weblog:status,weblog:createdatabase,weblog:listfiles,weblog:editfile
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