]>
git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - html/cgi-bin/traffic.cgi
5 # This code is distributed under the terms of the GPL
7 # (c) The SmoothWall Team
12 # enable only the following on debugging purpose
14 use CGI
::Carp
'fatalsToBrowser';
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';
25 &General
::readhash
("${General::swroot}/ppp/settings", \
%pppsettings);
26 &General
::readhash
("${General::swroot}/ethernet/settings", \
%netsettings);
28 my @wday = ($Lang::tr
{'wday1'}, $Lang::tr
{'wday2'}, $Lang::tr
{'wday3'}, $Lang::tr
{'wday4'}, $Lang::tr
{'wday5'}, $Lang::tr
{'wday6'}, $Lang::tr
{'wday7'});
30 my ($s, $min, $h, $d, $m,$y) = localtime(time);
33 $m = $m < 10 ?
$m = "0".$m : $m;
35 $cgiparams{'MONTH'} = $m;
36 &Header
::getcgihash
(\
%cgiparams);
37 $cgiparams{'YEAR'} = $y;
38 &Header
::getcgihash
(\
%cgiparams);
40 &Header
::showhttpheaders
();
43 $selectYear{'YEAR'}{'2001'} = '';
44 $selectYear{'YEAR'}{'2002'} = '';
45 $selectYear{'YEAR'}{'2003'} = '';
46 $selectYear{'YEAR'}{'2004'} = '';
47 $selectYear{'YEAR'}{'2005'} = '';
48 $selectYear{'YEAR'}{'2006'} = '';
49 $selectYear{'YEAR'}{'2007'} = '';
50 $selectYear{'YEAR'}{'2008'} = '';
51 $selectYear{'YEAR'}{'2009'} = '';
52 $selectYear{'YEAR'}{'????'} = '';
53 $selectYear{'YEAR'}{$cgiparams{'YEAR'}} = 'selected=\'selected\'';
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\'';
73 &Header
::openpage
($Lang::tr
{'sstraffic'}, 1, '');
75 &Header
::openbigbox
('100%', 'left');
77 &Header
::openbox
('100%', 'left', $Lang::tr
{'settingsc'});
80 <table width='80%' align='center'>
82 <td width='95%' align='left' nowrap='nowrap'>
83 <form method='post' action='/cgi-bin/traffic.cgi'>
84 $Lang::tr{'selecttraffic'}
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>
101 <option $selectYear{'YEAR'}{'2001'} value='2001'>2001</option>
102 <option $selectYear{'YEAR'}{'2002'} value='2002'>2002</option>
103 <option $selectYear{'YEAR'}{'2003'} value='2003'>2003</option>
104 <option $selectYear{'YEAR'}{'2004'} value='2004'>2004</option>
105 <option $selectYear{'YEAR'}{'2005'} value='2005'>2005</option>
106 <option $selectYear{'YEAR'}{'2006'} value='2006'>2006</option>
107 <option $selectYear{'YEAR'}{'????'} value='????'>$Lang::tr{'allmsg'}</option>
109 <input type='submit' name='ACTION' value='$Lang::tr{'update'}' />
112 <td width='5%' align='center'>
113 <form method='post' action='/cgi-bin/traffics.cgi'>
114 <input type='submit' name='ACTION' value=' > ' />
123 &Header
::openbox
('100%', 'left', $Lang::tr
{'traffics'});
125 my $dateWidth = '20%';
126 my $netWidth = '34%';
127 my $inOutWidth = '17%';
130 if ($netsettings{'CONFIG_TYPE'} =~ /^(5|7)$/) {
136 if ($netsettings{'CONFIG_TYPE'} =~ /^(1|3|4|6)$/) {
145 <td width='$dateWidth' align='center' class='boldbase'></td>
146 <td width='$netWidth' align='center' class='boldbase' ><b>$Lang::tr{'trafficgreen'}</b></td>
149 if ($netsettings{'CONFIG_TYPE'} =~ /^(4|5|6|7)$/) {
150 print "<td width='$netWidth' align='center' class='boldbase' ><b>$Lang::tr{'trafficblue'}</b></td>";
153 if ($netsettings{'CONFIG_TYPE'} =~ /^(1|3|5|7)$/) {
154 print "<td width='$netWidth' align='center' class='boldbase' ><b>$Lang::tr{'trafficorange'}</b></td>";
158 <td width='$netWidth' align='center' class='boldbase'><b>$Lang::tr{'trafficred'}</b></td>
163 <td width='$dateWidth' align='center' class='boldbase'><b>$Lang::tr{'trafficdate'}</b></td>
164 <td width='$inOutWidth' align='center' class='boldbase'><font color='#16A61D'><b>$Lang::tr{'trafficin'}</b></font></td>
165 <td width='$inOutWidth' align='center' class='boldbase'><font color='#16A61D'><b>$Lang::tr{'trafficout'}</b></font></td>
168 if ($netsettings{'CONFIG_TYPE'} =~ /^(4|5|6|7)$/)
170 print "<td width='$inOutWidth' align='center' class='boldbase'><font color='${Header::colourblue}'><b>$Lang::tr{'trafficin'}</b></font></td>";
171 print "<td width='$inOutWidth' align='center' class='boldbase'><font color='${Header::colourblue}'><b>$Lang::tr{'trafficout'}</b></font></td>";
174 if ($netsettings{'CONFIG_TYPE'} =~ /^(1|3|5|7)$/)
176 print "<td width='$inOutWidth' align='center' class='boldbase'><font color='#FF9933'><b>$Lang::tr{'trafficin'}</b></font></td>";
177 print "<td width='$inOutWidth' align='center' class='boldbase'><font color='#FF9933'><b>$Lang::tr{'trafficout'}</b></font></td>";
180 <td width='$inOutWidth' align='center' class='boldbase'><font color='#CE1B31'><b>$Lang::tr{'trafficin'}</b></font></td>
181 <td width='$inOutWidth' align='center' class='boldbase'><font color='#CE1B31'><b>$Lang::tr{'trafficout'}</b></font></td>
186 my $total_blue_out=0;
187 my $total_green_in=0;
188 my $total_green_out=0;
189 my $total_orange_in=0;
190 my $total_orange_out=0;
195 my $displayMode = "daily";
196 my $startMonth = $cgiparams{'MONTH'};
197 my $endMonth = $cgiparams{'MONTH'};
199 if ($cgiparams{'MONTH'} eq '??') {
200 $displayMode = "monthly";
205 my $start = "$cgiparams{'YEAR'}$startMonth"."01";
206 my $end = "$cgiparams{'YEAR'}$endMonth"."32";
207 my %allDaysBytes = ();
208 my @allDays = &Traffic
::calcTraffic
(\
%allDaysBytes,$start,$end, $displayMode);
212 $total_green_in += $allDaysBytes{$_}{${Traffic
::green_in
}};
213 $total_green_out += $allDaysBytes{$_}{${Traffic
::green_out
}};
215 if ($netsettings{'CONFIG_TYPE'} =~ /^(4|5|6|7)$/)
217 $total_blue_in += $allDaysBytes{$_}{${Traffic
::blue_in
}};
218 $total_blue_out += $allDaysBytes{$_}{${Traffic
::blue_out
}};
221 if ($netsettings{'CONFIG_TYPE'} =~ /^(1|3|5|7)$/)
223 $total_orange_in += $allDaysBytes{$_}{${Traffic
::orange_in
}};
224 $total_orange_out += $allDaysBytes{$_}{${Traffic
::orange_out
}};
227 $total_red_in += $allDaysBytes{$_}{${Traffic
::red_in
}};
228 $total_red_out += $allDaysBytes{$_}{${Traffic
::red_out
}};
231 print "<tr bgcolor='${Header::table1colour}'>"; }
233 print "<tr bgcolor='${Header::table2colour}'>"; }
235 printf "<td align='center' nowrap='nowrap'>%s</td>\n", $allDaysBytes{$_}{'Day'};
236 printf "<td align='center' nowrap='nowrap'>%.3f</td>\n", ($allDaysBytes{$_}{${Traffic
::green_in
}}/1048576);
237 printf "<td align='center' nowrap='nowrap'>%.3f</td>\n", ($allDaysBytes{$_}{${Traffic
::green_out
}}/1048576);
239 if ($netsettings{'CONFIG_TYPE'} =~ /^(4|5|6|7)$/)
241 printf "<td align='center' nowrap='nowrap'>%.3f</td>\n", ($allDaysBytes{$_}{${Traffic
::blue_in
}}/1048576);
242 printf "<td align='center' nowrap='nowrap'>%.3f</td>\n", ($allDaysBytes{$_}{${Traffic
::blue_out
}}/1048576);
244 if ($netsettings{'CONFIG_TYPE'} =~ /^(1|3|5|7)$/)
246 printf "<td align='center' nowrap='nowrap'>%.3f</td>\n", ($allDaysBytes{$_}{${Traffic
::orange_in
}}/1048576);
247 printf "<td align='center' nowrap='nowrap'>%.3f</td>\n", ($allDaysBytes{$_}{${Traffic
::orange_out
}}/1048576);
250 printf "<td align='center' nowrap='nowrap'>%.3f</td>\n", ($allDaysBytes{$_}{${Traffic
::red_in
}}/1048576);
251 printf "<td align='center' nowrap='nowrap'>%.3f</td></tr>\n", ($allDaysBytes{$_}{${Traffic
::red_out
}}/1048576);
256 $total_green_in=sprintf("%.2f", ($total_green_in/1048576));
257 $total_green_out=sprintf("%.2f", ($total_green_out/1048576));
258 $total_blue_in=sprintf("%.2f", ($total_blue_in/1048576));
259 $total_blue_out=sprintf("%.2f", ($total_blue_out/1048576));
260 $total_orange_in=sprintf("%.2f", ($total_orange_in/1048576));
261 $total_orange_out=sprintf("%.2f", ($total_orange_out/1048576));
262 $total_red_in=sprintf("%.2f", ($total_red_in/1048576));
263 $total_red_out=sprintf("%.2f", ($total_red_out/1048576));
265 if ($lines % 2) {print "<tr bgcolor='${Header::table1colour}'>"; }
266 else {print "<tr bgcolor='${Header::table2colour}'>"; }
269 <td align='center' class='boldbase' height='20' nowrap='nowrap'><b>$Lang::tr{'trafficsum'}</b></td>
270 <td align='center' class='boldbase' nowrap='nowrap'><b>$total_green_in MB</b></td>
271 <td align='center' class='boldbase' nowrap='nowrap'><b>$total_green_out MB</b></td>
274 if ($netsettings{'CONFIG_TYPE'} =~ /^(4|5|6|7)$/)
276 print "<td align='center' class='boldbase' nowrap='nowrap'><b>$total_blue_in MB</b></td>";
277 print "<td align='center' class='boldbase' nowrap='nowrap'><b>$total_blue_out MB</b></td>";
280 if ($netsettings{'CONFIG_TYPE'} =~ /^(1|3|5|7)$/)
282 print "<td align='center' class='boldbase' nowrap='nowrap'><b>$total_orange_in MB</b></td>";
283 print "<td align='center' class='boldbase' nowrap='nowrap'><b>$total_orange_out MB</b></td>";
287 <td align='center' class='boldbase' nowrap='nowrap'><b>$total_red_in MB</b></td>
288 <td align='center' class='boldbase' nowrap='nowrap'><b>$total_red_out MB</b></td>
295 &Header
::closebigbox
();
297 &Header
::closepage
();