summaryrefslogtreecommitdiffstats
path: root/weblog-controller.lua
blob: 20b31341485fe1fc4448f83dea549f3dc280356b (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
123
124
125
126
127
128
129
130
131
132
133
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.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

function downloadweblog(self)
	self.conf.viewtype = "stream"
	local retval = viewweblog(self)
	local file = cfe({ type="longtext", value="", label="Weblog-"..os.date()..".tab" })
	local content = {"sourcename\tclientuserid\tclientip\tlogdatetime\turi\tbytes\treason\tscore\treason\tbadyesno\tdeniedyesno\tbypassyesno"}
	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%s\t%s\t%s\t%s",
			log.sourcename, log.clientuserid, log.clientip, log.logdatetime, log.uri, log.bytes, log.reason, log.score, log.reason, log.badyesno, log.deniedyesno, log.bypassyesno)
	end
	file.value = table.concat(content, "\n")
	return file
end

function updateselected(self)
	return controllerfunctions.handle_form(self, self.model.geteditselected, self.model.editselected, self.clientdata, "Submit", "Submit select update", "Select fields updated")
end

function clearselected(self)
	 return self:redirect_to_referrer(self.model.clearselected())
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

function listfiles(self)
	return self.model.listfiles(self)
end

function editfile(self)
	return controllerfunctions.handle_form(self, function() return self.model.readfile(self.clientdata.filename) end, self.model.updatefile, self.clientdata, "Save", "Edit Weblog File", "Weblog File Saved" )
end