]> git.ipfire.org Git - people/teissler/ipfire-2.x.git/blob - html/cgi-bin/traffics.cgi
Sprachdateien gefixt
[people/teissler/ipfire-2.x.git] / html / cgi-bin / traffics.cgi
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
10 use strict;
11
12 # enable only the following on debugging purpose
13 use warnings;
14 use CGI::Carp 'fatalsToBrowser';
15
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';
20
21 my %cgiparams;
22 my %netsettings;
23
24 &General::readhash("${General::swroot}/ethernet/settings", \%netsettings);
25
26 my @years=("2007","2008","2009","2010","2011","2012","2013","2014","2015");
27
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'} );
32
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 );
35
36 my @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
46 if ($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 }
55 else {
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
73 &Header::openbox('100%', 'left', $Lang::tr{'settings'});
74
75 print <<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'>
82 END
83
84 foreach (@days)
85 {
86 print "\t<option ";
87 if ($_ == $cgiparams{'STARTDAY'}) {
88 print 'selected=\'selected\' '; }
89 print "value='$_'>$_</option>\n";
90 }
91 print <<END;
92 </select>
93 <select name='STARTMONTH'>
94 END
95
96 foreach (@months)
97 {
98 print "\t<option ";
99 if ($_ == $cgiparams{'STARTMONTH'}) {
100 print 'selected=\'selected\' '; }
101 print "value='$_'>$longmonths[$_]</option>\n";
102 }
103
104 print <<END;
105 </select>
106 <select name='STARTYEAR'>
107 END
108
109 for (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
116 print <<END;
117 </select>
118 $Lang::tr{'trafficto'}
119 <select name='STOPDAY'>
120 END
121
122 foreach (@days)
123 {
124 print "\t<option ";
125 if ($_ == $cgiparams{'STOPDAY'})
126 {
127 print 'selected=\'selected\' '; }
128 print "value='$_'>$_</option>\n";
129 }
130
131 print <<END;
132 </select>
133 <select name='STOPMONTH'>
134 END
135
136 foreach (@months)
137 {
138 print "\t<option ";
139 if ($_ == $cgiparams{'STOPMONTH'}) {
140 print 'selected=\'selected\' '; }
141 print "value='$_'>$longmonths[$_]</option>\n";
142 }
143
144 print <<END;
145 </select>
146 <select name='STOPYEAR'>
147 END
148
149 for (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
157 print <<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>
169 END
170
171 &Header::closebox();
172
173 &Header::openbox('100%', 'left', $Lang::tr{'traffics'});
174
175 my $dateWidth = '20%';
176 my $netWidth = '34%';
177 my $inOutWidth = '17%';
178
179 # 4 networks
180 if ($netsettings{'CONFIG_TYPE'} =~ /^(5|7)$/) {
181 $dateWidth = '12%';
182 $netWidth = '22%';
183 $inOutWidth = '11%';
184 }
185 # 3 networks
186 if ($netsettings{'CONFIG_TYPE'} =~ /^(1|3|4|6)$/) {
187 $dateWidth = '16%';
188 $netWidth = '28%';
189 $inOutWidth = '14%';
190 }
191
192 print <<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>
197 END
198
199 if ($netsettings{'CONFIG_TYPE'} =~ /^(4|5|6|7)$/) {
200 print "<td width='$netWidth' align='center' class='boldbase' ><b>$Lang::tr{'trafficblue'}</b></td>";
201 }
202
203 if ($netsettings{'CONFIG_TYPE'} =~ /^(1|3|5|7)$/) {
204 print "<td width='$netWidth' align='center' class='boldbase' ><b>$Lang::tr{'trafficorange'}</b></td>";
205 }
206
207 print <<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>
216 END
217
218 if ($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
224 if ($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 }
229 print <<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>
233 END
234
235 my $total_blue_in=0;
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;
241 my $total_red_in=0;
242 my $total_red_out=0;
243 my $lines=0;
244
245
246 my $startyear = $cgiparams{'STARTYEAR'};
247 my $stopyear = $cgiparams{'STOPYEAR'};
248
249 my $startMonth = $cgiparams{'STARTMONTH'}+1;
250 $startMonth = $startMonth < 10 ? $startMonth = "0".$startMonth : $startMonth;
251
252 my $endMonth = $cgiparams{'STOPMONTH'}+1;
253 $endMonth = $endMonth < 10 ? $endMonth = "0".$endMonth : $endMonth;
254
255 my $startDay = $cgiparams{'STARTDAY'};
256 $startDay = $startDay < 10 ? $startDay = "0".$startDay : $startDay;
257
258 my $endDay = $cgiparams{'STOPDAY'}+1;
259 $endDay = $endDay < 10 ? $endDay = "0".$endDay : $endDay;
260
261 my $displayMode = "daily_multi";
262 my $start = $startyear.$startMonth.$startDay;
263 my $end = $stopyear.$endMonth.$endDay;
264
265 my %allDaysBytes = ();
266 my @allDays = &Traffic::calcTraffic(\%allDaysBytes,$start,$end, $displayMode);
267
268
269 foreach (@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
323 if ($lines % 2) {print "<tr bgcolor='${Header::table1colour}'>"; }
324 else {print "<tr bgcolor='${Header::table2colour}'>"; }
325
326 print <<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>
330 END
331
332 if ($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
338 if ($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
344 print <<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>
349 END
350
351 &Header::closebox();
352
353 &Header::closebigbox();
354
355 &Header::closepage();