1
|
<?php
|
2
|
/*
|
3
|
diag_logs_filter_summary.php
|
4
|
Copyright (C) 2009 Jim Pingle (jpingle@gmail.com)
|
5
|
All rights reserved.
|
6
|
|
7
|
Redistribution and use in source and binary forms, with or without
|
8
|
modification, are permitted provided that the following conditions are met:
|
9
|
|
10
|
1. Redistributions of source code must retain the above copyright notice,
|
11
|
this list of conditions and the following disclaimer.
|
12
|
|
13
|
2. Redistributions in binary form must reproduce the above copyright
|
14
|
notice, this list of conditions and the following disclaimer in the
|
15
|
documentation and/or other materials provided with the distribution.
|
16
|
|
17
|
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
18
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
19
|
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
20
|
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
21
|
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
22
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
23
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
24
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
25
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
26
|
POSSIBILITY OF SUCH DAMAGE.
|
27
|
*/
|
28
|
|
29
|
/*
|
30
|
pfSense_BUILDER_BINARIES:
|
31
|
pfSense_MODULE: filter
|
32
|
*/
|
33
|
|
34
|
$pgtitle = gettext("Status").": ".gettext("System logs").": ".gettext("Firewall Log Summary");
|
35
|
$shortcut_section = "firewall";
|
36
|
require_once("guiconfig.inc");
|
37
|
include_once("filter_log.inc");
|
38
|
|
39
|
$filter_logfile = "{$g['varlog_path']}/filter.log";
|
40
|
$lines = 5000;
|
41
|
$entriesperblock = 5;
|
42
|
|
43
|
$filterlog = conv_log_filter($filter_logfile, $lines, $lines);
|
44
|
$gotlines = count($filterlog);
|
45
|
$fields = array(
|
46
|
'act' => gettext("Actions"),
|
47
|
'interface' => gettext("Interfaces"),
|
48
|
'proto' => gettext("Protocols"),
|
49
|
'srcip' => gettext("Source IPs"),
|
50
|
'dstip' => gettext("Destination IPs"),
|
51
|
'srcport' => gettext("Source Ports"),
|
52
|
'dstport' => gettext("Destination Ports"));
|
53
|
|
54
|
$summary = array();
|
55
|
foreach (array_keys($fields) as $f) {
|
56
|
$summary[$f] = array();
|
57
|
}
|
58
|
|
59
|
$totals = array();
|
60
|
|
61
|
function cmp($a, $b) {
|
62
|
if ($a == $b) {
|
63
|
return 0;
|
64
|
}
|
65
|
return ($a < $b) ? 1 : -1;
|
66
|
}
|
67
|
|
68
|
function stat_block($summary, $stat, $num) {
|
69
|
global $g, $gotlines, $fields;
|
70
|
uasort($summary[$stat] , 'cmp');
|
71
|
print "<table width=\"200\" cellpadding=\"3\" cellspacing=\"0\" border=\"1\" summary=\"source destination ip\">";
|
72
|
print "<tr><th colspan=\"2\">{$fields[$stat]} ".gettext("data")."</th></tr>";
|
73
|
$k = array_keys($summary[$stat]);
|
74
|
$total = 0;
|
75
|
$numentries = 0;
|
76
|
for ($i=0; $i < $num; $i++) {
|
77
|
if ($k[$i]) {
|
78
|
$total += $summary[$stat][$k[$i]];
|
79
|
$numentries++;
|
80
|
$outstr = $k[$i];
|
81
|
if (is_ipaddr($outstr)) {
|
82
|
$outstr = "<a href=\"diag_dns.php?host={$outstr}\" title=\"".gettext("Reverse Resolve with DNS")."\"><img border=\"0\" src=\"/themes/{$g['theme']}/images/icons/icon_log.gif\" alt=\"log\" /></a> {$outstr}";
|
83
|
} elseif (substr_count($outstr, '/') == 1) {
|
84
|
list($proto, $port) = explode('/', $outstr);
|
85
|
$service = getservbyport($port, strtolower($proto));
|
86
|
if ($service)
|
87
|
$outstr .= ": {$service}";
|
88
|
}
|
89
|
print "<tr><td>{$outstr}</td><td width=\"50\" align=\"right\">{$summary[$stat][$k[$i]]}</td></tr>";
|
90
|
}
|
91
|
}
|
92
|
$leftover = $gotlines - $total;
|
93
|
if ($leftover > 0) {
|
94
|
print "<tr><td>Other</td><td width=\"50\" align=\"right\">{$leftover}</td></tr>";
|
95
|
}
|
96
|
print "</table>";
|
97
|
}
|
98
|
|
99
|
function pie_block($summary, $stat, $num) {
|
100
|
global $gotlines, $fields;
|
101
|
uasort($summary[$stat] , 'cmp');
|
102
|
$k = array_keys($summary[$stat]);
|
103
|
$total = 0;
|
104
|
$numentries = 0;
|
105
|
print "\n<script type=\"text/javascript\">\n";
|
106
|
print "//<![CDATA[\n";
|
107
|
for ($i=0; $i < $num; $i++) {
|
108
|
if ($k[$i]) {
|
109
|
$total += $summary[$stat][$k[$i]];
|
110
|
$numentries++;
|
111
|
print "var d{$stat}{$i} = [];\n";
|
112
|
print "d{$stat}{$i}.push([1, {$summary[$stat][$k[$i]]}]);\n";
|
113
|
}
|
114
|
}
|
115
|
$leftover = $gotlines - $total;
|
116
|
if ($leftover > 0) {
|
117
|
print "var d{$stat}{$num} = [];\n";
|
118
|
print "d{$stat}{$num}.push([1, {$leftover}]);\n";
|
119
|
}
|
120
|
|
121
|
print "Event.observe(window, 'load', function() {\n";
|
122
|
print " new Proto.Chart($('piechart{$stat}'),\n";
|
123
|
print " [\n";
|
124
|
for ($i=0; $i < $num; $i++) {
|
125
|
if ($k[$i]) {
|
126
|
print " { data: d{$stat}{$i}, label: \"{$k[$i]}\"}";
|
127
|
if (!(($i == ($numentries - 1)) && ($leftover <= 0)))
|
128
|
print ",\n";
|
129
|
else
|
130
|
print "\n";
|
131
|
}
|
132
|
}
|
133
|
if ($leftover > 0)
|
134
|
print " { data: d{$stat}{$i}, label: \"Other\"}\n";
|
135
|
print " ],\n";
|
136
|
print " {\n";
|
137
|
print " pies: {show: true, autoScale: true},\n";
|
138
|
print " legend: {show: true, labelFormatter: lblfmt}\n";
|
139
|
print " });\n";
|
140
|
print "});\n";
|
141
|
print "//]]>\n";
|
142
|
print "</script>\n";
|
143
|
print "<table cellpadding=\"3\" cellspacing=\"0\" border=\"0\" summary=\"pie chart\">";
|
144
|
print "<tr><th><font size=\"+1\">{$fields[$stat]}</font></th></tr>";
|
145
|
print "<tr><td><div id=\"piechart{$stat}\" style=\"width:450px;height:300px\"></div></td></tr>";
|
146
|
print "</table>\n";
|
147
|
}
|
148
|
|
149
|
foreach ($filterlog as $fe) {
|
150
|
$specialfields = array('srcport', 'dstport');
|
151
|
foreach (array_keys($fields) as $field) {
|
152
|
if (!in_array($field, $specialfields))
|
153
|
$summary[$field][$fe[$field]]++;
|
154
|
}
|
155
|
/* Handle some special cases */
|
156
|
if ($fe['srcport'])
|
157
|
$summary['srcport'][$fe['proto'].'/'.$fe['srcport']]++;
|
158
|
else
|
159
|
$summary['srcport'][$fe['srcport']]++;
|
160
|
if ($fe['dstport'])
|
161
|
$summary['dstport'][$fe['proto'].'/'.$fe['dstport']]++;
|
162
|
else
|
163
|
$summary['dstport'][$fe['dstport']]++;
|
164
|
}
|
165
|
|
166
|
include("head.inc"); ?>
|
167
|
<body link="#000000" vlink="#000000" alink="#000000">
|
168
|
<script src="/javascript/filter_log.js" type="text/javascript"></script>
|
169
|
<script type="text/javascript" src="/protochart/prototype.js"></script>
|
170
|
<script type="text/javascript" src="/protochart/ProtoChart.js"></script>
|
171
|
<!--[if IE]>
|
172
|
<script type="text/javascript" src="/protochart/excanvas.js">
|
173
|
</script>
|
174
|
<![endif]-->
|
175
|
<script type="text/javascript">
|
176
|
//<![CDATA[
|
177
|
function lblfmt(lbl) {
|
178
|
return '<font size=\"-2\">' + lbl + '<\/font>'
|
179
|
}
|
180
|
//]]>
|
181
|
</script>
|
182
|
|
183
|
<?php include("fbegin.inc"); ?>
|
184
|
<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="logs filter summary">
|
185
|
<tr><td>
|
186
|
<?php
|
187
|
$tab_array = array();
|
188
|
$tab_array[] = array(gettext("System"), false, "diag_logs.php");
|
189
|
$tab_array[] = array(gettext("Firewall"), true, "diag_logs_filter.php");
|
190
|
$tab_array[] = array(gettext("DHCP"), false, "diag_logs_dhcp.php");
|
191
|
$tab_array[] = array(gettext("Portal Auth"), false, "diag_logs_auth.php");
|
192
|
$tab_array[] = array(gettext("IPsec"), false, "diag_logs_ipsec.php");
|
193
|
$tab_array[] = array(gettext("PPP"), false, "diag_logs_ppp.php");
|
194
|
$tab_array[] = array(gettext("VPN"), false, "diag_logs_vpn.php");
|
195
|
$tab_array[] = array(gettext("Load Balancer"), false, "diag_logs_relayd.php");
|
196
|
$tab_array[] = array(gettext("OpenVPN"), false, "diag_logs_openvpn.php");
|
197
|
$tab_array[] = array(gettext("NTP"), false, "diag_logs_ntpd.php");
|
198
|
$tab_array[] = array(gettext("Settings"), false, "diag_logs_settings.php");
|
199
|
display_top_tabs($tab_array);
|
200
|
?>
|
201
|
</td></tr>
|
202
|
<tr><td class="tabnavtbl">
|
203
|
<?php
|
204
|
$tab_array = array();
|
205
|
$tab_array[] = array(gettext("Normal View"), false, "/diag_logs_filter.php");
|
206
|
$tab_array[] = array(gettext("Dynamic View"), false, "/diag_logs_filter_dynamic.php");
|
207
|
$tab_array[] = array(gettext("Summary View"), true, "/diag_logs_filter_summary.php");
|
208
|
display_top_tabs($tab_array);
|
209
|
?>
|
210
|
</td>
|
211
|
</tr>
|
212
|
<tr>
|
213
|
<td>
|
214
|
<div id="mainarea">
|
215
|
<table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0" align="center" summary="main area">
|
216
|
<tr><td align="center">
|
217
|
|
218
|
<?php printf (gettext('This is a firewall log summary, of the last %1$s lines of the firewall log (Max %2$s).'), $gotlines, $lines)?><br />
|
219
|
<?=gettext("NOTE: IE8 users must enable compatibility view.")?>
|
220
|
|
221
|
<?php
|
222
|
foreach(array_keys($fields) as $field) {
|
223
|
pie_block($summary, $field , $entriesperblock);
|
224
|
echo "<br /><br />";
|
225
|
stat_block($summary, $field , $entriesperblock);
|
226
|
echo "<br /><br />";
|
227
|
}
|
228
|
?>
|
229
|
</td></tr></table>
|
230
|
</div>
|
231
|
</td>
|
232
|
</tr>
|
233
|
</table>
|
234
|
<?php include("fend.inc"); ?>
|
235
|
</body>
|
236
|
</html>
|