"Fossies" - the Fresh Open Source Software Archive

Member "vnstat-2.9/examples/vnstat-json.php" (22 May 2021, 914 Bytes) of package /linux/misc/vnstat-2.9.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. See also the last Fossies "Diffs" side-by-side code changes report for "vnstat-json.php": 2.7_vs_2.8.

    1 <?php
    2 
    3 /* vnstat-json.php -- example php for vnStat json output */
    4 /* copyright (c) 2015-2021 Teemu Toivola <tst at iki dot fi> */
    5 /* released under the GNU General Public License */
    6 
    7 
    8 /* location of vnstat binary */
    9 $vnstat_cmd = "/usr/bin/vnstat";
   10 
   11 /* individually accessible interfaces with ?interface=N */
   12 /* for static list, uncomment first line below, update the list and comment out second line */
   13 //$interfaces = array("eth0", "eth1");
   14 $interfaces = explode("\n", trim(shell_exec("$vnstat_cmd --dbiflist 1")));
   15 
   16 /* no editing should be needed below this line */
   17 
   18 $iface = "";
   19 $getiface = "";
   20 if (isset($_GET['interface']) && ctype_digit($_GET['interface'])) {
   21     $getiface = $_GET['interface'];
   22 }
   23 
   24 if (strlen($getiface) > 0 && $getiface >= 0 && $getiface < count($interfaces)) {
   25     $iface = " -i ".$interfaces[$getiface];
   26 }
   27 
   28 header("Content-Type: application/json");
   29 passthru($vnstat_cmd." --json".$iface);
   30 ?>