]>
git.ipfire.org Git - people/trikolon/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'}{'2007'} = '';
44 $selectYear{'YEAR'}{'2008'} = '';
45 $selectYear{'YEAR'}{'2009'} = '';
46 $selectYear{'YEAR'}{'2010'} = '';
47 $selectYear{'YEAR'}{'2011'} = '';
48 $selectYear{'YEAR'}{'2012'} = '';
49 $selectYear{'YEAR'}{'????'} = '';
50 $selectYear{'YEAR'}{$cgiparams{'YEAR'}} = 'selected=\'selected\'';
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\'';
70 &Header
::openpage
($Lang::tr
{'sstraffic'}, 1, '');
72 &Header
::openbigbox
('100%', 'left');
74 &Header
::openbox
('100%', 'left', $Lang::tr
{'settingsc'});
77 <table width='80%' align='center'>
79 <td width='95%' align='left' nowrap='nowrap'>
80 <form method='post' action='/cgi-bin/traffic.cgi'>
81 $Lang::tr{'selecttraffic'}
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>
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>
104 <option $selectYear{'YEAR'}{'????'} value='????'>$Lang::tr{'allmsg'}</option>
106 <input type='submit' name='ACTION' value='$Lang::tr{'update'}' />
109 <td width='5%' align='center'>
110 <form method='post' action='/cgi-bin/traffics.cgi'>
111 <input type='submit' name='ACTION' value=' > ' />
120 &Header
::openbox
('100%', 'left', $Lang::tr
{'traffics'});
122 my $dateWidth = '20%';
123 my $netWidth = '34%';
124 my $inOutWidth = '17%';
127 if ($netsettings{'CONFIG_TYPE'} =~ /^(5|7)$/) {
133 if ($netsettings{'CONFIG_TYPE'} =~ /^(1|3|4|6)$/) {
142 <td width='$dateWidth' align='center' class='boldbase'></td>
143 <td width='$netWidth' align='center' class='boldbase' ><b>$Lang::tr{'trafficgreen'}</b></td>
146 if ($netsettings{'CONFIG_TYPE'} =~ /^(4|5|6|7)$/) {
147 print "<td width='$netWidth' align='center' class='boldbase' ><b>$Lang::tr{'trafficblue'}</b></td>";
150 if ($netsettings{'CONFIG_TYPE'} =~ /^(1|3|5|7)$/) {
151 print "<td width='$netWidth' align='center' class='boldbase' ><b>$Lang::tr{'trafficorange'}</b></td>";
155 <td width='$netWidth' align='center' class='boldbase'><b>$Lang::tr{'trafficred'}</b></td>
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>
165 if ($netsettings{'CONFIG_TYPE'} =~ /^(4|5|6|7)$/)
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>";
171 if ($netsettings{'CONFIG_TYPE'} =~ /^(1|3|5|7)$/)
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>";
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>
183 my $total_blue_out=0;
184 my $total_green_in=0;
185 my $total_green_out=0;
186 my $total_orange_in=0;
187 my $total_orange_out=0;
192 my $displayMode = "daily";
193 my $startMonth = $cgiparams{'MONTH'};
194 my $endMonth = $cgiparams{'MONTH'};
196 if ($cgiparams{'MONTH'} eq '??') {
197 $displayMode = "monthly";
202 my $start = "$cgiparams{'YEAR'}$startMonth"."01";
203 my $end = "$cgiparams{'YEAR'}$endMonth"."32";
204 my %allDaysBytes = ();
205 my @allDays = &Traffic
::calcTraffic
(\
%allDaysBytes,$start,$end, $displayMode);
209 $total_green_in += $allDaysBytes{$_}{${Traffic
::green_in
}};
210 $total_green_out += $allDaysBytes{$_}{${Traffic
::green_out
}};
212 if ($netsettings{'CONFIG_TYPE'} =~ /^(4|5|6|7)$/)
214 $total_blue_in += $allDaysBytes{$_}{${Traffic
::blue_in
}};
215 $total_blue_out += $allDaysBytes{$_}{${Traffic
::blue_out
}};
218 if ($netsettings{'CONFIG_TYPE'} =~ /^(1|3|5|7)$/)
220 $total_orange_in += $allDaysBytes{$_}{${Traffic
::orange_in
}};
221 $total_orange_out += $allDaysBytes{$_}{${Traffic
::orange_out
}};
224 $total_red_in += $allDaysBytes{$_}{${Traffic
::red_in
}};
225 $total_red_out += $allDaysBytes{$_}{${Traffic
::red_out
}};
228 print "<tr bgcolor='${Header::table1colour}'>"; }
230 print "<tr bgcolor='${Header::table2colour}'>"; }
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);
236 if ($netsettings{'CONFIG_TYPE'} =~ /^(4|5|6|7)$/)
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);
241 if ($netsettings{'CONFIG_TYPE'} =~ /^(1|3|5|7)$/)
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);
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);
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));
262 if ($lines % 2) {print "<tr bgcolor='${Header::table1colour}'>"; }
263 else {print "<tr bgcolor='${Header::table2colour}'>"; }
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>
271 if ($netsettings{'CONFIG_TYPE'} =~ /^(4|5|6|7)$/)
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>";
277 if ($netsettings{'CONFIG_TYPE'} =~ /^(1|3|5|7)$/)
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>";
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>
292 &Header
::closebigbox
();
294 &Header
::closepage
();