]>
Commit | Line | Data |
---|---|---|
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 | ||
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 | ||
a08a5f33 CS |
21 | my %color = (); |
22 | my %mainsettings = (); | |
23 | &General::readhash("${General::swroot}/main/settings", \%mainsettings); | |
24 | &General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color); | |
25 | ||
10a04d70 MT |
26 | my %cgiparams; |
27 | my %netsettings; | |
28 | ||
29 | &General::readhash("${General::swroot}/ethernet/settings", \%netsettings); | |
30 | ||
1be59789 | 31 | my @years=("2007","2008","2009","2010","2011","2012","2013","2014","2015"); |
10a04d70 MT |
32 | |
33 | my @longmonths = ( $Lang::tr{'january'}, $Lang::tr{'february'}, $Lang::tr{'march'}, | |
34 | $Lang::tr{'april'}, $Lang::tr{'may'}, $Lang::tr{'june'}, $Lang::tr{'july'}, $Lang::tr{'august'}, | |
35 | $Lang::tr{'september'}, $Lang::tr{'october'}, $Lang::tr{'november'}, | |
36 | $Lang::tr{'december'} ); | |
37 | ||
38 | my @months = ( 0,1,2,3,4,5,6,7,8,9,10,11 ); | |
39 | 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 ); | |
40 | ||
10a04d70 MT |
41 | my @now = localtime(time); |
42 | ||
43 | $now[5] = $now[5]+1900; | |
44 | ||
45 | $cgiparams{'STARTDAY'} = 10; | |
46 | $cgiparams{'STOPDAY'} = 11; | |
47 | $cgiparams{'STARTYEAR'} = $now[5]; | |
48 | $cgiparams{'STOPYEAR'} = $now[5]; | |
49 | ||
50 | # this periode started last month | |
51 | if ($now[3] < 10) { | |
52 | $cgiparams{'STARTMONTH'} = $now[4]-1; | |
53 | $cgiparams{'STOPMONTH'} = $now[4]; | |
54 | # when current month is january we start in last year december | |
55 | if ($now[4] == 0) { | |
56 | $cgiparams{'STARTYEAR'} = $now[5]-1; | |
57 | $cgiparams{'STARTMONTH'} = 11; | |
58 | } | |
59 | } | |
60 | else { | |
61 | $cgiparams{'STARTMONTH'} = $now[4]; | |
62 | $cgiparams{'STOPMONTH'} = $now[4]+1; | |
63 | # when we are december, this periode ends next year january | |
64 | if ($now[4] == 11) { | |
65 | $cgiparams{'STOPYEAR'} = $now[5]+1; | |
66 | $cgiparams{'STOPMONTH'} = 0; | |
67 | } | |
68 | } | |
69 | ||
70 | &Header::getcgihash(\%cgiparams); | |
71 | ||
72 | &Header::showhttpheaders(); | |
73 | ||
74 | &Header::openpage($Lang::tr{'sstraffic'}, 1, ''); | |
75 | ||
76 | &Header::openbigbox('100%', 'left'); | |
77 | ||
15f635cc | 78 | &Header::openbox('100%', 'left', $Lang::tr{'settings'}); |
10a04d70 MT |
79 | |
80 | print <<END; | |
81 | <table width='100%' align='center'> | |
82 | <tr> | |
83 | <td width='95%' class='base' align='center'> | |
84 | <form method='post' action='/cgi-bin/traffics.cgi'> | |
85 | $Lang::tr{'trafficfrom'} | |
86 | <select name='STARTDAY'> | |
87 | END | |
88 | ||
89 | foreach (@days) | |
90 | { | |
91 | print "\t<option "; | |
92 | if ($_ == $cgiparams{'STARTDAY'}) { | |
93 | print 'selected=\'selected\' '; } | |
94 | print "value='$_'>$_</option>\n"; | |
95 | } | |
96 | print <<END; | |
97 | </select> | |
98 | <select name='STARTMONTH'> | |
99 | END | |
100 | ||
101 | foreach (@months) | |
102 | { | |
103 | print "\t<option "; | |
104 | if ($_ == $cgiparams{'STARTMONTH'}) { | |
105 | print 'selected=\'selected\' '; } | |
106 | print "value='$_'>$longmonths[$_]</option>\n"; | |
107 | } | |
108 | ||
109 | print <<END; | |
110 | </select> | |
111 | <select name='STARTYEAR'> | |
112 | END | |
113 | ||
114 | for (my $index=0; $index<=$#years; $index++) { | |
115 | print "\t<option "; | |
116 | if ($years[$index] == $cgiparams{'STARTYEAR'}) { | |
117 | print 'selected=\'selected\' '; } | |
118 | print "value='$years[$index]'>$years[$index]</option>\n"; | |
119 | } | |
120 | ||
121 | print <<END; | |
122 | </select> | |
123 | $Lang::tr{'trafficto'} | |
124 | <select name='STOPDAY'> | |
125 | END | |
126 | ||
127 | foreach (@days) | |
128 | { | |
129 | print "\t<option "; | |
130 | if ($_ == $cgiparams{'STOPDAY'}) | |
131 | { | |
132 | print 'selected=\'selected\' '; } | |
133 | print "value='$_'>$_</option>\n"; | |
134 | } | |
135 | ||
136 | print <<END; | |
137 | </select> | |
138 | <select name='STOPMONTH'> | |
139 | END | |
140 | ||
141 | foreach (@months) | |
142 | { | |
143 | print "\t<option "; | |
144 | if ($_ == $cgiparams{'STOPMONTH'}) { | |
145 | print 'selected=\'selected\' '; } | |
146 | print "value='$_'>$longmonths[$_]</option>\n"; | |
147 | } | |
148 | ||
149 | print <<END; | |
150 | </select> | |
151 | <select name='STOPYEAR'> | |
152 | END | |
153 | ||
154 | for (my $index = 0; $index <=$#years; $index++) { | |
155 | print "\t<option "; | |
156 | if ($years[$index] == $cgiparams{'STOPYEAR'}) { | |
157 | print 'selected=\'selected\' '; } | |
158 | print "value='$years[$index]'>$years[$index]</option>\n"; | |
159 | } | |
160 | ||
161 | ||
162 | print <<END; | |
163 | </select> | |
164 | <input type='submit' name='ACTION' value='$Lang::tr{'update'}' /> | |
165 | </form> | |
166 | </td> | |
167 | <td width='5%' align='center'> | |
168 | <form method='post' action='/cgi-bin/traffic.cgi'> | |
169 | <input type='submit' name='ACTION' value=' > ' /> | |
170 | </form> | |
171 | </td> | |
172 | </tr> | |
173 | </table> | |
174 | END | |
175 | ||
176 | &Header::closebox(); | |
177 | ||
178 | &Header::openbox('100%', 'left', $Lang::tr{'traffics'}); | |
179 | ||
180 | my $dateWidth = '20%'; | |
181 | my $netWidth = '34%'; | |
182 | my $inOutWidth = '17%'; | |
183 | ||
184 | # 4 networks | |
a08a5f33 | 185 | if ($netsettings{'CONFIG_TYPE'} =~ /^(4)$/) { |
10a04d70 MT |
186 | $dateWidth = '12%'; |
187 | $netWidth = '22%'; | |
188 | $inOutWidth = '11%'; | |
189 | } | |
190 | # 3 networks | |
a08a5f33 | 191 | if ($netsettings{'CONFIG_TYPE'} =~ /^(2|3)$/) { |
10a04d70 MT |
192 | $dateWidth = '16%'; |
193 | $netWidth = '28%'; | |
194 | $inOutWidth = '14%'; | |
195 | } | |
196 | ||
197 | print <<END; | |
198 | <table width='100%'> | |
199 | <tr> | |
200 | <td width='$dateWidth' align='center' class='boldbase'></td> | |
201 | <td width='$netWidth' align='center' class='boldbase' ><b>$Lang::tr{'trafficgreen'}</b></td> | |
202 | END | |
203 | ||
a08a5f33 | 204 | if ($netsettings{'CONFIG_TYPE'} =~ /^(3|4)$/) { |
10a04d70 MT |
205 | print "<td width='$netWidth' align='center' class='boldbase' ><b>$Lang::tr{'trafficblue'}</b></td>"; |
206 | } | |
207 | ||
a08a5f33 | 208 | if ($netsettings{'CONFIG_TYPE'} =~ /^(2|4)$/) { |
10a04d70 MT |
209 | print "<td width='$netWidth' align='center' class='boldbase' ><b>$Lang::tr{'trafficorange'}</b></td>"; |
210 | } | |
211 | ||
a08a5f33 CS |
212 | if ($netsettings{'CONFIG_TYPE'} =~ /^(1|2|3|4)$/) { |
213 | print "<td width='$netWidth' align='center' class='boldbase'><b>$Lang::tr{'trafficred'}</b></td>"; | |
214 | } | |
215 | ||
10a04d70 MT |
216 | print <<END; |
217 | <td width='$netWidth' align='center' class='boldbase'><b>$Lang::tr{'trafficred'}</b></td> | |
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='#16A61D'><b>$Lang::tr{'trafficin'}</b></font></td> | |
224 | <td width='$inOutWidth' align='center' class='boldbase'><font color='#16A61D'><b>$Lang::tr{'trafficout'}</b></font></td> | |
225 | END | |
226 | ||
a08a5f33 | 227 | if ($netsettings{'CONFIG_TYPE'} =~ /^(3|4)$/) |
10a04d70 MT |
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 | ||
a08a5f33 | 233 | if ($netsettings{'CONFIG_TYPE'} =~ /^(2|4)$/) |
10a04d70 MT |
234 | { |
235 | print "<td width='$inOutWidth' align='center' class='boldbase'><font color='#FF9933'><b>$Lang::tr{'trafficin'}</b></font></td>"; | |
236 | print "<td width='$inOutWidth' align='center' class='boldbase'><font color='#FF9933'><b>$Lang::tr{'trafficout'}</b></font></td>"; | |
237 | } | |
a08a5f33 CS |
238 | if ($netsettings{'CONFIG_TYPE'} =~ /^(1|2|3|4)$/) |
239 | { | |
240 | print "<td width='$inOutWidth' align='center' class='boldbase'><font color='#CE1B31'><b>$Lang::tr{'trafficin'}</b></font></td>"; | |
241 | print "<td width='$inOutWidth' align='center' class='boldbase'><font color='#CE1B31'><b>$Lang::tr{'trafficout'}</b></font></td>"; | |
242 | } | |
243 | print"</tr>"; | |
10a04d70 MT |
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 | ||
a08a5f33 | 283 | if ($netsettings{'CONFIG_TYPE'} =~ /^(3|4)$/) |
10a04d70 MT |
284 | { |
285 | $total_blue_in += $allDaysBytes{$_}{${Traffic::blue_in}}; | |
286 | $total_blue_out += $allDaysBytes{$_}{${Traffic::blue_out}}; | |
287 | } | |
288 | ||
a08a5f33 | 289 | if ($netsettings{'CONFIG_TYPE'} =~ /^(2|4)$/) |
10a04d70 MT |
290 | { |
291 | $total_orange_in += $allDaysBytes{$_}{${Traffic::orange_in}}; | |
292 | $total_orange_out += $allDaysBytes{$_}{${Traffic::orange_out}}; | |
293 | } | |
a08a5f33 CS |
294 | |
295 | if ($netsettings{'CONFIG_TYPE'} =~ /^(1|2|3|4)$/) | |
296 | { | |
10a04d70 MT |
297 | $total_red_in += $allDaysBytes{$_}{${Traffic::red_in}}; |
298 | $total_red_out += $allDaysBytes{$_}{${Traffic::red_out}}; | |
a08a5f33 | 299 | } |
10a04d70 MT |
300 | |
301 | if ($lines % 2) { | |
a08a5f33 | 302 | print "<tr bgcolor='$color{'color20'}'>"; } |
10a04d70 | 303 | else { |
a08a5f33 | 304 | print "<tr bgcolor='$color{'color22'}'>"; } |
10a04d70 MT |
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 | ||
a08a5f33 CS |
310 | if ($netsettings{'CONFIG_TYPE'} =~ /^(3|4)$/) |
311 | { | |
10a04d70 MT |
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 | } | |
a08a5f33 | 315 | if ($netsettings{'CONFIG_TYPE'} =~ /^(2|4)$/) |
10a04d70 MT |
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 | } | |
a08a5f33 CS |
320 | if ($netsettings{'CONFIG_TYPE'} =~ /^(1|2|3|4)$/) |
321 | { | |
10a04d70 MT |
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); | |
a08a5f33 | 324 | } |
10a04d70 MT |
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 | ||
a08a5f33 CS |
337 | if ($lines % 2) {print "<tr bgcolor='$color{'color20'}'>"; } |
338 | else {print "<tr bgcolor='$color{'color22'}'>"; } | |
10a04d70 MT |
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 | ||
a08a5f33 | 346 | if ($netsettings{'CONFIG_TYPE'} =~ /^(3|4)$/) |
10a04d70 MT |
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 | ||
a08a5f33 | 352 | if ($netsettings{'CONFIG_TYPE'} =~ /^(2|4)$/) |
10a04d70 MT |
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 | } | |
a08a5f33 CS |
357 | if ($netsettings{'CONFIG_TYPE'} =~ /^(1|2|3|4)$/) |
358 | { | |
359 | print "<td align='center' class='boldbase' nowrap='nowrap'><b>$total_red_in MB</b></td>"; | |
360 | print "<td align='center' class='boldbase' nowrap='nowrap'><b>$total_red_out MB</b></td>"; | |
361 | } | |
10a04d70 | 362 | print <<END; |
10a04d70 MT |
363 | </tr> |
364 | </table> | |
365 | END | |
366 | ||
367 | &Header::closebox(); | |
368 | ||
369 | &Header::closebigbox(); | |
370 | ||
371 | &Header::closepage(); |