- print "<td width='$inOutWidth' align='center' class='boldbase'><font color='#CE1B31'><b>$Lang::tr{'trafficin'}</b></font></td>";
- print "<td width='$inOutWidth' align='center' class='boldbase'><font color='#CE1B31'><b>$Lang::tr{'trafficout'}</b></font></td>";
-}
- print"</tr>";
-
-my $total_blue_in=0;
-my $total_blue_out=0;
-my $total_green_in=0;
-my $total_green_out=0;
-my $total_orange_in=0;
-my $total_orange_out=0;
-my $total_red_in=0;
-my $total_red_out=0;
-my $lines=0;
-
-my $displayMode = "daily";
-my $startMonth = $cgiparams{'MONTH'};
-my $endMonth = $cgiparams{'MONTH'};
-
-if ($cgiparams{'MONTH'} eq '??') {
- $displayMode = "monthly";
- $startMonth = '01';
- $endMonth = '12';
-}
-
-my $start = "$cgiparams{'YEAR'}$startMonth"."01";
-my $end = "$cgiparams{'YEAR'}$endMonth"."32";
-my %allDaysBytes = ();
-my @allDays = &Traffic::calcTraffic(\%allDaysBytes,$start,$end, $displayMode);
-
-
-foreach (@allDays) {
- $total_green_in += $allDaysBytes{$_}{${Traffic::green_in}};
- $total_green_out += $allDaysBytes{$_}{${Traffic::green_out}};
-
- if ($netsettings{'CONFIG_TYPE'} =~ /^(3|4)$/)
- {
- $total_blue_in += $allDaysBytes{$_}{${Traffic::blue_in}};
- $total_blue_out += $allDaysBytes{$_}{${Traffic::blue_out}};
- }
-
- if ($netsettings{'CONFIG_TYPE'} =~ /^(2|4)$/)
- {
- $total_orange_in += $allDaysBytes{$_}{${Traffic::orange_in}};
- $total_orange_out += $allDaysBytes{$_}{${Traffic::orange_out}};
- }
-
- if ($netsettings{'CONFIG_TYPE'} =~ /^(1|2|3|4)$/)
- {
- $total_red_in += $allDaysBytes{$_}{${Traffic::red_in}};
- $total_red_out += $allDaysBytes{$_}{${Traffic::red_out}};
- }
-
- if ($lines % 2) {
- print "<tr bgcolor='$color{'color20'}'>"; }
- else {
- print "<tr bgcolor='$color{'color22'}'>"; }
-
- printf "<td align='center' nowrap='nowrap'>%s</td>\n", $allDaysBytes{$_}{'Day'};
- printf "<td align='center' nowrap='nowrap'>%.3f</td>\n", ($allDaysBytes{$_}{${Traffic::green_in}}/1048576);
- printf "<td align='center' nowrap='nowrap'>%.3f</td>\n", ($allDaysBytes{$_}{${Traffic::green_out}}/1048576);
-
- if ($netsettings{'CONFIG_TYPE'} =~ /^(3|4)$/)
- {
- printf "<td align='center' nowrap='nowrap'>%.3f</td>\n", ($allDaysBytes{$_}{${Traffic::blue_in}}/1048576);
- printf "<td align='center' nowrap='nowrap'>%.3f</td>\n", ($allDaysBytes{$_}{${Traffic::blue_out}}/1048576);
- }
- if ($netsettings{'CONFIG_TYPE'} =~ /^(2|4)$/)
- {
- printf "<td align='center' nowrap='nowrap'>%.3f</td>\n", ($allDaysBytes{$_}{${Traffic::orange_in}}/1048576);
- printf "<td align='center' nowrap='nowrap'>%.3f</td>\n", ($allDaysBytes{$_}{${Traffic::orange_out}}/1048576);
- }
- if ($netsettings{'CONFIG_TYPE'} =~ /^(1|2|3|4)$/)
- {
- printf "<td align='center' nowrap='nowrap'>%.3f</td>\n", ($allDaysBytes{$_}{${Traffic::red_in}}/1048576);
- printf "<td align='center' nowrap='nowrap'>%.3f</td></tr>\n", ($allDaysBytes{$_}{${Traffic::red_out}}/1048576);
- }
- $lines++;
-}
-
-$total_green_in=sprintf("%.2f", ($total_green_in/1048576));
-$total_green_out=sprintf("%.2f", ($total_green_out/1048576));
-$total_blue_in=sprintf("%.2f", ($total_blue_in/1048576));
-$total_blue_out=sprintf("%.2f", ($total_blue_out/1048576));
-$total_orange_in=sprintf("%.2f", ($total_orange_in/1048576));
-$total_orange_out=sprintf("%.2f", ($total_orange_out/1048576));
-$total_red_in=sprintf("%.2f", ($total_red_in/1048576));
-$total_red_out=sprintf("%.2f", ($total_red_out/1048576));
-
-if ($lines % 2) {print "<tr bgcolor='$color{'color20'}'>"; }
-else {print "<tr bgcolor='$color{'color22'}'>"; }
-
-print <<END;
- <td align='center' class='boldbase' height='20' nowrap='nowrap'><b>$Lang::tr{'trafficsum'}</b></td>
- <td align='center' class='boldbase' nowrap='nowrap'><b>$total_green_in MB</b></td>
- <td align='center' class='boldbase' nowrap='nowrap'><b>$total_green_out MB</b></td>
+ my $device = $_[0];
+
+ my $testdata = `/usr/bin/vnstat -i $device`;
+
+ if ( $testdata =~ 'enough') {
+ print"No data for $device !<br>";
+ } else {
+ # Falls back to textoutput if there was no % value because vnstati hang in this case
+ if (!($testdata =~ 'nan%')) {
+ system("/usr/bin/vnstati -c 5 -s -i $device -o /srv/web/ipfire/html/graphs/vnstat-s-$device.png");
+ }
+ # Hour graph
+ system("/usr/bin/vnstati -c 5 -h -i $device -o /srv/web/ipfire/html/graphs/vnstat-h-$device.png");
+ # Day graph
+ system("/usr/bin/vnstati -c 5 -d -i $device -o /srv/web/ipfire/html/graphs/vnstat-d-$device.png");
+ # Month graph
+ system("/usr/bin/vnstati -c 5 -m -i $device -o /srv/web/ipfire/html/graphs/vnstat-m-$device.png");
+ # Top10 graph
+ system("/usr/bin/vnstati -c 5 -t -i $device -o /srv/web/ipfire/html/graphs/vnstat-t-$device.png");
+
+# Generate HTML-Table with the graphs
+ print "<table>";
+ if ($testdata =~ 'nan%') {
+ print "<tr><td><b><pre>";
+ system("/usr/bin/vnstat -i $device");
+ print "</pre></b></td></tr>";
+ } else {
+ print"<tr><td><img src=\"/graphs/vnstat-s-$device.png\"></td></tr>";
+ }
+print <<END
+<tr><td><img src="/graphs/vnstat-h-$device.png"></td></tr>
+<tr><td><img src="/graphs/vnstat-d-$device.png"></td></tr>
+<tr><td><img src="/graphs/vnstat-m-$device.png"></td></tr>
+<tr><td><img src="/graphs/vnstat-t-$device.png"></td></tr>
+</table>