Sprachdateien gefixt
[people/pmueller/ipfire-2.x.git] / html / cgi-bin / traffics.cgi
CommitLineData
10a04d70
MT
1#!/usr/bin/perl
2#
3# SmoothWall CGIs
4#
5# This code is distributed under the terms of the GPL
6#
7# (c) The SmoothWall Team
8#
9
10use strict;
11
12# enable only the following on debugging purpose
13use warnings;
14use CGI::Carp 'fatalsToBrowser';
15
16require '/var/ipfire/general-functions.pl';
17require "${General::swroot}/lang.pl";
18require "${General::swroot}/header.pl";
19require '/var/ipfire/net-traffic/net-traffic-lib.pl';
20
21my %cgiparams;
22my %netsettings;
23
24&General::readhash("${General::swroot}/ethernet/settings", \%netsettings);
25
1be59789 26my @years=("2007","2008","2009","2010","2011","2012","2013","2014","2015");
10a04d70
MT
27
28my @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'} );
32
33my @months = ( 0,1,2,3,4,5,6,7,8,9,10,11 );
34my @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 );
35
10a04d70
MT
36my @now = localtime(time);
37
38$now[5] = $now[5]+1900;
39
40$cgiparams{'STARTDAY'} = 10;
41$cgiparams{'STOPDAY'} = 11;
42$cgiparams{'STARTYEAR'} = $now[5];
43$cgiparams{'STOPYEAR'} = $now[5];
44
45# this periode started last month
46if ($now[3] < 10) {
47 $cgiparams{'STARTMONTH'} = $now[4]-1;
48 $cgiparams{'STOPMONTH'} = $now[4];
49 # when current month is january we start in last year december
50 if ($now[4] == 0) {
51 $cgiparams{'STARTYEAR'} = $now[5]-1;
52 $cgiparams{'STARTMONTH'} = 11;
53 }
54}
55else {
56 $cgiparams{'STARTMONTH'} = $now[4];
57 $cgiparams{'STOPMONTH'} = $now[4]+1;
58 # when we are december, this periode ends next year january
59 if ($now[4] == 11) {
60 $cgiparams{'STOPYEAR'} = $now[5]+1;
61 $cgiparams{'STOPMONTH'} = 0;
62 }
63}
64
65&Header::getcgihash(\%cgiparams);
66
67&Header::showhttpheaders();
68
69&Header::openpage($Lang::tr{'sstraffic'}, 1, '');
70
71&Header::openbigbox('100%', 'left');
72
15f635cc 73&Header::openbox('100%', 'left', $Lang::tr{'settings'});
10a04d70
MT
74
75print <<END;
76<table width='100%' align='center'>
77<tr>
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'>
82END
83
84foreach (@days)
85{
86 print "\t<option ";
87 if ($_ == $cgiparams{'STARTDAY'}) {
88 print 'selected=\'selected\' '; }
89 print "value='$_'>$_</option>\n";
90}
91print <<END;
92 </select>
93 <select name='STARTMONTH'>
94END
95
96foreach (@months)
97{
98 print "\t<option ";
99 if ($_ == $cgiparams{'STARTMONTH'}) {
100 print 'selected=\'selected\' '; }
101 print "value='$_'>$longmonths[$_]</option>\n";
102}
103
104print <<END;
105 </select>
106 <select name='STARTYEAR'>
107END
108
109for (my $index=0; $index<=$#years; $index++) {
110 print "\t<option ";
111 if ($years[$index] == $cgiparams{'STARTYEAR'}) {
112 print 'selected=\'selected\' '; }
113 print "value='$years[$index]'>$years[$index]</option>\n";
114}
115
116print <<END;
117 </select>
118 $Lang::tr{'trafficto'}
119 <select name='STOPDAY'>
120END
121
122foreach (@days)
123{
124 print "\t<option ";
125 if ($_ == $cgiparams{'STOPDAY'})
126 {
127 print 'selected=\'selected\' '; }
128 print "value='$_'>$_</option>\n";
129}
130
131print <<END;
132 </select>
133 <select name='STOPMONTH'>
134END
135
136foreach (@months)
137{
138 print "\t<option ";
139 if ($_ == $cgiparams{'STOPMONTH'}) {
140 print 'selected=\'selected\' '; }
141 print "value='$_'>$longmonths[$_]</option>\n";
142}
143
144print <<END;
145 </select>
146 <select name='STOPYEAR'>
147END
148
149for (my $index = 0; $index <=$#years; $index++) {
150 print "\t<option ";
151 if ($years[$index] == $cgiparams{'STOPYEAR'}) {
152 print 'selected=\'selected\' '; }
153 print "value='$years[$index]'>$years[$index]</option>\n";
154}
155
156
157print <<END;
158 </select>
159 <input type='submit' name='ACTION' value='$Lang::tr{'update'}' />
160 </form>
161 </td>
162 <td width='5%' align='center'>
163 <form method='post' action='/cgi-bin/traffic.cgi'>
164 <input type='submit' name='ACTION' value=' > ' />
165 </form>
166 </td>
167 </tr>
168 </table>
169END
170
171&Header::closebox();
172
173&Header::openbox('100%', 'left', $Lang::tr{'traffics'});
174
175my $dateWidth = '20%';
176my $netWidth = '34%';
177my $inOutWidth = '17%';
178
179# 4 networks
180if ($netsettings{'CONFIG_TYPE'} =~ /^(5|7)$/) {
181 $dateWidth = '12%';
182 $netWidth = '22%';
183 $inOutWidth = '11%';
184}
185# 3 networks
186if ($netsettings{'CONFIG_TYPE'} =~ /^(1|3|4|6)$/) {
187 $dateWidth = '16%';
188 $netWidth = '28%';
189 $inOutWidth = '14%';
190}
191
192print <<END;
193 <table width='100%'>
194 <tr>
195 <td width='$dateWidth' align='center' class='boldbase'></td>
196 <td width='$netWidth' align='center' class='boldbase' ><b>$Lang::tr{'trafficgreen'}</b></td>
197END
198
199if ($netsettings{'CONFIG_TYPE'} =~ /^(4|5|6|7)$/) {
200 print "<td width='$netWidth' align='center' class='boldbase' ><b>$Lang::tr{'trafficblue'}</b></td>";
201}
202
203if ($netsettings{'CONFIG_TYPE'} =~ /^(1|3|5|7)$/) {
204 print "<td width='$netWidth' align='center' class='boldbase' ><b>$Lang::tr{'trafficorange'}</b></td>";
205}
206
207print <<END;
208 <td width='$netWidth' align='center' class='boldbase'><b>$Lang::tr{'trafficred'}</b></td>
209 </tr>
210 </table>
211 <table width='100%'>
212 <tr>
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>
216END
217
218if ($netsettings{'CONFIG_TYPE'} =~ /^(4|5|6|7)$/)
219{
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>";
222}
223
224if ($netsettings{'CONFIG_TYPE'} =~ /^(1|3|5|7)$/)
225{
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>";
228}
229print <<END;
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>
232 </tr>
233END
234
235my $total_blue_in=0;
236my $total_blue_out=0;
237my $total_green_in=0;
238my $total_green_out=0;
239my $total_orange_in=0;
240my $total_orange_out=0;
241my $total_red_in=0;
242my $total_red_out=0;
243my $lines=0;
244
245
246my $startyear = $cgiparams{'STARTYEAR'};
247my $stopyear = $cgiparams{'STOPYEAR'};
248
249my $startMonth = $cgiparams{'STARTMONTH'}+1;
250$startMonth = $startMonth < 10 ? $startMonth = "0".$startMonth : $startMonth;
251
252my $endMonth = $cgiparams{'STOPMONTH'}+1;
253$endMonth = $endMonth < 10 ? $endMonth = "0".$endMonth : $endMonth;
254
255my $startDay = $cgiparams{'STARTDAY'};
256$startDay = $startDay < 10 ? $startDay = "0".$startDay : $startDay;
257
258my $endDay = $cgiparams{'STOPDAY'}+1;
259$endDay = $endDay < 10 ? $endDay = "0".$endDay : $endDay;
260
261my $displayMode = "daily_multi";
262my $start = $startyear.$startMonth.$startDay;
263my $end = $stopyear.$endMonth.$endDay;
264
265my %allDaysBytes = ();
266my @allDays = &Traffic::calcTraffic(\%allDaysBytes,$start,$end, $displayMode);
267
268
269foreach (@allDays) {
270 $total_green_in += $allDaysBytes{$_}{${Traffic::green_in}};
271 $total_green_out += $allDaysBytes{$_}{${Traffic::green_out}};
272
273 if ($netsettings{'CONFIG_TYPE'} =~ /^(4|5|6|7)$/)
274 {
275 $total_blue_in += $allDaysBytes{$_}{${Traffic::blue_in}};
276 $total_blue_out += $allDaysBytes{$_}{${Traffic::blue_out}};
277 }
278
279 if ($netsettings{'CONFIG_TYPE'} =~ /^(1|3|5|7)$/)
280 {
281 $total_orange_in += $allDaysBytes{$_}{${Traffic::orange_in}};
282 $total_orange_out += $allDaysBytes{$_}{${Traffic::orange_out}};
283 }
284
285 $total_red_in += $allDaysBytes{$_}{${Traffic::red_in}};
286 $total_red_out += $allDaysBytes{$_}{${Traffic::red_out}};
287
288 if ($lines % 2) {
289 print "<tr bgcolor='${Header::table1colour}'>"; }
290 else {
291 print "<tr bgcolor='${Header::table2colour}'>"; }
292
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);
296
297 if ($netsettings{'CONFIG_TYPE'} =~ /^(4|5|6|7)$/)
298 {
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);
301 }
302 if ($netsettings{'CONFIG_TYPE'} =~ /^(1|3|5|7)$/)
303 {
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);
306 }
307
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);
310
311 $lines++;
312}
313
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));
322
323if ($lines % 2) {print "<tr bgcolor='${Header::table1colour}'>"; }
324else {print "<tr bgcolor='${Header::table2colour}'>"; }
325
326print <<END;
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>
330END
331
332if ($netsettings{'CONFIG_TYPE'} =~ /^(4|5|6|7)$/)
333{
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>";
336}
337
338if ($netsettings{'CONFIG_TYPE'} =~ /^(1|3|5|7)$/)
339{
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>";
342}
343
344print <<END;
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>
347 </tr>
348 </table>
349END
350
351&Header::closebox();
352
353&Header::closebigbox();
354
355&Header::closepage();