Projet

Général

Profil

Télécharger (7,64 ko) Statistiques
| Branche: | Tag: | Révision:

univnautes / usr / local / www / diag_logs_filter_summary.php @ 2d1e985d

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 $gotlines, $fields;
70
	uasort($summary[$stat] , 'cmp');
71
	print '<table width="200px" cellpadding="3" cellspacing="0" border="1">';
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\"></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='50px' align='right'>{$summary[$stat][$k[$i]]}</td></tr>\n";
90
		}
91
	}
92
	$leftover = $gotlines - $total;
93
	if ($leftover > 0) {
94
		print "<tr><td>Other</td><td width='50px' align='right'>{$leftover}</td></tr>\n";
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 language=\"javascript\" type=\"text/javascript\">\n";
106
	for ($i=0; $i < $num; $i++) {
107
		if ($k[$i]) {
108
			$total += $summary[$stat][$k[$i]];
109
			$numentries++;
110
			print "var d{$stat}{$i} = [];\n";
111
			print "d{$stat}{$i}.push([1, {$summary[$stat][$k[$i]]}]);\n";
112
		}
113
	}
114
	$leftover = $gotlines - $total;
115
	if ($leftover > 0) {
116
		print "var d{$stat}{$num} = [];\n";
117
		print "d{$stat}{$num}.push([1, {$leftover}]);\n";
118
	}
119

    
120
	print "Event.observe(window, 'load', function() {\n";
121
	print "	new Proto.Chart($('piechart{$stat}'),           \n";
122
	print "			[\n";
123
	for ($i=0; $i < $num; $i++) {
124
		if ($k[$i]) {
125
			print "			{ data: d{$stat}{$i}, label: \"{$k[$i]}\"}";
126
			if (!(($i == ($numentries - 1)) && ($leftover <= 0)))
127
				print ",\n";
128
			else
129
				print "\n";
130
		}
131
	}
132
	if ($leftover > 0)
133
		print "			{ data: d{$stat}{$i}, label: \"Other\"}\n";
134
	print "			],\n";
135
	print "			{\n";
136
	print "				pies: {show: true, autoScale: true},\n";
137
	print "				legend: {show: true, labelFormatter: lblfmt}\n";
138
	print "			});\n";
139
	print "});\n";
140

    
141
	print "</script>";
142
	print "<table cellpadding=\"3\" cellspacing=\"0\" border=\"0\">";
143
	print "<tr><th><font size=\"+1\">{$fields[$stat]}</font></th></tr>";
144
	print "<tr><td><div id=\"piechart{$stat}\" style=\"width:450px;height:300px\"></div>\n";
145
	print "</table>";
146
}
147

    
148
foreach ($filterlog as $fe) {
149
	$specialfields = array('srcport', 'dstport');
150
	foreach (array_keys($fields) as $field) {
151
		if (!in_array($field, $specialfields))
152
			$summary[$field][$fe[$field]]++;
153
	}
154
	/* Handle some special cases */
155
	if ($fe['srcport'])
156
		$summary['srcport'][$fe['proto'].'/'.$fe['srcport']]++;
157
	else
158
		$summary['srcport'][$fe['srcport']]++;
159
	if ($fe['dstport'])
160
		$summary['dstport'][$fe['proto'].'/'.$fe['dstport']]++;
161
	else
162
		$summary['dstport'][$fe['dstport']]++;
163
}
164

    
165
include("head.inc"); ?>
166
<body link="#000000" vlink="#000000" alink="#000000">
167
<script src="/javascript/filter_log.js" type="text/javascript"></script>
168
<script language="javascript" type="text/javascript" src="/protochart/prototype.js"></script>
169
<script language="javascript" type="text/javascript" src="/protochart/ProtoChart.js"></script>
170
<!--[if IE]>
171
<script language="javascript" type="text/javascript" src="/protochart/excanvas.js">
172
</script>
173
<![endif]-->
174
<script language="javascript" type="text/javascript">
175
	function lblfmt(lbl) {
176
		return '<font size=\"-2\">' + lbl + '</font>'
177
	}
178
</script>
179

    
180
<?php include("fbegin.inc"); ?>
181
<table width="100%" border="0" cellpadding="0" cellspacing="0">
182
  <tr><td>
183
<?php
184
	$tab_array = array();
185
	$tab_array[] = array(gettext("System"), false, "diag_logs.php");
186
	$tab_array[] = array(gettext("Firewall"), true, "diag_logs_filter.php");
187
	$tab_array[] = array(gettext("DHCP"), false, "diag_logs_dhcp.php");
188
	$tab_array[] = array(gettext("Portal Auth"), false, "diag_logs_auth.php");
189
	$tab_array[] = array(gettext("IPsec"), false, "diag_logs_ipsec.php");
190
	$tab_array[] = array(gettext("PPP"), false, "diag_logs_ppp.php");
191
	$tab_array[] = array(gettext("VPN"), false, "diag_logs_vpn.php");
192
	$tab_array[] = array(gettext("Load Balancer"), false, "diag_logs_relayd.php");
193
	$tab_array[] = array(gettext("OpenVPN"), false, "diag_logs_openvpn.php");
194
	$tab_array[] = array(gettext("NTP"), false, "diag_logs_ntpd.php");
195
	$tab_array[] = array(gettext("Settings"), false, "diag_logs_settings.php");
196
	display_top_tabs($tab_array);
197
?>
198
 </td></tr>
199
  <tr>
200
    <td>
201
	<div id="mainarea">
202
		<table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0" align="center">
203
		<tr><td colspan="6" align="left">
204
			<a href="diag_logs_filter.php"><?=gettext("Normal View");?></a> | <a href="diag_logs_filter_dynamic.php"><?=gettext("Dynamic View");?></a> | <?=gettext("Summary View");?><br/><br/>
205
		</td></tr>
206
		<tr><td align="center">
207

    
208
<?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 />
209
<?=gettext("NOTE: IE8 users must enable compatibility view.")?>
210

    
211
<?php
212
foreach(array_keys($fields) as $field) {
213
	pie_block($summary, $field , $entriesperblock);
214
	echo "<br /><br />";
215
	stat_block($summary, $field , $entriesperblock);
216
	echo "<br /><br />";
217
}
218
?>
219
		</td></tr></table>
220
		</div>
221
	</td>
222
  </tr>
223
</table>
224
<?php include("fend.inc"); ?>
(23-23/246)