-
Notifications
You must be signed in to change notification settings - Fork 6
/
log.phtml
357 lines (309 loc) · 9.96 KB
/
log.phtml
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
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
<?php
require '/etc/cdrtool/global.inc';
page_open(
array(
"sess" => "CDRTool_Session",
"auth" => "CDRTool_Auth",
"perm" => "CDRTool_Perm"
)
);
$loginname = $auth->auth["uname"];
$title = "Logs";
$search_text = isset($_REQUEST['search_text']) ? $_REQUEST['search_text'] : '';
$task = isset($_REQUEST['task']) ? $_REQUEST['task'] : '';
$current_log = isset($_REQUEST['current_log']) ? $_REQUEST['current_log'] : '';
$log_description = isset($_REQUEST['log_description']) ? $_REQUEST['log_description'] : '';
$next = isset($_REQUEST['next']) ? intval($_REQUEST['next']) : 0;
$maxrowsperpage = 20;
$PHP_SELF = htmlentities($_SERVER['PHP_SELF']);
$thisMonth = isset($_REQUEST['thisMonth']) ? $_REQUEST['thisMonth'] : '';
$recipient = isset($_REQUEST['recipient']) ? $_REQUEST['recipient'] : '';
$db = new DB_CDRTool;
if (is_readable("/etc/cdrtool/local/header.phtml")) {
include '/etc/cdrtool/local/header.phtml';
} else {
include 'header.phtml';
}
if ($search_text) {
$search_text = preg_replace("/[^\d|\w| -\.@_]/s", "", $search_text);
}
$layout = new pageLayoutLocal();
$layout->showTopMenu($title);
if ($thisMonth) {
$checked_thisMonth = 'checked';
} else {
$checked_thisMonth = '';
}
$where = " (1=1) ";
if ($CDRTool['filter']['reseller']) {
$where .= sprintf(' and reseller_id = %s', addslashes($CDRTool['filter']['reseller']));
} else if (!$perm->have_perm("admin")) {
$where .= sprintf(" and login = '%s'", addslashes($auth->auth["uname"]));
}
if ($perm->have_perm('admin')) {
$query = "select * from auth_user where perms like '%admin%'";
$db->query($query);
while ($db->next_record()) {
$Collegues[$db->f('email')] = $db->f('name');
if ($loginname == $db->f('username')) {
$myEmailAddress = $db->f('email');
$myName = $db->f('name');
}
}
} else {
$Collegues[$CDRTool['provider']['toEmail']] = $CDRTool['provider']['name'];
$myName = $CDRTool["loginName"];
$myEmailAddress = $CDRTool["loginEmail"];
}
if ($current_log) {
if ($task == "edit") {
$query = sprintf(
"update log set description = '%s' where %s and id = %d",
addslashes($log_description),
$where,
intval($current_log)
);
$db->query($query);
} else if ($task == "mailLog" && $recipient) {
$query = sprintf(
"select * from log where %s and id = %d",
$where,
intval($current_log)
);
$db->query($query);
$db->next_record();
$rerun = $db->f('rerun');
$description = $db->f('description');
if ($_SERVER['HTTPS']=="on") {
$protocolURL="https://";
} else {
$protocolURL="http://";
}
$subject = "CDRTool";
$fullURL = $protocolURL.$_SERVER['HTTP_HOST'].$CDRTool['tld']."/".$rerun;
$body = "CDRTool query to analyse:\n\n$fullURL\n\n";
if ($description) {
$body = $body."The query id $current_log is saved with name \"$description\"\n\n";
$subject = $subject.": ".$description;
}
$body = $body."This notification has been sent to you from CDRTool log interface by $myName";
mail($recipient, $subject, $body, "From: $myEmailAddress");
print "<p>Notified $recipient.";
}
}
$url_log = array();
if ($search_text) {
$where.= sprintf(
" and (description like '%s%s%s' or url like '%s' or id = '%s')",
"%",
addslashes($search_text),
"%",
addslashes($search_text),
addslashes($search_text)
);
$url_log["search_text"] = $search_text;
}
if ($thisMonth) {
$where .= sprintf(" and date like '%s'", date('Y-m').'%');
$url_log["thisMonth"] = 1;
}
$query = sprintf("select count(*) as records from log where %s ", $where);
if ($db->query($query)) {
$db->next_record();
$rows = $db->f('records');
} else {
$rows = 0;
}
if (!$next) {
$i = 0;
$next = 0;
} else {
$i = intval($next);
}
$j = 0;
$z = 0;
print "
<form method=post action=$PHP_SELF>
<table border=0 align=center>
<tr>
<td>
Found $rows records.
</td>
<td>
<div class='input-append'>
<input class=span2 type=text size=30 name=search_text value=\"$search_text\"><button class='btn btn-primary' type=submit value=Search>Search</button></div>
</td>
<td>
<input type=checkbox name=thisMonth value=1 $checked_thisMonth>
Only this month?
</td>
</tr>
</table>
</form>
";
if ($rows > 0) {
if ($rows > $maxrowsperpage) {
$maxrows=$maxrowsperpage + $next;
if ($maxrows > $rows) {
$maxrows = $rows;
$prev_rows = $maxrows;
}
} else {
$maxrows=$rows;
}
$_max_rows= intval($maxrowsperpage);
if (!$_max_rows) {
$_max_rows = 10;
}
$query = sprintf("select * from log where %s order by id desc limit %d, %d", $where, intval($i), $_max_rows);
$db->query($query);
print "<br/>
<table id='log' class='table table-striped table-condensed' width=100% align=center>
<thead>
<tr>
<th> </th>
<th> <b>Log id</th>
<th> <b>Reseller</th>
<th> <b>Date and time</th>
<th> <b>Account</th>
<th> <b>IP address</th>
<th> <b>Data source</th>
<th> <b>Rows</th>
<th> <b>Description </th>
<th> <b>Actions</th>
</tr>
</thead>
";
while ($i < $maxrows) {
$found = $i+1;
$db->next_record();
$current_log = $db->f('id');
$reseller_id = $db->f('reseller_id');
$log_date = $db->f('date');
$login = $db->f('login');
$ip = $db->f('ip');
$url = $db->f('url');
$reedit = $db->f('reedit');
$rerun = $db->f('rerun');
$results = $db->f('results');
$description = $db->f('description');
$datasource = $db->f('datasource');
if ($rerun && $DATASOURCES[$datasource]['name']) {
$datasource_print=$DATASOURCES[$datasource]['name'];
} else {
$datasource_print=$datasource;
}
if (!$reedit || !$rerun) {
if (preg_match("/do_search/", $url)) {
$url_run = "<a href=\"../search_call/$url"."&history_id=$current_log"."\">Run</a>";
$url_edit = preg_replace("/do_/", "", $url);
$url_edit = "<a href=\"../search_call/$url_edit\">Edit</a>";
$display_form = 1;
} elseif (preg_match("/do_statistics/", $url)) {
$url_run = "<a href=\"../statistics/$url"."&history_id=$current_log"."\">Run</a>";
$url_edit = preg_replace("/do_/", "", $url);
$url_edit = "<a href=\"../statistics/$url_edit\">Edit stat</a>";
$display_form = 1;
} else {
$url_edit = "";
$url_run = "";
$display_form = 0;
}
} else {
$display_form=1;
$url_run="<a class='btn' href=\"$rerun\">Run</a>";
$url_edit="<a class='btn btn-info' href=\"$reedit\">Edit</a>";
}
$rr = floor($found / 2);
$mod = $found - $rr * 2;
if ($mod == 0) {
//$bgcolor="lightgrey";
} else {
//$bgcolor="white";
}
print "
<tr>
<td class=cdr><b>$found.</b></td>
<td class=cdr>$current_log</td>
<td class=cdr>$reseller_id</td>
<td class=cdr>$log_date</td>
<td class=cdr>$login</td>
<td class=cdr>$ip</td>
<td class=cdr>$datasource_print</td>
<td class=cdr>$results</td>
<td class=cdr><form class='cform form-inline' method=post>";
if ($display_form == 1) {
print "
<input type=hidden name=current_log value=\"$current_log\">
<input type=hidden name=task value=edit>
<input type=hidden name=next value=$next>
<input type=hidden name=search_text value=\"$search_text\">
<div class='input-append'>
<input type=text class=span2 size=25 name=log_description value=\"$description\"><button class=btn type=submit value=Save>Save</button>
</div>
";
} else {
print "$description";
}
print "</form>
</td> <td class=cdr>
<form class='cform form-inline' method=post>
<div class='btn-group'>
$url_run $url_edit
";
if (strlen($description) && $rerun) {
print "
<button class='btn' type=submit value=Notify>Notify</button>
<select class=span3 name=recipient>
";
foreach (array_keys($Collegues) as $col) {
print "<option value=\"$col\">$Collegues[$col]";
}
print "
</select>
<input type=hidden name=current_log value=\"$current_log\">
<input type=hidden name=task value=mailLog>
<input type=hidden name=next value=$next>
<input type=hidden name=search_text value=\"$search_text\">
";
}
print "</div></form>
</td>
</tr>
";
$i++;
}
print "</table>";
}
print "<ul class=\"pager\">";
if ($next != 0) {
$show_next = $maxrowsperpage - $next;
$url_log['action'] = "search";
if ($show_next < 0) {
$url_log['next'] = $show_next - 2 * $show_next;
}
$url_prev = sprintf(
"%s?%s",
$PHP_SELF,
http_build_query($url_log)
);
print "<li><a href=\"$url_prev\">← Previous</a></li>";
}
if ($rows > $maxrowsperpage && $rows != $maxrows) {
$url_log['action'] = "search";
$url_log['next'] = $maxrowsperpage + $next;
$url_next = sprintf(
"%s?%s",
$PHP_SELF,
http_build_query($url_log)
);
print "<li><a href=\"$url_next\">Next →</a></li>";
}
print "</div>";
$layout->showFooter();
print "
</body>
</html>
";
page_close();
?>