]>
Commit | Line | Data |
---|---|---|
e4aac473 AH |
1 | #!/usr/bin/perl |
2 | # | |
3 | # SmoothWall CGIs | |
4 | # | |
5 | # This code is distributed under the terms of the GPL | |
6 | # | |
7 | # JC HERITIER | |
8 | # page inspired from the initial firewalllog.dat | |
9 | # | |
10 | # Modified for IPFire by Christian Schmidt | |
43638be5 | 11 | # and Michael Tremer (www.ipfire.org) |
e4aac473 AH |
12 | |
13 | use strict; | |
e4aac473 AH |
14 | use Getopt::Std; |
15 | ||
16 | # enable only the following on debugging purpose | |
17 | #use warnings; | |
18 | #use CGI::Carp 'fatalsToBrowser'; | |
19 | ||
20 | require '/var/ipfire/general-functions.pl'; | |
3ea01fe0 | 21 | require "${General::swroot}/geoip-functions.pl"; |
e4aac473 AH |
22 | require "${General::swroot}/lang.pl"; |
23 | require "${General::swroot}/header.pl"; | |
24 | ||
50494dfd SS |
25 | # Libloc database handle. |
26 | my $libloc_db_handle = &GeoIP::init(); | |
27 | ||
e4aac473 AH |
28 | use POSIX(); |
29 | ||
30 | my %cgiparams=(); | |
31 | my %settings=(); | |
32 | my $pienumber; | |
33 | my $otherspie; | |
34 | my $showpie; | |
35 | my $sortcolumn; | |
36 | my $errormessage = ''; | |
37 | ||
38 | $cgiparams{'pienumber'} = 10; | |
39 | $cgiparams{'otherspie'} = 1; | |
40 | $cgiparams{'showpie'} = 1; | |
41 | $cgiparams{'sortcolumn'} = 1; | |
42 | ||
43 | my @shortmonths = ( 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', | |
43638be5 | 44 | 'Sep', 'Oct', 'Nov', 'Dec' ); |
e4aac473 | 45 | my @longmonths = ( $Lang::tr{'january'}, $Lang::tr{'february'}, $Lang::tr{'march'}, |
43638be5 ME |
46 | $Lang::tr{'april'}, $Lang::tr{'may'}, $Lang::tr{'june'}, $Lang::tr{'july'}, $Lang::tr{'august'}, |
47 | $Lang::tr{'september'}, $Lang::tr{'october'}, $Lang::tr{'november'}, | |
48 | $Lang::tr{'december'} ); | |
e4aac473 AH |
49 | |
50 | my @now = localtime(); | |
51 | my $dow = $now[6]; | |
52 | my $doy = $now[7]; | |
53 | my $tdoy = $now[7]; | |
54 | my $year = $now[5]+1900; | |
55 | ||
56 | $cgiparams{'DAY'} = $now[3]; | |
57 | $cgiparams{'MONTH'} = $now[4]; | |
58 | $cgiparams{'ACTION'} = ''; | |
59 | ||
60 | &General::readhash("${General::swroot}/fwlogs/ipsettings", \%settings); | |
61 | if ($settings{'pienumber'} != 0) { $cgiparams{'pienumber'} = $settings{'pienumber'} }; | |
62 | if ($settings{'otherspie'} != 0) { $cgiparams{'otherspie'} = $settings{'otherspie'} }; | |
63 | if ($settings{'showpie'} != 0) { $cgiparams{'showpie'} = $settings{'showpie'} }; | |
64 | if ($settings{'sortcolumn'} != 0) { $cgiparams{'sortcolumn'} = $settings{'sortcolumn'} }; | |
65 | ||
66 | &Header::getcgihash(\%cgiparams); | |
67 | if ($cgiparams{'pienumber'} != 0) { $settings{'pienumber'} = $cgiparams{'pienumber'} }; | |
68 | if ($cgiparams{'otherspie'} != 0) { $settings{'otherspie'} = $cgiparams{'otherspie'} }; | |
69 | if ($cgiparams{'showpie'} != 0) { $settings{'showpie'} = $cgiparams{'showpie'} }; | |
70 | if ($cgiparams{'sortcolumn'} != 0) { $settings{'sortcolumn'} = $cgiparams{'sortcolumn'} }; | |
71 | ||
72 | if ($cgiparams{'ACTION'} eq $Lang::tr{'save'}) | |
73 | { | |
43638be5 | 74 | &General::writehash("${General::swroot}/fwlogs/ipsettings", \%settings); |
e4aac473 AH |
75 | } |
76 | ||
77 | my $start = -1; | |
78 | if ($ENV{'QUERY_STRING'} && $cgiparams{'ACTION'} ne $Lang::tr{'update'}) | |
79 | { | |
43638be5 ME |
80 | my @temp = split(',',$ENV{'QUERY_STRING'}); |
81 | $start = $temp[0]; | |
82 | $cgiparams{'MONTH'} = $temp[1]; | |
83 | $cgiparams{'DAY'} = $temp[2]; | |
e4aac473 AH |
84 | } |
85 | ||
86 | if (!($cgiparams{'MONTH'} =~ /^(0|1|2|3|4|5|6|7|8|9|10|11)$/) || | |
87 | !($cgiparams{'DAY'} =~ /^(1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31)$/)) | |
88 | { | |
43638be5 ME |
89 | $cgiparams{'DAY'} = $now[3]; |
90 | $cgiparams{'MONTH'} = $now[4]; | |
e4aac473 AH |
91 | } |
92 | elsif($cgiparams{'ACTION'} eq '>>') | |
93 | { | |
43638be5 ME |
94 | my @temp_then=(); |
95 | my @temp_now = localtime(time); | |
96 | $temp_now[4] = $cgiparams{'MONTH'}; | |
97 | $temp_now[3] = $cgiparams{'DAY'}; | |
98 | @temp_then = localtime(POSIX::mktime(@temp_now) + 86400); | |
99 | ## Retrieve the same time on the next day - | |
100 | ## 86400 seconds in a day | |
101 | $cgiparams{'MONTH'} = $temp_then[4]; | |
102 | $cgiparams{'DAY'} = $temp_then[3]; | |
e4aac473 AH |
103 | } |
104 | elsif($cgiparams{'ACTION'} eq '<<') | |
105 | { | |
43638be5 ME |
106 | my @temp_then=(); |
107 | my @temp_now = localtime(time); | |
108 | $temp_now[4] = $cgiparams{'MONTH'}; | |
109 | $temp_now[3] = $cgiparams{'DAY'}; | |
110 | @temp_then = localtime(POSIX::mktime(@temp_now) - 86400); | |
111 | ## Retrieve the same time on the previous day - | |
112 | ## 86400 seconds in a day | |
113 | $cgiparams{'MONTH'} = $temp_then[4]; | |
114 | $cgiparams{'DAY'} = $temp_then[3]; | |
e4aac473 AH |
115 | } |
116 | ||
117 | if (($cgiparams{'DAY'} ne $now[3]) || ($cgiparams{'MONTH'} ne $now[4])) | |
118 | { | |
43638be5 ME |
119 | my @then = (); |
120 | if ( ( $cgiparams{'MONTH'} eq $now[4]) && ($cgiparams{'DAY'} > $now[3]) || | |
121 | ( $cgiparams{'MONTH'} > $now[4] ) ) { | |
122 | @then = localtime(POSIX::mktime( 0, 0, 0, $cgiparams{'DAY'}, $cgiparams{'MONTH'}, $year - 1901 )); | |
123 | } else { | |
124 | @then = localtime(POSIX::mktime( 0, 0, 0, $cgiparams{'DAY'}, $cgiparams{'MONTH'}, $year - 1900 )); | |
125 | } | |
126 | $tdoy = $then[7]; | |
127 | my $lastleap=($year-1)%4; | |
128 | if ($tdoy>$doy) { | |
129 | if ($lastleap == 0 && $tdoy < 60) { | |
130 | $doy=$tdoy+366; | |
131 | } else { | |
132 | $doy=$doy+365; | |
133 | } | |
134 | } | |
e4aac473 AH |
135 | } |
136 | ||
137 | my $datediff=0; | |
138 | my $dowd=0; | |
139 | my $multifile=0; | |
140 | if ($tdoy ne $doy) { | |
43638be5 ME |
141 | $datediff=int(($doy-$tdoy)/7); |
142 | $dowd=($doy-$tdoy)%7; | |
143 | if (($dow-$dowd)<1) { | |
144 | $datediff=$datediff+1; | |
145 | } | |
146 | if (($dow-$dowd)==0) { | |
147 | $multifile=1; | |
148 | } | |
e4aac473 AH |
149 | } |
150 | ||
151 | my $monthstr = $shortmonths[$cgiparams{'MONTH'}]; | |
152 | my $longmonthstr = $longmonths[$cgiparams{'MONTH'}]; | |
153 | my $day = $cgiparams{'DAY'}; | |
154 | my $daystr=''; | |
155 | if ($day <= 9) { | |
43638be5 ME |
156 | $daystr = " $day"; |
157 | } | |
e4aac473 | 158 | else { |
43638be5 | 159 | $daystr = $day; |
e4aac473 AH |
160 | } |
161 | ||
162 | my $skip=0; | |
163 | my $filestr=''; | |
164 | if ($datediff==0) { | |
43638be5 | 165 | $filestr="/var/log/messages"; |
e4aac473 | 166 | } else { |
43638be5 ME |
167 | $filestr="/var/log/messages.$datediff"; |
168 | $filestr = "$filestr.gz" if -f "$filestr.gz"; | |
e4aac473 AH |
169 | } |
170 | ||
171 | if (!(open (FILE,($filestr =~ /.gz$/ ? "gzip -dc $filestr |" : $filestr)))) { | |
43638be5 ME |
172 | $errormessage = "$Lang::tr{'date not in logs'}: $filestr $Lang::tr{'could not be opened'}"; |
173 | $skip=1; | |
174 | # Note: This is in case the log does not exist for that date | |
e4aac473 AH |
175 | } |
176 | my $lines = 0; | |
177 | my @log=(); | |
178 | ||
179 | if (!$skip) | |
180 | { | |
43638be5 ME |
181 | while (<FILE>) |
182 | { | |
183 | if (/(^${monthstr} ${daystr} ..:..:..) [\w\-]+ kernel:.*(IN=.*)$/) { | |
184 | $log[$lines] = $_; | |
185 | $lines++; | |
186 | } | |
187 | } | |
188 | close (FILE); | |
e4aac473 AH |
189 | } |
190 | ||
191 | $skip=0; | |
192 | if ($multifile) { | |
43638be5 ME |
193 | $datediff=$datediff-1; |
194 | if ($datediff==0) { | |
195 | $filestr="/var/log/messages"; | |
196 | } else { | |
197 | $filestr="/var/log/messages.$datediff"; | |
198 | $filestr = "$filestr.gz" if -f "$filestr.gz"; | |
199 | } | |
200 | if (!(open (FILE,($filestr =~ /.gz$/ ? "gzip -dc $filestr |" : $filestr)))) { | |
201 | $errormessage="$Lang::tr{'date not in logs'}: $filestr $Lang::tr{'could not be opened'}"; | |
202 | $skip=1; | |
203 | } | |
204 | if (!$skip) { | |
205 | while (<FILE>) { | |
206 | if (/(^${monthstr} ${daystr} ..:..:..) [\w\-]+ kernel:.*(IN=.*)$/) { | |
207 | $log[$lines] = $_; | |
208 | $lines++; | |
209 | } | |
210 | } | |
211 | close (FILE); | |
212 | } | |
e4aac473 AH |
213 | } |
214 | ||
215 | my $MODNAME="fwlogs"; | |
216 | ||
217 | &Header::showhttpheaders(); | |
1bea8be2 | 218 | &Header::openpage($Lang::tr{'firewall log country'}, 1, ''); |
e4aac473 AH |
219 | &Header::openbigbox('100%', 'left', '', $errormessage); |
220 | ||
221 | ||
222 | if ($errormessage) { | |
43638be5 ME |
223 | &Header::openbox('100%', 'left', $Lang::tr{'error messages'}); |
224 | print "<font class='base'>$errormessage </font>\n"; | |
225 | &Header::closebox(); | |
e4aac473 AH |
226 | } |
227 | ||
f4248975 | 228 | &Header::openbox('100%', 'left', "$Lang::tr{'settings'}"); |
e4aac473 AH |
229 | |
230 | print <<END | |
231 | <form method='post' action='$ENV{'SCRIPT_NAME'}'> | |
232 | <table width='100%'> | |
233 | <tr> | |
43638be5 ME |
234 | <td width='10%' class='base'>$Lang::tr{'month'}: </td> |
235 | <td width='10%'> | |
236 | <select name='MONTH'> | |
e4aac473 AH |
237 | END |
238 | ; | |
239 | my $month; | |
240 | for ($month = 0; $month < 12; $month++) | |
241 | { | |
43638be5 ME |
242 | print "\t<option "; |
243 | if ($month == $cgiparams{'MONTH'}) { | |
244 | print "selected='selected' "; } | |
245 | print "value='$month'>$longmonths[$month]</option>\n"; | |
e4aac473 AH |
246 | } |
247 | print <<END | |
43638be5 ME |
248 | </select> |
249 | </td> | |
250 | <td width='10%' class='base' align='right'> $Lang::tr{'day'}: </td> | |
251 | <td width='40%'> | |
252 | <select name='DAY'> | |
e4aac473 AH |
253 | END |
254 | ; | |
255 | for ($day = 1; $day <= 31; $day++) | |
256 | { | |
43638be5 ME |
257 | print "\t<option "; |
258 | if ($day == $cgiparams{'DAY'}) { | |
259 | print "selected='selected' "; } | |
260 | print "value='$day'>$day</option>\n"; | |
e4aac473 AH |
261 | } |
262 | ||
263 | if( $cgiparams{'pienumber'} != 0){$pienumber=$cgiparams{'pienumber'};} | |
264 | if( $cgiparams{'otherspie'} != 0){$otherspie=$cgiparams{'otherspie'};} | |
265 | if( $cgiparams{'showpie'} != 0){$showpie=$cgiparams{'showpie'};} | |
266 | if( $cgiparams{'sortcolumn'} != 0){$sortcolumn=$cgiparams{'sortcolumn'};} | |
e4aac473 AH |
267 | print <<END |
268 | </select> | |
269 | </td> | |
270 | <td width='5%' align='center'><input type='submit' name='ACTION' title='$Lang::tr{'day before'}' value='<<' /></td> | |
271 | <td width='5%' align='center'><input type='submit' name='ACTION' title='$Lang::tr{'day after'}' value='>>' /></td> | |
f4248975 AH |
272 | <td width='20%' align='right'><input type='submit' name='ACTION' value='$Lang::tr{'update'}' /></td> |
273 | </tr> | |
274 | <tr> | |
275 | <td colspan='3' align='left' valign="left">$Lang::tr{'Number of Countries for the pie chart'}:</td> | |
276 | <td colspan='3' align='left' valign="center"><input type='text' name='pienumber' value='$pienumber' size='4'></td> | |
277 | <td align='right'><input type='submit' name='ACTION' value='$Lang::tr{'save'}' /></td> | |
e4aac473 AH |
278 | </tr> |
279 | </table> | |
f4248975 | 280 | </form> |
e4aac473 AH |
281 | END |
282 | ; | |
283 | ||
284 | &Header::closebox(); | |
285 | ||
1bea8be2 | 286 | &Header::openbox('100%', 'left', $Lang::tr{'firewall graph country'}); |
e4aac473 AH |
287 | print "<p><b>$Lang::tr{'firewall hits'} $longmonthstr $daystr: $lines</b></p>"; |
288 | ||
4fca9c99 | 289 | my $red_interface = &General::get_red_interface(); |
e4aac473 AH |
290 | my $linesjc = 0; |
291 | my %tabjc; | |
e4aac473 AH |
292 | |
293 | if ($pienumber == -1 || $pienumber > $lines || $sortcolumn == 2) { $pienumber = $lines; }; | |
294 | $lines = 0; | |
4fca9c99 | 295 | |
e4aac473 AH |
296 | foreach $_ (@log) |
297 | { | |
43638be5 ME |
298 | # If ipv6 uses bridge, use PHYSIN for iface, otherwise IN |
299 | if (/^... (..) (..:..:..) [\w\-]+ kernel:(.*)(PHYSIN=.*)$/) {} | |
300 | elsif (/^... (..) (..:..:..) [\w\-]+ kernel:(.*)(IN=.*)$/) {} | |
301 | my $packet = $4; | |
302 | my $iface = ''; | |
303 | if ($packet =~ /PHYSIN=(\w+)/) { $iface = $1; } elsif ($packet =~ /IN=(\w+)/) { $iface = $1; } | |
304 | if ( $1 =~ /2./ ) { $iface=''; } | |
305 | my $srcaddr = ''; | |
306 | # Find ipv4 and ipv6 addresses | |
307 | if ($packet =~ /SRC\=(([\d]{1,3})(\.([\d]{1,3})){3})/) { $srcaddr = $1; } | |
308 | elsif ($packet =~ /SRC\=(([0-9a-fA-F]{0,4})(\:([0-9a-fA-F]{0,4})){2,7})/) { $srcaddr = $1; } | |
309 | ||
310 | if($iface eq $red_interface) { | |
311 | # Traffic from red | |
312 | if($srcaddr ne '') { | |
313 | # srcaddr is set | |
50494dfd | 314 | my $ccode = &GeoIP::lookup_country_code($libloc_db_handle, $srcaddr); |
43638be5 ME |
315 | if ($ccode eq '') { |
316 | $ccode = 'unknown'; | |
317 | } | |
318 | $tabjc{$ccode} = $tabjc{$ccode} + 1; | |
319 | if(($tabjc{$ccode} == 1) && ($lines < $pienumber)) { $lines = $lines + 1; } | |
320 | $linesjc++; | |
321 | } | |
322 | } | |
323 | else { | |
324 | # Traffic not from red | |
325 | if($iface ne '') { | |
326 | $tabjc{$iface} = $tabjc{$iface} + 1 ; | |
327 | if(($tabjc{$iface} == 1) && ($lines < $pienumber)) { $lines = $lines + 1; } | |
328 | $linesjc++; | |
329 | } | |
330 | else { | |
331 | # What to do with empty iface lines? | |
332 | # This probably is traffic from ipfire itself (IN= OUT=XY)? | |
333 | } | |
334 | } | |
e4aac473 AH |
335 | } |
336 | ||
337 | $pienumber = $lines; | |
338 | ||
339 | my @keytabjc = keys %tabjc; | |
340 | ||
341 | my @slice; | |
342 | my $go; | |
343 | my $nblinejc; | |
344 | ||
345 | if( $cgiparams{'linejc'} eq 'all' ){ $nblinejc = $linesjc; $go=1; } | |
346 | if( ($cgiparams{'linejc'} != 0) && ($cgiparams{'linejc'} ne 'all') ){ $nblinejc = $cgiparams{'linejc'}; $go=1;} | |
347 | if( $go != 1){ $nblinejc = 1000; } | |
348 | ||
349 | my @key; | |
350 | my @value; | |
351 | my $indice=0; | |
352 | my @tabjc2; | |
353 | ||
43638be5 ME |
354 | if ($sortcolumn == 1) { |
355 | @tabjc2 = sort { $b <=> $a } values (%tabjc); | |
e4aac473 | 356 | } |
43638be5 ME |
357 | else { |
358 | @tabjc2 = sort { $a <=> $b } keys (%tabjc); | |
e4aac473 AH |
359 | } |
360 | ||
361 | my $colour=1; | |
362 | ||
363 | ############################################## | |
364 | #pie chart generation | |
365 | use GD::Graph::pie; | |
366 | use GD::Graph::colour; | |
367 | #ips sort by hits number | |
368 | my $v; | |
369 | ||
43638be5 ME |
370 | if ($sortcolumn == 1) { |
371 | for ($v=0;$v<$pienumber;$v++){ | |
372 | findkey($tabjc2[$v]); | |
373 | } | |
e4aac473 | 374 | } |
43638be5 ME |
375 | else { |
376 | foreach $v (@tabjc2) { | |
377 | $key[$indice] = $v; | |
378 | $value[$indice] = $tabjc{$v}; | |
379 | $indice++; | |
380 | } | |
e4aac473 AH |
381 | } |
382 | ||
383 | my @ips; | |
384 | my @numb; | |
385 | ||
386 | @ips = @key; | |
387 | @numb = @value; | |
388 | ||
389 | my $o; | |
390 | ||
391 | if($cgiparams{'otherspie'} == 2 ){} | |
392 | else{ | |
43638be5 ME |
393 | my $numothers; |
394 | for($o=0;$o<$pienumber;$o++){ | |
395 | $numothers = $numothers + $numb[$o]; | |
396 | } | |
397 | $numothers = $linesjc - $numothers; | |
398 | if ($numothers > 0) { | |
399 | $ips[$pienumber]="$Lang::tr{'otherip'}"; | |
400 | $numb[$pienumber] = $numothers; | |
401 | } | |
e4aac473 AH |
402 | } |
403 | ||
404 | my @data = (\@ips,\@numb); | |
405 | use GD::Graph::colour qw( :files ); | |
406 | ||
407 | my $color=0; | |
408 | my %color = (); | |
409 | my %mainsettings = (); | |
410 | &General::readhash("${General::swroot}/main/settings", \%mainsettings); | |
411 | &General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color); | |
412 | ||
413 | if ($showpie != 2 && $pienumber <= 50 && $pienumber != 0) { | |
43638be5 ME |
414 | my $mygraph = GD::Graph::pie->new(500, 350); |
415 | $mygraph->set( | |
416 | 'title' => '', | |
417 | 'pie_height' => 50, | |
418 | 'start_angle' => 89 | |
419 | ) or warn $mygraph->error; | |
420 | ||
421 | $mygraph->set_value_font(GD::gdMediumBoldFont); | |
422 | $mygraph->set( dclrs => [ "$color{'color1'}" , "$color{'color2'}" , "$color{'color3'}" , "$color{'color4'}" , "$color{'color5'}" , "$color{'color6'}" , "$color{'color7'}" , "$color{'color8'}" , "$color{'color9'}" , "$color{'color10'}" ] ); | |
423 | my $myimage = $mygraph->plot(\@data) or die $mygraph->error; | |
424 | ||
425 | my @filenames = glob("/srv/web/ipfire/html/graphs/fwlog-country*.png"); | |
426 | unlink(@filenames); | |
427 | my $imagerandom = rand(1000000); | |
428 | my $imagename = "/srv/web/ipfire/html/graphs/fwlog-country$imagerandom.png"; | |
429 | open(FILE,">$imagename"); | |
430 | print FILE $myimage->png; | |
431 | close(FILE); | |
432 | ##################################################### | |
433 | print "<div style='text-align:center;'>"; | |
434 | print "<img src='/graphs/fwlog-country$imagerandom.png'>"; | |
435 | print "</div>"; | |
e4aac473 | 436 | } |
e4aac473 | 437 | print <<END |
f4248975 AH |
438 | <table width='100%' class='tbl'> |
439 | <tr> | |
440 | <th width='10%' align='center' class='boldbase'></th> | |
441 | <th width='30%' align='center' class='boldbase'><b>$Lang::tr{'country'}</b></th> | |
442 | <th width='30%' align='center' class='boldbase'><b>Count</b></th> | |
443 | <th width='30%' align='center' class='boldbase'><b>$Lang::tr{'percentage'}</b></th> | |
444 | </tr> | |
e4aac473 AH |
445 | END |
446 | ; | |
447 | ||
448 | my $total=0; | |
449 | my $show=0; | |
450 | ||
451 | my $s; | |
452 | my $percent; | |
f4248975 | 453 | my $col=""; |
e4aac473 AH |
454 | |
455 | for($s=0;$s<$lines;$s++) | |
456 | { | |
43638be5 ME |
457 | $show++; |
458 | $percent = $value[$s] * 100 / $linesjc; | |
459 | $percent = sprintf("%.f", $percent); | |
460 | $total = $total + $value[$s]; | |
461 | # colors are numbered 1 to 10 | |
462 | my $colorIndex = ($color % 10) + 1; | |
463 | $col="bgcolor='$color{\"color$colorIndex\"}'"; | |
464 | $color++; | |
465 | print "<tr>"; | |
466 | ||
467 | print "<td align='center' $col>"; | |
468 | ||
469 | # Dont show details button for "unknown" location. | |
470 | if ($key[$s] ne 'unknown') { | |
471 | print"<form method='post' action='showrequestfromcountry.dat'>"; | |
472 | print"<input type='hidden' name='MONTH' value='$cgiparams{'MONTH'}'>"; | |
473 | print"<input type='hidden' name='DAY' value='$cgiparams{'DAY'}'>"; | |
474 | print"<input type='hidden' name='country' value='$key[$s]'>"; | |
1bea8be2 | 475 | print"<input type='submit' value='$Lang::tr{'details'}'></form>"; |
43638be5 ME |
476 | } |
477 | elsif ($key[$s] eq 'unknown') { | |
478 | print "unknown"; | |
479 | } | |
480 | # Looks dangerous to use hardcoded interface names here. Probably needs fixing. | |
481 | if ($key[$s] eq 'blue0' || $key[$s] eq 'green0' || $key[$s] eq 'orange0' ) { | |
3ea01fe0 | 482 | print "<td align='center' $col>$key[$s]</td>"; |
43638be5 ME |
483 | } |
484 | else { | |
485 | my $fcode = lc($key[$s]); | |
486 | ||
487 | # Get flag icon for of the country. | |
488 | my $flag_icon = &GeoIP::get_flag_icon($fcode); | |
489 | ||
490 | if($flag_icon) { | |
491 | print "<td align='center' $col><a href='/cgi-bin/country.cgi#$fcode'><img src='$flag_icon' border='0' align='absmiddle' alt='$key[$s]' title='$key[$s]'></a></td>"; | |
492 | } else { | |
493 | print "<td align='center' $col>$key[$s]</td>"; | |
494 | } | |
495 | } | |
496 | print "<td align='center' $col>$value[$s]</td>"; | |
497 | print "<td align='center' $col>$percent</td>"; | |
498 | print "</tr>"; | |
f4248975 | 499 | } |
e4aac473 AH |
500 | |
501 | if($cgiparams{'otherspie'} == 2 ){} | |
502 | else{ | |
43638be5 ME |
503 | # colors are numbered 1 to 10 |
504 | my $colorIndex = ($color % 10) + 1; | |
505 | $col="bgcolor='$color{\"color$colorIndex\"}'"; | |
506 | print "<tr>"; | |
507 | ||
508 | if ( $linesjc ne "0") | |
509 | { | |
510 | my $dif; | |
511 | $dif = $linesjc - $total; | |
512 | $percent = $dif * 100 / $linesjc; | |
513 | $percent = sprintf("%.f", $percent); | |
514 | print <<END | |
515 | <td align='center' $col></TD> | |
516 | <td align='center' $col>$Lang::tr{'other countries'}</td> | |
517 | <td align='center' $col>$dif</TD> | |
518 | <td align='center' $col>$percent</TD> | |
519 | </tr> | |
e4aac473 | 520 | END |
43638be5 ME |
521 | ; |
522 | } | |
e4aac473 AH |
523 | } |
524 | print <<END | |
525 | </TABLE> | |
526 | END | |
527 | ; | |
528 | ||
529 | &Header::closebox(); | |
530 | &Header::closebigbox(); | |
531 | &Header::closepage(); | |
532 | ||
533 | sub findkey { | |
43638be5 ME |
534 | my $v; |
535 | foreach $v (@keytabjc) { | |
536 | if ($tabjc{$v} eq $_[0]) { | |
537 | delete $tabjc{$v}; | |
538 | $key[$indice] = "$v"; | |
539 | $value[$indice] = $_[0]; | |
540 | $indice++; | |
541 | last; | |
542 | } | |
543 | } | |
e4aac473 AH |
544 | } |
545 | sub checkversion { | |
43638be5 ME |
546 | #Automatic Updates is disabled |
547 | return "0","0"; | |
e4aac473 AH |
548 | } |
549 |