|
1
|
<?php
|
|
2
|
/*
|
|
3
|
* ifstats.php
|
|
4
|
*
|
|
5
|
* part of pfSense (https://www.pfsense.org)
|
|
6
|
* Copyright (c) 2004-2013 BSD Perimeter
|
|
7
|
* Copyright (c) 2013-2016 Electric Sheep Fencing
|
|
8
|
* Copyright (c) 2014-2022 Rubicon Communications, LLC (Netgate)
|
|
9
|
* All rights reserved.
|
|
10
|
*
|
|
11
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
12
|
* you may not use this file except in compliance with the License.
|
|
13
|
* You may obtain a copy of the License at
|
|
14
|
*
|
|
15
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
16
|
*
|
|
17
|
* Unless required by applicable law or agreed to in writing, software
|
|
18
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
19
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
20
|
* See the License for the specific language governing permissions and
|
|
21
|
* limitations under the License.
|
|
22
|
*/
|
|
23
|
|
|
24
|
##|+PRIV
|
|
25
|
##|*IDENT=page-xmlrpcinterfacestats
|
|
26
|
##|*NAME=XMLRPC Interface Stats
|
|
27
|
##|*DESCR=Allow access to the 'XMLRPC Interface Stats' page.
|
|
28
|
##|*MATCH=ifstats.php*
|
|
29
|
##|-PRIV
|
|
30
|
|
|
31
|
$nocsrf = true;
|
|
32
|
|
|
33
|
require_once('auth_check.inc');
|
|
34
|
|
|
35
|
if($_POST['if']) {
|
|
36
|
$ifs = $_POST['if'];
|
|
37
|
$realifs = $_POST['realif'];
|
|
38
|
|
|
39
|
$ifarray = explode("|", $ifs);
|
|
40
|
$realifarray = explode("|", $realifs);
|
|
41
|
|
|
42
|
$temp = gettimeofday();
|
|
43
|
$timing = (double)$temp["sec"] + (double)$temp["usec"] / 1000000.0;
|
|
44
|
$obj = [];
|
|
45
|
$count = 0;
|
|
46
|
|
|
47
|
$i = 0;
|
|
48
|
for ($i = 0; $i < count($ifarray); $i++) {
|
|
49
|
$if = $ifarray[$i];
|
|
50
|
$realif = $realifarray[$i];
|
|
51
|
if (!$realif) {
|
|
52
|
$realif = $if; // Need for IPsec case interface.
|
|
53
|
}
|
|
54
|
|
|
55
|
$ifinfo = pfSense_get_interface_stats($realif);
|
|
56
|
|
|
57
|
$obj[$if] = [];
|
|
58
|
|
|
59
|
$obj[$if][0]['key'] = $if . "in";
|
|
60
|
$obj[$if][0]['values'] = array($timing, $ifinfo['inbytes']);
|
|
61
|
|
|
62
|
$obj[$if][1]['key'] = $if . "out";
|
|
63
|
$obj[$if][1]['values'] = array($timing, $ifinfo['outbytes']);
|
|
64
|
}
|
|
65
|
|
|
66
|
header('Content-Type: application/json');
|
|
67
|
echo json_encode($obj,JSON_PRETTY_PRINT|JSON_PARTIAL_OUTPUT_ON_ERROR|JSON_NUMERIC_CHECK);
|
|
68
|
}
|