Commit c43001a6 authored by Ted Trask's avatar Ted Trask

Removed calls to redirect_to_referrer

parent 2f7c6b91
......@@ -15,7 +15,7 @@ function createsource(self)
end
function deletesource(self)
return self:redirect_to_referrer(self.model.deletesource(self.clientdata.sourcename))
return self.handle_form(self, self.model.getdeletesource, self.model.deletesource, self.clientdata, "Delete", "Delete source", "Source deleted")
end
function editsource(self)
......@@ -23,11 +23,11 @@ function editsource(self)
end
function testsource(self)
return self:redirect_to_referrer(self.model.testsource(self.clientdata.sourcename))
return self.handle_form(self, self.model.gettestsource, self.model.testsource, self.clientdata, "Test", "Test Source")
end
function importlogs(self)
return self:redirect_to_referrer(self.model.importlogs())
return self.handle_form(self, self.model.getimportlogs, self.model.importlogs, self.clientdata, "Import", "Import Logs")
end
function viewactivitylog(self)
......@@ -62,7 +62,7 @@ function updateselected(self)
end
function clearselected(self)
return self:redirect_to_referrer(self.model.clearselected())
return self.handle_form(self, self.model.getclearselected, self.model.clearselected, self.clientdata, "Clear", "Clear select fields", "Select fields cleared")
end
function viewusagestats(self)
......@@ -74,7 +74,7 @@ function viewauditstats(self)
end
function completeaudit(self)
return self:redirect_to_referrer(self.model.completeaudit(self.clientdata.auditend))
return self.handle_form(self, self.model.getcompleteaudit, self.model.completeaudit, self.clientdata, "Complete", "Complete Audit", "Audit completed")
end
function adhocquery(self)
......
......@@ -20,8 +20,8 @@ require("htmlviewfunctions")
<TR>
<TD style="padding-right:20px;white-space:nowrap;">
<%= html.link{value = "editsource?sourcename=" .. source.sourcename.."&redir="..page_info.orig_action, label="Edit "} %>
<%= html.link{value = "deletesource?sourcename=" .. source.sourcename, label="Delete "} %>
<%= html.link{value = "testsource?sourcename=" .. source.sourcename, label="Test "} %>
<%= html.link{value = "deletesource?submit=true&sourcename=" .. source.sourcename, label="Delete "} %>
<%= html.link{value = "testsource?submit=true&sourcename=" .. source.sourcename, label="Test "} %>
</TD>
<TD style="padding-right:20px;white-space:nowrap;"><%= html.html_escape(source.sourcename) %></TD>
<TD style="padding-right:20px;white-space:nowrap;"><%= html.html_escape(tostring(source.enabled)) %></TD>
......@@ -47,6 +47,6 @@ require("htmlviewfunctions")
<form action="<%= html.html_escape(page_info.script .. page_info.prefix .. page_info.controller .. "/importlogs") %>">
<DT>Import Logs</DT>
<DD><input class="submit" type="submit" value="Import"></DD>
<DD><input class="submit" type="submit" name="submit" value="Import"></DD>
</form>
</DL>
......@@ -799,43 +799,57 @@ function createsource(self, sourcedata)
return sourcedata
end
function deletesource(sourcename)
local result = cfe({ errtxt="Failed to delete source", label="Delete source result" })
function getdeletesource(self, clientdata)
local retval = {}
retval.sourcename = cfe({ value=clientdata.sourcename or "", label="Source Name" })
return cfe({ type="group", value=retval, label="Delete Source" })
end
function deletesource(self, delsource)
delsource.errtxt="Failed to delete source"
local res, err = pcall(function()
databaseconnect(DatabaseUser)
local number = deletesourceentry(sourcename)
local number = deletesourceentry(delsource.value.sourcename.value)
databasedisconnect()
if number > 0 then
result.errtxt = nil
result.value = "Source Deleted"
delsource.errtxt = nil
else
delsource.value.sourcename.errtxt = "Failed to find source"
end
end)
if not res and err then
result.errtxt = result.errtxt .. "\n" .. err
delsource.errtxt = delsource.errtxt .. "\n" .. err
end
return result
return delsource
end
function testsource(sourcename)
local result = cfe({ label="Test source result" })
function gettestsource(self, clientdata)
local retval = {}
retval.sourcename = cfe({ value=clientdata.sourcename or "", label="Source Name" })
return cfe({ type="group", value=retval, label="Test Source" })
end
function testsource(self, test)
-- temporary override of logme function to capture messages to result.value
result.value = {}
test.descr = {}
local temp = logme
logme = function(message) table.insert(result.value, message) end
logme = function(message) table.insert(test.descr.value, message) end
test.errtxt = "Test Failed"
local cookiesfile = "/tmp/cookies-"..tostring(os.time())
local res, err = pcall(function()
databaseconnect(DatabaseUser)
local sources = listsourceentries(sourcename)
local sources = listsourceentries(test.value.sourcename.value)
databasedisconnect()
if #sources < 1 then
result.errtxt = "Failed to find source"
test.value.sourcename.errtxt = "Failed to find source"
else
local source = sources[1]
-- run the test
if connecttosource(source, cookiesfile) then
local files = getlogcandidates(source, cookiesfile)
test.errtxt = nil
if #files == 0 then
logme("No log files found")
else
......@@ -846,19 +860,20 @@ function testsource(sourcename)
end
end
end)
if not res then
result.errtxt = "Failed to connect to source"
if err then
result.errtxt = result.errtxt .. "\n" .. err
end
if err and not res then
test.errtxt = test.errtxt .. "\n" .. err
end
os.remove(cookiesfile)
-- fix the result
result.value = table.concat(result.value, "\n") or ""
if test.errtxt then
test.descr = nil
else
test.descr = table.concat(test.descr, "\n") or ""
end
logme = temp
return result
return test
end
-- import a logfile and delete logfile after
......@@ -910,8 +925,12 @@ local function importlogfile(source, cookiesfile, file, parselog_func)
return res
end
function importlogs()
local result = cfe({ label="Weblog Import Logs Result" })
function getimportlogs(self, clientdata)
local retval = {}
return cfe({ type="group", value=retval, label="Import Logs" })
end
function importlogs(self, import)
local count = 0
local success = true
......@@ -965,17 +984,17 @@ function importlogs()
databasedisconnect()
end)
if not res or not success then
result.errtxt = "Import Logs Failure"
import.errtxt = "Import Logs Failure"
if err then
pcall(function() logme(err) end)
result.errtxt = result.errtxt .. "\n" .. err
import.errtxt = import.errtxt .. "\n" .. err
end
pcall(function() databasedisconnect() end)
else
import.descr = "Imported "..tostring(count).." logs"
end
result.value = "Imported "..tostring(count).." logs"
return result
return import
end
function getactivitylog()
......@@ -1018,19 +1037,24 @@ function editselected(self, data)
return data
end
function clearselected()
local retval = cfe({ label="Clear selected records" })
function getclearselected(self, clientdata)
local retval = {}
return cfe({ type="group", value=retval, label="Clear select fields" })
end
function clearselected(self, clear)
clear.errtxt = "Failed to clear select fields"
local res, err = pcall(function()
sql = "UPDATE pubweblog SET selected = false WHERE selected = true"
databaseconnect(DatabaseOwner)
assert (con:execute(sql))
databasedisconnect()
retval.value = "Cleared"
clear.errtxt = nil
end)
if not res then
retval.errtxt = err
clear.errtxt = clear.errtxt.."\n"..err
end
return retval
return clear
end
local validateweblogparameters = function(params)
......@@ -1139,18 +1163,25 @@ function getauditstats()
return cfe({ type="group", value=result, errtxt=err, label="Weblog Audit Statistics" })
end
function completeaudit(timestamp)
function getcompleteaudit(self, clientdata)
local retval = {}
retval.timestamp = cfe({ value=clientdata.timestamp or "", label="New Audit End Time" })
return cfe({ type="group", value=retval, label="Complete Audit" })
end
function completeaudit(self, complete)
if "" == complete.value.timestamp.value then
local now = os.time()
complete.value.timestamp.value = os.date("%Y-%m-%d %H:%M:%S", now - now%86400 - 86400)
end
local conf = getconfig()
conf.value.auditstart.value = conf.value.auditend.value
local now = os.time()
conf.value.auditend.value = timestamp or os.date("%Y-%m-%d %H:%M:%S", now - now%86400 - 86400)
conf.value.auditend.value = complete.value.timestamp.value
conf = updateconfig(self, conf)
local retval = cfe({ value="Audit completed", label="Complete Audit Result" })
if conf.errtxt then
retval.value = ""
retval.errtxt = "Failed to complete audit\n"..conf.errtxt.."\n"..conf.value.auditend.errtxt
complete.errtxt = "Failed to complete audit\n"..conf.errtxt.."\n"..conf.value.auditend.errtxt
end
return retval
return complete
end
function getconfig()
......
......@@ -54,6 +54,6 @@
<form action="<%= html.html_escape(page_info.script .. page_info.prefix .. page_info.controller .. "/completeaudit") %>">
<DT>Complete Audit</DT>
<DD><input class="submit" type="submit" value="Complete"></DD>
<DD><input class="submit" type="submit" name="submit" value="Complete"></DD>
</form>
</DL>
#!/bin/sh
/usr/share/acf/www/cgi-bin/cli weblog/weblog/importlogs
/usr/bin/acf-cli weblog/weblog/importlogs submit=true
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