]>
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';
22 my %mainsettings = ();
23 &General
::readhash
("${General::swroot}/main/settings", \
%mainsettings);
24 &General
::readhash
("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \
%color);
29 &General
::readhash
("${General::swroot}/ethernet/settings", \
%netsettings);
31 my @years=("2007","2008","2009","2010","2011","2012","2013","2014","2015");
33 my @longmonths = ( $Lang::tr
{'january'}, $Lang::tr
{'february'}, $Lang::tr
{'march'},
34 $Lang::tr
{'april'}, $Lang::tr
{'may'}, $Lang::tr
{'june'}, $Lang::tr
{'july'}, $Lang::tr
{'august'},
35 $Lang::tr
{'september'}, $Lang::tr
{'october'}, $Lang::tr
{'november'},
36 $Lang::tr
{'december'} );
38 my @months = ( 0,1,2,3,4,5,6,7,8,9,10,11 );
39 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 );
41 my @now = localtime(time);
43 $now[5] = $now[5]+1900;
45 $cgiparams{'STARTDAY'} = 10;
46 $cgiparams{'STOPDAY'} = 11;
47 $cgiparams{'STARTYEAR'} = $now[5];
48 $cgiparams{'STOPYEAR'} = $now[5];
50 # this periode started last month
52 $cgiparams{'STARTMONTH'} = $now[4]-1;
53 $cgiparams{'STOPMONTH'} = $now[4];
54 # when current month is january we start in last year december
56 $cgiparams{'STARTYEAR'} = $now[5]-1;
57 $cgiparams{'STARTMONTH'} = 11;
61 $cgiparams{'STARTMONTH'} = $now[4];
62 $cgiparams{'STOPMONTH'} = $now[4]+1;
63 # when we are december, this periode ends next year january
65 $cgiparams{'STOPYEAR'} = $now[5]+1;
66 $cgiparams{'STOPMONTH'} = 0;
70 &Header
::getcgihash
(\
%cgiparams);
72 &Header
::showhttpheaders
();
74 &Header
::openpage
($Lang::tr
{'sstraffic'}, 1, '');
76 &Header
::openbigbox
('100%', 'left');
78 &Header
::openbox
('100%', 'left', $Lang::tr
{'settings'});
81 <table width='100%' align='center'>
83 <td width='95%' class='base' align='center'>
84 <form method='post' action='/cgi-bin/traffics.cgi'>
85 $Lang::tr{'trafficfrom'}
86 <select name='STARTDAY'>
92 if ($_ == $cgiparams{'STARTDAY'}) {
93 print 'selected=\'selected\' '; }
94 print "value='$_'>$_</option>\n";
98 <select name='STARTMONTH'>
104 if ($_ == $cgiparams{'STARTMONTH'}) {
105 print 'selected=\'selected\' '; }
106 print "value='$_'>$longmonths[$_]</option>\n";
111 <select name='STARTYEAR'>
114 for (my $index=0; $index<=$#years; $index++) {
116 if ($years[$index] == $cgiparams{'STARTYEAR'}) {
117 print 'selected=\'selected\' '; }
118 print "value='$years[$index]'>$years[$index]</option>\n";
123 $Lang::tr{'trafficto'}
124 <select name='STOPDAY'>
130 if ($_ == $cgiparams{'STOPDAY'})
132 print 'selected=\'selected\' '; }
133 print "value='$_'>$_</option>\n";
138 <select name='STOPMONTH'>
144 if ($_ == $cgiparams{'STOPMONTH'}) {
145 print 'selected=\'selected\' '; }
146 print "value='$_'>$longmonths[$_]</option>\n";
151 <select name='STOPYEAR'>
154 for (my $index = 0; $index <=$#years; $index++) {
156 if ($years[$index] == $cgiparams{'STOPYEAR'}) {
157 print 'selected=\'selected\' '; }
158 print "value='$years[$index]'>$years[$index]</option>\n";
164 <input type='submit' name='ACTION' value='$Lang::tr{'update'}' />
167 <td width='5%' align='center'>
168 <form method='post' action='/cgi-bin/traffic.cgi'>
169 <input type='submit' name='ACTION' value=' > ' />
178 &Header
::openbox
('100%', 'left', $Lang::tr
{'traffics'});
180 my $dateWidth = '20%';
181 my $netWidth = '34%';
182 my $inOutWidth = '17%';
185 if ($netsettings{'CONFIG_TYPE'} =~ /^(4)$/) {
191 if ($netsettings{'CONFIG_TYPE'} =~ /^(2|3)$/) {
200 <td width='$dateWidth' align='center' class='boldbase'></td>
201 <td width='$netWidth' align='center' class='boldbase' ><b>$Lang::tr{'trafficgreen'}</b></td>
204 if ($netsettings{'CONFIG_TYPE'} =~ /^(3|4)$/) {
205 print "<td width='$netWidth' align='center' class='boldbase' ><b>$Lang::tr{'trafficblue'}</b></td>";
208 if ($netsettings{'CONFIG_TYPE'} =~ /^(2|4)$/) {
209 print "<td width='$netWidth' align='center' class='boldbase' ><b>$Lang::tr{'trafficorange'}</b></td>";
212 if ($netsettings{'CONFIG_TYPE'} =~ /^(1|2|3|4)$/) {
213 print "<td width='$netWidth' align='center' class='boldbase'><b>$Lang::tr{'trafficred'}</b></td>";
217 <td width='$netWidth' align='center' class='boldbase'><b>$Lang::tr{'trafficred'}</b></td>
222 <td width='$dateWidth' align='center' class='boldbase'><b>$Lang::tr{'trafficdate'}</b></td>
223 <td width='$inOutWidth' align='center' class='boldbase'><font color='#16A61D'><b>$Lang::tr{'trafficin'}</b></font></td>
224 <td width='$inOutWidth' align='center' class='boldbase'><font color='#16A61D'><b>$Lang::tr{'trafficout'}</b></font></td>
227 if ($netsettings{'CONFIG_TYPE'} =~ /^(3|4)$/)
229 print "<td width='$inOutWidth' align='center' class='boldbase'><font color='${Header::colourblue}'><b>$Lang::tr{'trafficin'}</b></font></td>";
230 print "<td width='$inOutWidth' align='center' class='boldbase'><font color='${Header::colourblue}'><b>$Lang::tr{'trafficout'}</b></font></td>";
233 if ($netsettings{'CONFIG_TYPE'} =~ /^(2|4)$/)
235 print "<td width='$inOutWidth' align='center' class='boldbase'><font color='#FF9933'><b>$Lang::tr{'trafficin'}</b></font></td>";
236 print "<td width='$inOutWidth' align='center' class='boldbase'><font color='#FF9933'><b>$Lang::tr{'trafficout'}</b></font></td>";
238 if ($netsettings{'CONFIG_TYPE'} =~ /^(1|2|3|4)$/)
240 print "<td width='$inOutWidth' align='center' class='boldbase'><font color='#CE1B31'><b>$Lang::tr{'trafficin'}</b></font></td>";
241 print "<td width='$inOutWidth' align='center' class='boldbase'><font color='#CE1B31'><b>$Lang::tr{'trafficout'}</b></font></td>";
246 my $total_blue_out=0;
247 my $total_green_in=0;
248 my $total_green_out=0;
249 my $total_orange_in=0;
250 my $total_orange_out=0;
256 my $startyear = $cgiparams{'STARTYEAR'};
257 my $stopyear = $cgiparams{'STOPYEAR'};
259 my $startMonth = $cgiparams{'STARTMONTH'}+1;
260 $startMonth = $startMonth < 10 ?
$startMonth = "0".$startMonth : $startMonth;
262 my $endMonth = $cgiparams{'STOPMONTH'}+1;
263 $endMonth = $endMonth < 10 ?
$endMonth = "0".$endMonth : $endMonth;
265 my $startDay = $cgiparams{'STARTDAY'};
266 $startDay = $startDay < 10 ?
$startDay = "0".$startDay : $startDay;
268 my $endDay = $cgiparams{'STOPDAY'}+1;
269 $endDay = $endDay < 10 ?
$endDay = "0".$endDay : $endDay;
271 my $displayMode = "daily_multi";
272 my $start = $startyear.$startMonth.$startDay;
273 my $end = $stopyear.$endMonth.$endDay;
275 my %allDaysBytes = ();
276 my @allDays = &Traffic
::calcTraffic
(\
%allDaysBytes,$start,$end, $displayMode);
280 $total_green_in += $allDaysBytes{$_}{${Traffic
::green_in
}};
281 $total_green_out += $allDaysBytes{$_}{${Traffic
::green_out
}};
283 if ($netsettings{'CONFIG_TYPE'} =~ /^(3|4)$/)
285 $total_blue_in += $allDaysBytes{$_}{${Traffic
::blue_in
}};
286 $total_blue_out += $allDaysBytes{$_}{${Traffic
::blue_out
}};
289 if ($netsettings{'CONFIG_TYPE'} =~ /^(2|4)$/)
291 $total_orange_in += $allDaysBytes{$_}{${Traffic
::orange_in
}};
292 $total_orange_out += $allDaysBytes{$_}{${Traffic
::orange_out
}};
295 if ($netsettings{'CONFIG_TYPE'} =~ /^(1|2|3|4)$/)
297 $total_red_in += $allDaysBytes{$_}{${Traffic
::red_in
}};
298 $total_red_out += $allDaysBytes{$_}{${Traffic
::red_out
}};
302 print "<tr bgcolor='$color{'color20'}'>"; }
304 print "<tr bgcolor='$color{'color22'}'>"; }
306 printf "<td align='center' nowrap='nowrap'>%s</td>\n", $allDaysBytes{$_}{'Day'};
307 printf "<td align='center' nowrap='nowrap'>%.3f</td>\n", ($allDaysBytes{$_}{${Traffic
::green_in
}}/1048576);
308 printf "<td align='center' nowrap='nowrap'>%.3f</td>\n", ($allDaysBytes{$_}{${Traffic
::green_out
}}/1048576);
310 if ($netsettings{'CONFIG_TYPE'} =~ /^(3|4)$/)
312 printf "<td align='center' nowrap='nowrap'>%.3f</td>\n", ($allDaysBytes{$_}{${Traffic
::blue_in
}}/1048576);
313 printf "<td align='center' nowrap='nowrap'>%.3f</td>\n", ($allDaysBytes{$_}{${Traffic
::blue_out
}}/1048576);
315 if ($netsettings{'CONFIG_TYPE'} =~ /^(2|4)$/)
317 printf "<td align='center' nowrap='nowrap'>%.3f</td>\n", ($allDaysBytes{$_}{${Traffic
::orange_in
}}/1048576);
318 printf "<td align='center' nowrap='nowrap'>%.3f</td>\n", ($allDaysBytes{$_}{${Traffic
::orange_out
}}/1048576);
320 if ($netsettings{'CONFIG_TYPE'} =~ /^(1|2|3|4)$/)
322 printf "<td align='center' nowrap='nowrap'>%.3f</td>\n", ($allDaysBytes{$_}{${Traffic
::red_in
}}/1048576);
323 printf "<td align='center' nowrap='nowrap'>%.3f</td></tr>\n", ($allDaysBytes{$_}{${Traffic
::red_out
}}/1048576);
328 $total_green_in=sprintf("%.2f", ($total_green_in/1048576));
329 $total_green_out=sprintf("%.2f", ($total_green_out/1048576));
330 $total_blue_in=sprintf("%.2f", ($total_blue_in/1048576));
331 $total_blue_out=sprintf("%.2f", ($total_blue_out/1048576));
332 $total_orange_in=sprintf("%.2f", ($total_orange_in/1048576));
333 $total_orange_out=sprintf("%.2f", ($total_orange_out/1048576));
334 $total_red_in=sprintf("%.2f", ($total_red_in/1048576));
335 $total_red_out=sprintf("%.2f", ($total_red_out/1048576));
337 if ($lines % 2) {print "<tr bgcolor='$color{'color20'}'>"; }
338 else {print "<tr bgcolor='$color{'color22'}'>"; }
341 <td align='center' class='boldbase' height='20' nowrap='nowrap'><b>$Lang::tr{'trafficsum'}</b></td>
342 <td align='center' class='boldbase' nowrap='nowrap'><b>$total_green_in MB</b></td>
343 <td align='center' class='boldbase' nowrap='nowrap'><b>$total_green_out MB</b></td>
346 if ($netsettings{'CONFIG_TYPE'} =~ /^(3|4)$/)
348 print "<td align='center' class='boldbase' nowrap='nowrap'><b>$total_blue_in MB</b></td>";
349 print "<td align='center' class='boldbase' nowrap='nowrap'><b>$total_blue_out MB</b></td>";
352 if ($netsettings{'CONFIG_TYPE'} =~ /^(2|4)$/)
354 print "<td align='center' class='boldbase' nowrap='nowrap'><b>$total_orange_in MB</b></td>";
355 print "<td align='center' class='boldbase' nowrap='nowrap'><b>$total_orange_out MB</b></td>";
357 if ($netsettings{'CONFIG_TYPE'} =~ /^(1|2|3|4)$/)
359 print "<td align='center' class='boldbase' nowrap='nowrap'><b>$total_red_in MB</b></td>";
360 print "<td align='center' class='boldbase' nowrap='nowrap'><b>$total_red_out MB</b></td>";
369 &Header
::closebigbox
();
371 &Header
::closepage
();