summaryrefslogtreecommitdiffstats
path: root/weblog-viewweblog-html.lsp
blob: 51c158d4c99d20748edff7ce20ce4b07dd87eab9 (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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
<% local data, viewlibrary, page_info, session = ... %>
<% htmlviewfunctions = require("htmlviewfunctions") %>
<% html = require("acf.html") %>
<% format = require("acf.format") %>

<%
-- Insert a string into another string
function string_insert(value, insert, place)
	if place == nil then
		place = string.len(value)+1
	end

	return string.sub(value, 1,place-1) .. tostring(insert) .. string.sub(value, place, string.len(value))
end

--Highlight occurences of a word in a string
function string_highlight(txtvalue, searchval, fcolour, bcolour)
	if txtvalue ~=nil and searchval ~= nil then
		sStart = string.find(string.lower(txtvalue),string.lower(searchval))
		if sStart ~= nil then
			sEnd = sStart + string.len(searchval)
			txtvalue = string_insert(txtvalue,"</font>", sEnd)
			txtvalue = string_insert(txtvalue,"<font style='color:"..fcolour.."; background-color:"..bcolour..";'>", sStart)
		end
	end 

	return txtvalue
end
%>

<script type="text/javascript">
	if (typeof jQuery == 'undefined') {
		document.write('<script type="text/javascript" src="<%= html.html_escape(page_info.wwwprefix) %>/js/jquery-latest.js"><\/script>');
	}
</script>

<script type="text/javascript">
	if (typeof $.tablesorter == 'undefined') {
		document.write('<script type="text/javascript" src="<%= html.html_escape(page_info.wwwprefix) %>/js/jquery.tablesorter.js"><\/script>');
	}
</script>

<script type="text/javascript">
	function clickhead(e) {
		var selectdata = "";
		var deselectdata = "";
		var array=[];
		$(".chktbl").each(function () {
			array.push(this.id);
		});
		if (this.checked == false) {
			$('.chktbl:checked').attr('checked', false);
			$("#loglist").find('tr:not(#chktbl)').css("background-color","#FFF");
			deselectdata = array.join("%0D%0A");
		} else {
			$('.chktbl:not(:checked)').attr('checked', true);
			$("#loglist").find('tr:not(#chktbl)').css("background-color","#FC9A01");
			selectdata = array.join("%0D%0A");
		}
		$.getJSON(
			'<%= html.html_escape(page_info.script .. page_info.prefix .. page_info.controller .. "/updateselected") %>?viewtype=json&Submit=true&select='+selectdata+'&deselect='+deselectdata,
			function(data) {}
		);
	}

	function clicktable(e) {
		var selectdata = "";
		var deselectdata = "";
		if (this.checked == true) {
			$(this).closest('tr').css("background-color","#FC9A01");
			selectdata = this.id;
		} else {
			// If clearing, clear the Head too
			$("#chkHead").attr("checked", false);
			$(this).closest('tr').css("background-color","#ffffff");
			deselectdata = this.id;
		}
		$.getJSON(
			'<%= html.html_escape(page_info.script .. page_info.prefix .. page_info.controller .. "/updateselected") %>?viewtype=json&Submit=true&select='+selectdata+'&deselect='+deselectdata,
			function(data) {}
		);
	}

	$(function(){
		$("#loglist").tablesorter({headers: {0:{sorter: false}, 1:{sorter: 'text'}, 5:{sorter: false}, 6:{sorter: false}, 7:{sorter: false}}});
		$('#chkHead').click(clickhead);
		$('.chktbl').click(clicktable);
<% if data.value.focus.value ~= "" then %>
		if ($("#focus").length) {
			var top = $("#focus").offset().top;
			$("html,body").scrollTop(top);
		}
<% end %>
	});
</script>

<% local subdata, pagedata = htmlviewfunctions.paginate(data.value.log.value, page_info.clientdata, 200) %>

<style type="text/css">
  #content table { border-collapse: collapse; width: 100%; }
  #content table td { border-bottom: none; white-space: normal; padding-right:20px; }
  #content table th { border-bottom: none; white-space: normal; vertical-align: middle; padding-right:15px }
  #content table tr.mark { background: #E9E9E9; }
  #content table tr.selected { background: #FC9A01; } 
</style>

<H1>Search Parameters</H1>
<DL>
<% -- Display the form, but skip log, window, and focus fields
local log = data.value.log
data.value.log = nil
local window = data.value.window
data.value.window = nil
local focus = data.value.focus
data.value.focus = nil
htmlviewfunctions.displayform(data, nil, nil, page_info, 2)
data.value.log = log
data.value.window = window
data.value.focus = focus
%>
</DL>

<%
local clientinfo = ""
if data.value.clientuserid.value ~= "" then
	clientinfo = clientinfo .. "clientuserid="..data.value.clientuserid.value.."&"
end
if data.value.clientip.value ~= "" then
	clientinfo = clientinfo .. "clientip="..data.value.clientip.value.."&"
end
%>

<% htmlviewfunctions.displaypagination(pagedata, page_info) %>
<H1><%= html.html_escape(data.label) %></H1>
<DL>
<TABLE id="loglist" class="tablesorter">
<THEAD>
<TR style=font-weight:bold;>
<% local checkhead = true
for i,watch in ipairs(subdata) do
	if watch.selected ~= "t" then
		checkhead = false
		break
	end
end %>
		<TH><input type="checkbox" id="chkHead"<% if checkhead then %> checked<% end %>></TH>
		<TH>Timestamp</TH>
		<TH>Source</TH>
		<TH>Client IP</TH>
		<TH>User ID</TH>
		<TH>Size</TH>
		<TH style=font-weight:bold >Sus</TH>
		<TH style=font-weight:bold >Den</TH>
		<TH style=font-weight:bold >Byp</TH>
		<TH>Score</TH>
		<TH>Reason</TH>
		<TH WIDTH="90%">URL</TH>
		<TH>Bad Words</TH>
	</TR>
</THEAD>
<TBODY>
<% for i,watch in ipairs(subdata) do
	local a,b = math.modf((i/2))
	local mark = ''
	if (b == 0) and watch.selected ~= "t" then mark=' class="mark"' end
	if watch.selected == "t" then mark=' class="selected"' end
	local time = {}
	time.year, time.month, time.day, time.hour, time.min, time.sec = 
		string.match(watch.logdatetime, "(%d+)%-(%d+)-(%d+)%s+(%d+):(%d+):(%d+)")
	time = os.time(time) %>
<TR<%= mark %>>
		<TD><input class="chktbl" type="checkbox" id="<%= html.html_escape(watch.id) %>"<% if watch.selected == "t" then %> checked <% end %>></TD>
		<TD <% if data.value.focus.value == watch.logdatetime then %> style="font-weight:bold;" id="focus" <% end %> ><%= html.link{value = "viewweblog?"..clientinfo..
			"starttime="..os.date("%Y-%m-%d %H:%M:%S", time - 60*(tonumber(data.value.window.value)))..
			"&endtime="..os.date("%Y-%m-%d %H:%M:%S", time + 60*(tonumber(data.value.window.value)))..
			"&focus="..watch.logdatetime,
			label=watch.logdatetime} %></TD>
		<TD> <%= html.html_escape(watch.sourcename) %></TD>
		<TD <% if data.value.clientip.value == watch.clientip then %> style="font-weight:bold;" <% end %> ><%= html.html_escape(watch.clientip) %></TD>
		<TD <% if data.value.clientuserid.value == watch.clientuserid then %> style="font-weight:bold;" <% end %> ><%= html.html_escape(watch.clientuserid) %></TD>
		<TD><%= html.html_escape(watch.bytes) %></TD>
		<TD WIDTH="2%"><% if watch.badyesno ~= "0" then %><IMG SRC='<%= html.html_escape(page_info.wwwprefix..page_info.staticdir) %>/dodgy.png' width='13' height='13'><% end %></TD>
		<TD WIDTH="2%"><% if watch.deniedyesno ~= "0" then %> <IMG SRC='<%= html.html_escape(page_info.wwwprefix..page_info.staticdir) %>/denied.png' width='13' height='13'><% end %></TD>
		<TD WIDTH="2%"><% if watch.bypassyesno ~= "0" then %> <IMG SRC='<%= html.html_escape(page_info.wwwprefix..page_info.staticdir) %>/bypass.png' width='13' height='13'><% end %></TD>   
		<TD><%= html.html_escape(watch.score) %></TD>
		<TD<% if (watch.shortreason and watch.shortreason ~= "" and watch.reason and watch.reason ~= "") then %> title="<%= html.html_escape(watch.reason) %>"<% end %>>
			<% if (watch.shortreason and watch.shortreason ~= "") then %>
				<%= html.html_escape(watch.shortreason) %>
			<% elseif (watch.reason and watch.reason ~= "") then %>
				<%= html.html_escape(watch.reason) %>
			<% end %>
		</TD>
		<TD style="word-wrap: break-word" width="500" title="<%= html.html_escape(watch.uri) %>"><% highlight_uri=html.html_escape(watch.shorturi or watch.uri)
		if watch.wordloc ~= nil then 
			if string.find(watch.wordloc, "|") then 
				badwords = format.string_to_table(watch.wordloc, "|")
				for key,wrd in ipairs(badwords) do
					highlight_uri = string_highlight(highlight_uri, wrd, "yellow", "red")
				end
			else
				highlight_uri = string_highlight(highlight_uri, watch.wordloc, "yellow", "red")
			end
		end %> 
		<%= highlight_uri %></TD>
		<TD><%= watch.wordloc %></TD>
</TR>
<% end %>
</TBODY>
</TABLE>
<% htmlviewfunctions.displaypagination(pagedata, page_info) %>

<% if data.errtxt then %>
<p class="error"><%= html.html_escape(data.errtxt) %></p>
<% end %>
<% if #data.value.log.value == 0 then %>
<p>No results, try adjusting search parameters</p>
<% end %>

<% if viewlibrary.check_permission("downloadweblog") then
data.action = "downloadweblog"
data.option = "Download"
data.value.log = nil
data.value.window = nil
data.value.focus = nil
data.value.viewtype = cfe({ value="stream" })
for n,v in pairs(data.value) do
	v.type = "hidden"
	v.checked = nil
end
htmlviewfunctions.displayform(data, nil, nil, page_info, 2)
end %>
</DL>