module(..., package.seeall) -- Load libraries require("controllerfunctions") default_action = "viewauditstats" function config(self) return controllerfunctions.handle_form(self, self.model.getconfig, self.model.updateconfig, self.clientdata, "Save", "Edit Configuration", "Configuration Saved") end function listsources(self) return self.model.getsourcelist() end function createsource(self) return controllerfunctions.handle_form(self, self.model.getnewsource, self.model.createsource, self.clientdata, "Create", "Create new source", "New source created") end function deletesource(self) return self:redirect_to_referrer(self.model.deletesource(self.clientdata.sourcename)) end function editsource(self) return controllerfunctions.handle_form(self, function() return self.model.getsource(self.clientdata.sourcename) end, self.model.updatesource, self.clientdata, "Save", "Edit Source", "Source Saved") end function testsource(self) return self:redirect_to_referrer(self.model.testsource(self.clientdata.sourcename)) end function importlogs(self) return self:redirect_to_referrer(self.model.importlogs()) end 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.clientuserid, self.clientdata.starttime, self.clientdata.endtime, self.clientdata.clientip, clientdata.focus) end function downloadweblog(self) self.conf.viewtype = "stream" local retval = viewweblog(self) local file = cfe({ type="longtext", value="", label=retval.value.clientuserid.value .. ".log" }) local content = {"sourcename\tclientip\tclientuserid\tlogdatetime\turi\tbytes\treason\tscore"} for i,log in ipairs(retval.value.log.value) do content[#content+1] = string.format("%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t", log.sourcename, log.clientip, log.clientuserid, log.logdatetime, log.uri, log.bytes, log.reason or "", log.score or "0") end file.value = table.concat(content, "\n") return file end function viewblocklog(self) return self.model.getblocklog(self.clientdata.clientuserid, self.clientdata.starttime, self.clientdata.endtime, self.clientdata.clientip, clientdata.focus) end function viewusagestats(self) return self.model.getusagestats() end function viewauditstats(self) return self.model.getauditstats() end function completeaudit(self) return self:redirect_to_referrer(self.model.completeaudit(self.clientdata.auditend)) end function adhocquery(self) return controllerfunctions.handle_form(self, self.model.getnewadhocquery, self.model.adhocquery, self.clientdata, "Submit", "Submit ad-hoc query") end function downloadadhocquery(self) self.conf.viewtype = "stream" local retval = self.model.getnewadhocquery() controllerfunctions.handle_clientdata(retval, self.clientdata) retval = self.model.adhocquery(retval) local file = cfe({ type="longtext", value="", label="query" }) if retval.value.result and #retval.value.result.value > 0 then local columns = {} for name,val in pairs(retval.value.result.value[1]) do columns[#columns+1] = name end local content = {table.concat(columns, "\t")} for i,entry in ipairs(retval.value.result.value) do local line = {} for i,name in ipairs(columns) do line[#line+1] = entry[name] or "" end content[#content+1] = table.concat(line, "\t") end file.value = table.concat(content, "\n") end return file end function status(self) return self.model.testdatabase() end function createdatabase(self) return controllerfunctions.handle_form(self, self.model.getnewdatabase, self.model.create_database, self.clientdata, "Create", "Create New Database", "Database Created") end