]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blame - html/cgi-bin/traffic.cgi
WOL Config Types angepasst, Nettraffic und Firewall Graphs Translations, Graph Direct...
[people/pmueller/ipfire-2.x.git] / html / cgi-bin / traffic.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
f2fdd0c1
CS
21my %color = ();
22my %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
26my %cgiparams;
27my %pppsettings;
28my %netsettings;
29
30&General::readhash("${General::swroot}/ppp/settings", \%pppsettings);
31&General::readhash("${General::swroot}/ethernet/settings", \%netsettings);
32
10a04d70
MT
33my ($s, $min, $h, $d, $m,$y) = localtime(time);
34$y+=1900;
35$m+=1;
36$m = $m < 10 ? $m = "0".$m : $m;
37
38$cgiparams{'MONTH'} = $m;
39&Header::getcgihash(\%cgiparams);
40$cgiparams{'YEAR'} = $y;
41&Header::getcgihash(\%cgiparams);
42
43&Header::showhttpheaders();
44
45my %selectYear;
10a04d70
MT
46$selectYear{'YEAR'}{'2007'} = '';
47$selectYear{'YEAR'}{'2008'} = '';
48$selectYear{'YEAR'}{'2009'} = '';
1be59789
MT
49$selectYear{'YEAR'}{'2010'} = '';
50$selectYear{'YEAR'}{'2011'} = '';
51$selectYear{'YEAR'}{'2012'} = '';
10a04d70
MT
52$selectYear{'YEAR'}{'????'} = '';
53$selectYear{'YEAR'}{$cgiparams{'YEAR'}} = 'selected=\'selected\'';
54
55
56my %selected;
57
58$selected{'MONTH'}{'01'} = '';
59$selected{'MONTH'}{'02'} = '';
60$selected{'MONTH'}{'03'} = '';
61$selected{'MONTH'}{'04'} = '';
62$selected{'MONTH'}{'05'} = '';
63$selected{'MONTH'}{'06'} = '';
64$selected{'MONTH'}{'07'} = '';
65$selected{'MONTH'}{'08'} = '';
66$selected{'MONTH'}{'09'} = '';
67$selected{'MONTH'}{'10'} = '';
68$selected{'MONTH'}{'11'} = '';
69$selected{'MONTH'}{'12'} = '';
70$selected{'MONTH'}{'??'} = '';
71$selected{'MONTH'}{$cgiparams{'MONTH'}} = 'selected=\'selected\'';
72
73&Header::openpage($Lang::tr{'sstraffic'}, 1, '');
74
75&Header::openbigbox('100%', 'left');
76
77&Header::openbox('100%', 'left', $Lang::tr{'settingsc'});
78
79print <<END;
80 <table width='80%' align='center'>
81 <tr>
82 <td width='95%' align='left' nowrap='nowrap'>
83 <form method='post' action='/cgi-bin/traffic.cgi'>
84 $Lang::tr{'selecttraffic'}
85 <select name='MONTH'>
86 <option $selected{'MONTH'}{'01'} value='01'>$Lang::tr{'january'}</option>
87 <option $selected{'MONTH'}{'02'} value='02'>$Lang::tr{'february'}</option>
88 <option $selected{'MONTH'}{'03'} value='03'>$Lang::tr{'march'}</option>
89 <option $selected{'MONTH'}{'04'} value='04'>$Lang::tr{'april'}</option>
90 <option $selected{'MONTH'}{'05'} value='05'>$Lang::tr{'may'}</option>
91 <option $selected{'MONTH'}{'06'} value='06'>$Lang::tr{'june'}</option>
92 <option $selected{'MONTH'}{'07'} value='07'>$Lang::tr{'july'}</option>
93 <option $selected{'MONTH'}{'08'} value='08'>$Lang::tr{'august'}</option>
94 <option $selected{'MONTH'}{'09'} value='09'>$Lang::tr{'september'}</option>
95 <option $selected{'MONTH'}{'10'} value='10'>$Lang::tr{'october'}</option>
96 <option $selected{'MONTH'}{'11'} value='11'>$Lang::tr{'november'}</option>
97 <option $selected{'MONTH'}{'12'} value='12'>$Lang::tr{'december'}</option>
98 <option $selected{'MONTH'}{'??'} value='??'>$Lang::tr{'allmsg'}</option>
99 </select>
100 <select name='YEAR'>
1be59789
MT
101 <option $selectYear{'YEAR'}{'2007'} value='2007'>2007</option>
102 <option $selectYear{'YEAR'}{'2008'} value='2008'>2008</option>
103 <option $selectYear{'YEAR'}{'2009'} value='2009'>2009</option>
104 <option $selectYear{'YEAR'}{'2010'} value='2010'>2010</option>
105 <option $selectYear{'YEAR'}{'2011'} value='2011'>2011</option>
106 <option $selectYear{'YEAR'}{'2012'} value='2012'>2012</option>
10a04d70
MT
107 <option $selectYear{'YEAR'}{'????'} value='????'>$Lang::tr{'allmsg'}</option>
108 </select>
109 <input type='submit' name='ACTION' value='$Lang::tr{'update'}' />
110 </form>
111 </td>
112 <td width='5%' align='center'>
113 <form method='post' action='/cgi-bin/traffics.cgi'>
114 <input type='submit' name='ACTION' value=' > ' />
115 </form>
116 </td>
117 </tr>
118 </table>
119END
120
121&Header::closebox();
122
123&Header::openbox('100%', 'left', $Lang::tr{'traffics'});
124
125my $dateWidth = '20%';
126my $netWidth = '34%';
127my $inOutWidth = '17%';
128
129# 4 networks
b05768be 130if ($netsettings{'CONFIG_TYPE'} =~ /^(4)$/) {
10a04d70
MT
131 $dateWidth = '12%';
132 $netWidth = '22%';
133 $inOutWidth = '11%';
134}
135# 3 networks
b05768be 136if ($netsettings{'CONFIG_TYPE'} =~ /^(2|3)$/) {
10a04d70
MT
137 $dateWidth = '16%';
138 $netWidth = '28%';
139 $inOutWidth = '14%';
140}
141
142print <<END;
143 <table width='100%'>
144 <tr>
145 <td width='$dateWidth' align='center' class='boldbase'></td>
146 <td width='$netWidth' align='center' class='boldbase' ><b>$Lang::tr{'trafficgreen'}</b></td>
147END
148
b05768be 149if ($netsettings{'CONFIG_TYPE'} =~ /^(3|4)$/) {
10a04d70
MT
150 print "<td width='$netWidth' align='center' class='boldbase' ><b>$Lang::tr{'trafficblue'}</b></td>";
151}
152
b05768be 153if ($netsettings{'CONFIG_TYPE'} =~ /^(2|4)$/) {
10a04d70
MT
154 print "<td width='$netWidth' align='center' class='boldbase' ><b>$Lang::tr{'trafficorange'}</b></td>";
155}
156
b05768be
CS
157if ($netsettings{'CONFIG_TYPE'} =~ /^(1|2|3|4)$/) {
158 print "<td width='$netWidth' align='center' class='boldbase'><b>$Lang::tr{'trafficred'}</b></td>";
159 }
10a04d70 160print <<END;
10a04d70
MT
161 </tr>
162 </table>
163 <table width='100%'>
164 <tr>
165 <td width='$dateWidth' align='center' class='boldbase'><b>$Lang::tr{'trafficdate'}</b></td>
166 <td width='$inOutWidth' align='center' class='boldbase'><font color='#16A61D'><b>$Lang::tr{'trafficin'}</b></font></td>
167 <td width='$inOutWidth' align='center' class='boldbase'><font color='#16A61D'><b>$Lang::tr{'trafficout'}</b></font></td>
168END
169
b05768be 170if ($netsettings{'CONFIG_TYPE'} =~ /^(3|4)$/)
10a04d70
MT
171{
172 print "<td width='$inOutWidth' align='center' class='boldbase'><font color='${Header::colourblue}'><b>$Lang::tr{'trafficin'}</b></font></td>";
173 print "<td width='$inOutWidth' align='center' class='boldbase'><font color='${Header::colourblue}'><b>$Lang::tr{'trafficout'}</b></font></td>";
174}
175
b05768be 176if ($netsettings{'CONFIG_TYPE'} =~ /^(2|4)$/)
10a04d70
MT
177{
178 print "<td width='$inOutWidth' align='center' class='boldbase'><font color='#FF9933'><b>$Lang::tr{'trafficin'}</b></font></td>";
179 print "<td width='$inOutWidth' align='center' class='boldbase'><font color='#FF9933'><b>$Lang::tr{'trafficout'}</b></font></td>";
180}
b05768be
CS
181if ($netsettings{'CONFIG_TYPE'} =~ /^(1|2|3|4)$/)
182{
183 print "<td width='$inOutWidth' align='center' class='boldbase'><font color='#CE1B31'><b>$Lang::tr{'trafficin'}</b></font></td>";
184 print "<td width='$inOutWidth' align='center' class='boldbase'><font color='#CE1B31'><b>$Lang::tr{'trafficout'}</b></font></td>";
185}
186 print"</tr>";
10a04d70
MT
187
188my $total_blue_in=0;
189my $total_blue_out=0;
190my $total_green_in=0;
191my $total_green_out=0;
192my $total_orange_in=0;
193my $total_orange_out=0;
194my $total_red_in=0;
195my $total_red_out=0;
196my $lines=0;
197
198my $displayMode = "daily";
199my $startMonth = $cgiparams{'MONTH'};
200my $endMonth = $cgiparams{'MONTH'};
201
202if ($cgiparams{'MONTH'} eq '??') {
203 $displayMode = "monthly";
204 $startMonth = '01';
205 $endMonth = '12';
206}
207
208my $start = "$cgiparams{'YEAR'}$startMonth"."01";
209my $end = "$cgiparams{'YEAR'}$endMonth"."32";
210my %allDaysBytes = ();
211my @allDays = &Traffic::calcTraffic(\%allDaysBytes,$start,$end, $displayMode);
212
213
214foreach (@allDays) {
215 $total_green_in += $allDaysBytes{$_}{${Traffic::green_in}};
216 $total_green_out += $allDaysBytes{$_}{${Traffic::green_out}};
217
b05768be 218 if ($netsettings{'CONFIG_TYPE'} =~ /^(3|4)$/)
10a04d70
MT
219 {
220 $total_blue_in += $allDaysBytes{$_}{${Traffic::blue_in}};
221 $total_blue_out += $allDaysBytes{$_}{${Traffic::blue_out}};
222 }
223
b05768be 224 if ($netsettings{'CONFIG_TYPE'} =~ /^(2|4)$/)
10a04d70
MT
225 {
226 $total_orange_in += $allDaysBytes{$_}{${Traffic::orange_in}};
227 $total_orange_out += $allDaysBytes{$_}{${Traffic::orange_out}};
228 }
b05768be
CS
229
230 if ($netsettings{'CONFIG_TYPE'} =~ /^(1|2|3|4)$/)
231 {
10a04d70
MT
232 $total_red_in += $allDaysBytes{$_}{${Traffic::red_in}};
233 $total_red_out += $allDaysBytes{$_}{${Traffic::red_out}};
b05768be
CS
234 }
235
10a04d70 236 if ($lines % 2) {
f2fdd0c1 237 print "<tr bgcolor='$color{'color20'}'>"; }
10a04d70 238 else {
f2fdd0c1 239 print "<tr bgcolor='$color{'color22'}'>"; }
10a04d70
MT
240
241 printf "<td align='center' nowrap='nowrap'>%s</td>\n", $allDaysBytes{$_}{'Day'};
242 printf "<td align='center' nowrap='nowrap'>%.3f</td>\n", ($allDaysBytes{$_}{${Traffic::green_in}}/1048576);
243 printf "<td align='center' nowrap='nowrap'>%.3f</td>\n", ($allDaysBytes{$_}{${Traffic::green_out}}/1048576);
244
b05768be 245 if ($netsettings{'CONFIG_TYPE'} =~ /^(3|4)$/)
10a04d70
MT
246 {
247 printf "<td align='center' nowrap='nowrap'>%.3f</td>\n", ($allDaysBytes{$_}{${Traffic::blue_in}}/1048576);
248 printf "<td align='center' nowrap='nowrap'>%.3f</td>\n", ($allDaysBytes{$_}{${Traffic::blue_out}}/1048576);
249 }
b05768be 250 if ($netsettings{'CONFIG_TYPE'} =~ /^(2|4)$/)
10a04d70
MT
251 {
252 printf "<td align='center' nowrap='nowrap'>%.3f</td>\n", ($allDaysBytes{$_}{${Traffic::orange_in}}/1048576);
253 printf "<td align='center' nowrap='nowrap'>%.3f</td>\n", ($allDaysBytes{$_}{${Traffic::orange_out}}/1048576);
254 }
b05768be
CS
255 if ($netsettings{'CONFIG_TYPE'} =~ /^(1|2|3|4)$/)
256 {
10a04d70
MT
257 printf "<td align='center' nowrap='nowrap'>%.3f</td>\n", ($allDaysBytes{$_}{${Traffic::red_in}}/1048576);
258 printf "<td align='center' nowrap='nowrap'>%.3f</td></tr>\n", ($allDaysBytes{$_}{${Traffic::red_out}}/1048576);
b05768be 259 }
10a04d70
MT
260 $lines++;
261}
262
263$total_green_in=sprintf("%.2f", ($total_green_in/1048576));
264$total_green_out=sprintf("%.2f", ($total_green_out/1048576));
265$total_blue_in=sprintf("%.2f", ($total_blue_in/1048576));
266$total_blue_out=sprintf("%.2f", ($total_blue_out/1048576));
267$total_orange_in=sprintf("%.2f", ($total_orange_in/1048576));
268$total_orange_out=sprintf("%.2f", ($total_orange_out/1048576));
269$total_red_in=sprintf("%.2f", ($total_red_in/1048576));
270$total_red_out=sprintf("%.2f", ($total_red_out/1048576));
271
f2fdd0c1
CS
272if ($lines % 2) {print "<tr bgcolor='$color{'color20'}'>"; }
273else {print "<tr bgcolor='$color{'color22'}'>"; }
10a04d70
MT
274
275print <<END;
276 <td align='center' class='boldbase' height='20' nowrap='nowrap'><b>$Lang::tr{'trafficsum'}</b></td>
277 <td align='center' class='boldbase' nowrap='nowrap'><b>$total_green_in MB</b></td>
278 <td align='center' class='boldbase' nowrap='nowrap'><b>$total_green_out MB</b></td>
279END
280
b05768be 281if ($netsettings{'CONFIG_TYPE'} =~ /^(3|4)$/)
10a04d70
MT
282{
283 print "<td align='center' class='boldbase' nowrap='nowrap'><b>$total_blue_in MB</b></td>";
284 print "<td align='center' class='boldbase' nowrap='nowrap'><b>$total_blue_out MB</b></td>";
285}
286
b05768be 287if ($netsettings{'CONFIG_TYPE'} =~ /^(2|4)$/)
10a04d70
MT
288{
289 print "<td align='center' class='boldbase' nowrap='nowrap'><b>$total_orange_in MB</b></td>";
290 print "<td align='center' class='boldbase' nowrap='nowrap'><b>$total_orange_out MB</b></td>";
291}
b05768be
CS
292if ($netsettings{'CONFIG_TYPE'} =~ /^(1|2|3|4)$/)
293{
294 print "<td align='center' class='boldbase' nowrap='nowrap'><b>$total_red_in MB</b></td>";
295 print "<td align='center' class='boldbase' nowrap='nowrap'><b>$total_red_out MB</b></td>";
296}
10a04d70 297print <<END;
10a04d70
MT
298 </tr>
299 </table>
300END
301
302&Header::closebox();
303
304&Header::closebigbox();
305
306&Header::closepage();