1
|
<?php
|
2
|
/*
|
3
|
$Id$
|
4
|
Copyright 2007 Scott Dale
|
5
|
Part of pfSense widgets (https://www.pfsense.org)
|
6
|
originally based on m0n0wall (http://m0n0.ch/wall)
|
7
|
|
8
|
Copyright (C) 2004-2005 T. Lechat <dev@lechat.org>, Manuel Kasper <mk@neon1.net>
|
9
|
and Jonathan Watt <jwatt@jwatt.org>.
|
10
|
All rights reserved.
|
11
|
|
12
|
Redistribution and use in source and binary forms, with or without
|
13
|
modification, are permitted provided that the following conditions are met:
|
14
|
|
15
|
1. Redistributions of source code must retain the above copyright notice,
|
16
|
this list of conditions and the following disclaimer.
|
17
|
|
18
|
2. Redistributions in binary form must reproduce the above copyright
|
19
|
notice, this list of conditions and the following disclaimer in the
|
20
|
documentation and/or other materials provided with the distribution.
|
21
|
|
22
|
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
23
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
24
|
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
25
|
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
26
|
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
27
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
28
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
29
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
30
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
31
|
POSSIBILITY OF SUCH DAMAGE.
|
32
|
*/
|
33
|
|
34
|
$nocsrf = true;
|
35
|
|
36
|
require_once("guiconfig.inc");
|
37
|
require_once("pfsense-utils.inc");
|
38
|
require_once("functions.inc");
|
39
|
|
40
|
/* In an effort to reduce duplicate code, many shared functions have been moved here. */
|
41
|
require_once("filter_log.inc");
|
42
|
|
43
|
if($_POST['filterlogentries']) {
|
44
|
unset($config['widgets']['filterlogentries']);
|
45
|
if( ($_POST['filterlogentries']) and ($_POST['filterlogentries'] != ' ') ) $config['widgets']['filterlogentries'] = $_POST['filterlogentries'];
|
46
|
|
47
|
unset($config['widgets']['filterlogentriesacts']);
|
48
|
if($_POST['actpass']) $config['widgets']['filterlogentriesacts'] .= $_POST['actpass'] . " ";
|
49
|
if($_POST['actblock']) $config['widgets']['filterlogentriesacts'] .= $_POST['actblock'] . " ";
|
50
|
if($_POST['actreject']) $config['widgets']['filterlogentriesacts'] .= $_POST['actreject'] . " ";
|
51
|
if (isset($config['widgets']['filterlogentriesacts'])) $config['widgets']['filterlogentriesacts'] = trim($config['widgets']['filterlogentriesacts']);
|
52
|
|
53
|
unset($config['widgets']['filterlogentriesinterfaces']);
|
54
|
if( ($_POST['filterlogentriesinterfaces']) and ($_POST['filterlogentriesinterfaces'] != "All") ) $config['widgets']['filterlogentriesinterfaces'] = $_POST['filterlogentriesinterfaces'];
|
55
|
if (isset($config['widgets']['filterlogentriesinterfaces'])) $config['widgets']['filterlogentriesinterfaces'] = trim($config['widgets']['filterlogentriesinterfaces']);
|
56
|
|
57
|
write_config("Saved Filter Log Entries via Dashboard");
|
58
|
$filename = $_SERVER['HTTP_REFERER'];
|
59
|
if(headers_sent($file, $line)){
|
60
|
echo '<script type="text/javascript">';
|
61
|
echo '//<![CDATA[';
|
62
|
echo 'window.location.href="'.$filename.'";';
|
63
|
echo '//]]>';
|
64
|
echo '</script>';
|
65
|
echo '<noscript>';
|
66
|
echo '<meta http-equiv="refresh" content="0;url='.$filename.'" />';
|
67
|
echo '</noscript>';
|
68
|
}
|
69
|
Header("Location: /");
|
70
|
}
|
71
|
|
72
|
$nentries = isset($config['widgets']['filterlogentries']) ? $config['widgets']['filterlogentries'] : 5;
|
73
|
|
74
|
//set variables for log
|
75
|
|
76
|
$nentriesacts = isset($config['widgets']['filterlogentriesacts']) ? $config['widgets']['filterlogentriesacts'] : 'All';
|
77
|
$nentriesinterfaces = isset($config['widgets']['filterlogentriesinterfaces']) ? $config['widgets']['filterlogentriesinterfaces'] : 'All';
|
78
|
|
79
|
$filterfieldsarray = array("act", "interface");
|
80
|
$filterfieldsarray['act'] = $nentriesacts;
|
81
|
$filterfieldsarray['interface'] = $nentriesinterfaces;
|
82
|
|
83
|
$filter_logfile = "{$g['varlog_path']}/filter.log";
|
84
|
$filterlog = conv_log_filter($filter_logfile, $nentries, 50, $filterfieldsarray); //Get log entries
|
85
|
|
86
|
/* AJAX related routines */
|
87
|
handle_ajax($nentries, $nentries + 20);
|
88
|
|
89
|
?>
|
90
|
|
91
|
<script type="text/javascript">
|
92
|
//<![CDATA[
|
93
|
lastsawtime = '<?php echo time(); ?>';
|
94
|
var lines = Array();
|
95
|
var timer;
|
96
|
var updateDelay = 30000;
|
97
|
var isBusy = false;
|
98
|
var isPaused = false;
|
99
|
var nentries = <?php echo $nentries; ?>;
|
100
|
|
101
|
<?php
|
102
|
if(isset($config['syslog']['reverse']))
|
103
|
echo "var isReverse = true;\n";
|
104
|
else
|
105
|
echo "var isReverse = false;\n";
|
106
|
?>
|
107
|
|
108
|
/* Called by the AJAX updater */
|
109
|
function format_log_line(row) {
|
110
|
var line = '<td class="listMRlr" align="center">' + row[0] + '<\/td>' +
|
111
|
'<td class="listMRr ellipsis" title="' + row[1] + '">' + row[1].slice(0,-3) + '<\/td>' +
|
112
|
'<td class="listMRr ellipsis" title="' + row[2] + '">' + row[2] + '<\/td>' +
|
113
|
'<td class="listMRr ellipsis" title="' + row[3] + '">' + row[3] + '<\/td>' +
|
114
|
'<td class="listMRr ellipsis" title="' + row[4] + '">' + row[4] + '<\/td>';
|
115
|
|
116
|
var nentriesacts = "<?php echo $nentriesacts; ?>";
|
117
|
var nentriesinterfaces = "<?php echo $nentriesinterfaces; ?>";
|
118
|
|
119
|
var Action = row[0].match(/alt=.*?(pass|block|reject)/i).join("").match(/pass|block|reject/i).join("");
|
120
|
var Interface = row[2];
|
121
|
|
122
|
if ( !(in_arrayi(Action, nentriesacts.replace (/\s+/g, ',').split(',') ) ) && (nentriesacts != 'All') ) return false;
|
123
|
if ( !(in_arrayi(Interface, nentriesinterfaces.replace(/\s+/g, ',').split(',') ) ) && (nentriesinterfaces != 'All') ) return false;
|
124
|
|
125
|
return line;
|
126
|
}
|
127
|
//]]>
|
128
|
</script>
|
129
|
<script src="/javascript/filter_log.js" type="text/javascript"></script>
|
130
|
<input type="hidden" id="log-config" name="log-config" value="" />
|
131
|
|
132
|
<div id="log-settings" class="widgetconfigdiv" style="display:none;">
|
133
|
<form action="/widgets/widgets/log.widget.php" method="post" name="iforma">
|
134
|
Number of lines to display:
|
135
|
<select name="filterlogentries" class="formfld unknown" id="filterlogentries">
|
136
|
<?php for ($i = 1; $i <= 20; $i++) { ?>
|
137
|
<option value="<?php echo $i;?>" <?php if ($nentries == $i) echo "selected=\"selected\"";?>><?php echo $i;?></option>
|
138
|
<?php } ?>
|
139
|
</select>
|
140
|
|
141
|
<?php
|
142
|
$Include_Act = explode(",", str_replace(" ", ",", $nentriesacts));
|
143
|
if ($nentriesinterfaces == "All") $nentriesinterfaces = "";
|
144
|
?>
|
145
|
<input id="actpass" name="actpass" type="checkbox" value="Pass" <?php if (in_arrayi('Pass', $Include_Act)) echo "checked=\"checked\""; ?> /> Pass
|
146
|
<input id="actblock" name="actblock" type="checkbox" value="Block" <?php if (in_arrayi('Block', $Include_Act)) echo "checked=\"checked\""; ?> /> Block
|
147
|
<input id="actreject" name="actreject" type="checkbox" value="Reject" <?php if (in_arrayi('Reject', $Include_Act)) echo "checked=\"checked\""; ?> /> Reject
|
148
|
<br/>
|
149
|
Interfaces:
|
150
|
<input id="filterlogentriesinterfaces" name="filterlogentriesinterfaces" class="formfld unknown" type="text" size="20" value="<?= $nentriesinterfaces ?>" />
|
151
|
|
152
|
<input id="submita" name="submita" type="submit" class="formbtn" value="Save" />
|
153
|
</form>
|
154
|
</div>
|
155
|
|
156
|
<table width="100%" border="0" cellpadding="0" cellspacing="0" style="table-layout: fixed;" summary="logs">
|
157
|
<colgroup>
|
158
|
<col style='width: 7%;' />
|
159
|
<col style='width: 23%;' />
|
160
|
<col style='width: 11%;' />
|
161
|
<col style='width: 28%;' />
|
162
|
<col style='width: 31%;' />
|
163
|
</colgroup>
|
164
|
<thead>
|
165
|
<tr>
|
166
|
<td class="listhdrr"><?=gettext("Act");?></td>
|
167
|
<td class="listhdrr"><?=gettext("Time");?></td>
|
168
|
<td class="listhdrr"><?=gettext("IF");?></td>
|
169
|
<td class="listhdrr"><?=gettext("Source");?></td>
|
170
|
<td class="listhdrr"><?=gettext("Destination");?></td>
|
171
|
</tr>
|
172
|
</thead>
|
173
|
<tbody id='filter-log-entries'>
|
174
|
<?php
|
175
|
$rowIndex = 0;
|
176
|
foreach ($filterlog as $filterent):
|
177
|
$evenRowClass = $rowIndex % 2 ? " listMReven" : " listMRodd";
|
178
|
$rowIndex++;
|
179
|
?>
|
180
|
<tr class="<?=$evenRowClass?>">
|
181
|
<td class="listMRlr" nowrap="nowrap" align="center">
|
182
|
<a href="#" onclick="javascript:getURL('diag_logs_filter.php?getrulenum=<?php echo "{$filterent['rulenum']},{$filterent['act']}"; ?>', outputrule);">
|
183
|
<img border="0" src="<?php echo find_action_image($filterent['act']);?>" width="11" height="11" alt="<?php echo $filterent['act'];?>" title="<?php echo $filterent['act'];?>" />
|
184
|
</a>
|
185
|
</td>
|
186
|
<td class="listMRr ellipsis nowrap" title="<?php echo htmlspecialchars($filterent['time']);?>"><?php echo substr(htmlspecialchars($filterent['time']),0,-3);?></td>
|
187
|
<td class="listMRr ellipsis nowrap" title="<?php echo htmlspecialchars($filterent['interface']);?>"><?php echo htmlspecialchars($filterent['interface']);?></td>
|
188
|
<td class="listMRr ellipsis nowrap" title="<?php echo htmlspecialchars($filterent['src']);?>">
|
189
|
<a href="#" onclick="javascript:getURL('diag_dns.php?host=<?php echo "{$filterent['srcip']}"; ?>&dialog_output=true', outputrule);" title="<?=gettext("Reverse Resolve with DNS");?>">
|
190
|
<?php echo htmlspecialchars($filterent['srcip']);?></a></td>
|
191
|
<td class="listMRr ellipsis nowrap" title="<?php echo htmlspecialchars($filterent['dst']);?>">
|
192
|
<a href="#" onclick="javascript:getURL('diag_dns.php?host=<?php echo "{$filterent['dstip']}"; ?>&dialog_output=true', outputrule);" title="<?=gettext("Reverse Resolve with DNS");?>">
|
193
|
<?php echo htmlspecialchars($filterent['dstip']);?></a><?php echo ":" . htmlspecialchars($filterent['dstport']);?></td>
|
194
|
<?php
|
195
|
if ($filterent['proto'] == "TCP")
|
196
|
$filterent['proto'] .= ":{$filterent['tcpflags']}";
|
197
|
?>
|
198
|
</tr>
|
199
|
<?php
|
200
|
endforeach;
|
201
|
if ($rowIndex == 0) {
|
202
|
?>
|
203
|
<tr><td></td></tr>
|
204
|
<?php
|
205
|
}
|
206
|
?>
|
207
|
</tbody>
|
208
|
</table>
|
209
|
|
210
|
<!-- needed to display the widget settings menu -->
|
211
|
<script type="text/javascript">
|
212
|
//<![CDATA[
|
213
|
selectIntLink = "log-configure";
|
214
|
textlink = document.getElementById(selectIntLink);
|
215
|
textlink.style.display = "inline";
|
216
|
//]]>
|
217
|
</script>
|