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