1
|
<?php
|
2
|
/*
|
3
|
status_logs_filter.php
|
4
|
*/
|
5
|
/* ====================================================================
|
6
|
* Copyright (c) 2004-2015 Electric Sheep Fencing, LLC. All rights reserved.
|
7
|
*
|
8
|
* Some or all of this file is based on the m0n0wall project which is
|
9
|
* Copyright (c) 2004 Manuel Kasper (BSD 2 clause)
|
10
|
*
|
11
|
* Redistribution and use in source and binary forms, with or without modification,
|
12
|
* are permitted provided that the following conditions are met:
|
13
|
*
|
14
|
* 1. Redistributions of source code must retain the above copyright notice,
|
15
|
* this list of conditions and the following disclaimer.
|
16
|
*
|
17
|
* 2. Redistributions in binary form must reproduce the above copyright
|
18
|
* notice, this list of conditions and the following disclaimer in
|
19
|
* the documentation and/or other materials provided with the
|
20
|
* distribution.
|
21
|
*
|
22
|
* 3. All advertising materials mentioning features or use of this software
|
23
|
* must display the following acknowledgment:
|
24
|
* "This product includes software developed by the pfSense Project
|
25
|
* for use in the pfSense software distribution. (http://www.pfsense.org/).
|
26
|
*
|
27
|
* 4. The names "pfSense" and "pfSense Project" must not be used to
|
28
|
* endorse or promote products derived from this software without
|
29
|
* prior written permission. For written permission, please contact
|
30
|
* coreteam@pfsense.org.
|
31
|
*
|
32
|
* 5. Products derived from this software may not be called "pfSense"
|
33
|
* nor may "pfSense" appear in their names without prior written
|
34
|
* permission of the Electric Sheep Fencing, LLC.
|
35
|
*
|
36
|
* 6. Redistributions of any form whatsoever must retain the following
|
37
|
* acknowledgment:
|
38
|
*
|
39
|
* "This product includes software developed by the pfSense Project
|
40
|
* for use in the pfSense software distribution (http://www.pfsense.org/).
|
41
|
*
|
42
|
* THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
|
43
|
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
44
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
45
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
|
46
|
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
47
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
48
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
49
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
50
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
51
|
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
52
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
53
|
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
54
|
*
|
55
|
* ====================================================================
|
56
|
*
|
57
|
*/
|
58
|
|
59
|
##|+PRIV
|
60
|
##|*IDENT=page-diagnostics-logs-firewall
|
61
|
##|*NAME=Status: Logs: Firewall
|
62
|
##|*DESCR=Allow access to the 'Status: Logs: Firewall' page.
|
63
|
##|*MATCH=status_logs_filter.php*
|
64
|
##|-PRIV
|
65
|
|
66
|
require_once("status_logs_common.inc");
|
67
|
require_once("ipsec.inc");
|
68
|
|
69
|
|
70
|
# --- AJAX RESOLVE ---
|
71
|
if (isset($_POST['resolve'])) {
|
72
|
$ip = strtolower($_POST['resolve']);
|
73
|
$res = (is_ipaddr($ip) ? gethostbyaddr($ip) : '');
|
74
|
|
75
|
if ($res && $res != $ip) {
|
76
|
$response = array('resolve_ip' => $ip, 'resolve_text' => $res);
|
77
|
} else {
|
78
|
$response = array('resolve_ip' => $ip, 'resolve_text' => gettext("Cannot resolve"));
|
79
|
}
|
80
|
|
81
|
echo json_encode(str_replace("\\", "\\\\", $response)); // single escape chars can break JSON decode
|
82
|
exit;
|
83
|
}
|
84
|
|
85
|
|
86
|
/*
|
87
|
Build a list of allowed log files so we can reject others to prevent the page
|
88
|
from acting on unauthorized files.
|
89
|
*/
|
90
|
$allowed_logs = array(
|
91
|
"filter" => array("name" => "Firewall",
|
92
|
"shortcut" => "filter"),
|
93
|
);
|
94
|
|
95
|
// The logs to display are specified in a GET argument. Default to 'system' logs
|
96
|
if (!$_GET['logfile']) {
|
97
|
$logfile = 'filter';
|
98
|
$view = 'normal';
|
99
|
} else {
|
100
|
$logfile = $_GET['logfile'];
|
101
|
$view = $_GET['view'];
|
102
|
if (!array_key_exists($logfile, $allowed_logs)) {
|
103
|
/* Do not let someone attempt to load an unauthorized log. */
|
104
|
$logfile = 'filter';
|
105
|
$view = 'normal';
|
106
|
}
|
107
|
}
|
108
|
|
109
|
if ($view == 'normal') { $view_title = gettext("Normal View"); }
|
110
|
if ($view == 'dynamic') { $view_title = gettext("Dynamic View"); }
|
111
|
if ($view == 'summary') { $view_title = gettext("Summary View"); }
|
112
|
|
113
|
$rulenum = getGETPOSTsettingvalue('getrulenum', null);
|
114
|
|
115
|
if ($rulenum) {
|
116
|
list($rulenum, $tracker, $type) = explode(',', $rulenum);
|
117
|
$rule = find_rule_by_number($rulenum, $tracker, $type);
|
118
|
echo gettext("The rule that triggered this action is") . ":\n\n{$rule}";
|
119
|
exit;
|
120
|
}
|
121
|
|
122
|
|
123
|
// Log Filter Submit - Firewall
|
124
|
log_filter_form_firewall_submit();
|
125
|
|
126
|
|
127
|
// Manage Log Section - Code
|
128
|
manage_log_code();
|
129
|
|
130
|
|
131
|
// Status Logs Common - Code
|
132
|
status_logs_common_code();
|
133
|
|
134
|
|
135
|
$pgtitle = array(gettext("Status"), gettext("System Logs"), gettext($allowed_logs[$logfile]["name"]), $view_title);
|
136
|
include("head.inc");
|
137
|
|
138
|
if (!$input_errors && $savemsg) {
|
139
|
print_info_box($savemsg, 'success');
|
140
|
$manage_log_active = false;
|
141
|
}
|
142
|
|
143
|
|
144
|
// Tab Array
|
145
|
tab_array_logs_common();
|
146
|
|
147
|
|
148
|
// Manage Log - Section/Form
|
149
|
if ($system_logs_manage_log_form_hidden) {
|
150
|
manage_log_section();
|
151
|
}
|
152
|
|
153
|
|
154
|
// Filter Section/Form - Firewall
|
155
|
filter_form_firewall();
|
156
|
|
157
|
|
158
|
// Now the forms are complete we can draw the log table and its controls
|
159
|
if (!$rawfilter) {
|
160
|
$iflist = get_configured_interface_with_descr(false, true);
|
161
|
|
162
|
if ($iflist[$interfacefilter]) {
|
163
|
$interfacefilter = $iflist[$interfacefilter];
|
164
|
}
|
165
|
|
166
|
system_log_filter();
|
167
|
?>
|
168
|
|
169
|
<div class="panel panel-default">
|
170
|
<div class="panel-heading">
|
171
|
<h2 class="panel-title">
|
172
|
<?php
|
173
|
print(system_log_table_panel_title());
|
174
|
?>
|
175
|
</h2>
|
176
|
</div>
|
177
|
<div class="panel-body">
|
178
|
<div class="table-responsive">
|
179
|
<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap" data-sortable>
|
180
|
<thead>
|
181
|
<tr class="text-nowrap">
|
182
|
<th><?=gettext("Action")?></th>
|
183
|
<th><?=gettext("Time")?></th>
|
184
|
<th><?=gettext("Interface")?></th>
|
185
|
<?php
|
186
|
if ($config['syslog']['filterdescriptions'] === "1") {
|
187
|
?>
|
188
|
<th style="width:100%">
|
189
|
<?=gettext("Rule")?>
|
190
|
</th>
|
191
|
<?php
|
192
|
}
|
193
|
?>
|
194
|
<th><?=gettext("Source")?></th>
|
195
|
<th><?=gettext("Destination")?></th>
|
196
|
<th><?=gettext("Protocol")?></th>
|
197
|
</tr>
|
198
|
</thead>
|
199
|
<tbody>
|
200
|
<?php
|
201
|
if ($config['syslog']['filterdescriptions']) {
|
202
|
buffer_rules_load();
|
203
|
}
|
204
|
|
205
|
foreach ($filterlog as $filterent) {
|
206
|
?>
|
207
|
<tr class="text-nowrap">
|
208
|
<td>
|
209
|
<?php
|
210
|
if ($filterent['act'] == "block") {
|
211
|
$icon_act = "fa-times text-danger";
|
212
|
} else {
|
213
|
$icon_act = "fa-check text-success";
|
214
|
}
|
215
|
|
216
|
if ($filterent['count']) {
|
217
|
$margin_left = '0em';
|
218
|
} else {
|
219
|
$margin_left = '0.4em';
|
220
|
}
|
221
|
?>
|
222
|
<i style="margin-left:<?=$margin_left;?>" class="fa <?=$icon_act;?> icon-pointer" title="<?php echo $filterent['act'] .'/'. $filterent['tracker'];?>" onclick="javascript:getURL('status_logs_filter.php?getrulenum=<?="{$filterent['rulenum']},{$filterent['tracker']},{$filterent['act']}"; ?>', outputrule);"></i>
|
223
|
<?php
|
224
|
if ($filterent['count']) {
|
225
|
echo $filterent['count'];
|
226
|
}
|
227
|
?>
|
228
|
</td>
|
229
|
<td>
|
230
|
<?=htmlspecialchars($filterent['time'])?>
|
231
|
</td>
|
232
|
<td>
|
233
|
<?php
|
234
|
if ($filterent['direction'] == "out") {
|
235
|
print('►' . ' ');
|
236
|
}
|
237
|
?>
|
238
|
<?=htmlspecialchars($filterent['interface'])?>
|
239
|
</td>
|
240
|
<?php
|
241
|
if ($config['syslog']['filterdescriptions'] === "1") {
|
242
|
?>
|
243
|
<td style="white-space:normal;">
|
244
|
<?=find_rule_by_number_buffer($filterent['rulenum'], $filterent['tracker'], $filterent['act'])?>
|
245
|
</td>
|
246
|
<?php
|
247
|
}
|
248
|
|
249
|
$int = strtolower($filterent['interface']);
|
250
|
$proto = strtolower($filterent['proto']);
|
251
|
$rawsrcip = $filterent['srcip'];
|
252
|
$rawdstip = $filterent['dstip'];
|
253
|
|
254
|
if ($filterent['version'] == '6') {
|
255
|
$ipproto = "inet6";
|
256
|
$filterent['srcip'] = "[{$filterent['srcip']}]";
|
257
|
$filterent['dstip'] = "[{$filterent['dstip']}]";
|
258
|
} else {
|
259
|
$ipproto = "inet";
|
260
|
}
|
261
|
|
262
|
$srcstr = $filterent['srcip'] . get_port_with_service($filterent['srcport'], $proto);
|
263
|
$src_htmlclass = str_replace(array('.', ':'), '-', $rawsrcip);
|
264
|
$dststr = $filterent['dstip'] . get_port_with_service($filterent['dstport'], $proto);
|
265
|
$dst_htmlclass = str_replace(array('.', ':'), '-', $rawdstip);
|
266
|
?>
|
267
|
<td class="text-nowrap">
|
268
|
<i class="fa fa-info icon-pointer icon-primary" onclick="javascript:resolve_with_ajax('<?="{$rawsrcip}"; ?>');" title="<?=gettext("Click to resolve")?>">
|
269
|
</i>
|
270
|
|
271
|
<a class="fa fa-minus-square-o icon-pointer icon-primary" href="easyrule.php?<?="action=block&int={$int}&src={$filterent['srcip']}&ipproto={$ipproto}"; ?>" title="<?=gettext("Easy Rule: Add to Block List")?>" onclick="return confirm('<?=gettext("Confirmation required to add this BLOCK rule.")?>')">
|
272
|
</a>
|
273
|
|
274
|
<?=$srcstr . '<span class="RESOLVE-' . $src_htmlclass . '"></span>'?>
|
275
|
</td>
|
276
|
<td class="text-nowrap">
|
277
|
<i class="fa fa-info icon-pointer icon-primary; ICON-<?= $dst_htmlclass; ?>" onclick="javascript:resolve_with_ajax('<?="{$rawdstip}"; ?>');" title="<?=gettext("Click to resolve")?>">
|
278
|
</i>
|
279
|
|
280
|
<a class="fa fa-plus-square-o icon-pointer icon-primary" href="easyrule.php?<?="action=pass&int={$int}&proto={$proto}&src={$filterent['srcip']}&dst={$filterent['dstip']}&dstport={$filterent['dstport']}&ipproto={$ipproto}"; ?>" title="<?=gettext("Easy Rule: Pass this traffic")?>" onclick="return confirm('<?=gettext("Confirmation required to add this PASS rule.")?>')">
|
281
|
</a>
|
282
|
<?=$dststr . '<span class="RESOLVE-' . $dst_htmlclass . '"></span>'?>
|
283
|
</td>
|
284
|
<?php
|
285
|
if ($filterent['proto'] == "TCP") {
|
286
|
$filterent['proto'] .= ":{$filterent['tcpflags']}";
|
287
|
}
|
288
|
?>
|
289
|
<td>
|
290
|
<?=htmlspecialchars($filterent['proto'])?>
|
291
|
</td>
|
292
|
</tr>
|
293
|
<?php
|
294
|
if (isset($config['syslog']['filterdescriptions']) && $config['syslog']['filterdescriptions'] === "2") {
|
295
|
?>
|
296
|
<tr>
|
297
|
<td colspan="2" />
|
298
|
<td colspan="4"><?=find_rule_by_number_buffer($filterent['rulenum'], $filterent['tracker'], $filterent['act'])?></td>
|
299
|
</tr>
|
300
|
<?php
|
301
|
}
|
302
|
} // e-o-foreach
|
303
|
buffer_rules_clear();
|
304
|
?>
|
305
|
</tbody>
|
306
|
</table>
|
307
|
<?php
|
308
|
if (count($filterlog) == 0) {
|
309
|
print_info_box(gettext('No logs to display.'));
|
310
|
}
|
311
|
?>
|
312
|
</div>
|
313
|
</div>
|
314
|
</div>
|
315
|
|
316
|
<?php
|
317
|
} else {
|
318
|
?>
|
319
|
<div class="panel panel-default">
|
320
|
<div class="panel-heading">
|
321
|
<h2 class="panel-title">
|
322
|
<?php
|
323
|
print(system_log_table_panel_title());
|
324
|
?>
|
325
|
</h2>
|
326
|
</div>
|
327
|
<div class="table table-responsive">
|
328
|
<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap" data-sortable>
|
329
|
<thead>
|
330
|
<tr class="text-nowrap">
|
331
|
<th><?=gettext("Time")?></th>
|
332
|
<th style="width:100%"><?=gettext("Message")?></th>
|
333
|
</tr>
|
334
|
</thead>
|
335
|
<tbody>
|
336
|
<?php
|
337
|
system_log_filter();
|
338
|
?>
|
339
|
</tbody>
|
340
|
</table>
|
341
|
|
342
|
<script type="text/javascript">
|
343
|
//<![CDATA[
|
344
|
events.push(function() {
|
345
|
$("#count").html(<?=$rows?>);
|
346
|
});
|
347
|
//]]>
|
348
|
</script>
|
349
|
|
350
|
<?php
|
351
|
if ($rows == 0) {
|
352
|
print_info_box(gettext('No logs to display.'));
|
353
|
}
|
354
|
?>
|
355
|
</div>
|
356
|
</div>
|
357
|
<?php
|
358
|
}
|
359
|
?>
|
360
|
|
361
|
<div class="infoblock">
|
362
|
<?php
|
363
|
print_info_box('<a href="https://doc.pfsense.org/index.php/What_are_TCP_Flags%3F">' .
|
364
|
gettext("TCP Flags") . '</a>: F - FIN, S - SYN, A or . - ACK, R - RST, P - PSH, U - URG, E - ECE, C - CWR.' . '<br />' .
|
365
|
'<i class="fa fa-minus-square-o icon-primary"></i> = Add to block list., <i class="fa fa-plus-square-o icon-primary"></i> = Pass traffic, <i class="fa fa-info icon-primary"></i> = Resolve', 'info', false);
|
366
|
?>
|
367
|
</div>
|
368
|
|
369
|
<?php
|
370
|
# Manage Log - Section/Form
|
371
|
if (!$system_logs_manage_log_form_hidden) {
|
372
|
manage_log_section();
|
373
|
}
|
374
|
?>
|
375
|
|
376
|
<!-- AJAXY STUFF -->
|
377
|
<script type="text/javascript">
|
378
|
//<![CDATA[
|
379
|
function outputrule(req) {
|
380
|
alert(req.content);
|
381
|
}
|
382
|
|
383
|
function resolve_with_ajax(ip_to_resolve) {
|
384
|
var url = "/status_logs_filter.php";
|
385
|
|
386
|
$.ajax(
|
387
|
url,
|
388
|
{
|
389
|
method: 'post',
|
390
|
dataType: 'json',
|
391
|
data: {
|
392
|
resolve: ip_to_resolve,
|
393
|
},
|
394
|
complete: resolve_ip_callback
|
395
|
});
|
396
|
|
397
|
}
|
398
|
|
399
|
function resolve_ip_callback(transport) {
|
400
|
var response = $.parseJSON(transport.responseText);
|
401
|
var resolve_class = htmlspecialchars(response.resolve_ip.replace(/[.:]/g, '-'));
|
402
|
var resolve_text = '<small><br />' + htmlspecialchars(response.resolve_text) + '<\/small>';
|
403
|
|
404
|
$('span.RESOLVE-' + resolve_class).html(resolve_text);
|
405
|
}
|
406
|
|
407
|
// From http://stackoverflow.com/questions/5499078/fastest-method-to-escape-html-tags-as-html-entities
|
408
|
function htmlspecialchars(str) {
|
409
|
return str.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"').replace(/'/g, ''');
|
410
|
}
|
411
|
|
412
|
if (typeof getURL == 'undefined') {
|
413
|
getURL = function(url, callback) {
|
414
|
if (!url)
|
415
|
throw 'No URL for getURL';
|
416
|
try {
|
417
|
if (typeof callback.operationComplete == 'function')
|
418
|
callback = callback.operationComplete;
|
419
|
} catch (e) {}
|
420
|
if (typeof callback != 'function')
|
421
|
throw 'No callback function for getURL';
|
422
|
var http_request = null;
|
423
|
if (typeof XMLHttpRequest != 'undefined') {
|
424
|
http_request = new XMLHttpRequest();
|
425
|
}
|
426
|
else if (typeof ActiveXObject != 'undefined') {
|
427
|
try {
|
428
|
http_request = new ActiveXObject('Msxml2.XMLHTTP');
|
429
|
} catch (e) {
|
430
|
try {
|
431
|
http_request = new ActiveXObject('Microsoft.XMLHTTP');
|
432
|
} catch (e) {}
|
433
|
}
|
434
|
}
|
435
|
if (!http_request)
|
436
|
throw 'Both getURL and XMLHttpRequest are undefined';
|
437
|
http_request.onreadystatechange = function() {
|
438
|
if (http_request.readyState == 4) {
|
439
|
callback( { success : true,
|
440
|
content : http_request.responseText,
|
441
|
contentType : http_request.getResponseHeader("Content-Type") } );
|
442
|
}
|
443
|
};
|
444
|
http_request.open('GET', url, true);
|
445
|
http_request.send(null);
|
446
|
};
|
447
|
}
|
448
|
|
449
|
events.push(function() {
|
450
|
$('.fa').tooltip();
|
451
|
});
|
452
|
//]]>
|
453
|
</script>
|
454
|
|
455
|
<?php include("foot.inc");
|
456
|
?>
|