1 |
9d71da81
|
jim-p
|
<?php
|
2 |
2a2af670
|
jim-p
|
/*
|
3 |
|
|
diag_states_summary.php
|
4 |
|
|
Copyright (C) 2010 Jim Pingle
|
5 |
|
|
|
6 |
|
|
Portions borrowed from diag_dump_states.php:
|
7 |
|
|
Copyright (C) 2005-2009 Scott Ullrich
|
8 |
|
|
Copyright (C) 2005 Colin Smith
|
9 |
|
|
All rights reserved.
|
10 |
|
|
|
11 |
|
|
Redistribution and use in source and binary forms, with or without
|
12 |
|
|
modification, 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 the
|
19 |
|
|
documentation and/or other materials provided with the distribution.
|
20 |
|
|
|
21 |
|
|
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
22 |
|
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
23 |
|
|
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
24 |
|
|
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
25 |
|
|
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
26 |
|
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
27 |
|
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
28 |
|
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
29 |
|
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
30 |
|
|
POSSIBILITY OF SUCH DAMAGE.
|
31 |
|
|
*/
|
32 |
|
|
|
33 |
|
|
/*
|
34 |
|
|
pfSense_BUILDER_BINARIES: /sbin/pfctl
|
35 |
|
|
pfSense_MODULE: filter
|
36 |
|
|
*/
|
37 |
|
|
|
38 |
|
|
##|+PRIV
|
39 |
|
|
##|*IDENT=page-diagnostics-statessummary
|
40 |
|
|
##|*NAME=Diagnostics: States Summary page
|
41 |
|
|
##|*DESCR=Allow access to the 'Diagnostics: States Summary' page.
|
42 |
|
|
##|*MATCH=diag_states_summary.php*
|
43 |
|
|
##|-PRIV
|
44 |
9d71da81
|
jim-p
|
|
45 |
|
|
exec("/sbin/pfctl -s state", $states);
|
46 |
|
|
|
47 |
|
|
$srcipinfo = array();
|
48 |
c1613ade
|
jim-p
|
$dstipinfo = array();
|
49 |
63284430
|
jim-p
|
$allipinfo = array();
|
50 |
c1613ade
|
jim-p
|
$pairipinfo = array();
|
51 |
9d71da81
|
jim-p
|
|
52 |
63284430
|
jim-p
|
function addipinfo(&$iparr, $ip, $proto, $srcport, $dstport) {
|
53 |
|
|
$iparr[$ip]['seen']++;
|
54 |
|
|
$iparr[$ip]['protos'][$proto]['seen']++;
|
55 |
|
|
if (!empty($srcport)) {
|
56 |
|
|
$iparr[$ip]['protos'][$proto]['srcports'][$srcport]++;
|
57 |
|
|
}
|
58 |
|
|
if (!empty($dstport)) {
|
59 |
|
|
$iparr[$ip]['protos'][$proto]['dstports'][$dstport]++;
|
60 |
|
|
}
|
61 |
|
|
}
|
62 |
|
|
|
63 |
9d71da81
|
jim-p
|
$row = 0;
|
64 |
|
|
if(count($states) > 0) {
|
65 |
|
|
foreach($states as $line) {
|
66 |
|
|
$line_split = preg_split("/\s+/", $line);
|
67 |
|
|
$type = array_shift($line_split);
|
68 |
|
|
$proto = array_shift($line_split);
|
69 |
|
|
$state = array_pop($line_split);
|
70 |
|
|
$info = implode(" ", $line_split);
|
71 |
|
|
|
72 |
|
|
/* break up info and extract $srcip and $dstip */
|
73 |
|
|
$ends = preg_split("/\<?-\>?/", $info);
|
74 |
c1613ade
|
jim-p
|
|
75 |
|
|
if (strpos($info, '->') === FALSE) {
|
76 |
|
|
$srcinfo = $ends[count($ends) - 1];
|
77 |
|
|
$dstinfo = $ends[0];
|
78 |
|
|
} else {
|
79 |
|
|
$srcinfo = $ends[0];
|
80 |
|
|
$dstinfo = $ends[count($ends) - 1];
|
81 |
|
|
}
|
82 |
|
|
|
83 |
|
|
$parts = split(":", $srcinfo);
|
84 |
9d71da81
|
jim-p
|
$srcip = trim($parts[0]);
|
85 |
|
|
$srcport = trim($parts[1]);
|
86 |
|
|
|
87 |
c1613ade
|
jim-p
|
$parts = split(":", $dstinfo);
|
88 |
9d71da81
|
jim-p
|
$dstip = trim($parts[0]);
|
89 |
|
|
$dstport = trim($parts[1]);
|
90 |
|
|
|
91 |
63284430
|
jim-p
|
addipinfo($srcipinfo, $srcip, $proto, $srcport, $dstport);
|
92 |
|
|
addipinfo($dstipinfo, $dstip, $proto, $srcport, $dstport);
|
93 |
|
|
addipinfo($pairipinfo, "{$srcip} -> {$dstip}", $proto, $srcport, $dstport);
|
94 |
c1613ade
|
jim-p
|
|
95 |
63284430
|
jim-p
|
addipinfo($allipinfo, $srcip, $proto, $srcport, $dstport);
|
96 |
|
|
addipinfo($allipinfo, $dstip, $proto, $srcport, $dstport);
|
97 |
c1613ade
|
jim-p
|
|
98 |
9d71da81
|
jim-p
|
}
|
99 |
|
|
}
|
100 |
|
|
|
101 |
|
|
function sort_by_ip($a, $b) {
|
102 |
96033063
|
Erik Fonnesbeck
|
return ip2ulong($a) < ip2ulong($b) ? -1 : 1;
|
103 |
9d71da81
|
jim-p
|
}
|
104 |
|
|
|
105 |
2a63c863
|
jim-p
|
function build_port_info($portarr, $proto) {
|
106 |
|
|
$ports = array();
|
107 |
|
|
asort($portarr);
|
108 |
|
|
foreach (array_reverse($portarr, TRUE) as $port => $count) {
|
109 |
|
|
$str = "";
|
110 |
|
|
$service = getservbyport($port, strtolower($proto));
|
111 |
|
|
$port = "{$proto}/{$port}";
|
112 |
|
|
if ($service)
|
113 |
|
|
$port = "{$port} ({$service})";
|
114 |
|
|
$ports[] = "{$port}: {$count}";
|
115 |
|
|
}
|
116 |
|
|
return implode($ports, ', ');
|
117 |
|
|
}
|
118 |
|
|
|
119 |
63284430
|
jim-p
|
function print_summary_table($label, $iparr, $sort = TRUE) { ?>
|
120 |
|
|
|
121 |
|
|
<h3><?php echo $label; ?></h3>
|
122 |
9d71da81
|
jim-p
|
<table class="tabcont" width="100%" border="0" cellspacing="0" cellpadding="0">
|
123 |
|
|
<tr>
|
124 |
e99a1c28
|
Rafaellucas
|
<td class="listhdrr"><?=gettext("IP");?></td>
|
125 |
9049e088
|
Vinicius Coque
|
<td class="listhdrr"># <?=gettext("States");?></td>
|
126 |
e99a1c28
|
Rafaellucas
|
<td class="listhdrr"><?=gettext("Proto");?></td>
|
127 |
9049e088
|
Vinicius Coque
|
<td class="listhdrr"># <?=gettext("States");?></td>
|
128 |
e99a1c28
|
Rafaellucas
|
<td class="listhdrr"><?=gettext("Src Ports");?></td>
|
129 |
|
|
<td class="listhdrr"><?=gettext("Dst Ports");?></td>
|
130 |
9d71da81
|
jim-p
|
</tr>
|
131 |
63284430
|
jim-p
|
<?php if ($sort)
|
132 |
|
|
uksort($iparr, "sort_by_ip");
|
133 |
|
|
foreach($iparr as $ip => $ipinfo) { ?>
|
134 |
9d71da81
|
jim-p
|
<tr>
|
135 |
|
|
<td class='vncell'><?php echo $ip; ?></td>
|
136 |
|
|
<td class='vncell'><?php echo $ipinfo['seen']; ?></td>
|
137 |
|
|
<td class='vncell'> </td>
|
138 |
|
|
<td class='vncell'> </td>
|
139 |
|
|
<td class='vncell'> </td>
|
140 |
|
|
<td class='vncell'> </td>
|
141 |
|
|
</tr>
|
142 |
|
|
<?php foreach($ipinfo['protos'] as $proto => $protoinfo) { ?>
|
143 |
|
|
<tr>
|
144 |
|
|
<td class='list'> </td>
|
145 |
|
|
<td class='list'> </td>
|
146 |
|
|
<td class='listlr'><?php echo $proto; ?></td>
|
147 |
|
|
<td class='listr' align="center"><?php echo $protoinfo['seen']; ?></td>
|
148 |
2a63c863
|
jim-p
|
<td class='listr' align="center"><span title="<?php echo build_port_info($protoinfo['srcports'], $proto); ?>"><?php echo count($protoinfo['srcports']); ?></span></td>
|
149 |
|
|
<td class='listr' align="center"><span title="<?php echo build_port_info($protoinfo['dstports'], $proto); ?>"><?php echo count($protoinfo['dstports']); ?></span></td>
|
150 |
9d71da81
|
jim-p
|
</tr>
|
151 |
|
|
<?php } ?>
|
152 |
|
|
<?php } ?>
|
153 |
|
|
|
154 |
|
|
</table>
|
155 |
|
|
|
156 |
3e6ec5df
|
Renato Botelho
|
<?php
|
157 |
63284430
|
jim-p
|
}
|
158 |
c1613ade
|
jim-p
|
|
159 |
e99a1c28
|
Rafaellucas
|
$pgtitle = array(gettext("Diagnostics"),gettext("State Table Summary"));
|
160 |
63284430
|
jim-p
|
require_once("guiconfig.inc");
|
161 |
|
|
include("head.inc");
|
162 |
|
|
include("fbegin.inc");
|
163 |
c1613ade
|
jim-p
|
|
164 |
|
|
|
165 |
e99a1c28
|
Rafaellucas
|
print_summary_table(gettext("By Source IP"), $srcipinfo);
|
166 |
|
|
print_summary_table(gettext("By Destination IP"), $dstipinfo);
|
167 |
|
|
print_summary_table(gettext("Total per IP"), $allipinfo);
|
168 |
|
|
print_summary_table(gettext("By IP Pair"), $pairipinfo, FALSE);
|
169 |
63284430
|
jim-p
|
?>
|
170 |
c1613ade
|
jim-p
|
|
171 |
9d71da81
|
jim-p
|
<?php include("fend.inc"); ?>
|