File: vnstat-json.php

package info (click to toggle)
vnstat 2.13-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,148 kB
  • sloc: ansic: 25,669; sh: 4,495; perl: 472; makefile: 179; php: 12
file content (30 lines) | stat: -rw-r--r-- 914 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<?php

/* vnstat-json.php -- example php for vnStat json output */
/* copyright (c) 2015-2021 Teemu Toivola <tst at iki dot fi> */
/* released under the GNU General Public License */


/* location of vnstat binary */
$vnstat_cmd = "/usr/bin/vnstat";

/* individually accessible interfaces with ?interface=N */
/* for static list, uncomment first line below, update the list and comment out second line */
//$interfaces = array("eth0", "eth1");
$interfaces = explode("\n", trim(shell_exec("$vnstat_cmd --dbiflist 1")));

/* no editing should be needed below this line */

$iface = "";
$getiface = "";
if (isset($_GET['interface']) && ctype_digit($_GET['interface'])) {
	$getiface = $_GET['interface'];
}

if (strlen($getiface) > 0 && $getiface >= 0 && $getiface < count($interfaces)) {
	$iface = " -i ".$interfaces[$getiface];
}

header("Content-Type: application/json");
passthru($vnstat_cmd." --json".$iface);
?>