-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathEventLog.php
320 lines (292 loc) · 11.4 KB
/
EventLog.php
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
312
313
314
315
316
317
318
319
320
<?php
include("inc/checkperm.inc");
get_request_values("id,cmd,submit,rowcount,sortorder,sortdesc,startingwith,start,prev,next,last,cond,EditMode,WithSelected,widemode,Field,_http_referer,export_results");
$orig_cmd=$cmd;
$f = new EventLogform;
$db = new DB_probind;
$db->ConnectFlag = MYSQL_CLIENT_INTERACTIVE;
class MyEventLogTable extends EventLogTable {
var $classname="MyEventLogTable";
function table_row_add_extra($row, $row_key, $data, $class="") {
global $sess, $auth, $perm;
echo "<td class=btable><a href=\"".$sess->url('EventLog.php').
$sess->add_query(array("cmd"=>"View","id"=>$data["id"]))."\">view</a>";
if (isset($data["ExtraInfo"])) {
if (strlen($data["ExtraInfo"])<300) {
echo " <a href=\"javascript:alert('";
echo htmlspecialchars(str_replace("\n","\\n",str_replace("'","`",$data["ExtraInfo"])),ENT_QUOTES,"UTF-8");
echo "');\">extra</a>";
}
}
echo "</td>";
}
}
if ($submit) {
switch ($submit) {
case "Save":
if ($id) $submit = "Edit";
else $submit = "Add";
case "Add":
case "Edit":
if (isset($auth)) {
check_edit_perms();
if (!$f->validate($result)) {
$cmd = $submit;
echo "<font class=bigTextBold>$cmd Event Log</font>\n";
$f->display();
page_close();
exit;
}
else
{
echo "Saving....";
$f->save_values();
echo "<b>Done!</b><br>\n";
echo "<META HTTP-EQUIV=REFRESH CONTENT=\"2; URL=".$sess->self_url()."\">";
echo " <a href=\"".$sess->self_url()."\">Back to EventLog.</a><br>\n";
page_close();
exit;
}
} else {
echo "You are not logged in....";
echo "<b>Aborted!</b><br>\n";
}
case "View":
case "Back":
echo "<META HTTP-EQUIV=REFRESH CONTENT=\"0; URL=".$sess->self_url()."\">";
echo " <a href=\"".$sess->self_url()."\">Back to EventLog.</a><br>\n";
page_close();
exit;
case "Delete":
if (isset($auth)) {
check_edit_perms();
echo "Deleting....";
$f->save_values();
echo "<b>Done!</b><br>\n";
} else {
echo "You are not logged in....";
echo "<b>Aborted!</b><br>\n";
}
echo "<META HTTP-EQUIV=REFRESH CONTENT=\"2; URL=".$sess->self_url()."\">";
echo " <a href=\"".$sess->self_url()."\">Back to EventLog.</a><br>\n";
page_close();
exit;
}
} else {
if ($id) {
$f->find_values($id);
}
}
switch ($cmd) {
case "View":
case "Delete":
$f->freeze();
case "Add":
case "Edit":
echo "<font class=bigTextBold>$cmd Event Log</font>\n";
$f->display();
break;
default:
$cmd="Query";
$t = new MyEventLogTable;
$t->heading = 'on';
$t->trust_the_data = true;
$t->add_extra = 'on';
$db = new DB_probind;
echo "<font class=bigTextBold>$cmd Event Log</font>\n";
get_request_values("SrchLevel,SrchProgram,SrchWebUser,SrchDesc,SrchDesc2,SrchExtra,EventTime,SrchIPAddr,hidehello,hidepoll");
if (!is_array($SrchLevel)) $SrchLevel=array("Info","Warning","Error");
#$sess->register("SrchLevel,SrchProgram,SrchWebUser,SrchDesc,hidepoll");
?>
<form name=EventLogform method=POST><br>
<input type=checkbox <?php if (in_array("Info",$SrchLevel)) echo "checked"; ?> name=SrchLevel[] value=Info>Info
<input type=checkbox <?php if (in_array("Warning",$SrchLevel)) echo "checked"; ?> name=SrchLevel[] value=Warning>Warning
<input type=checkbox <?php if (in_array("Error",$SrchLevel)) echo "checked"; ?> name=SrchLevel[] value=Error>Error
<input type=checkbox <?php if (in_array("Debug",$SrchLevel)) echo "checked"; ?> name=SrchLevel[] value=Debug>Debug
<br>
<!--
Description <select name=SrchDesc>
<option value=''>Any
<option <?php if ($SrchDesc=='SQL') echo 'selected'; ?> value='SQL'>SQL Adds/Edits/Deletes
<option <?php if ($SrchDesc=='IPN') echo 'selected'; ?> value='IPN'>PayPal IPNs
<option <?php if ($SrchDesc=='logged in') echo 'selected'; ?> value='logged in'>Logins
<option <?php if ($SrchDesc=='Exceeded Usage') echo 'selected'; ?> value='Exceeded Usage'>Exceeded Limits
<option <?php if ($SrchDesc=='Client Purchase') echo 'selected'; ?> value='Client Purchase'>Client Purchase
<option <?php if ($SrchDesc=='Subscriber Renewal') echo 'selected'; ?> value='Subscriber Renewal'>Subscriber Renewal
<option <?php if ($SrchDesc=='Boot User') echo 'selected'; ?> value='Boot User'>Boot User
</select>-->
<input name=SrchDesc2 value='<?=$SrchDesc2?>' size=30>
<input type=submit value=Search>
<br>
IP Address<input name=SrchIPAddr value='<?=$SrchIPAddr?>'><br>
Program <select name=SrchProgram>
<option value=''>Any
<?php
$db->query("SELECT Program, count(*) AS cnt FROM EventLog GROUP BY Program ORDER BY cnt DESC");
while ($db->next_record()) {
$p=$db->f(0);
echo "<option ";
if ($SrchProgram==$p) echo 'selected';
echo " value='$p'>$p</option>\n";
}
?>
</select><br />
Username<input name='SrchWebUser' value='<?=$SrchWebUser?>'>
<br> Event Time
<input name=EventTime id=EventTime value='<?=$EventTime?>' size=40>
<a href="javascript:show_calendar('document.EventLogform.EventTime', document.EventLogform.EventTime.value);">
<img src=/images/cal.gif width=16 height=16 border=0 alt="Click here to pick a date from the calendar"></a>
<a href="javascript:show_help('helpdate.php');" alt="Click here to find out about acceptable date formats">Help</a>
<?php if (substr($sortorder,-5,5)==" desc") { $sortdesc=1; $sortorder=substr($sortorder,0,-5); } ?>
<br>Sorted by
<select name=sortorder>
<option value='id desc'>Most Recent First
<option <?php if ($sortorder=='EventTime') echo 'selected'; ?> value='EventTime'>Event Time
<option <?php if ($sortorder=='Program') echo 'selected'; ?> value='Program'>Program
<option <?php if ($sortorder=='IPAddress') echo 'selected'; ?> value='IPAddress'>IP Address
<option <?php if ($sortorder=='UserName') echo 'selected'; ?> value='UserName'>WebUser
<option <?php if ($sortorder=='Description') echo 'selected'; ?> value='Description'>Description
<option <?php if ($sortorder=='ExtraInfo') echo 'selected'; ?> value='ExtraInfo'>Extra Info
<option <?php if ($sortorder=='Level') echo 'selected'; ?> value='Level'>Level
</select>
<input type=checkbox name=sortdesc <?php if ($sortdesc) { echo "checked"; $sortorder .= ' desc'; } ?> value='desc'> reversed
<br />Display
<?php
if ($rowcount) {
if ($start) $startingwith = 0;
if ($prev) $startingwith -= $rowcount;
if ($next) $startingwith += $rowcount;
if ($last) $startingwith = $total-$rowcount;
} else $rowcount=500;
if (!$startingwith) $startingwith='0';
?>
<input name=rowcount value='<?=$rowcount?>' size=5>
rows, starting from row
<input name=startingwith value='<?=$startingwith?>' size=5>
<input name=start type=submit value='<<' width=30>
<input name=prev type=submit value='<' width=30>
<input name=next type=submit value='>' width=30>
<input name=last type=submit value='>>' width=30>
<br />
<?php
$sql = "";
$match=Array();
if ($SrchDesc2) $match = explode(" ",$SrchDesc2);
if ($SrchDesc) $match[] = $SrchDesc;
if ($SrchWebUser) $match[] = $SrchWebUser;
if ($SrchIPAddr) $match[] = $SrchIPAddr;
if (!empty($match)) {
$sql .= "MATCH (Description,ExtraInfo) AGAINST ('".implode(" +",$match)."' IN BOOLEAN MODE)";
}
if ($SrchProgram) {
if ($sql) $sql .= " and ";
$sql .= "Program='$SrchProgram'";
}
if ($SrchWebUser) {
if ($sql) $sql .= " and ";
$sql .= " UserName = '$SrchWebUser' ";
}
if ($hidepoll) {
if ($sql) $sql .= " and ";
$sql .= "( Program not like '%poll%' )";
}
if ($hidehello) {
if ($sql) $sql .= " and ";
$sql .= "( Program not like '%hello%' )";
}
if ($EventTime) {
if ($sql) $sql .= " and ";
$sql .= "( EventTime like '$EventTime%' )";
}
if ($SrchIPAddr) {
if ($sql) $sql .= " and ";
$sql .= "( IPAddress like '%$SrchIPAddr%' )";;
}
$cj = " and ";
foreach ($SrchLevel as $k => $v) {
if ($sql) { $sql .= $cj; }
if ($cj==" and ") $sql .= " ( ";
$cj = " or ";
$sql .= "Level='$v'";
}
if ($cj==" or ") $sql .= " ) ";
$query = $sql;
// These fields will be searchable and displayed in results.
// Format is "RealFieldName"=>"Field Name Formatted For Display",
$t->fields = array(
"EventTime",
"Program",
"IPAddress",
"UserName",
"Description",
"Level");
$t->map_cols = array(
"EventTime"=>"Event Time",
"Program"=>"Program",
"IPAddress"=>"IP Address",
"UserName"=>"User Name",
"Description"=>"Description",
"Level"=>"Level");
$q->map_cols = array(
"EventTime"=>"Event Time",
"Program"=>"Program",
"IPAddress"=>"IP Address",
"UserName"=>"User Name",
"Description"=>"Description",
"ExtraInfo"=>"Extra Info",
"Level"=>"Level");
// When we hit this page the first time,
// there is no .
if (!isset($q_EventLog)) {
$q_EventLog = new EventLog_Sql_Query; // We make one
$q_EventLog->conditions = 1; // ... with a single condition (at first)
$q_EventLog->translate = "on"; // ... column names are to be translated
$q_EventLog->container = "on"; // ... with a nice container table
$q_EventLog->variable = "on"; // ... # of conditions is variable
$q_EventLog->lang = "en"; // ... in English, please
$q_EventLog->primary_key = "id"; // let Query engine know primary key
$q_EventLog->row_count = 10;
$sess->register("q_EventLog"); // and don't forget this!
}
if ($rowcount) {
$q_EventLog->start_row = $startingwith;
$q_EventLog->row_count = $rowcount;
}
// When we hit that page a second time, the array named
// by $base will be set and we must generate the $query.
// Ah, and don\'t set $base to "q" when $q is your Sql_Query
// object... :-)
if (isset($x)) {
$query = $q_EventLog->where("x", 1);
}
if (!$sortorder) $sortorder="id desc";
if (!$query) { $query="Description<>'Poll Gateways' order by id desc"; }
/*
$db->query("SELECT COUNT(*) as total from EventLog where ".$query);
$db->next_record();
$total = $db->f("total");
if ($db->f("total") < ($q_EventLog->start_row - $q_EventLog->row_count))
{ $q_EventLog->start_row = $db->f("total") - $q_EventLog->row_count; }
*/
if ($q_EventLog->start_row < 0) { $q_EventLog->start_row = 0; }
#echo "<input name=total value=$total type=hidden>\n</form>\n";
$query .= " ORDER BY $sortorder";
$query .= " LIMIT ".$q_EventLog->start_row.",".$q_EventLog->row_count;
// In any case we must display that form now. Note that the
// "x" here and in the call to $q->where must match.
// Tag everything as a CSS "query" class.
// printf($q_EventLog->form("x", $q->map_cols, "query"));
printf("<hr>");
// Do we have a valid query string?
if ($query) {
// Show that condition
printf("Query Condition = %s<br>\n", $query);
// Do that query
$db->query("select `id`, `EventTime`, `Program`, `IPAddress`, `UserName`, `Description`, `Level`, `ExtraInfo` from EventLog where ". $query);
// Dump the results (tagged as CSS class default)
printf("Query Results = %s<br>\n", $db->num_rows());
$t->show_result($db, "default");
}
} // switch $cmd
page_close();
?>