]>
git.ipfire.org Git - people/mfischer/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
9 # $Id: traffics.cgi,v 1.12 2006/11/15 21:14:02 dotzball Exp $
11 # traffics.cgi, v1.1.0 2003/10/18
18 # enable only the following on debugging purpose
20 #use CGI::Carp 'fatalsToBrowser';
22 require '/var/ipfire/general-functions.pl';
23 require "${General::swroot}/lang.pl";
24 require "${General::swroot}/header.pl";
25 require "${General::swroot}/net-traffic/net-traffic-admin.pl";
26 require "${General::swroot}/net-traffic/net-traffic-lib.pl";
29 my %mainsettings = ();
30 &General
::readhash
("${General::swroot}/main/settings", \
%mainsettings);
31 &General
::readhash
("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \
%color);
36 &General
::readhash
("${General::swroot}/ethernet/settings", \
%netsettings);
38 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 );
40 my @now = localtime(time);
42 $now[5] = $now[5]+1900;
44 $cgiparams{'STARTDAY'} = 10;
45 $cgiparams{'STOPDAY'} = 11;
46 $cgiparams{'STARTYEAR'} = $now[5];
47 $cgiparams{'STOPYEAR'} = $now[5];
49 if($NETTRAFF::settings
{'MONTHLY_VOLUME_ON'} eq 'on')
51 $cgiparams{'STARTDAY'} = $NETTRAFF::settings
{'STARTDAY'};
52 $cgiparams{'STOPDAY'} = $NETTRAFF::settings
{'STARTDAY'};
55 # this periode started last month
56 if ($now[3] < $cgiparams{'STARTDAY'}) {
57 $cgiparams{'STARTMONTH'} = $now[4]-1;
58 $cgiparams{'STOPMONTH'} = $now[4];
59 # when current month is january we start in last year december
60 if ($cgiparams{'STOPMONTH'} == 0) {
61 $cgiparams{'STARTYEAR'} = $now[5]-1;
62 $cgiparams{'STARTMONTH'} = 11;
66 $cgiparams{'STARTMONTH'} = $now[4];
67 $cgiparams{'STOPMONTH'} = $now[4]+1;
68 # when we are in december, this periode ends next year january
69 if ($cgiparams{'STARTMONTH'} == 11) {
70 $cgiparams{'STOPYEAR'} = $now[5]+1;
71 $cgiparams{'STOPMONTH'} = 0;
75 &Header
::getcgihash
(\
%cgiparams);
76 &Header
::showhttpheaders
();
77 &Header
::openpage
($Lang::tr
{'sstraffic'}, 1, '');
78 &Header
::openbigbox
('100%', 'left');
79 &Header
::openbox
('100%', 'left', "");
82 <table width='100%' align='center'>
84 <td width='90%' class='base' align='center'>
85 <form method='post' action='/cgi-bin/traffics.cgi'>
86 $Lang::tr{'trafficfrom'}
87 <select name='STARTDAY'>
90 foreach my $day (@days)
93 if ($day == $cgiparams{'STARTDAY'}) {
94 print 'selected=\'selected\' '; }
95 print "value='$day'>$day</option>\n";
99 <select name='STARTMONTH'>
102 foreach my $month (@NETTRAFF::months
)
105 if ($month == $cgiparams{'STARTMONTH'}) {
106 print 'selected=\'selected\' '; }
107 print "value='$month'>$NETTRAFF::longmonths[$month]</option>\n";
112 <select name='STARTYEAR'>
115 foreach my $year (@NETTRAFF::years
) {
117 if ($year == $cgiparams{'STARTYEAR'}) {
118 print 'selected=\'selected\' '; }
119 print "value='$year'>$year</option>\n";
124 $Lang::tr{'trafficto'}
125 <select name='STOPDAY'>
128 foreach my $day (@days)
131 if ($day == $cgiparams{'STOPDAY'})
133 print 'selected=\'selected\' '; }
134 print "value='$day'>$day</option>\n";
139 <select name='STOPMONTH'>
142 foreach my $month (@NETTRAFF::months
)
145 if ($month == $cgiparams{'STOPMONTH'}) {
146 print 'selected=\'selected\' '; }
147 print "value='$month'>$NETTRAFF::longmonths[$month]</option>\n";
152 <select name='STOPYEAR'>
155 foreach my $year (@NETTRAFF::years
) {
157 if ($year == $cgiparams{'STOPYEAR'}) {
158 print 'selected=\'selected\' '; }
159 print "value='$year'>$year</option>\n";
165 <input type='submit' name='ACTION' value='$Lang::tr{'update'}' />
168 <td width='5%' align='center'>
169 <form method='post' action='/cgi-bin/traffic.cgi'>
170 <input type='submit' name='ACTION' value=' > ' />
179 &Header
::openbox
('100%', 'left', "$Lang::tr{'traffics'}");
181 my $dateWidth = '20%';
182 my $netWidth = '34%';
183 my $inOutWidth = '17%';
186 if ($netsettings{'CONFIG_TYPE'} =~ /^(4)$/) {
192 if ($netsettings{'CONFIG_TYPE'} =~ /^(2|3)$/) {
201 <td width='$dateWidth' align='center' class='boldbase'></td>
202 <td width='$netWidth' align='center' class='boldbase' ><b>$Lang::tr{'trafficgreen'}</b></td>
205 if ($netsettings{'CONFIG_TYPE'} =~ /^(3|4)$/) {
206 print "<td width='$netWidth' align='center' class='boldbase' ><b>$Lang::tr{'trafficblue'}</b></td>";
209 if ($netsettings{'CONFIG_TYPE'} =~ /^(2|4)$/) {
210 print "<td width='$netWidth' align='center' class='boldbase' ><b>$Lang::tr{'trafficorange'}</b></td>";
213 if ($netsettings{'CONFIG_TYPE'} =~ /^(1|2|3|4)$/)
215 print "<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='$Header::colourgreen'><b>$Lang::tr{'trafficin'}</b></font></td>
224 <td width='$inOutWidth' align='center' class='boldbase'><font color='$Header::colourgreen'><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='$Header::colourorange'><b>$Lang::tr{'trafficin'}</b></font></td>";
236 print "<td width='$inOutWidth' align='center' class='boldbase'><font color='$Header::colourorange'><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='$Header::colourred'><b>$Lang::tr{'trafficin'}</b></font></td>";
241 print "<td width='$inOutWidth' align='center' class='boldbase'><font color='$Header::colourred'><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>";
358 if ($netsettings{'CONFIG_TYPE'} =~ /^(1|2|3|4)$/)
360 print "<td align='center' class='boldbase' nowrap='nowrap'><b>$total_red_in MB</b></td>";
361 print "<td align='center' class='boldbase' nowrap='nowrap'><b>$total_red_out MB</b></td>";
363 print "</tr></table>";
366 &Header
::closebigbox
();
367 &Header
::closepage
();