1 |
19ac33af
|
Scott Ullrich
|
<?php
|
2 |
|
|
/* $Id$ */
|
3 |
|
|
/*
|
4 |
|
|
ifstats.php
|
5 |
|
|
part of pfSense (http://www.pfsense.com)
|
6 |
|
|
|
7 |
|
|
Copyright (C) 2005-2006 Scott Ullrich (sullrich@gmail.com)
|
8 |
|
|
All rights reserved.
|
9 |
|
|
|
10 |
|
|
Redistribution and use in source and binary forms, with or without
|
11 |
|
|
modification, are permitted provided that the following conditions are met:
|
12 |
|
|
|
13 |
|
|
1. Redistributions of source code must retain the above copyright notice,
|
14 |
|
|
this list of conditions and the following disclaimer.
|
15 |
|
|
|
16 |
|
|
2. Redistributions in binary form must reproduce the above copyright
|
17 |
|
|
notice, this list of conditions and the following disclaimer in the
|
18 |
|
|
documentation and/or other materials provided with the distribution.
|
19 |
|
|
|
20 |
|
|
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
21 |
|
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
22 |
|
|
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
23 |
|
|
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
24 |
|
|
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
25 |
|
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
26 |
|
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
27 |
|
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
28 |
|
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
29 |
|
|
POSSIBILITY OF SUCH DAMAGE.
|
30 |
|
|
*/
|
31 |
|
|
|
32 |
|
|
require("functions.inc");
|
33 |
|
|
require("config.inc");
|
34 |
|
|
|
35 |
|
|
$ifinfo = array();
|
36 |
|
|
|
37 |
|
|
$if = $_GET['if'];
|
38 |
|
|
|
39 |
|
|
$ifinfo['hwif'] = $config['interfaces'][$if]['if'];
|
40 |
|
|
if(!$ifinfo['hwif'])
|
41 |
|
|
$ifinfo['hwif'] = $if;
|
42 |
0543e1e9
|
Scott Ullrich
|
|
43 |
|
|
$ifinfo['if'] = $ifinfo['hwif'];
|
44 |
19ac33af
|
Scott Ullrich
|
|
45 |
|
|
/* run netstat to determine link info */
|
46 |
|
|
$linkinfo = "";
|
47 |
|
|
unset($linkinfo);
|
48 |
|
|
exec("/usr/bin/netstat -I " . $ifinfo['hwif'] . " -nWb -f link", $linkinfo);
|
49 |
|
|
$linkinfo = preg_split("/\s+/", $linkinfo[1]);
|
50 |
|
|
if (preg_match("/\*$/", $linkinfo[0])) {
|
51 |
|
|
$ifinfo['status'] = "down";
|
52 |
|
|
} else {
|
53 |
|
|
$ifinfo['status'] = "up";
|
54 |
|
|
}
|
55 |
|
|
|
56 |
|
|
if (!strstr($ifinfo['if'],'tun')) {
|
57 |
|
|
$ifinfo['macaddr'] = $linkinfo[3];
|
58 |
|
|
$ifinfo['inpkts'] = $linkinfo[4];
|
59 |
|
|
$ifinfo['inerrs'] = $linkinfo[5];
|
60 |
|
|
$ifinfo['inbytes'] = $linkinfo[6];
|
61 |
|
|
$ifinfo['outpkts'] = $linkinfo[7];
|
62 |
|
|
$ifinfo['outerrs'] = $linkinfo[8];
|
63 |
|
|
$ifinfo['outbytes'] = $linkinfo[9];
|
64 |
|
|
$ifinfo['collisions'] = $linkinfo[10];
|
65 |
|
|
} else {
|
66 |
|
|
$ifinfo['inpkts'] = $linkinfo[3];
|
67 |
|
|
$ifinfo['inbytes'] = $linkinfo[5];
|
68 |
|
|
$ifinfo['outpkts'] = $linkinfo[6];
|
69 |
|
|
$ifinfo['outbytes'] = $linkinfo[8];
|
70 |
|
|
}
|
71 |
|
|
|
72 |
|
|
$temp = gettimeofday();
|
73 |
31cb8b31
|
Scott Ullrich
|
$timing = (double)$temp["sec"] + (double)$temp["usec"] / 1000000.0;
|
74 |
19ac33af
|
Scott Ullrich
|
|
75 |
deea2272
|
Scott Ullrich
|
echo "$timing|" . $ifinfo['inbytes'] . "|" . $ifinfo['outbytes'] . "\n";
|
76 |
19ac33af
|
Scott Ullrich
|
|
77 |
|
|
?>
|