]> git.ipfire.org Git - ipfire-2.x.git/blame - html/cgi-bin/traffic.cgi
Merge remote-tracking branch 'origin/master' into next
[ipfire-2.x.git] / html / cgi-bin / traffic.cgi
CommitLineData
10a04d70 1#!/usr/bin/perl
70df8302
MT
2###############################################################################
3# #
4# IPFire.org - A linux based firewall #
5# Copyright (C) 2007 Michael Tremer & Christian Schmidt #
6# #
7# This program is free software: you can redistribute it and/or modify #
8# it under the terms of the GNU General Public License as published by #
9# the Free Software Foundation, either version 3 of the License, or #
10# (at your option) any later version. #
11# #
12# This program is distributed in the hope that it will be useful, #
13# but WITHOUT ANY WARRANTY; without even the implied warranty of #
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15# GNU General Public License for more details. #
16# #
17# You should have received a copy of the GNU General Public License #
18# along with this program. If not, see <http://www.gnu.org/licenses/>. #
19# #
20###############################################################################
10a04d70
MT
21
22use strict;
23
24# enable only the following on debugging purpose
cb5e9c6c
CS
25#use warnings;
26#use CGI::Carp 'fatalsToBrowser';
10a04d70
MT
27
28require '/var/ipfire/general-functions.pl';
29require "${General::swroot}/lang.pl";
30require "${General::swroot}/header.pl";
d81292e0
CS
31require "${General::swroot}/net-traffic/net-traffic-admin.pl";
32require "${General::swroot}/net-traffic/net-traffic-lib.pl";
10a04d70 33
f2fdd0c1
CS
34my %color = ();
35my %mainsettings = ();
36&General::readhash("${General::swroot}/main/settings", \%mainsettings);
37&General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color);
38
d81292e0 39my %cgiparams;
10a04d70
MT
40my %pppsettings;
41my %netsettings;
42
43&General::readhash("${General::swroot}/ppp/settings", \%pppsettings);
44&General::readhash("${General::swroot}/ethernet/settings", \%netsettings);
45
10a04d70 46
10a04d70
MT
47&Header::getcgihash(\%cgiparams);
48
d81292e0 49&Header::showhttpheaders();
10a04d70 50&Header::openpage($Lang::tr{'sstraffic'}, 1, '');
10a04d70 51&Header::openbigbox('100%', 'left');
10a04d70 52
7b42e677 53&Header::openbox('100%', 'center', "$Lang::tr{'traffics'}");
10a04d70 54
6c33dc5c
AF
55# Display internal network
56display_vnstat($netsettings{'GREEN_DEV'});
10a04d70 57
6c33dc5c
AF
58# Display external network / check if it is PPP or ETH
59# and dont display if RED_DEV=GREEN_DEV (green only mode)
60if ($netsettings{'RED_TYPE'} ne 'PPPOE') {
61 if ($netsettings{'RED_DEV'} ne $netsettings{'GREEN_DEV'}) {
62 display_vnstat($netsettings{'RED_DEV'});
63 }
64} else {
65 display_vnstat("ppp0");
10a04d70
MT
66}
67
6c33dc5c
AF
68# Check config and display aditional Networks (BLUE and ORANGE)
69# if they exist
b05768be 70if ($netsettings{'CONFIG_TYPE'} =~ /^(3|4)$/) {
6c33dc5c 71 display_vnstat($netsettings{'BLUE_DEV'});
10a04d70
MT
72}
73
b05768be 74if ($netsettings{'CONFIG_TYPE'} =~ /^(2|4)$/) {
6c33dc5c 75 display_vnstat($netsettings{'ORANGE_DEV'});
d81292e0 76}
10a04d70
MT
77
78&Header::closebox();
10a04d70 79&Header::closebigbox();
10a04d70 80&Header::closepage();
6c33dc5c
AF
81
82sub display_vnstat
83{
84 my $device = $_[0];
85
da205291 86 my $testdata = `/usr/bin/vnstat -i $device`;
7b42e677 87
da205291
AF
88 if ( $testdata =~ 'enough') {
89 print"No data for $device !<br>";
90 } else {
91 # Falls back to textoutput if there was no % value because vnstati hang in this case
92 if (!($testdata =~ 'nan%')) {
93 system("/usr/bin/vnstati -c 5 -s -i $device -o /srv/web/ipfire/html/graphs/vnstat-s-$device.png");
94 }
7b42e677
AF
95 # Hour graph
96 system("/usr/bin/vnstati -c 5 -h -i $device -o /srv/web/ipfire/html/graphs/vnstat-h-$device.png");
97 # Day graph
98 system("/usr/bin/vnstati -c 5 -d -i $device -o /srv/web/ipfire/html/graphs/vnstat-d-$device.png");
99 # Month graph
100 system("/usr/bin/vnstati -c 5 -m -i $device -o /srv/web/ipfire/html/graphs/vnstat-m-$device.png");
101 # Top10 graph
102 system("/usr/bin/vnstati -c 5 -t -i $device -o /srv/web/ipfire/html/graphs/vnstat-t-$device.png");
6c33dc5c
AF
103
104# Generate HTML-Table with the graphs
da205291
AF
105 print "<table>";
106 if ($testdata =~ 'nan%') {
107 print "<tr><td><b><pre>";
108 system("/usr/bin/vnstat -i $device");
109 print "</pre></b></td></tr>";
110 } else {
111 print"<tr><td><img src=\"/graphs/vnstat-s-$device.png\"></td></tr>";
112 }
6c33dc5c 113print <<END
6c33dc5c
AF
114<tr><td><img src="/graphs/vnstat-h-$device.png"></td></tr>
115<tr><td><img src="/graphs/vnstat-d-$device.png"></td></tr>
116<tr><td><img src="/graphs/vnstat-m-$device.png"></td></tr>
117<tr><td><img src="/graphs/vnstat-t-$device.png"></td></tr>
118</table>
119END
120;
7b42e677
AF
121 }
122 print"<hr>";
6c33dc5c 123}