]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - html/cgi-bin/traffics.cgi
Am Pakfire weitergearbeitet.
[people/pmueller/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 # $Id: traffics.cgi,v 1.12 2006/11/15 21:14:02 dotzball Exp $
10 #
11 # traffics.cgi, v1.1.0 2003/10/18
12 # supports now:
13 # * IPCop v1.3.0
14 # * choosing year
15
16 use strict;
17
18 # enable only the following on debugging purpose
19 use warnings;
20 use CGI::Carp 'fatalsToBrowser';
21
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";
27
28 my %color = ();
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);
32
33 my %cgiparams;
34 my %netsettings;
35
36 &General::readhash("${General::swroot}/ethernet/settings", \%netsettings);
37
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 );
39
40 my @now = localtime(time);
41
42 $now[5] = $now[5]+1900;
43
44 $cgiparams{'STARTDAY'} = 10;
45 $cgiparams{'STOPDAY'} = 11;
46 $cgiparams{'STARTYEAR'} = $now[5];
47 $cgiparams{'STOPYEAR'} = $now[5];
48
49 if($NETTRAFF::settings{'MONTHLY_VOLUME_ON'} eq 'on')
50 {
51 $cgiparams{'STARTDAY'} = $NETTRAFF::settings{'STARTDAY'};
52 $cgiparams{'STOPDAY'} = $NETTRAFF::settings{'STARTDAY'};
53 }
54
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;
63 }
64 }
65 else {
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;
72 }
73 }
74
75 &Header::getcgihash(\%cgiparams);
76 &Header::showhttpheaders();
77 &Header::openpage($Lang::tr{'sstraffic'}, 1, '');
78 &Header::openbigbox('100%', 'left');
79 &Header::openbox('100%', 'left', "");
80
81 print <<END;
82 <table width='100%' align='center'>
83 <tr>
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'>
88 END
89
90 foreach my $day (@days)
91 {
92 print "\t<option ";
93 if ($day == $cgiparams{'STARTDAY'}) {
94 print 'selected=\'selected\' '; }
95 print "value='$day'>$day</option>\n";
96 }
97 print <<END;
98 </select>
99 <select name='STARTMONTH'>
100 END
101
102 foreach my $month (@NETTRAFF::months)
103 {
104 print "\t<option ";
105 if ($month == $cgiparams{'STARTMONTH'}) {
106 print 'selected=\'selected\' '; }
107 print "value='$month'>$NETTRAFF::longmonths[$month]</option>\n";
108 }
109
110 print <<END;
111 </select>
112 <select name='STARTYEAR'>
113 END
114
115 foreach my $year (@NETTRAFF::years) {
116 print "\t<option ";
117 if ($year == $cgiparams{'STARTYEAR'}) {
118 print 'selected=\'selected\' '; }
119 print "value='$year'>$year</option>\n";
120 }
121
122 print <<END;
123 </select>
124 $Lang::tr{'trafficto'}
125 <select name='STOPDAY'>
126 END
127
128 foreach my $day (@days)
129 {
130 print "\t<option ";
131 if ($day == $cgiparams{'STOPDAY'})
132 {
133 print 'selected=\'selected\' '; }
134 print "value='$day'>$day</option>\n";
135 }
136
137 print <<END;
138 </select>
139 <select name='STOPMONTH'>
140 END
141
142 foreach my $month (@NETTRAFF::months)
143 {
144 print "\t<option ";
145 if ($month == $cgiparams{'STOPMONTH'}) {
146 print 'selected=\'selected\' '; }
147 print "value='$month'>$NETTRAFF::longmonths[$month]</option>\n";
148 }
149
150 print <<END;
151 </select>
152 <select name='STOPYEAR'>
153 END
154
155 foreach my $year (@NETTRAFF::years) {
156 print "\t<option ";
157 if ($year == $cgiparams{'STOPYEAR'}) {
158 print 'selected=\'selected\' '; }
159 print "value='$year'>$year</option>\n";
160 }
161
162
163 print <<END;
164 </select>
165 <input type='submit' name='ACTION' value='$Lang::tr{'update'}' />
166 </form>
167 </td>
168 <td width='5%' align='center'>
169 <form method='post' action='/cgi-bin/traffic.cgi'>
170 <input type='submit' name='ACTION' value=' > ' />
171 </form>
172 </td>
173 </tr>
174 </table>
175 END
176
177 &Header::closebox();
178
179 &Header::openbox('100%', 'left', "$Lang::tr{'traffics'}");
180
181 my $dateWidth = '20%';
182 my $netWidth = '34%';
183 my $inOutWidth = '17%';
184
185 # 4 networks
186 if ($netsettings{'CONFIG_TYPE'} =~ /^(4)$/) {
187 $dateWidth = '12%';
188 $netWidth = '22%';
189 $inOutWidth = '11%';
190 }
191 # 3 networks
192 if ($netsettings{'CONFIG_TYPE'} =~ /^(2|3)$/) {
193 $dateWidth = '16%';
194 $netWidth = '28%';
195 $inOutWidth = '14%';
196 }
197
198 print <<END;
199 <table width='100%'>
200 <tr>
201 <td width='$dateWidth' align='center' class='boldbase'></td>
202 <td width='$netWidth' align='center' class='boldbase' ><b>$Lang::tr{'trafficgreen'}</b></td>
203 END
204
205 if ($netsettings{'CONFIG_TYPE'} =~ /^(3|4)$/) {
206 print "<td width='$netWidth' align='center' class='boldbase' ><b>$Lang::tr{'trafficblue'}</b></td>";
207 }
208
209 if ($netsettings{'CONFIG_TYPE'} =~ /^(2|4)$/) {
210 print "<td width='$netWidth' align='center' class='boldbase' ><b>$Lang::tr{'trafficorange'}</b></td>";
211 }
212
213 if ($netsettings{'CONFIG_TYPE'} =~ /^(1|2|3|4)$/)
214 {
215 print "<td width='$netWidth' align='center' class='boldbase'><b>$Lang::tr{'trafficred'}</b></td>";
216 }
217 print <<END;
218 </tr>
219 </table>
220 <table width='100%'>
221 <tr>
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>
225 END
226
227 if ($netsettings{'CONFIG_TYPE'} =~ /^(3|4)$/)
228 {
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>";
231 }
232
233 if ($netsettings{'CONFIG_TYPE'} =~ /^(2|4)$/)
234 {
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>";
237 }
238 if ($netsettings{'CONFIG_TYPE'} =~ /^(1|2|3|4)$/)
239 {
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>";
242 }
243 print "</tr>";
244
245 my $total_blue_in=0;
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;
251 my $total_red_in=0;
252 my $total_red_out=0;
253 my $lines=0;
254
255
256 my $startyear = $cgiparams{'STARTYEAR'};
257 my $stopyear = $cgiparams{'STOPYEAR'};
258
259 my $startMonth = $cgiparams{'STARTMONTH'}+1;
260 $startMonth = $startMonth < 10 ? $startMonth = "0".$startMonth : $startMonth;
261
262 my $endMonth = $cgiparams{'STOPMONTH'}+1;
263 $endMonth = $endMonth < 10 ? $endMonth = "0".$endMonth : $endMonth;
264
265 my $startDay = $cgiparams{'STARTDAY'};
266 $startDay = $startDay < 10 ? $startDay = "0".$startDay : $startDay;
267
268 my $endDay = $cgiparams{'STOPDAY'}+1;
269 $endDay = $endDay < 10 ? $endDay = "0".$endDay : $endDay;
270
271 my $displayMode = "daily_multi";
272 my $start = $startyear.$startMonth.$startDay;
273 my $end = $stopyear.$endMonth.$endDay;
274
275 my %allDaysBytes = ();
276 my @allDays = &Traffic::calcTraffic(\%allDaysBytes,$start,$end, $displayMode);
277
278
279 foreach (@allDays) {
280 $total_green_in += $allDaysBytes{$_}{${Traffic::green_in}};
281 $total_green_out += $allDaysBytes{$_}{${Traffic::green_out}};
282
283 if ($netsettings{'CONFIG_TYPE'} =~ /^(3|4)$/)
284 {
285 $total_blue_in += $allDaysBytes{$_}{${Traffic::blue_in}};
286 $total_blue_out += $allDaysBytes{$_}{${Traffic::blue_out}};
287 }
288
289 if ($netsettings{'CONFIG_TYPE'} =~ /^(2|4)$/)
290 {
291 $total_orange_in += $allDaysBytes{$_}{${Traffic::orange_in}};
292 $total_orange_out += $allDaysBytes{$_}{${Traffic::orange_out}};
293 }
294
295 if ($netsettings{'CONFIG_TYPE'} =~ /^(1|2|3|4)$/)
296 {
297 $total_red_in += $allDaysBytes{$_}{${Traffic::red_in}};
298 $total_red_out += $allDaysBytes{$_}{${Traffic::red_out}};
299 }
300
301 if ($lines % 2) {
302 print "<tr bgcolor='$color{'color20'}'>"; }
303 else {
304 print "<tr bgcolor='$color{'color22'}'>"; }
305
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);
309
310 if ($netsettings{'CONFIG_TYPE'} =~ /^(3|4)$/)
311 {
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);
314 }
315 if ($netsettings{'CONFIG_TYPE'} =~ /^(2|4)$/)
316 {
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);
319 }
320 if ($netsettings{'CONFIG_TYPE'} =~ /^(1|2|3|4)$/)
321 {
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);
324 }
325 $lines++;
326 }
327
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));
336
337 if ($lines % 2) {print "<tr bgcolor='$color{'color20'}'>"; }
338 else {print "<tr bgcolor='$color{'color22'}'>"; }
339
340 print <<END;
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>
344 END
345
346 if ($netsettings{'CONFIG_TYPE'} =~ /^(3|4)$/)
347 {
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>";
350 }
351
352 if ($netsettings{'CONFIG_TYPE'} =~ /^(2|4)$/)
353 {
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>";
356 }
357
358 if ($netsettings{'CONFIG_TYPE'} =~ /^(1|2|3|4)$/)
359 {
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>";
362 }
363 print "</tr></table>";
364
365 &Header::closebox();
366 &Header::closebigbox();
367 &Header::closepage();