summaryrefslogtreecommitdiffstats
path: root/weblog-controller.lua
blob: 26a69ae3279c723853ceddc8ce6a6ca73749e58c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
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