]>
git.ipfire.org Git - people/teissler/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=("2007","2008","2009","2010","2011","2012","2013","2014","2015");
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 @now = localtime(time);
38 $now[5] = $now[5]+1900;
40 $cgiparams{'STARTDAY'} = 10;
41 $cgiparams{'STOPDAY'} = 11;
42 $cgiparams{'STARTYEAR'} = $now[5];
43 $cgiparams{'STOPYEAR'} = $now[5];
45 # this periode started last month
47 $cgiparams{'STARTMONTH'} = $now[4]-1;
48 $cgiparams{'STOPMONTH'} = $now[4];
49 # when current month is january we start in last year december
51 $cgiparams{'STARTYEAR'} = $now[5]-1;
52 $cgiparams{'STARTMONTH'} = 11;
56 $cgiparams{'STARTMONTH'} = $now[4];
57 $cgiparams{'STOPMONTH'} = $now[4]+1;
58 # when we are december, this periode ends next year january
60 $cgiparams{'STOPYEAR'} = $now[5]+1;
61 $cgiparams{'STOPMONTH'} = 0;
65 &Header
::getcgihash
(\
%cgiparams);
67 &Header
::showhttpheaders
();
69 &Header
::openpage
($Lang::tr
{'sstraffic'}, 1, '');
71 &Header
::openbigbox
('100%', 'left');
73 &Header
::openbox
('100%', 'left', $Lang::tr
{'settings'});
76 <table width='100%' align='center'>
78 <td width='95%' class='base' align='center'>
79 <form method='post' action='/cgi-bin/traffics.cgi'>
80 $Lang::tr{'trafficfrom'}
81 <select name='STARTDAY'>
87 if ($_ == $cgiparams{'STARTDAY'}) {
88 print 'selected=\'selected\' '; }
89 print "value='$_'>$_</option>\n";
93 <select name='STARTMONTH'>
99 if ($_ == $cgiparams{'STARTMONTH'}) {
100 print 'selected=\'selected\' '; }
101 print "value='$_'>$longmonths[$_]</option>\n";
106 <select name='STARTYEAR'>
109 for (my $index=0; $index<=$#years; $index++) {
111 if ($years[$index] == $cgiparams{'STARTYEAR'}) {
112 print 'selected=\'selected\' '; }
113 print "value='$years[$index]'>$years[$index]</option>\n";
118 $Lang::tr{'trafficto'}
119 <select name='STOPDAY'>
125 if ($_ == $cgiparams{'STOPDAY'})
127 print 'selected=\'selected\' '; }
128 print "value='$_'>$_</option>\n";
133 <select name='STOPMONTH'>
139 if ($_ == $cgiparams{'STOPMONTH'}) {
140 print 'selected=\'selected\' '; }
141 print "value='$_'>$longmonths[$_]</option>\n";
146 <select name='STOPYEAR'>
149 for (my $index = 0; $index <=$#years; $index++) {
151 if ($years[$index] == $cgiparams{'STOPYEAR'}) {
152 print 'selected=\'selected\' '; }
153 print "value='$years[$index]'>$years[$index]</option>\n";
159 <input type='submit' name='ACTION' value='$Lang::tr{'update'}' />
162 <td width='5%' align='center'>
163 <form method='post' action='/cgi-bin/traffic.cgi'>
164 <input type='submit' name='ACTION' value=' > ' />
173 &Header
::openbox
('100%', 'left', $Lang::tr
{'traffics'});
175 my $dateWidth = '20%';
176 my $netWidth = '34%';
177 my $inOutWidth = '17%';
180 if ($netsettings{'CONFIG_TYPE'} =~ /^(5|7)$/) {
186 if ($netsettings{'CONFIG_TYPE'} =~ /^(1|3|4|6)$/) {
195 <td width='$dateWidth' align='center' class='boldbase'></td>
196 <td width='$netWidth' align='center' class='boldbase' ><b>$Lang::tr{'trafficgreen'}</b></td>
199 if ($netsettings{'CONFIG_TYPE'} =~ /^(4|5|6|7)$/) {
200 print "<td width='$netWidth' align='center' class='boldbase' ><b>$Lang::tr{'trafficblue'}</b></td>";
203 if ($netsettings{'CONFIG_TYPE'} =~ /^(1|3|5|7)$/) {
204 print "<td width='$netWidth' align='center' class='boldbase' ><b>$Lang::tr{'trafficorange'}</b></td>";
208 <td width='$netWidth' align='center' class='boldbase'><b>$Lang::tr{'trafficred'}</b></td>
213 <td width='$dateWidth' align='center' class='boldbase'><b>$Lang::tr{'trafficdate'}</b></td>
214 <td width='$inOutWidth' align='center' class='boldbase'><font color='#16A61D'><b>$Lang::tr{'trafficin'}</b></font></td>
215 <td width='$inOutWidth' align='center' class='boldbase'><font color='#16A61D'><b>$Lang::tr{'trafficout'}</b></font></td>
218 if ($netsettings{'CONFIG_TYPE'} =~ /^(4|5|6|7)$/)
220 print "<td width='$inOutWidth' align='center' class='boldbase'><font color='${Header::colourblue}'><b>$Lang::tr{'trafficin'}</b></font></td>";
221 print "<td width='$inOutWidth' align='center' class='boldbase'><font color='${Header::colourblue}'><b>$Lang::tr{'trafficout'}</b></font></td>";
224 if ($netsettings{'CONFIG_TYPE'} =~ /^(1|3|5|7)$/)
226 print "<td width='$inOutWidth' align='center' class='boldbase'><font color='#FF9933'><b>$Lang::tr{'trafficin'}</b></font></td>";
227 print "<td width='$inOutWidth' align='center' class='boldbase'><font color='#FF9933'><b>$Lang::tr{'trafficout'}</b></font></td>";
230 <td width='$inOutWidth' align='center' class='boldbase'><font color='#CE1B31'><b>$Lang::tr{'trafficin'}</b></font></td>
231 <td width='$inOutWidth' align='center' class='boldbase'><font color='#CE1B31'><b>$Lang::tr{'trafficout'}</b></font></td>
236 my $total_blue_out=0;
237 my $total_green_in=0;
238 my $total_green_out=0;
239 my $total_orange_in=0;
240 my $total_orange_out=0;
246 my $startyear = $cgiparams{'STARTYEAR'};
247 my $stopyear = $cgiparams{'STOPYEAR'};
249 my $startMonth = $cgiparams{'STARTMONTH'}+1;
250 $startMonth = $startMonth < 10 ?
$startMonth = "0".$startMonth : $startMonth;
252 my $endMonth = $cgiparams{'STOPMONTH'}+1;
253 $endMonth = $endMonth < 10 ?
$endMonth = "0".$endMonth : $endMonth;
255 my $startDay = $cgiparams{'STARTDAY'};
256 $startDay = $startDay < 10 ?
$startDay = "0".$startDay : $startDay;
258 my $endDay = $cgiparams{'STOPDAY'}+1;
259 $endDay = $endDay < 10 ?
$endDay = "0".$endDay : $endDay;
261 my $displayMode = "daily_multi";
262 my $start = $startyear.$startMonth.$startDay;
263 my $end = $stopyear.$endMonth.$endDay;
265 my %allDaysBytes = ();
266 my @allDays = &Traffic
::calcTraffic
(\
%allDaysBytes,$start,$end, $displayMode);
270 $total_green_in += $allDaysBytes{$_}{${Traffic
::green_in
}};
271 $total_green_out += $allDaysBytes{$_}{${Traffic
::green_out
}};
273 if ($netsettings{'CONFIG_TYPE'} =~ /^(4|5|6|7)$/)
275 $total_blue_in += $allDaysBytes{$_}{${Traffic
::blue_in
}};
276 $total_blue_out += $allDaysBytes{$_}{${Traffic
::blue_out
}};
279 if ($netsettings{'CONFIG_TYPE'} =~ /^(1|3|5|7)$/)
281 $total_orange_in += $allDaysBytes{$_}{${Traffic
::orange_in
}};
282 $total_orange_out += $allDaysBytes{$_}{${Traffic
::orange_out
}};
285 $total_red_in += $allDaysBytes{$_}{${Traffic
::red_in
}};
286 $total_red_out += $allDaysBytes{$_}{${Traffic
::red_out
}};
289 print "<tr bgcolor='${Header::table1colour}'>"; }
291 print "<tr bgcolor='${Header::table2colour}'>"; }
293 printf "<td align='center' nowrap='nowrap'>%s</td>\n", $allDaysBytes{$_}{'Day'};
294 printf "<td align='center' nowrap='nowrap'>%.3f</td>\n", ($allDaysBytes{$_}{${Traffic
::green_in
}}/1048576);
295 printf "<td align='center' nowrap='nowrap'>%.3f</td>\n", ($allDaysBytes{$_}{${Traffic
::green_out
}}/1048576);
297 if ($netsettings{'CONFIG_TYPE'} =~ /^(4|5|6|7)$/)
299 printf "<td align='center' nowrap='nowrap'>%.3f</td>\n", ($allDaysBytes{$_}{${Traffic
::blue_in
}}/1048576);
300 printf "<td align='center' nowrap='nowrap'>%.3f</td>\n", ($allDaysBytes{$_}{${Traffic
::blue_out
}}/1048576);
302 if ($netsettings{'CONFIG_TYPE'} =~ /^(1|3|5|7)$/)
304 printf "<td align='center' nowrap='nowrap'>%.3f</td>\n", ($allDaysBytes{$_}{${Traffic
::orange_in
}}/1048576);
305 printf "<td align='center' nowrap='nowrap'>%.3f</td>\n", ($allDaysBytes{$_}{${Traffic
::orange_out
}}/1048576);
308 printf "<td align='center' nowrap='nowrap'>%.3f</td>\n", ($allDaysBytes{$_}{${Traffic
::red_in
}}/1048576);
309 printf "<td align='center' nowrap='nowrap'>%.3f</td></tr>\n", ($allDaysBytes{$_}{${Traffic
::red_out
}}/1048576);
314 $total_green_in=sprintf("%.2f", ($total_green_in/1048576));
315 $total_green_out=sprintf("%.2f", ($total_green_out/1048576));
316 $total_blue_in=sprintf("%.2f", ($total_blue_in/1048576));
317 $total_blue_out=sprintf("%.2f", ($total_blue_out/1048576));
318 $total_orange_in=sprintf("%.2f", ($total_orange_in/1048576));
319 $total_orange_out=sprintf("%.2f", ($total_orange_out/1048576));
320 $total_red_in=sprintf("%.2f", ($total_red_in/1048576));
321 $total_red_out=sprintf("%.2f", ($total_red_out/1048576));
323 if ($lines % 2) {print "<tr bgcolor='${Header::table1colour}'>"; }
324 else {print "<tr bgcolor='${Header::table2colour}'>"; }
327 <td align='center' class='boldbase' height='20' nowrap='nowrap'><b>$Lang::tr{'trafficsum'}</b></td>
328 <td align='center' class='boldbase' nowrap='nowrap'><b>$total_green_in MB</b></td>
329 <td align='center' class='boldbase' nowrap='nowrap'><b>$total_green_out MB</b></td>
332 if ($netsettings{'CONFIG_TYPE'} =~ /^(4|5|6|7)$/)
334 print "<td align='center' class='boldbase' nowrap='nowrap'><b>$total_blue_in MB</b></td>";
335 print "<td align='center' class='boldbase' nowrap='nowrap'><b>$total_blue_out MB</b></td>";
338 if ($netsettings{'CONFIG_TYPE'} =~ /^(1|3|5|7)$/)
340 print "<td align='center' class='boldbase' nowrap='nowrap'><b>$total_orange_in MB</b></td>";
341 print "<td align='center' class='boldbase' nowrap='nowrap'><b>$total_orange_out MB</b></td>";
345 <td align='center' class='boldbase' nowrap='nowrap'><b>$total_red_in MB</b></td>
346 <td align='center' class='boldbase' nowrap='nowrap'><b>$total_red_out MB</b></td>
353 &Header
::closebigbox
();
355 &Header
::closepage
();