summaryrefslogtreecommitdiffstats
path: root/weblog-viewweblog-html.lsp
blob: 41931355207cb18f6a06bafa47b9615ac7d55444 (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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
<% local data, viewlibrary, page_info, session = ... %>
<% require("viewfunctions")%>

<%
-- 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" src="<%= html.html_escape(page_info.wwwprefix) %>/js/jquery-latest.js"></script>
<script type="text/javascript" src="<%= html.html_escape(page_info.wwwprefix) %>/js/jquery.tablesorter.js"></script>
<script type="text/javascript">
        $(document).ready(function() {
                $("#loglist").tablesorter({headers: {0:{sorter: false},1:{sorter: false}, 2:{sorter: 'text'}, 6:{sorter: false}, 7:{sorter: false}, 8:{sorter: false}}});
        });
        function hideColumn(myCol) {
        myCol.style.display = "none";
        };
</script>

<% if data.value.focus.value ~= "" then %>
<script type="text/javascript">
	$(function(){
	   	if ($("#focus").length) {
			var top = $("#focus").offset().top;
			$("html,body").scrollTop(top);
		}
	});
</script>
<% end %>

<% local subdata, pagedata = 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>
<% if data.errtxt then %><p class="error"><%= html.html_escape(data.errtxt) %></p><% end %>
<form action="<%= html.html_escape(page_info.script .. page_info.prefix .. page_info.controller .. "/" .. page_info.action) %>" method="POST">
<DT>Active Weblog</DT>
<DD><select name="activelog">
<option value="pubweblog">Current</option>
<option value="pubweblog_history"<% if data.value.activelog.value == "pubweblog_history" then %> selected="selected" <% end %> >History</option>
</select>  
</DD>
<DT>Start Time</DT>
<DD><input class="text" type="text" name="starttime" value="<%= html.html_escape(data.value.starttime.value) %>" >
<p><%= html.html_escape(data.value.starttime.value) %></p>
<% if data.value.starttime.errtxt then %><p class="error"><%= html.html_escape(data.value.starttime.errtxt) %></p><% end %>
</DD>
<DT>User ID</DT>
<DD><input class="text" type="text"  name="clientuserid"  value="<%= html.html_escape(data.value.clientuserid.value) %>" >
<p><%= html.html_escape(data.value.clientuserid.value) %></p>
<% if data.value.clientuserid.errtxt then %><p class="error"><%= html.html_escape(data.value.clientuserid.errtxt) %></p><% end %>
</DD>
<DT>Client IP</DT>
<DD><input class="text" type="text"  name="clientip"  value="<%= html.html_escape(data.value.clientip.value) %>" >
<p><%= html.html_escape(data.value.clientip.value) %></p>
<% if data.value.clientip.errtxt then %><p class="error"><%= html.html_escape(data.value.clientip.errtxt) %></p><% end %>
</DD>
<DT>End Time</DT>
<DD><input class="text" type="text"  name="endtime"  value="<%= html.html_escape(data.value.endtime.value) %>" >
<p><%= html.html_escape(data.value.endtime.value) %></p>
<% if data.value.endtime.errtxt then %><p class="error"><%= html.html_escape(data.value.endtime.errtxt) %></p><% end %>
</DD>
<DT>URI Contains</DT>
<DD><input class="text" type="text"  name="urisearch"  value="<%= html.html_escape(data.value.urisearch.value) %>" >
<P CLASS="descr">Retrieve records where the URI contains this word</P>
<p><%= html.html_escape(data.value.urisearch.value) %></p>
<% if data.value.urisearch.errtxt then %><p class="error"><%= html.html_escape(data.value.urisearch.errtxt) %></p><% end %>
</DD>
<DT>Minimum Score</DT>
<DD><input class="text" type="text"  name="score"  value="<%= html.html_escape(data.value.score.value) %>" >
<P CLASS="descr">Minimum score to search on</P>
<% if data.value.score.errtxt then %><p class="error"><%= html.html_escape(data.value.score.errtxt) %></p><% end %>
</DD>
<DT>Sort By</DT>
<DD><select name="sortby">
<option value="logdatetime"<% if data.value.log.value == "sortby" then %> selected="selected" <% end %> >Timestamp</option>
<option value="logdatetime DESC"<% if data.value.sortby.value == "logdatetime DESC" then %> selected="selected" <% end %> >Timestamp DESC</option>
<option value="clientuserid"<% if data.value.sortby.value == "clientuserid" then %> selected="selected" <% end %> >User ID</option>
<option value="clientuserid DESC"<% if data.value.sortby.value == "clientuserid DESC" then %> selected="selected" <% end %> >User ID DESC</option>
<option value="bytes"<% if data.value.sortby.value == "bytes" then %> selected="selected" <% end %> >Size</option>
<option value="bytes DESC"<% if data.value.sortby.value == "bytes DESC" then %> selected="selected" <% end %> >Size DESC</option>
<option value="score"<% if data.value.sortby.value == "score" then %> selected="selected" <% end %> >Score</option>
<option value="score DESC"<% if data.value.sortby.value == "score DESC" then %> selected="selected" <% end %> >Score DESC</option>
<option value="reason"<% if data.value.sortby.value == "reason" then %> selected="selected" <% end %> >Reason</option>
<option value="reason DESC"<% if data.value.sortby.value == "reason DESC" then %> selected="selected" <% end %> >Reason DESC</option>
</select>  
</DD>
<DT>Show Suspect Records</DT>
<DD>
<input class="checkbox" type="checkbox"  name="badyesno"  value="1" <% if data.value.badyesno.value == "1" then %> checked <% end %>>
<P CLASS="descr">Show only URIs containing flagged words</P>
<% if data.value.badyesno.errtxt then %><p class="error"><%= html.html_escape(data.value.badyesno.errtxt) %></p><% end %>
</DD>
<DT>Show Denied URIs</DT>
<DD>
<input class="checkbox" type="checkbox" name="deniedyesno" value="1" <% if data.value.deniedyesno.value == "1" then %>checked<% end %>>
<% if data.value.deniedyesno.errtxt then %><p class="error"><%= html.html_escape(data.value.deniedyesno.errtxt) %></p><% end %>
<P CLASS="descr">Show only Denied URIs</P>
</DD>
<DT>Show Bypass Attempts</DT>
<DD>
<input class="checkbox" type="checkbox"  name="bypassyesno"  value="1" <% if data.value.bypassyesno.value == "1" then %>checked <% end %>>
<% if data.value.bypassyesno.errtxt then %><p class="error"><%= html.html_escape(data.value.bypassyesno.errtxt) %></p><% end %>
<P CLASS="descr">Show only Bypass attempts</P>
</DD>
<DT>Show Selected Records</DT>
<DD>
<input class="checkbox" type="checkbox" name="selected" value="true" <% if data.value.selected.value == "true" then %>checked <% end %>>
<% if data.value.selected.errtxt then %><p class="error"><%= html.html_escape(data.value.selected.errtxt) %></p><% end %>
<P CLASS="descr">Show only records that have been selected</P>
</DD>
<DT></DT><DD><input class="submit" type="submit" name="Update" value="Update"></DD>
</FORM>
</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
%>

<% displaypagination(pagedata, page_info) %>
<H1><%= html.html_escape(data.label) %></H1>
<DL>
<TABLE id="loglist" class="tablesorter">
<THEAD>
<TR style=font-weight:bold;>
		<TH><input type="checkbox" id="chkHead" /></TH>
		<TH style="width:0%; display:none"></TH>
		<TH>Timestamp</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" value="true" <% if watch.selected == "t" then %> checked <% end %>></TD>
		<TD style="width:0%; display:none"><%= html.html_escape(watch.id) %></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 <% 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 == "1" 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><%= html.html_escape(watch.reason) %></TD>
		<TD style="word-wrap: break-word" width="500"><% highlight_uri=html.html_escape(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>
<% 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 %>
<DT>Download Options</DT>
<% if page_info.action == "viewweblog" then %>
<form action="<%= html.html_escape(page_info.script .. page_info.prefix .. page_info.controller .. "/downloadweblog") %>" method="POST">
<input type="hidden"  name="activelog" value="<%= html.html_escape(data.value.activelog.value) %>" >
<input type="hidden"  name="starttime" value="<%= html.html_escape(data.value.starttime.value) %>" >
<input type="hidden"  name="clientuserid" value="<%= html.html_escape(data.value.clientuserid.value) %>" >
<input type="hidden"  name="clientip" value="<%= html.html_escape(data.value.clientip.value) %>" >
<input type="hidden"  name="endtime" value="<%= html.html_escape(data.value.endtime.value) %>" >
<input type="hidden"  name="badyesno" value="<%= html.html_escape(data.value.badyesno.value) %>" >
<input type="hidden"  name="deniedyesno" value="<%= html.html_escape(data.value.deniedyesno.value) %>" >
<input type="hidden"  name="bypassyesno" value="<%= html.html_escape(data.value.bypassyesno.value) %>" >
<input type="hidden"  name="score" value="<%= html.html_escape(data.value.score.value) %>" >
<input type="hidden"  name="sortby" value="<%= html.html_escape(data.value.sortby.value) %>" >
<input type="hidden"  name="urisearch" value="<%= html.html_escape(data.value.urisearch.value) %>" >
<input type="hidden"  name="selected" value="<%= html.html_escape(data.value.selected.value) %>" >
<DD><input class="submit" type="submit" name="Download" value="Export List"></DD>
</form>
<% end %>

<script type="text/javascript">
	$('#chkHead').click(function () {
		if (this.checked == false) {
			$('.chktbl:checked').attr('checked', false);
		} else {
			$('.chktbl:not(:checked)').attr('checked', true);
		}
		if ($(this).attr("checked")==true) {
			$("#loglist").find('tr:not(#chktbl)').css("background-color","#FC9A01");
		} else {
			$("#loglist").find('tr:not(#chktbl)').css("background-color","#FFF");
		}
	});

	$('.chktbl').click(function () {
		if ($("chkHead").attr('checked') == true && this.checked == false) {
			var csv_data = "";
			var csv_cnt = 0;
			$(".chktbl").attr('checked',false);
			$(this).closest('tr').css("background-color","#ffffff");
			$(this).closest('tr').each(function () {
				$(this).find('td').each(function () {
					if (csv_cnt == 1) {
						document.viewweblog.chktbl.value = "false|" + $(this).text();
						return false;
					}
					csv_cnt +=1;
				});
			});
		}
		var selectdata = "";
		var deselectdata = "";
		if (this.checked == true) {
			$(this).closest('tr').css("background-color","#FC9A01");
			var csv_list = "";
			var csv_cnt = 0;
			$(this).closest('tr').each(function () {
				$(this).find('td').each(function () {
					if (csv_cnt == 1) {
						selectdata = $(this).text();
						//alert("this is: " + selectdata);
						return false;
					}
					csv_cnt +=1;
				});
			});
		} else {
			$(this).closest('tr').css("background-color","#ffffff");
			var csv_list = "";
			var csv_cnt = 0;
			$(this).closest('tr').each(function () {
				$(this).find('td').each(function () {
					if (csv_cnt == 1) {
						deselectdata = $(this).text();
						return false;
					}
					csv_cnt +=1;
				});
			});
		}
		$.getJSON(
			'<%= html.html_escape(page_info.script .. page_info.prefix .. page_info.controller .. "/updateselected") %>?viewtype=ajax&Submit=true&select='+selectdata+'&deselect='+deselectdata,
			function(data) {}
		);
	});
</script>
</DL>