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