]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blame - html/cgi-bin/traffics.cgi
Nettraffic aktualisiert.
[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
36my @wday = ($Lang::tr{'wday1'}, $Lang::tr{'wday2'}, $Lang::tr{'wday3'}, $Lang::tr{'wday4'}, $Lang::tr{'wday5'}, $Lang::tr{'wday6'}, $Lang::tr{'wday7'});
37
38my @now = localtime(time);
39
40$now[5] = $now[5]+1900;
41
42$cgiparams{'STARTDAY'} = 10;
43$cgiparams{'STOPDAY'} = 11;
44$cgiparams{'STARTYEAR'} = $now[5];
45$cgiparams{'STOPYEAR'} = $now[5];
46
47# this periode started last month
48if ($now[3] < 10) {
49 $cgiparams{'STARTMONTH'} = $now[4]-1;
50 $cgiparams{'STOPMONTH'} = $now[4];
51 # when current month is january we start in last year december
52 if ($now[4] == 0) {
53 $cgiparams{'STARTYEAR'} = $now[5]-1;
54 $cgiparams{'STARTMONTH'} = 11;
55 }
56}
57else {
58 $cgiparams{'STARTMONTH'} = $now[4];
59 $cgiparams{'STOPMONTH'} = $now[4]+1;
60 # when we are december, this periode ends next year january
61 if ($now[4] == 11) {
62 $cgiparams{'STOPYEAR'} = $now[5]+1;
63 $cgiparams{'STOPMONTH'} = 0;
64 }
65}
66
67&Header::getcgihash(\%cgiparams);
68
69&Header::showhttpheaders();
70
71&Header::openpage($Lang::tr{'sstraffic'}, 1, '');
72
73&Header::openbigbox('100%', 'left');
74
75&Header::openbox('100%', 'left', $Lang::tr{'settingsc'});
76
77print <<END;
78<table width='100%' align='center'>
79<tr>
80 <td width='95%' class='base' align='center'>
81 <form method='post' action='/cgi-bin/traffics.cgi'>
82 $Lang::tr{'trafficfrom'}
83 <select name='STARTDAY'>
84END
85
86foreach (@days)
87{
88 print "\t<option ";
89 if ($_ == $cgiparams{'STARTDAY'}) {
90 print 'selected=\'selected\' '; }
91 print "value='$_'>$_</option>\n";
92}
93print <<END;
94 </select>
95 <select name='STARTMONTH'>
96END
97
98foreach (@months)
99{
100 print "\t<option ";
101 if ($_ == $cgiparams{'STARTMONTH'}) {
102 print 'selected=\'selected\' '; }
103 print "value='$_'>$longmonths[$_]</option>\n";
104}
105
106print <<END;
107 </select>
108 <select name='STARTYEAR'>
109END
110
111for (my $index=0; $index<=$#years; $index++) {
112 print "\t<option ";
113 if ($years[$index] == $cgiparams{'STARTYEAR'}) {
114 print 'selected=\'selected\' '; }
115 print "value='$years[$index]'>$years[$index]</option>\n";
116}
117
118print <<END;
119 </select>
120 $Lang::tr{'trafficto'}
121 <select name='STOPDAY'>
122END
123
124foreach (@days)
125{
126 print "\t<option ";
127 if ($_ == $cgiparams{'STOPDAY'})
128 {
129 print 'selected=\'selected\' '; }
130 print "value='$_'>$_</option>\n";
131}
132
133print <<END;
134 </select>
135 <select name='STOPMONTH'>
136END
137
138foreach (@months)
139{
140 print "\t<option ";
141 if ($_ == $cgiparams{'STOPMONTH'}) {
142 print 'selected=\'selected\' '; }
143 print "value='$_'>$longmonths[$_]</option>\n";
144}
145
146print <<END;
147 </select>
148 <select name='STOPYEAR'>
149END
150
151for (my $index = 0; $index <=$#years; $index++) {
152 print "\t<option ";
153 if ($years[$index] == $cgiparams{'STOPYEAR'}) {
154 print 'selected=\'selected\' '; }
155 print "value='$years[$index]'>$years[$index]</option>\n";
156}
157
158
159print <<END;
160 </select>
161 <input type='submit' name='ACTION' value='$Lang::tr{'update'}' />
162 </form>
163 </td>
164 <td width='5%' align='center'>
165 <form method='post' action='/cgi-bin/traffic.cgi'>
166 <input type='submit' name='ACTION' value=' > ' />
167 </form>
168 </td>
169 </tr>
170 </table>
171END
172
173&Header::closebox();
174
175&Header::openbox('100%', 'left', $Lang::tr{'traffics'});
176
177my $dateWidth = '20%';
178my $netWidth = '34%';
179my $inOutWidth = '17%';
180
181# 4 networks
182if ($netsettings{'CONFIG_TYPE'} =~ /^(5|7)$/) {
183 $dateWidth = '12%';
184 $netWidth = '22%';
185 $inOutWidth = '11%';
186}
187# 3 networks
188if ($netsettings{'CONFIG_TYPE'} =~ /^(1|3|4|6)$/) {
189 $dateWidth = '16%';
190 $netWidth = '28%';
191 $inOutWidth = '14%';
192}
193
194print <<END;
195 <table width='100%'>
196 <tr>
197 <td width='$dateWidth' align='center' class='boldbase'></td>
198 <td width='$netWidth' align='center' class='boldbase' ><b>$Lang::tr{'trafficgreen'}</b></td>
199END
200
201if ($netsettings{'CONFIG_TYPE'} =~ /^(4|5|6|7)$/) {
202 print "<td width='$netWidth' align='center' class='boldbase' ><b>$Lang::tr{'trafficblue'}</b></td>";
203}
204
205if ($netsettings{'CONFIG_TYPE'} =~ /^(1|3|5|7)$/) {
206 print "<td width='$netWidth' align='center' class='boldbase' ><b>$Lang::tr{'trafficorange'}</b></td>";
207}
208
209print <<END;
210 <td width='$netWidth' align='center' class='boldbase'><b>$Lang::tr{'trafficred'}</b></td>
211 </tr>
212 </table>
213 <table width='100%'>
214 <tr>
215 <td width='$dateWidth' align='center' class='boldbase'><b>$Lang::tr{'trafficdate'}</b></td>
216 <td width='$inOutWidth' align='center' class='boldbase'><font color='#16A61D'><b>$Lang::tr{'trafficin'}</b></font></td>
217 <td width='$inOutWidth' align='center' class='boldbase'><font color='#16A61D'><b>$Lang::tr{'trafficout'}</b></font></td>
218END
219
220if ($netsettings{'CONFIG_TYPE'} =~ /^(4|5|6|7)$/)
221{
222 print "<td width='$inOutWidth' align='center' class='boldbase'><font color='${Header::colourblue}'><b>$Lang::tr{'trafficin'}</b></font></td>";
223 print "<td width='$inOutWidth' align='center' class='boldbase'><font color='${Header::colourblue}'><b>$Lang::tr{'trafficout'}</b></font></td>";
224}
225
226if ($netsettings{'CONFIG_TYPE'} =~ /^(1|3|5|7)$/)
227{
228 print "<td width='$inOutWidth' align='center' class='boldbase'><font color='#FF9933'><b>$Lang::tr{'trafficin'}</b></font></td>";
229 print "<td width='$inOutWidth' align='center' class='boldbase'><font color='#FF9933'><b>$Lang::tr{'trafficout'}</b></font></td>";
230}
231print <<END;
232 <td width='$inOutWidth' align='center' class='boldbase'><font color='#CE1B31'><b>$Lang::tr{'trafficin'}</b></font></td>
233 <td width='$inOutWidth' align='center' class='boldbase'><font color='#CE1B31'><b>$Lang::tr{'trafficout'}</b></font></td>
234 </tr>
235END
236
237my $total_blue_in=0;
238my $total_blue_out=0;
239my $total_green_in=0;
240my $total_green_out=0;
241my $total_orange_in=0;
242my $total_orange_out=0;
243my $total_red_in=0;
244my $total_red_out=0;
245my $lines=0;
246
247
248my $startyear = $cgiparams{'STARTYEAR'};
249my $stopyear = $cgiparams{'STOPYEAR'};
250
251my $startMonth = $cgiparams{'STARTMONTH'}+1;
252$startMonth = $startMonth < 10 ? $startMonth = "0".$startMonth : $startMonth;
253
254my $endMonth = $cgiparams{'STOPMONTH'}+1;
255$endMonth = $endMonth < 10 ? $endMonth = "0".$endMonth : $endMonth;
256
257my $startDay = $cgiparams{'STARTDAY'};
258$startDay = $startDay < 10 ? $startDay = "0".$startDay : $startDay;
259
260my $endDay = $cgiparams{'STOPDAY'}+1;
261$endDay = $endDay < 10 ? $endDay = "0".$endDay : $endDay;
262
263my $displayMode = "daily_multi";
264my $start = $startyear.$startMonth.$startDay;
265my $end = $stopyear.$endMonth.$endDay;
266
267my %allDaysBytes = ();
268my @allDays = &Traffic::calcTraffic(\%allDaysBytes,$start,$end, $displayMode);
269
270
271foreach (@allDays) {
272 $total_green_in += $allDaysBytes{$_}{${Traffic::green_in}};
273 $total_green_out += $allDaysBytes{$_}{${Traffic::green_out}};
274
275 if ($netsettings{'CONFIG_TYPE'} =~ /^(4|5|6|7)$/)
276 {
277 $total_blue_in += $allDaysBytes{$_}{${Traffic::blue_in}};
278 $total_blue_out += $allDaysBytes{$_}{${Traffic::blue_out}};
279 }
280
281 if ($netsettings{'CONFIG_TYPE'} =~ /^(1|3|5|7)$/)
282 {
283 $total_orange_in += $allDaysBytes{$_}{${Traffic::orange_in}};
284 $total_orange_out += $allDaysBytes{$_}{${Traffic::orange_out}};
285 }
286
287 $total_red_in += $allDaysBytes{$_}{${Traffic::red_in}};
288 $total_red_out += $allDaysBytes{$_}{${Traffic::red_out}};
289
290 if ($lines % 2) {
291 print "<tr bgcolor='${Header::table1colour}'>"; }
292 else {
293 print "<tr bgcolor='${Header::table2colour}'>"; }
294
295 printf "<td align='center' nowrap='nowrap'>%s</td>\n", $allDaysBytes{$_}{'Day'};
296 printf "<td align='center' nowrap='nowrap'>%.3f</td>\n", ($allDaysBytes{$_}{${Traffic::green_in}}/1048576);
297 printf "<td align='center' nowrap='nowrap'>%.3f</td>\n", ($allDaysBytes{$_}{${Traffic::green_out}}/1048576);
298
299 if ($netsettings{'CONFIG_TYPE'} =~ /^(4|5|6|7)$/)
300 {
301 printf "<td align='center' nowrap='nowrap'>%.3f</td>\n", ($allDaysBytes{$_}{${Traffic::blue_in}}/1048576);
302 printf "<td align='center' nowrap='nowrap'>%.3f</td>\n", ($allDaysBytes{$_}{${Traffic::blue_out}}/1048576);
303 }
304 if ($netsettings{'CONFIG_TYPE'} =~ /^(1|3|5|7)$/)
305 {
306 printf "<td align='center' nowrap='nowrap'>%.3f</td>\n", ($allDaysBytes{$_}{${Traffic::orange_in}}/1048576);
307 printf "<td align='center' nowrap='nowrap'>%.3f</td>\n", ($allDaysBytes{$_}{${Traffic::orange_out}}/1048576);
308 }
309
310 printf "<td align='center' nowrap='nowrap'>%.3f</td>\n", ($allDaysBytes{$_}{${Traffic::red_in}}/1048576);
311 printf "<td align='center' nowrap='nowrap'>%.3f</td></tr>\n", ($allDaysBytes{$_}{${Traffic::red_out}}/1048576);
312
313 $lines++;
314}
315
316$total_green_in=sprintf("%.2f", ($total_green_in/1048576));
317$total_green_out=sprintf("%.2f", ($total_green_out/1048576));
318$total_blue_in=sprintf("%.2f", ($total_blue_in/1048576));
319$total_blue_out=sprintf("%.2f", ($total_blue_out/1048576));
320$total_orange_in=sprintf("%.2f", ($total_orange_in/1048576));
321$total_orange_out=sprintf("%.2f", ($total_orange_out/1048576));
322$total_red_in=sprintf("%.2f", ($total_red_in/1048576));
323$total_red_out=sprintf("%.2f", ($total_red_out/1048576));
324
325if ($lines % 2) {print "<tr bgcolor='${Header::table1colour}'>"; }
326else {print "<tr bgcolor='${Header::table2colour}'>"; }
327
328print <<END;
329 <td align='center' class='boldbase' height='20' nowrap='nowrap'><b>$Lang::tr{'trafficsum'}</b></td>
330 <td align='center' class='boldbase' nowrap='nowrap'><b>$total_green_in MB</b></td>
331 <td align='center' class='boldbase' nowrap='nowrap'><b>$total_green_out MB</b></td>
332END
333
334if ($netsettings{'CONFIG_TYPE'} =~ /^(4|5|6|7)$/)
335{
336 print "<td align='center' class='boldbase' nowrap='nowrap'><b>$total_blue_in MB</b></td>";
337 print "<td align='center' class='boldbase' nowrap='nowrap'><b>$total_blue_out MB</b></td>";
338}
339
340if ($netsettings{'CONFIG_TYPE'} =~ /^(1|3|5|7)$/)
341{
342 print "<td align='center' class='boldbase' nowrap='nowrap'><b>$total_orange_in MB</b></td>";
343 print "<td align='center' class='boldbase' nowrap='nowrap'><b>$total_orange_out MB</b></td>";
344}
345
346print <<END;
347 <td align='center' class='boldbase' nowrap='nowrap'><b>$total_red_in MB</b></td>
348 <td align='center' class='boldbase' nowrap='nowrap'><b>$total_red_out MB</b></td>
349 </tr>
350 </table>
351END
352
353&Header::closebox();
354
355&Header::closebigbox();
356
357&Header::closepage();