]>
git.ipfire.org Git - ipfire-2.x.git/blob - html/cgi-bin/traffics.cgi
5 # This code is distributed under the terms of the GPL
7 # (c) The SmoothWall Team
12 # enable only the following on debugging purpose
14 use CGI
::Carp
'fatalsToBrowser';
16 require '/var/ipfire/general-functions.pl';
17 require "${General::swroot}/lang.pl";
18 require "${General::swroot}/header.pl";
19 require '/var/ipfire/net-traffic/net-traffic-lib.pl';
24 &General
::readhash
("${General::swroot}/ethernet/settings", \
%netsettings);
26 my @years=("2001","2002","2003","2004","2005","2006","2007","2008","2009");
28 my @longmonths = ( $Lang::tr
{'january'}, $Lang::tr
{'february'}, $Lang::tr
{'march'},
29 $Lang::tr
{'april'}, $Lang::tr
{'may'}, $Lang::tr
{'june'}, $Lang::tr
{'july'}, $Lang::tr
{'august'},
30 $Lang::tr
{'september'}, $Lang::tr
{'october'}, $Lang::tr
{'november'},
31 $Lang::tr
{'december'} );
33 my @months = ( 0,1,2,3,4,5,6,7,8,9,10,11 );
34 my @days = ( 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,31 );
36 my @wday = ($Lang::tr
{'wday1'}, $Lang::tr
{'wday2'}, $Lang::tr
{'wday3'}, $Lang::tr
{'wday4'}, $Lang::tr
{'wday5'}, $Lang::tr
{'wday6'}, $Lang::tr
{'wday7'});
38 my @now = localtime(time);
40 $now[5] = $now[5]+1900;
42 $cgiparams{'STARTDAY'} = 10;
43 $cgiparams{'STOPDAY'} = 11;
44 $cgiparams{'STARTYEAR'} = $now[5];
45 $cgiparams{'STOPYEAR'} = $now[5];
47 # this periode started last month
49 $cgiparams{'STARTMONTH'} = $now[4]-1;
50 $cgiparams{'STOPMONTH'} = $now[4];
51 # when current month is january we start in last year december
53 $cgiparams{'STARTYEAR'} = $now[5]-1;
54 $cgiparams{'STARTMONTH'} = 11;
58 $cgiparams{'STARTMONTH'} = $now[4];
59 $cgiparams{'STOPMONTH'} = $now[4]+1;
60 # when we are december, this periode ends next year january
62 $cgiparams{'STOPYEAR'} = $now[5]+1;
63 $cgiparams{'STOPMONTH'} = 0;
67 &Header
::getcgihash
(\
%cgiparams);
69 &Header
::showhttpheaders
();
71 &Header
::openpage
($Lang::tr
{'sstraffic'}, 1, '');
73 &Header
::openbigbox
('100%', 'left');
75 &Header
::openbox
('100%', 'left', $Lang::tr
{'settingsc'});
78 <table width='100%' align='center'>
80 <td width='95%' class='base' align='center'>
81 <form method='post' action='/cgi-bin/traffics.cgi'>
82 $Lang::tr{'trafficfrom'}
83 <select name='STARTDAY'>
89 if ($_ == $cgiparams{'STARTDAY'}) {
90 print 'selected=\'selected\' '; }
91 print "value='$_'>$_</option>\n";
95 <select name='STARTMONTH'>
101 if ($_ == $cgiparams{'STARTMONTH'}) {
102 print 'selected=\'selected\' '; }
103 print "value='$_'>$longmonths[$_]</option>\n";
108 <select name='STARTYEAR'>
111 for (my $index=0; $index<=$#years; $index++) {
113 if ($years[$index] == $cgiparams{'STARTYEAR'}) {
114 print 'selected=\'selected\' '; }
115 print "value='$years[$index]'>$years[$index]</option>\n";
120 $Lang::tr{'trafficto'}
121 <select name='STOPDAY'>
127 if ($_ == $cgiparams{'STOPDAY'})
129 print 'selected=\'selected\' '; }
130 print "value='$_'>$_</option>\n";
135 <select name='STOPMONTH'>
141 if ($_ == $cgiparams{'STOPMONTH'}) {
142 print 'selected=\'selected\' '; }
143 print "value='$_'>$longmonths[$_]</option>\n";
148 <select name='STOPYEAR'>
151 for (my $index = 0; $index <=$#years; $index++) {
153 if ($years[$index] == $cgiparams{'STOPYEAR'}) {
154 print 'selected=\'selected\' '; }
155 print "value='$years[$index]'>$years[$index]</option>\n";
161 <input type='submit' name='ACTION' value='$Lang::tr{'update'}' />
164 <td width='5%' align='center'>
165 <form method='post' action='/cgi-bin/traffic.cgi'>
166 <input type='submit' name='ACTION' value=' > ' />
175 &Header
::openbox
('100%', 'left', $Lang::tr
{'traffics'});
177 my $dateWidth = '20%';
178 my $netWidth = '34%';
179 my $inOutWidth = '17%';
182 if ($netsettings{'CONFIG_TYPE'} =~ /^(5|7)$/) {
188 if ($netsettings{'CONFIG_TYPE'} =~ /^(1|3|4|6)$/) {
197 <td width='$dateWidth' align='center' class='boldbase'></td>
198 <td width='$netWidth' align='center' class='boldbase' ><b>$Lang::tr{'trafficgreen'}</b></td>
201 if ($netsettings{'CONFIG_TYPE'} =~ /^(4|5|6|7)$/) {
202 print "<td width='$netWidth' align='center' class='boldbase' ><b>$Lang::tr{'trafficblue'}</b></td>";
205 if ($netsettings{'CONFIG_TYPE'} =~ /^(1|3|5|7)$/) {
206 print "<td width='$netWidth' align='center' class='boldbase' ><b>$Lang::tr{'trafficorange'}</b></td>";
210 <td width='$netWidth' align='center' class='boldbase'><b>$Lang::tr{'trafficred'}</b></td>
215 <td width='$dateWidth' align='center' class='boldbase'><b>$Lang::tr{'trafficdate'}</b></td>
216 <td width='$inOutWidth' align='center' class='boldbase'><font color='#16A61D'><b>$Lang::tr{'trafficin'}</b></font></td>
217 <td width='$inOutWidth' align='center' class='boldbase'><font color='#16A61D'><b>$Lang::tr{'trafficout'}</b></font></td>
220 if ($netsettings{'CONFIG_TYPE'} =~ /^(4|5|6|7)$/)
222 print "<td width='$inOutWidth' align='center' class='boldbase'><font color='${Header::colourblue}'><b>$Lang::tr{'trafficin'}</b></font></td>";
223 print "<td width='$inOutWidth' align='center' class='boldbase'><font color='${Header::colourblue}'><b>$Lang::tr{'trafficout'}</b></font></td>";
226 if ($netsettings{'CONFIG_TYPE'} =~ /^(1|3|5|7)$/)
228 print "<td width='$inOutWidth' align='center' class='boldbase'><font color='#FF9933'><b>$Lang::tr{'trafficin'}</b></font></td>";
229 print "<td width='$inOutWidth' align='center' class='boldbase'><font color='#FF9933'><b>$Lang::tr{'trafficout'}</b></font></td>";
232 <td width='$inOutWidth' align='center' class='boldbase'><font color='#CE1B31'><b>$Lang::tr{'trafficin'}</b></font></td>
233 <td width='$inOutWidth' align='center' class='boldbase'><font color='#CE1B31'><b>$Lang::tr{'trafficout'}</b></font></td>
238 my $total_blue_out=0;
239 my $total_green_in=0;
240 my $total_green_out=0;
241 my $total_orange_in=0;
242 my $total_orange_out=0;
248 my $startyear = $cgiparams{'STARTYEAR'};
249 my $stopyear = $cgiparams{'STOPYEAR'};
251 my $startMonth = $cgiparams{'STARTMONTH'}+1;
252 $startMonth = $startMonth < 10 ?
$startMonth = "0".$startMonth : $startMonth;
254 my $endMonth = $cgiparams{'STOPMONTH'}+1;
255 $endMonth = $endMonth < 10 ?
$endMonth = "0".$endMonth : $endMonth;
257 my $startDay = $cgiparams{'STARTDAY'};
258 $startDay = $startDay < 10 ?
$startDay = "0".$startDay : $startDay;
260 my $endDay = $cgiparams{'STOPDAY'}+1;
261 $endDay = $endDay < 10 ?
$endDay = "0".$endDay : $endDay;
263 my $displayMode = "daily_multi";
264 my $start = $startyear.$startMonth.$startDay;
265 my $end = $stopyear.$endMonth.$endDay;
267 my %allDaysBytes = ();
268 my @allDays = &Traffic
::calcTraffic
(\
%allDaysBytes,$start,$end, $displayMode);
272 $total_green_in += $allDaysBytes{$_}{${Traffic
::green_in
}};
273 $total_green_out += $allDaysBytes{$_}{${Traffic
::green_out
}};
275 if ($netsettings{'CONFIG_TYPE'} =~ /^(4|5|6|7)$/)
277 $total_blue_in += $allDaysBytes{$_}{${Traffic
::blue_in
}};
278 $total_blue_out += $allDaysBytes{$_}{${Traffic
::blue_out
}};
281 if ($netsettings{'CONFIG_TYPE'} =~ /^(1|3|5|7)$/)
283 $total_orange_in += $allDaysBytes{$_}{${Traffic
::orange_in
}};
284 $total_orange_out += $allDaysBytes{$_}{${Traffic
::orange_out
}};
287 $total_red_in += $allDaysBytes{$_}{${Traffic
::red_in
}};
288 $total_red_out += $allDaysBytes{$_}{${Traffic
::red_out
}};
291 print "<tr bgcolor='${Header::table1colour}'>"; }
293 print "<tr bgcolor='${Header::table2colour}'>"; }
295 printf "<td align='center' nowrap='nowrap'>%s</td>\n", $allDaysBytes{$_}{'Day'};
296 printf "<td align='center' nowrap='nowrap'>%.3f</td>\n", ($allDaysBytes{$_}{${Traffic
::green_in
}}/1048576);
297 printf "<td align='center' nowrap='nowrap'>%.3f</td>\n", ($allDaysBytes{$_}{${Traffic
::green_out
}}/1048576);
299 if ($netsettings{'CONFIG_TYPE'} =~ /^(4|5|6|7)$/)
301 printf "<td align='center' nowrap='nowrap'>%.3f</td>\n", ($allDaysBytes{$_}{${Traffic
::blue_in
}}/1048576);
302 printf "<td align='center' nowrap='nowrap'>%.3f</td>\n", ($allDaysBytes{$_}{${Traffic
::blue_out
}}/1048576);
304 if ($netsettings{'CONFIG_TYPE'} =~ /^(1|3|5|7)$/)
306 printf "<td align='center' nowrap='nowrap'>%.3f</td>\n", ($allDaysBytes{$_}{${Traffic
::orange_in
}}/1048576);
307 printf "<td align='center' nowrap='nowrap'>%.3f</td>\n", ($allDaysBytes{$_}{${Traffic
::orange_out
}}/1048576);
310 printf "<td align='center' nowrap='nowrap'>%.3f</td>\n", ($allDaysBytes{$_}{${Traffic
::red_in
}}/1048576);
311 printf "<td align='center' nowrap='nowrap'>%.3f</td></tr>\n", ($allDaysBytes{$_}{${Traffic
::red_out
}}/1048576);
316 $total_green_in=sprintf("%.2f", ($total_green_in/1048576));
317 $total_green_out=sprintf("%.2f", ($total_green_out/1048576));
318 $total_blue_in=sprintf("%.2f", ($total_blue_in/1048576));
319 $total_blue_out=sprintf("%.2f", ($total_blue_out/1048576));
320 $total_orange_in=sprintf("%.2f", ($total_orange_in/1048576));
321 $total_orange_out=sprintf("%.2f", ($total_orange_out/1048576));
322 $total_red_in=sprintf("%.2f", ($total_red_in/1048576));
323 $total_red_out=sprintf("%.2f", ($total_red_out/1048576));
325 if ($lines % 2) {print "<tr bgcolor='${Header::table1colour}'>"; }
326 else {print "<tr bgcolor='${Header::table2colour}'>"; }
329 <td align='center' class='boldbase' height='20' nowrap='nowrap'><b>$Lang::tr{'trafficsum'}</b></td>
330 <td align='center' class='boldbase' nowrap='nowrap'><b>$total_green_in MB</b></td>
331 <td align='center' class='boldbase' nowrap='nowrap'><b>$total_green_out MB</b></td>
334 if ($netsettings{'CONFIG_TYPE'} =~ /^(4|5|6|7)$/)
336 print "<td align='center' class='boldbase' nowrap='nowrap'><b>$total_blue_in MB</b></td>";
337 print "<td align='center' class='boldbase' nowrap='nowrap'><b>$total_blue_out MB</b></td>";
340 if ($netsettings{'CONFIG_TYPE'} =~ /^(1|3|5|7)$/)
342 print "<td align='center' class='boldbase' nowrap='nowrap'><b>$total_orange_in MB</b></td>";
343 print "<td align='center' class='boldbase' nowrap='nowrap'><b>$total_orange_out MB</b></td>";
347 <td align='center' class='boldbase' nowrap='nowrap'><b>$total_red_in MB</b></td>
348 <td align='center' class='boldbase' nowrap='nowrap'><b>$total_red_out MB</b></td>
355 &Header
::closebigbox
();
357 &Header
::closepage
();