Project

General

Profile

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