1
|
<?php
|
2
|
/*
|
3
|
log.widget.php
|
4
|
Copyright (C) 2013-2015 Electric Sheep Fencing, LP
|
5
|
|
6
|
Copyright 2007 Scott Dale
|
7
|
Part of pfSense widgets (https://www.pfsense.org)
|
8
|
originally based on m0n0wall (http://m0n0.ch/wall)
|
9
|
|
10
|
Copyright (C) 2004-2005 T. Lechat <dev@lechat.org>, Manuel Kasper <mk@neon1.net>
|
11
|
and Jonathan Watt <jwatt@jwatt.org>.
|
12
|
All rights reserved.
|
13
|
|
14
|
Redistribution and use in source and binary forms, with or without
|
15
|
modification, are permitted provided that the following conditions are met:
|
16
|
|
17
|
1. Redistributions of source code must retain the above copyright notice,
|
18
|
this list of conditions and the following disclaimer.
|
19
|
|
20
|
2. Redistributions in binary form must reproduce the above copyright
|
21
|
notice, this list of conditions and the following disclaimer in the
|
22
|
documentation and/or other materials provided with the distribution.
|
23
|
|
24
|
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
25
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
26
|
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
27
|
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
28
|
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
29
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
30
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
31
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
32
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
33
|
POSSIBILITY OF SUCH DAMAGE.
|
34
|
*/
|
35
|
|
36
|
$nocsrf = true;
|
37
|
|
38
|
require_once("guiconfig.inc");
|
39
|
require_once("pfsense-utils.inc");
|
40
|
require_once("functions.inc");
|
41
|
|
42
|
/* In an effort to reduce duplicate code, many shared functions have been moved here. */
|
43
|
require_once("filter_log.inc");
|
44
|
|
45
|
if(is_numeric($_POST['filterlogentries'])) {
|
46
|
$config['widgets']['filterlogentries'] = $_POST['filterlogentries'];
|
47
|
|
48
|
$acts = array();
|
49
|
if ($_POST['actpass']) $acts[] = "Pass";
|
50
|
if ($_POST['actblock']) $acts[] = "Block";
|
51
|
if ($_POST['actreject']) $acts[] = "Reject";
|
52
|
|
53
|
if (!empty($acts))
|
54
|
$config['widgets']['filterlogentriesacts'] = implode(" ", $acts);
|
55
|
else
|
56
|
unset($config['widgets']['filterlogentriesacts']);
|
57
|
unset($acts);
|
58
|
|
59
|
if( ($_POST['filterlogentriesinterfaces']) and ($_POST['filterlogentriesinterfaces'] != "All") )
|
60
|
$config['widgets']['filterlogentriesinterfaces'] = trim($_POST['filterlogentriesinterfaces']);
|
61
|
else
|
62
|
unset($config['widgets']['filterlogentriesinterfaces']);
|
63
|
|
64
|
write_config("Saved Filter Log Entries via Dashboard");
|
65
|
Header("Location: /");
|
66
|
exit(0);
|
67
|
}
|
68
|
|
69
|
$nentries = isset($config['widgets']['filterlogentries']) ? $config['widgets']['filterlogentries'] : 5;
|
70
|
|
71
|
//set variables for log
|
72
|
$nentriesacts = isset($config['widgets']['filterlogentriesacts']) ? $config['widgets']['filterlogentriesacts'] : 'All';
|
73
|
$nentriesinterfaces = isset($config['widgets']['filterlogentriesinterfaces']) ? $config['widgets']['filterlogentriesinterfaces'] : 'All';
|
74
|
|
75
|
$filterfieldsarray = array(
|
76
|
"act" => $nentriesacts,
|
77
|
"interface" => $nentriesinterfaces
|
78
|
);
|
79
|
|
80
|
$filter_logfile = "{$g['varlog_path']}/filter.log";
|
81
|
|
82
|
/* AJAX related routines */
|
83
|
if (isset($_POST['lastsawtime'])) {
|
84
|
$filterlog = conv_log_filter($filter_logfile, $nentries, $nentries + 20);
|
85
|
|
86
|
foreach ($filterlog as $idx => $row) {
|
87
|
if (strtotime($log_row['time']) <= $_POST['lastsawtime'])
|
88
|
unset($filterlog[$idx]);
|
89
|
}
|
90
|
}
|
91
|
else
|
92
|
$filterlog = conv_log_filter($filter_logfile, $nentries, 50, $filterfieldsarray);
|
93
|
?>
|
94
|
<script>
|
95
|
var logWidgetLastRefresh = <?=time()?>;
|
96
|
</script>
|
97
|
|
98
|
<table class="table table-striped">
|
99
|
<thead>
|
100
|
<tr>
|
101
|
<th><?=gettext("Act");?></th>
|
102
|
<th><?=gettext("Time");?></th>
|
103
|
<th><?=gettext("IF");?></th>
|
104
|
<th><?=gettext("Source");?></th>
|
105
|
<th><?=gettext("Destination");?></th>
|
106
|
</tr>
|
107
|
</thead>
|
108
|
<tbody>
|
109
|
<?php
|
110
|
foreach ($filterlog as $filterent):
|
111
|
if ($filterent['version'] == '6') {
|
112
|
$srcIP = "[" . htmlspecialchars($filterent['srcip']) . "]";
|
113
|
$dstIP = "[" . htmlspecialchars($filterent['dstip']) . "]";
|
114
|
} else {
|
115
|
$srcIP = htmlspecialchars($filterent['srcip']);
|
116
|
$dstIP = htmlspecialchars($filterent['dstip']);
|
117
|
}
|
118
|
|
119
|
if ($filterent['act'] == "block")
|
120
|
$iconfn = "remove";
|
121
|
else if ($filterent['act'] == "reject")
|
122
|
$iconfn = "fire";
|
123
|
else if ($filterent['act'] == "match")
|
124
|
$iconfn = "filter";
|
125
|
else
|
126
|
$iconfn = "ok";
|
127
|
|
128
|
$rule = find_rule_by_number($filterent['rulenum'], $filterent['tracker'], $filterent['act']);
|
129
|
?>
|
130
|
<tr>
|
131
|
<td><a role="button" data-toggle="popover" data-trigger="hover"
|
132
|
data-title="Rule that triggered this action"
|
133
|
data-content="<?=htmlspecialchars($rule)?>"> <i
|
134
|
class="icon icon-<?=$iconfn?>"></i>
|
135
|
</a></td>
|
136
|
<td title="<?=htmlspecialchars($filterent['time'])?>"><?=substr(htmlspecialchars($filterent['time']),0,-3)?></td>
|
137
|
<td><?=htmlspecialchars($filterent['interface']);?></td>
|
138
|
<td><a href="diag_dns.php?host=<?=$filterent['srcip']?>"
|
139
|
title="<?=gettext("Reverse Resolve with DNS")?>"><?=$srcIP?></a>:<?=htmlspecialchars($filterent['srcport'])?>
|
140
|
</td>
|
141
|
<td><a href="diag_dns.php?host=<?=$filterent['dstip']?>"
|
142
|
title="<?=gettext("Reverse Resolve with DNS");?>"><?=$dstIP?></a>:<?=htmlspecialchars($filterent['dstport'])?>
|
143
|
</td>
|
144
|
</tr>
|
145
|
<?php endforeach; ?>
|
146
|
</tbody>
|
147
|
</table>
|
148
|
|
149
|
<?php
|
150
|
|
151
|
/* for AJAX response, we only need the panel-body */
|
152
|
if (isset($_POST['lastsawtime']))
|
153
|
exit;
|
154
|
?>
|
155
|
|
156
|
<!-- close the body we're wrapped in and add a configuration-panel -->
|
157
|
</div>
|
158
|
<div class="panel-footer collapse">
|
159
|
|
160
|
<form action="/widgets/widgets/log.widget.php" method="post"
|
161
|
class="form-horizontal">
|
162
|
<div class="form-group">
|
163
|
<label for="filterlogentries" class="col-sm-4 control-label">Number
|
164
|
of entries</label>
|
165
|
<div class="col-sm-6">
|
166
|
<input type="number" name="filterlogentries" value="<?=$nentries?>"
|
167
|
min="1" max="20" class="form-control" />
|
168
|
</div>
|
169
|
</div>
|
170
|
|
171
|
<div class="form-group">
|
172
|
<label class="col-sm-4 control-label">Filter actions</label>
|
173
|
<div class="col-sm-6 checkbox">
|
174
|
<?php $include_acts = explode(" ", strtolower($nentriesacts)); ?>
|
175
|
<label><input name="actpass" type="checkbox" value="Pass"
|
176
|
<?=(in_array('pass', $include_acts) ? 'checked="checked"':'')?> />Pass</label>
|
177
|
<label><input name="actblock" type="checkbox" value="Block"
|
178
|
<?=(in_array('block', $include_acts) ? 'checked="checked"':'')?> />Block</label>
|
179
|
<label><input name="actreject" type="checkbox" value="Reject"
|
180
|
<?=(in_array('reject', $include_acts) ? 'checked="checked"':'')?> />Reject</label>
|
181
|
</div>
|
182
|
</div>
|
183
|
|
184
|
<div class="form-group">
|
185
|
<label for="filterlogentriesinterfaces"
|
186
|
class="col-sm-4 control-label">Filter interface</label>
|
187
|
<div class="col-sm-6 checkbox">
|
188
|
<select name="filterlogentriesinterfaces" class="form-control">
|
189
|
<?php foreach (array("All" => "ALL") + get_configured_interface_with_descr() as $iface => $ifacename):?>
|
190
|
<option value="<?=$iface?>"
|
191
|
<?=($nentriesinterfaces==$iface?'selected="selected"':'')?>><?=htmlspecialchars($ifacename)?></option>
|
192
|
<?php endforeach;?>
|
193
|
</select>
|
194
|
</div>
|
195
|
</div>
|
196
|
|
197
|
<div class="form-group">
|
198
|
<div class="col-sm-offset-4 col-sm-6">
|
199
|
<button type="submit" class="btn btn-default">Save</button>
|
200
|
</div>
|
201
|
</div>
|
202
|
</form>
|