]>
Commit | Line | Data |
---|---|---|
10a04d70 | 1 | #!/usr/bin/perl |
70df8302 MT |
2 | ############################################################################### |
3 | # # | |
4 | # IPFire.org - A linux based firewall # | |
5 | # Copyright (C) 2007 Michael Tremer & Christian Schmidt # | |
6 | # # | |
7 | # This program is free software: you can redistribute it and/or modify # | |
8 | # it under the terms of the GNU General Public License as published by # | |
9 | # the Free Software Foundation, either version 3 of the License, or # | |
10 | # (at your option) any later version. # | |
11 | # # | |
12 | # This program is distributed in the hope that it will be useful, # | |
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # | |
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # | |
15 | # GNU General Public License for more details. # | |
16 | # # | |
17 | # You should have received a copy of the GNU General Public License # | |
18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. # | |
19 | # # | |
20 | ############################################################################### | |
10a04d70 MT |
21 | |
22 | use strict; | |
23 | ||
24 | # enable only the following on debugging purpose | |
cb5e9c6c CS |
25 | #use warnings; |
26 | #use CGI::Carp 'fatalsToBrowser'; | |
10a04d70 MT |
27 | |
28 | require '/var/ipfire/general-functions.pl'; | |
29 | require "${General::swroot}/lang.pl"; | |
30 | require "${General::swroot}/header.pl"; | |
d81292e0 CS |
31 | require "${General::swroot}/net-traffic/net-traffic-admin.pl"; |
32 | require "${General::swroot}/net-traffic/net-traffic-lib.pl"; | |
10a04d70 | 33 | |
a08a5f33 CS |
34 | my %color = (); |
35 | my %mainsettings = (); | |
36 | &General::readhash("${General::swroot}/main/settings", \%mainsettings); | |
37 | &General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color); | |
38 | ||
d81292e0 | 39 | my %cgiparams; |
10a04d70 MT |
40 | my %netsettings; |
41 | ||
42 | &General::readhash("${General::swroot}/ethernet/settings", \%netsettings); | |
43 | ||
10a04d70 MT |
44 | 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 ); |
45 | ||
d81292e0 | 46 | my @now = localtime(time); |
10a04d70 MT |
47 | |
48 | $now[5] = $now[5]+1900; | |
49 | ||
d81292e0 CS |
50 | $cgiparams{'STARTDAY'} = 10; |
51 | $cgiparams{'STOPDAY'} = 11; | |
52 | $cgiparams{'STARTYEAR'} = $now[5]; | |
53 | $cgiparams{'STOPYEAR'} = $now[5]; | |
54 | ||
55 | if($NETTRAFF::settings{'MONTHLY_VOLUME_ON'} eq 'on') | |
56 | { | |
57 | $cgiparams{'STARTDAY'} = $NETTRAFF::settings{'STARTDAY'}; | |
58 | $cgiparams{'STOPDAY'} = $NETTRAFF::settings{'STARTDAY'}; | |
59 | } | |
10a04d70 MT |
60 | |
61 | # this periode started last month | |
d81292e0 | 62 | if ($now[3] < $cgiparams{'STARTDAY'}) { |
10a04d70 MT |
63 | $cgiparams{'STARTMONTH'} = $now[4]-1; |
64 | $cgiparams{'STOPMONTH'} = $now[4]; | |
65 | # when current month is january we start in last year december | |
d81292e0 | 66 | if ($cgiparams{'STOPMONTH'} == 0) { |
10a04d70 | 67 | $cgiparams{'STARTYEAR'} = $now[5]-1; |
d81292e0 | 68 | $cgiparams{'STARTMONTH'} = 11; |
10a04d70 MT |
69 | } |
70 | } | |
71 | else { | |
72 | $cgiparams{'STARTMONTH'} = $now[4]; | |
73 | $cgiparams{'STOPMONTH'} = $now[4]+1; | |
d81292e0 CS |
74 | # when we are in december, this periode ends next year january |
75 | if ($cgiparams{'STARTMONTH'} == 11) { | |
76 | $cgiparams{'STOPYEAR'} = $now[5]+1; | |
10a04d70 MT |
77 | $cgiparams{'STOPMONTH'} = 0; |
78 | } | |
79 | } | |
10a04d70 | 80 | |
d81292e0 | 81 | &Header::getcgihash(\%cgiparams); |
10a04d70 | 82 | &Header::showhttpheaders(); |
10a04d70 | 83 | &Header::openpage($Lang::tr{'sstraffic'}, 1, ''); |
10a04d70 | 84 | &Header::openbigbox('100%', 'left'); |
d81292e0 | 85 | &Header::openbox('100%', 'left', ""); |
10a04d70 MT |
86 | |
87 | print <<END; | |
88 | <table width='100%' align='center'> | |
89 | <tr> | |
d81292e0 | 90 | <td width='90%' class='base' align='center'> |
10a04d70 MT |
91 | <form method='post' action='/cgi-bin/traffics.cgi'> |
92 | $Lang::tr{'trafficfrom'} | |
93 | <select name='STARTDAY'> | |
94 | END | |
95 | ||
d81292e0 | 96 | foreach my $day (@days) |
10a04d70 MT |
97 | { |
98 | print "\t<option "; | |
d81292e0 | 99 | if ($day == $cgiparams{'STARTDAY'}) { |
10a04d70 | 100 | print 'selected=\'selected\' '; } |
d81292e0 | 101 | print "value='$day'>$day</option>\n"; |
10a04d70 MT |
102 | } |
103 | print <<END; | |
104 | </select> | |
105 | <select name='STARTMONTH'> | |
106 | END | |
107 | ||
d81292e0 | 108 | foreach my $month (@NETTRAFF::months) |
10a04d70 MT |
109 | { |
110 | print "\t<option "; | |
d81292e0 | 111 | if ($month == $cgiparams{'STARTMONTH'}) { |
10a04d70 | 112 | print 'selected=\'selected\' '; } |
d81292e0 | 113 | print "value='$month'>$NETTRAFF::longmonths[$month]</option>\n"; |
10a04d70 MT |
114 | } |
115 | ||
116 | print <<END; | |
117 | </select> | |
118 | <select name='STARTYEAR'> | |
119 | END | |
120 | ||
d81292e0 | 121 | foreach my $year (@NETTRAFF::years) { |
10a04d70 | 122 | print "\t<option "; |
d81292e0 | 123 | if ($year == $cgiparams{'STARTYEAR'}) { |
10a04d70 | 124 | print 'selected=\'selected\' '; } |
d81292e0 | 125 | print "value='$year'>$year</option>\n"; |
10a04d70 MT |
126 | } |
127 | ||
128 | print <<END; | |
129 | </select> | |
130 | $Lang::tr{'trafficto'} | |
131 | <select name='STOPDAY'> | |
132 | END | |
133 | ||
d81292e0 | 134 | foreach my $day (@days) |
10a04d70 MT |
135 | { |
136 | print "\t<option "; | |
d81292e0 | 137 | if ($day == $cgiparams{'STOPDAY'}) |
10a04d70 MT |
138 | { |
139 | print 'selected=\'selected\' '; } | |
d81292e0 | 140 | print "value='$day'>$day</option>\n"; |
10a04d70 MT |
141 | } |
142 | ||
143 | print <<END; | |
144 | </select> | |
145 | <select name='STOPMONTH'> | |
146 | END | |
147 | ||
d81292e0 | 148 | foreach my $month (@NETTRAFF::months) |
10a04d70 MT |
149 | { |
150 | print "\t<option "; | |
d81292e0 | 151 | if ($month == $cgiparams{'STOPMONTH'}) { |
10a04d70 | 152 | print 'selected=\'selected\' '; } |
d81292e0 | 153 | print "value='$month'>$NETTRAFF::longmonths[$month]</option>\n"; |
10a04d70 MT |
154 | } |
155 | ||
156 | print <<END; | |
157 | </select> | |
158 | <select name='STOPYEAR'> | |
159 | END | |
160 | ||
d81292e0 | 161 | foreach my $year (@NETTRAFF::years) { |
10a04d70 | 162 | print "\t<option "; |
d81292e0 | 163 | if ($year == $cgiparams{'STOPYEAR'}) { |
10a04d70 | 164 | print 'selected=\'selected\' '; } |
d81292e0 | 165 | print "value='$year'>$year</option>\n"; |
10a04d70 MT |
166 | } |
167 | ||
168 | ||
169 | print <<END; | |
170 | </select> | |
171 | <input type='submit' name='ACTION' value='$Lang::tr{'update'}' /> | |
d81292e0 CS |
172 | </form> |
173 | </td> | |
10a04d70 MT |
174 | <td width='5%' align='center'> |
175 | <form method='post' action='/cgi-bin/traffic.cgi'> | |
176 | <input type='submit' name='ACTION' value=' > ' /> | |
177 | </form> | |
d81292e0 | 178 | </td> |
10a04d70 MT |
179 | </tr> |
180 | </table> | |
181 | END | |
182 | ||
183 | &Header::closebox(); | |
184 | ||
d81292e0 | 185 | &Header::openbox('100%', 'left', "$Lang::tr{'traffics'}"); |
10a04d70 MT |
186 | |
187 | my $dateWidth = '20%'; | |
188 | my $netWidth = '34%'; | |
189 | my $inOutWidth = '17%'; | |
190 | ||
191 | # 4 networks | |
a08a5f33 | 192 | if ($netsettings{'CONFIG_TYPE'} =~ /^(4)$/) { |
10a04d70 MT |
193 | $dateWidth = '12%'; |
194 | $netWidth = '22%'; | |
195 | $inOutWidth = '11%'; | |
196 | } | |
197 | # 3 networks | |
a08a5f33 | 198 | if ($netsettings{'CONFIG_TYPE'} =~ /^(2|3)$/) { |
10a04d70 MT |
199 | $dateWidth = '16%'; |
200 | $netWidth = '28%'; | |
201 | $inOutWidth = '14%'; | |
202 | } | |
203 | ||
204 | print <<END; | |
205 | <table width='100%'> | |
206 | <tr> | |
207 | <td width='$dateWidth' align='center' class='boldbase'></td> | |
208 | <td width='$netWidth' align='center' class='boldbase' ><b>$Lang::tr{'trafficgreen'}</b></td> | |
209 | END | |
210 | ||
a08a5f33 | 211 | if ($netsettings{'CONFIG_TYPE'} =~ /^(3|4)$/) { |
10a04d70 MT |
212 | print "<td width='$netWidth' align='center' class='boldbase' ><b>$Lang::tr{'trafficblue'}</b></td>"; |
213 | } | |
214 | ||
a08a5f33 | 215 | if ($netsettings{'CONFIG_TYPE'} =~ /^(2|4)$/) { |
10a04d70 MT |
216 | print "<td width='$netWidth' align='center' class='boldbase' ><b>$Lang::tr{'trafficorange'}</b></td>"; |
217 | } | |
218 | ||
d81292e0 CS |
219 | if ($netsettings{'CONFIG_TYPE'} =~ /^(1|2|3|4)$/) |
220 | { | |
221 | print "<td width='$netWidth' align='center' class='boldbase'><b>$Lang::tr{'trafficred'}</b></td>"; | |
222 | } | |
10a04d70 | 223 | print <<END; |
10a04d70 MT |
224 | </tr> |
225 | </table> | |
226 | <table width='100%'> | |
227 | <tr> | |
228 | <td width='$dateWidth' align='center' class='boldbase'><b>$Lang::tr{'trafficdate'}</b></td> | |
d81292e0 CS |
229 | <td width='$inOutWidth' align='center' class='boldbase'><font color='$Header::colourgreen'><b>$Lang::tr{'trafficin'}</b></font></td> |
230 | <td width='$inOutWidth' align='center' class='boldbase'><font color='$Header::colourgreen'><b>$Lang::tr{'trafficout'}</b></font></td> | |
10a04d70 MT |
231 | END |
232 | ||
a08a5f33 | 233 | if ($netsettings{'CONFIG_TYPE'} =~ /^(3|4)$/) |
d81292e0 | 234 | { |
10a04d70 MT |
235 | print "<td width='$inOutWidth' align='center' class='boldbase'><font color='${Header::colourblue}'><b>$Lang::tr{'trafficin'}</b></font></td>"; |
236 | print "<td width='$inOutWidth' align='center' class='boldbase'><font color='${Header::colourblue}'><b>$Lang::tr{'trafficout'}</b></font></td>"; | |
d81292e0 | 237 | } |
10a04d70 | 238 | |
a08a5f33 | 239 | if ($netsettings{'CONFIG_TYPE'} =~ /^(2|4)$/) |
d81292e0 CS |
240 | { |
241 | print "<td width='$inOutWidth' align='center' class='boldbase'><font color='$Header::colourorange'><b>$Lang::tr{'trafficin'}</b></font></td>"; | |
242 | print "<td width='$inOutWidth' align='center' class='boldbase'><font color='$Header::colourorange'><b>$Lang::tr{'trafficout'}</b></font></td>"; | |
243 | } | |
a08a5f33 | 244 | if ($netsettings{'CONFIG_TYPE'} =~ /^(1|2|3|4)$/) |
d81292e0 CS |
245 | { |
246 | print "<td width='$inOutWidth' align='center' class='boldbase'><font color='$Header::colourred'><b>$Lang::tr{'trafficin'}</b></font></td>"; | |
247 | print "<td width='$inOutWidth' align='center' class='boldbase'><font color='$Header::colourred'><b>$Lang::tr{'trafficout'}</b></font></td>"; | |
a08a5f33 | 248 | } |
d81292e0 | 249 | print "</tr>"; |
10a04d70 MT |
250 | |
251 | my $total_blue_in=0; | |
252 | my $total_blue_out=0; | |
253 | my $total_green_in=0; | |
254 | my $total_green_out=0; | |
255 | my $total_orange_in=0; | |
256 | my $total_orange_out=0; | |
257 | my $total_red_in=0; | |
258 | my $total_red_out=0; | |
259 | my $lines=0; | |
260 | ||
261 | ||
262 | my $startyear = $cgiparams{'STARTYEAR'}; | |
263 | my $stopyear = $cgiparams{'STOPYEAR'}; | |
264 | ||
265 | my $startMonth = $cgiparams{'STARTMONTH'}+1; | |
266 | $startMonth = $startMonth < 10 ? $startMonth = "0".$startMonth : $startMonth; | |
267 | ||
268 | my $endMonth = $cgiparams{'STOPMONTH'}+1; | |
269 | $endMonth = $endMonth < 10 ? $endMonth = "0".$endMonth : $endMonth; | |
270 | ||
271 | my $startDay = $cgiparams{'STARTDAY'}; | |
272 | $startDay = $startDay < 10 ? $startDay = "0".$startDay : $startDay; | |
273 | ||
274 | my $endDay = $cgiparams{'STOPDAY'}+1; | |
275 | $endDay = $endDay < 10 ? $endDay = "0".$endDay : $endDay; | |
276 | ||
277 | my $displayMode = "daily_multi"; | |
278 | my $start = $startyear.$startMonth.$startDay; | |
279 | my $end = $stopyear.$endMonth.$endDay; | |
280 | ||
281 | my %allDaysBytes = (); | |
282 | my @allDays = &Traffic::calcTraffic(\%allDaysBytes,$start,$end, $displayMode); | |
283 | ||
284 | ||
285 | foreach (@allDays) { | |
286 | $total_green_in += $allDaysBytes{$_}{${Traffic::green_in}}; | |
287 | $total_green_out += $allDaysBytes{$_}{${Traffic::green_out}}; | |
d81292e0 | 288 | |
a08a5f33 | 289 | if ($netsettings{'CONFIG_TYPE'} =~ /^(3|4)$/) |
10a04d70 MT |
290 | { |
291 | $total_blue_in += $allDaysBytes{$_}{${Traffic::blue_in}}; | |
292 | $total_blue_out += $allDaysBytes{$_}{${Traffic::blue_out}}; | |
293 | } | |
d81292e0 | 294 | |
a08a5f33 | 295 | if ($netsettings{'CONFIG_TYPE'} =~ /^(2|4)$/) |
10a04d70 MT |
296 | { |
297 | $total_orange_in += $allDaysBytes{$_}{${Traffic::orange_in}}; | |
298 | $total_orange_out += $allDaysBytes{$_}{${Traffic::orange_out}}; | |
299 | } | |
d81292e0 | 300 | |
a08a5f33 CS |
301 | if ($netsettings{'CONFIG_TYPE'} =~ /^(1|2|3|4)$/) |
302 | { | |
10a04d70 MT |
303 | $total_red_in += $allDaysBytes{$_}{${Traffic::red_in}}; |
304 | $total_red_out += $allDaysBytes{$_}{${Traffic::red_out}}; | |
a08a5f33 | 305 | } |
d81292e0 | 306 | |
10a04d70 | 307 | if ($lines % 2) { |
a08a5f33 | 308 | print "<tr bgcolor='$color{'color20'}'>"; } |
10a04d70 | 309 | else { |
a08a5f33 | 310 | print "<tr bgcolor='$color{'color22'}'>"; } |
d81292e0 | 311 | |
10a04d70 MT |
312 | printf "<td align='center' nowrap='nowrap'>%s</td>\n", $allDaysBytes{$_}{'Day'}; |
313 | printf "<td align='center' nowrap='nowrap'>%.3f</td>\n", ($allDaysBytes{$_}{${Traffic::green_in}}/1048576); | |
314 | printf "<td align='center' nowrap='nowrap'>%.3f</td>\n", ($allDaysBytes{$_}{${Traffic::green_out}}/1048576); | |
d81292e0 | 315 | |
a08a5f33 | 316 | if ($netsettings{'CONFIG_TYPE'} =~ /^(3|4)$/) |
d81292e0 | 317 | { |
10a04d70 MT |
318 | printf "<td align='center' nowrap='nowrap'>%.3f</td>\n", ($allDaysBytes{$_}{${Traffic::blue_in}}/1048576); |
319 | printf "<td align='center' nowrap='nowrap'>%.3f</td>\n", ($allDaysBytes{$_}{${Traffic::blue_out}}/1048576); | |
d81292e0 | 320 | } |
a08a5f33 | 321 | if ($netsettings{'CONFIG_TYPE'} =~ /^(2|4)$/) |
d81292e0 | 322 | { |
10a04d70 MT |
323 | printf "<td align='center' nowrap='nowrap'>%.3f</td>\n", ($allDaysBytes{$_}{${Traffic::orange_in}}/1048576); |
324 | printf "<td align='center' nowrap='nowrap'>%.3f</td>\n", ($allDaysBytes{$_}{${Traffic::orange_out}}/1048576); | |
d81292e0 CS |
325 | } |
326 | if ($netsettings{'CONFIG_TYPE'} =~ /^(1|2|3|4)$/) | |
a08a5f33 | 327 | { |
10a04d70 MT |
328 | printf "<td align='center' nowrap='nowrap'>%.3f</td>\n", ($allDaysBytes{$_}{${Traffic::red_in}}/1048576); |
329 | printf "<td align='center' nowrap='nowrap'>%.3f</td></tr>\n", ($allDaysBytes{$_}{${Traffic::red_out}}/1048576); | |
d81292e0 | 330 | } |
10a04d70 MT |
331 | $lines++; |
332 | } | |
333 | ||
334 | $total_green_in=sprintf("%.2f", ($total_green_in/1048576)); | |
335 | $total_green_out=sprintf("%.2f", ($total_green_out/1048576)); | |
336 | $total_blue_in=sprintf("%.2f", ($total_blue_in/1048576)); | |
337 | $total_blue_out=sprintf("%.2f", ($total_blue_out/1048576)); | |
338 | $total_orange_in=sprintf("%.2f", ($total_orange_in/1048576)); | |
d81292e0 | 339 | $total_orange_out=sprintf("%.2f", ($total_orange_out/1048576)); |
10a04d70 MT |
340 | $total_red_in=sprintf("%.2f", ($total_red_in/1048576)); |
341 | $total_red_out=sprintf("%.2f", ($total_red_out/1048576)); | |
d81292e0 | 342 | |
c85ec3b4 | 343 | if ($lines % 2) {print "<tr bgcolor='$color{'color20'}'>"; } |
a08a5f33 | 344 | else {print "<tr bgcolor='$color{'color22'}'>"; } |
d81292e0 | 345 | |
10a04d70 MT |
346 | print <<END; |
347 | <td align='center' class='boldbase' height='20' nowrap='nowrap'><b>$Lang::tr{'trafficsum'}</b></td> | |
348 | <td align='center' class='boldbase' nowrap='nowrap'><b>$total_green_in MB</b></td> | |
349 | <td align='center' class='boldbase' nowrap='nowrap'><b>$total_green_out MB</b></td> | |
350 | END | |
d81292e0 | 351 | |
a08a5f33 | 352 | if ($netsettings{'CONFIG_TYPE'} =~ /^(3|4)$/) |
d81292e0 | 353 | { |
10a04d70 MT |
354 | print "<td align='center' class='boldbase' nowrap='nowrap'><b>$total_blue_in MB</b></td>"; |
355 | print "<td align='center' class='boldbase' nowrap='nowrap'><b>$total_blue_out MB</b></td>"; | |
356 | } | |
357 | ||
a08a5f33 | 358 | if ($netsettings{'CONFIG_TYPE'} =~ /^(2|4)$/) |
d81292e0 | 359 | { |
10a04d70 MT |
360 | print "<td align='center' class='boldbase' nowrap='nowrap'><b>$total_orange_in MB</b></td>"; |
361 | print "<td align='center' class='boldbase' nowrap='nowrap'><b>$total_orange_out MB</b></td>"; | |
362 | } | |
d81292e0 | 363 | |
a08a5f33 CS |
364 | if ($netsettings{'CONFIG_TYPE'} =~ /^(1|2|3|4)$/) |
365 | { | |
d81292e0 CS |
366 | print "<td align='center' class='boldbase' nowrap='nowrap'><b>$total_red_in MB</b></td>"; |
367 | print "<td align='center' class='boldbase' nowrap='nowrap'><b>$total_red_out MB</b></td>"; | |
368 | } | |
369 | print "</tr></table>"; | |
10a04d70 MT |
370 | |
371 | &Header::closebox(); | |
10a04d70 | 372 | &Header::closebigbox(); |
10a04d70 | 373 | &Header::closepage(); |