"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "examples/vnstat-json.cgi" between
vnstat-2.7.tar.gz and vnstat-2.8.tar.gz

About: vnStat is a console-based network traffic monitor (using the /proc filesystem).

vnstat-json.cgi  (vnstat-2.7):vnstat-json.cgi  (vnstat-2.8)
#!/usr/bin/perl -w #!/usr/bin/perl -w
# vnstat-json.cgi -- example cgi for vnStat json output # vnstat-json.cgi -- example cgi for vnStat json output
# copyright (c) 2015 Teemu Toivola <tst at iki dot fi> # copyright (c) 2015-2021 Teemu Toivola <tst at iki dot fi>
# released under the GNU General Public License # released under the GNU General Public License
use strict;
# location of vnstat binary # location of vnstat binary
my $vnstat_cmd = '/usr/bin/vnstat'; my $vnstat_cmd = '/usr/bin/vnstat';
# shown interfaces, edit as necessary # individually accessible interfaces with ?interface=N or /interfacename suffix
my @interfaces = ('eth0', 'eth1', 'ethX'); # for static list, uncomment first line below, update the list and comment out s
econd line
#my @interfaces = ('eth0', 'eth1');
my @interfaces = `$vnstat_cmd --dbiflist 1`;
################ ################
my $iface = ""; my $iface = "";
my $getiface = ""; chomp @interfaces;
my @values = split(/&/,$ENV{'QUERY_STRING'});
foreach $i (@values) { if (defined $ENV{PATH_INFO}) {
($varname, $varvalue) = split(/=/,$i); my @fields = split(/\//, $ENV{PATH_INFO});
if ($varname == 'interface' && $varvalue =~ /^(\d+)$/) { my $interface = $fields[-1];
$getiface = $varvalue; for my $i (0..$#interfaces) {
if ($interfaces[${i}] eq $interface) {
$iface = "-i $interface";
last;
}
} }
} }
if (length($getiface) > 0 && $getiface >= 0 && $getiface <= $#interfaces) { if (length($iface) == 0 and defined $ENV{QUERY_STRING}) {
$iface = "-i @interfaces[$getiface]"; my $getiface = "";
my @values = split(/&/, $ENV{QUERY_STRING});
foreach my $i (@values) {
my ($varname, $varvalue) = split(/=/, $i);
if ($varname eq 'interface' && $varvalue =~ /^(\d+)$/) {
$getiface = $varvalue;
}
}
if (length($getiface) > 0 && $getiface >= 0 && $getiface <= $#interfaces)
{
$iface = "-i @interfaces[int($getiface)]";
}
} }
print "Content-Type: application/json\n\n"; print "Content-Type: application/json\n\n";
exec("$vnstat_cmd --json $iface"); exec("$vnstat_cmd --json $iface");
 End of changes. 5 change blocks. 
11 lines changed or deleted 32 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)