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 |
7ac5a4cb
|
Scott Ullrich
|
/*
|
32 |
|
|
pfSense_BUILDER_BINARIES: /usr/bin/netstat
|
33 |
|
|
pfSense_MODULE: interfaces
|
34 |
|
|
*/
|
35 |
19ac33af
|
Scott Ullrich
|
|
36 |
6b07c15a
|
Matthew Grooms
|
##|+PRIV
|
37 |
|
|
##|*IDENT=page-xmlrpcinterfacestats
|
38 |
|
|
##|*NAME=XMLRPC Interface Stats page
|
39 |
|
|
##|*DESCR=Allow access to the 'XMLRPC Interface Stats' page.
|
40 |
|
|
##|*MATCH=ifstats.php*
|
41 |
|
|
##|-PRIV
|
42 |
|
|
|
43 |
2a2b79f4
|
Bill Marquette
|
require_once('guiconfig.inc');
|
44 |
872ce0dd
|
Ermal Luçi
|
require_once("interfaces.inc");
|
45 |
19ac33af
|
Scott Ullrich
|
|
46 |
|
|
$ifinfo = array();
|
47 |
|
|
|
48 |
|
|
$if = $_GET['if'];
|
49 |
|
|
|
50 |
85a5da13
|
Ermal Luçi
|
$realif = get_real_interface($if);
|
51 |
872ce0dd
|
Ermal Luçi
|
if(!$realif)
|
52 |
|
|
$realif = $if; // Need for IPSec case interface.
|
53 |
19ac33af
|
Scott Ullrich
|
|
54 |
|
|
/* run netstat to determine link info */
|
55 |
|
|
$linkinfo = "";
|
56 |
|
|
unset($linkinfo);
|
57 |
872ce0dd
|
Ermal Luçi
|
exec("/usr/bin/netstat -I {$realif} -nWb -f link", $linkinfo);
|
58 |
19ac33af
|
Scott Ullrich
|
$linkinfo = preg_split("/\s+/", $linkinfo[1]);
|
59 |
872ce0dd
|
Ermal Luçi
|
if (preg_match("/^enc|^tun|^pppoe|^pptp/i", $realif)) {
|
60 |
c1abd446
|
Seth Mos
|
$ifinfo['inpkts'] = $linkinfo[3];
|
61 |
d24b2dae
|
jim-p
|
$ifinfo['inbytes'] = $linkinfo[6];
|
62 |
|
|
$ifinfo['outpkts'] = $linkinfo[7];
|
63 |
|
|
$ifinfo['outbytes'] = $linkinfo[9];
|
64 |
c1abd446
|
Seth Mos
|
} else {
|
65 |
19ac33af
|
Scott Ullrich
|
$ifinfo['inpkts'] = $linkinfo[4];
|
66 |
e1c931ce
|
jim-p
|
$ifinfo['inbytes'] = $linkinfo[7];
|
67 |
|
|
$ifinfo['outpkts'] = $linkinfo[8];
|
68 |
|
|
$ifinfo['outbytes'] = $linkinfo[10];
|
69 |
19ac33af
|
Scott Ullrich
|
}
|
70 |
|
|
$temp = gettimeofday();
|
71 |
31cb8b31
|
Scott Ullrich
|
$timing = (double)$temp["sec"] + (double)$temp["usec"] / 1000000.0;
|
72 |
45581172
|
Ermal Luçi
|
|
73 |
|
|
header("Last-Modified: " . gmdate( "D, j M Y H:i:s" ) . " GMT" );
|
74 |
|
|
header("Expires: " . gmdate( "D, j M Y H:i:s", time() ) . " GMT" );
|
75 |
|
|
header("Cache-Control: no-store, no-cache, must-revalidate" ); // HTTP/1.1
|
76 |
|
|
header("Cache-Control: post-check=0, pre-check=0", FALSE );
|
77 |
|
|
header("Pragma: no-cache"); // HTTP/1.0
|
78 |
19ac33af
|
Scott Ullrich
|
|
79 |
deea2272
|
Scott Ullrich
|
echo "$timing|" . $ifinfo['inbytes'] . "|" . $ifinfo['outbytes'] . "\n";
|
80 |
19ac33af
|
Scott Ullrich
|
|
81 |
7ac5a4cb
|
Scott Ullrich
|
?>
|