Commit f2c79a9f authored by Timo Teräs's avatar Timo Teräs

Sort history by date.

Fix also some white space stuff (cleaned up automatically by my
editor).
parent a4762be0
......@@ -93,13 +93,13 @@ local createdatabase = function(password)
f = io.popen(cmd)
table.insert(result, f:read("*a"))
f:close()
-- Create the database
cmd = path..'psql -U postgres -c "CREATE DATABASE '..DatabaseName..' WITH OWNER '..DatabaseOwner..'" 2>&1'
f = io.popen(cmd)
table.insert(result, f:read("*a"))
f:close()
return table.concat(result, "\n")
end
......@@ -119,7 +119,7 @@ local deletedatabase = function()
f = io.popen(cmd)
table.insert(result, f:read("*a"))
f:close()
return table.concat(result, "\n")
end
......@@ -168,7 +168,7 @@ end
local listhistorylogentries = function()
local entries = {}
-- retrieve a cursor
cur = assert (con:execute"SELECT logdatetime, msgtext from dbhistlog")
cur = assert (con:execute"SELECT logdatetime, msgtext from dbhistlog ORDER BY logdatetime")
row = cur:fetch ({}, "a")
while row do
entries[#entries+1] = {logdatetime = row.logdatetime, msgtext = row.msgtext}
......@@ -289,7 +289,7 @@ local importpubweblog = function()
"weblog.uri like (blocklog.uri || '%')"
res = assert (con:execute(sql))
logme("importpubweblog merged " .. res .. " blocks with matching timestamps.")
sql = "insert into weblog select * from blocklog where " ..
" NOT EXISTS (select * from weblog where " ..
"blocklog.logdatetime >= date_trunc('second', weblog.logdatetime) and " ..
......@@ -312,12 +312,12 @@ local importpubweblog = function()
res = assert (con:execute(sql))
logme("importpubweblog imported " .. res .. " new blocks into block table.")
-- grab the bypass info
-- grab the bypass info
sql = "insert into pubblocklog select * from weblog where uri like '%?GBYPASS%'"
res = assert (con:execute(sql))
logme("importpubweblog imported " .. res .. " dg bybass events into block table.")
-- Truncate the staging tables
-- Truncate the staging tables
assert (con:execute("truncate weblog"))
assert (con:execute("truncate blocklog"))
logme("truncated staging tables")
......@@ -366,7 +366,7 @@ local groompublogs = function()
local temp = config.auditstart
if not temp or temp == "" then temp = os.date("%Y-%m-%d %H:%M:%S") end
logme("Purge date since last audit is " .. tostring(watchdays+historydays) .. " days before " .. temp .. ".")
sql = "delete from pubweblog where logdatetime < (timestamp '"..temp.."' - INTERVAL '"..tostring(watchdays+historydays).." days')"
res = assert (con:execute(sql))
logme("removed " .. res .. " old pubweblog records that are older than history+watchdays")
......@@ -377,7 +377,7 @@ local groompublogs = function()
-- purge good people after historydays
logme("The delete date for non-watchlist users is " .. tostring(historydays) .. " days before " .. temp .. ".")
sql = "delete from pubweblog where logdatetime < (timestamp '".. temp.."' - INTERVAL '"..tostring(historydays).." days') and clientuserid NOT IN (select clientuserid from watchlist)"
res = assert (con:execute(sql))
logme("removed " .. res .. " records for users not on the watchlist.")
......@@ -581,7 +581,7 @@ local parsedglog = function(logdata)
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
end
......@@ -1022,7 +1022,7 @@ function deletewatchlistent(clientuserid)
if not res and err then
result.errtxt = result.errtxt .. "\n" .. err
end
return result
end
......@@ -1177,19 +1177,19 @@ local function validateconfig(newconfig)
elseif not validator.is_integer(newconfig.value.window.value) then
newconfig.value.window.errtxt = "Must be a number"
success = false
end
end
if not validator.is_integer(newconfig.value.watchdays.value) then
newconfig.value.watchdays.errtxt = "Must be a number"
success = false
end
end
if not validator.is_integer(newconfig.value.purgedays.value) then
newconfig.value.purgedays.errtxt = "Must be a number"
success = false
end
end
if not validator.is_integer(newconfig.value.historydays.value) then
newconfig.value.historydays.errtxt = "Must be a number"
success = false
end
end
local res, err = pcall(function()
databaseconnect(DatabaseUser)
local s
......@@ -1221,7 +1221,7 @@ function updateconfig(newconfig)
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 {}
else
......@@ -1348,7 +1348,7 @@ function create_database(database)
deletedatabase()
end
end
if not success then
database.errtxt = "Failed to create database"
if errtxt then
......
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