]>
git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - html/cgi-bin/traffics.cgi
2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2007 Michael Tremer & Christian Schmidt #
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. #
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. #
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/>. #
20 ###############################################################################
24 # enable only the following on debugging purpose
26 #use CGI::Carp 'fatalsToBrowser';
28 require '/var/ipfire/general-functions.pl';
29 require "${General::swroot}/lang.pl";
30 require "${General::swroot}/header.pl";
31 require "${General::swroot}/net-traffic/net-traffic-admin.pl";
32 require "${General::swroot}/net-traffic/net-traffic-lib.pl";
35 my %mainsettings = ();
36 &General
::readhash
("${General::swroot}/main/settings", \
%mainsettings);
37 &General
::readhash
("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \
%color);
42 &General
::readhash
("${General::swroot}/ethernet/settings", \
%netsettings);
44 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 );
46 my @now = localtime(time);
48 $now[5] = $now[5]+1900;
50 $cgiparams{'STARTDAY'} = 10;
51 $cgiparams{'STOPDAY'} = 11;
52 $cgiparams{'STARTYEAR'} = $now[5];
53 $cgiparams{'STOPYEAR'} = $now[5];
55 if($NETTRAFF::settings
{'MONTHLY_VOLUME_ON'} eq 'on')
57 $cgiparams{'STARTDAY'} = $NETTRAFF::settings
{'STARTDAY'};
58 $cgiparams{'STOPDAY'} = $NETTRAFF::settings
{'STARTDAY'};
61 # this periode started last month
62 if ($now[3] < $cgiparams{'STARTDAY'}) {
63 $cgiparams{'STARTMONTH'} = $now[4]-1;
64 $cgiparams{'STOPMONTH'} = $now[4];
65 # when current month is january we start in last year december
66 if ($cgiparams{'STOPMONTH'} == 0) {
67 $cgiparams{'STARTYEAR'} = $now[5]-1;
68 $cgiparams{'STARTMONTH'} = 11;
72 $cgiparams{'STARTMONTH'} = $now[4];
73 $cgiparams{'STOPMONTH'} = $now[4]+1;
74 # when we are in december, this periode ends next year january
75 if ($cgiparams{'STARTMONTH'} == 11) {
76 $cgiparams{'STOPYEAR'} = $now[5]+1;
77 $cgiparams{'STOPMONTH'} = 0;
81 &Header
::getcgihash
(\
%cgiparams);
82 &Header
::showhttpheaders
();
83 &Header
::openpage
($Lang::tr
{'sstraffic'}, 1, '');
84 &Header
::openbigbox
('100%', 'left');
85 &Header
::openbox
('100%', 'left', "");
88 <table width='100%' align='center'>
90 <td width='90%' class='base' align='center'>
91 <form method='post' action='/cgi-bin/traffics.cgi'>
92 $Lang::tr{'trafficfrom'}
93 <select name='STARTDAY'>
96 foreach my $day (@days)
99 if ($day == $cgiparams{'STARTDAY'}) {
100 print 'selected=\'selected\' '; }
101 print "value='$day'>$day</option>\n";
105 <select name='STARTMONTH'>
108 foreach my $month (@NETTRAFF::months
)
111 if ($month == $cgiparams{'STARTMONTH'}) {
112 print 'selected=\'selected\' '; }
113 print "value='$month'>$NETTRAFF::longmonths[$month]</option>\n";
118 <select name='STARTYEAR'>
121 foreach my $year (@NETTRAFF::years
) {
123 if ($year == $cgiparams{'STARTYEAR'}) {
124 print 'selected=\'selected\' '; }
125 print "value='$year'>$year</option>\n";
130 $Lang::tr{'trafficto'}
131 <select name='STOPDAY'>
134 foreach my $day (@days)
137 if ($day == $cgiparams{'STOPDAY'})
139 print 'selected=\'selected\' '; }
140 print "value='$day'>$day</option>\n";
145 <select name='STOPMONTH'>
148 foreach my $month (@NETTRAFF::months
)
151 if ($month == $cgiparams{'STOPMONTH'}) {
152 print 'selected=\'selected\' '; }
153 print "value='$month'>$NETTRAFF::longmonths[$month]</option>\n";
158 <select name='STOPYEAR'>
161 foreach my $year (@NETTRAFF::years
) {
163 if ($year == $cgiparams{'STOPYEAR'}) {
164 print 'selected=\'selected\' '; }
165 print "value='$year'>$year</option>\n";
171 <input type='submit' name='ACTION' value='$Lang::tr{'update'}' />
174 <td width='5%' align='center'>
175 <form method='post' action='/cgi-bin/traffic.cgi'>
176 <input type='submit' name='ACTION' value=' > ' />
185 &Header
::openbox
('100%', 'left', "$Lang::tr{'traffics'}");
187 my $dateWidth = '20%';
188 my $netWidth = '34%';
189 my $inOutWidth = '17%';
192 if ($netsettings{'CONFIG_TYPE'} =~ /^(4)$/) {
198 if ($netsettings{'CONFIG_TYPE'} =~ /^(2|3)$/) {
207 <td width='$dateWidth' align='center' class='boldbase'></td>
208 <td width='$netWidth' align='center' class='boldbase' ><b>$Lang::tr{'trafficgreen'}</b></td>
211 if ($netsettings{'CONFIG_TYPE'} =~ /^(3|4)$/) {
212 print "<td width='$netWidth' align='center' class='boldbase' ><b>$Lang::tr{'trafficblue'}</b></td>";
215 if ($netsettings{'CONFIG_TYPE'} =~ /^(2|4)$/) {
216 print "<td width='$netWidth' align='center' class='boldbase' ><b>$Lang::tr{'trafficorange'}</b></td>";
219 if ($netsettings{'CONFIG_TYPE'} =~ /^(1|2|3|4)$/)
221 print "<td width='$netWidth' align='center' class='boldbase'><b>$Lang::tr{'trafficred'}</b></td>";
228 <td width='$dateWidth' align='center' class='boldbase'><b>$Lang::tr{'trafficdate'}</b></td>
229 <td width='$inOutWidth' align='center' class='boldbase'><font color='$Header::colourgreen'><b>$Lang::tr{'trafficin'}</b></font></td>
230 <td width='$inOutWidth' align='center' class='boldbase'><font color='$Header::colourgreen'><b>$Lang::tr{'trafficout'}</b></font></td>
233 if ($netsettings{'CONFIG_TYPE'} =~ /^(3|4)$/)
235 print "<td width='$inOutWidth' align='center' class='boldbase'><font color='${Header::colourblue}'><b>$Lang::tr{'trafficin'}</b></font></td>";
236 print "<td width='$inOutWidth' align='center' class='boldbase'><font color='${Header::colourblue}'><b>$Lang::tr{'trafficout'}</b></font></td>";
239 if ($netsettings{'CONFIG_TYPE'} =~ /^(2|4)$/)
241 print "<td width='$inOutWidth' align='center' class='boldbase'><font color='$Header::colourorange'><b>$Lang::tr{'trafficin'}</b></font></td>";
242 print "<td width='$inOutWidth' align='center' class='boldbase'><font color='$Header::colourorange'><b>$Lang::tr{'trafficout'}</b></font></td>";
244 if ($netsettings{'CONFIG_TYPE'} =~ /^(1|2|3|4)$/)
246 print "<td width='$inOutWidth' align='center' class='boldbase'><font color='$Header::colourred'><b>$Lang::tr{'trafficin'}</b></font></td>";
247 print "<td width='$inOutWidth' align='center' class='boldbase'><font color='$Header::colourred'><b>$Lang::tr{'trafficout'}</b></font></td>";
252 my $total_blue_out=0;
253 my $total_green_in=0;
254 my $total_green_out=0;
255 my $total_orange_in=0;
256 my $total_orange_out=0;
262 my $startyear = $cgiparams{'STARTYEAR'};
263 my $stopyear = $cgiparams{'STOPYEAR'};
265 my $startMonth = $cgiparams{'STARTMONTH'}+1;
266 $startMonth = $startMonth < 10 ?
$startMonth = "0".$startMonth : $startMonth;
268 my $endMonth = $cgiparams{'STOPMONTH'}+1;
269 $endMonth = $endMonth < 10 ?
$endMonth = "0".$endMonth : $endMonth;
271 my $startDay = $cgiparams{'STARTDAY'};
272 $startDay = $startDay < 10 ?
$startDay = "0".$startDay : $startDay;
274 my $endDay = $cgiparams{'STOPDAY'}+1;
275 $endDay = $endDay < 10 ?
$endDay = "0".$endDay : $endDay;
277 my $displayMode = "daily_multi";
278 my $start = $startyear.$startMonth.$startDay;
279 my $end = $stopyear.$endMonth.$endDay;
281 my %allDaysBytes = ();
282 my @allDays = &Traffic
::calcTraffic
(\
%allDaysBytes,$start,$end, $displayMode);
286 $total_green_in += $allDaysBytes{$_}{${Traffic
::green_in
}};
287 $total_green_out += $allDaysBytes{$_}{${Traffic
::green_out
}};
289 if ($netsettings{'CONFIG_TYPE'} =~ /^(3|4)$/)
291 $total_blue_in += $allDaysBytes{$_}{${Traffic
::blue_in
}};
292 $total_blue_out += $allDaysBytes{$_}{${Traffic
::blue_out
}};
295 if ($netsettings{'CONFIG_TYPE'} =~ /^(2|4)$/)
297 $total_orange_in += $allDaysBytes{$_}{${Traffic
::orange_in
}};
298 $total_orange_out += $allDaysBytes{$_}{${Traffic
::orange_out
}};
301 if ($netsettings{'CONFIG_TYPE'} =~ /^(1|2|3|4)$/)
303 $total_red_in += $allDaysBytes{$_}{${Traffic
::red_in
}};
304 $total_red_out += $allDaysBytes{$_}{${Traffic
::red_out
}};
308 print "<tr bgcolor='$color{'color20'}'>"; }
310 print "<tr bgcolor='$color{'color22'}'>"; }
312 printf "<td align='center' nowrap='nowrap'>%s</td>\n", $allDaysBytes{$_}{'Day'};
313 printf "<td align='center' nowrap='nowrap'>%.3f</td>\n", ($allDaysBytes{$_}{${Traffic
::green_in
}}/1048576);
314 printf "<td align='center' nowrap='nowrap'>%.3f</td>\n", ($allDaysBytes{$_}{${Traffic
::green_out
}}/1048576);
316 if ($netsettings{'CONFIG_TYPE'} =~ /^(3|4)$/)
318 printf "<td align='center' nowrap='nowrap'>%.3f</td>\n", ($allDaysBytes{$_}{${Traffic
::blue_in
}}/1048576);
319 printf "<td align='center' nowrap='nowrap'>%.3f</td>\n", ($allDaysBytes{$_}{${Traffic
::blue_out
}}/1048576);
321 if ($netsettings{'CONFIG_TYPE'} =~ /^(2|4)$/)
323 printf "<td align='center' nowrap='nowrap'>%.3f</td>\n", ($allDaysBytes{$_}{${Traffic
::orange_in
}}/1048576);
324 printf "<td align='center' nowrap='nowrap'>%.3f</td>\n", ($allDaysBytes{$_}{${Traffic
::orange_out
}}/1048576);
326 if ($netsettings{'CONFIG_TYPE'} =~ /^(1|2|3|4)$/)
328 printf "<td align='center' nowrap='nowrap'>%.3f</td>\n", ($allDaysBytes{$_}{${Traffic
::red_in
}}/1048576);
329 printf "<td align='center' nowrap='nowrap'>%.3f</td></tr>\n", ($allDaysBytes{$_}{${Traffic
::red_out
}}/1048576);
334 $total_green_in=sprintf("%.2f", ($total_green_in/1048576));
335 $total_green_out=sprintf("%.2f", ($total_green_out/1048576));
336 $total_blue_in=sprintf("%.2f", ($total_blue_in/1048576));
337 $total_blue_out=sprintf("%.2f", ($total_blue_out/1048576));
338 $total_orange_in=sprintf("%.2f", ($total_orange_in/1048576));
339 $total_orange_out=sprintf("%.2f", ($total_orange_out/1048576));
340 $total_red_in=sprintf("%.2f", ($total_red_in/1048576));
341 $total_red_out=sprintf("%.2f", ($total_red_out/1048576));
343 if ($lines % 2) {print "<tr bgcolor='$color{'color20'}'>"; }
344 else {print "<tr bgcolor='$color{'color22'}'>"; }
347 <td align='center' class='boldbase' height='20' nowrap='nowrap'><b>$Lang::tr{'trafficsum'}</b></td>
348 <td align='center' class='boldbase' nowrap='nowrap'><b>$total_green_in MB</b></td>
349 <td align='center' class='boldbase' nowrap='nowrap'><b>$total_green_out MB</b></td>
352 if ($netsettings{'CONFIG_TYPE'} =~ /^(3|4)$/)
354 print "<td align='center' class='boldbase' nowrap='nowrap'><b>$total_blue_in MB</b></td>";
355 print "<td align='center' class='boldbase' nowrap='nowrap'><b>$total_blue_out MB</b></td>";
358 if ($netsettings{'CONFIG_TYPE'} =~ /^(2|4)$/)
360 print "<td align='center' class='boldbase' nowrap='nowrap'><b>$total_orange_in MB</b></td>";
361 print "<td align='center' class='boldbase' nowrap='nowrap'><b>$total_orange_out MB</b></td>";
364 if ($netsettings{'CONFIG_TYPE'} =~ /^(1|2|3|4)$/)
366 print "<td align='center' class='boldbase' nowrap='nowrap'><b>$total_red_in MB</b></td>";
367 print "<td align='center' class='boldbase' nowrap='nowrap'><b>$total_red_out MB</b></td>";
369 print "</tr></table>";
372 &Header
::closebigbox
();
373 &Header
::closepage
();