]> git.ipfire.org Git - ipfire-2.x.git/blob - html/cgi-bin/connections.cgi
ids.cgi: Fix downloading rules if source changed
[ipfire-2.x.git] / html / cgi-bin / connections.cgi
1 #!/usr/bin/perl
2 ###############################################################################
3 # #
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2007-2012 IPFire Team <info@ipfire.org> #
6 # #
7 # This program is free software: you can redistribute it and/or modify #
8 # it under the terms of the GNU General Public License as published by #
9 # the Free Software Foundation, either version 3 of the License, or #
10 # (at your option) any later version. #
11 # #
12 # This program is distributed in the hope that it will be useful, #
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15 # GNU General Public License for more details. #
16 # #
17 # You should have received a copy of the GNU General Public License #
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
19 # #
20 ###############################################################################
21
22 use strict;
23
24 use Net::IPv4Addr qw( :all );
25 use Switch;
26
27 # enable only the following on debugging purpose
28 #use warnings;
29 #use CGI::Carp 'fatalsToBrowser';
30
31 require '/var/ipfire/general-functions.pl';
32 require "${General::swroot}/lang.pl";
33 require "${General::swroot}/header.pl";
34 require "${General::swroot}/geoip-functions.pl";
35
36 my $colour_multicast = "#A0A0A0";
37
38 # sort arguments for connection tracking table
39 # the sort field. eg. 1=src IP, 2=dst IP, 3=src port, 4=dst port
40 my $SORT_FIELD = 0;
41 # the sort order. (a)scending orr (d)escending
42 my $SORT_ORDER = 0;
43 # cgi query arguments
44 my %cgiin;
45 # debug mode
46 my $debug = 0;
47
48 # retrieve query arguments
49 # note: let a-z A-Z and 0-9 pass as value only
50 if (length ($ENV{'QUERY_STRING'}) > 0){
51 my $name;
52 my $value;
53 my $buffer = $ENV{'QUERY_STRING'};
54 my @pairs = split(/&/, $buffer);
55 foreach my $pair (@pairs){
56 ($name, $value) = split(/=/, $pair);
57 $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; # e.g. "%20" => " "
58 $value =~ s/[^a-zA-Z0-9]*//g; # a-Z 0-9 will pass
59 $cgiin{$name} = $value;
60 }
61 }
62
63 &Header::showhttpheaders();
64
65 my @network=();
66 my @masklen=();
67 my @colour=();
68
69 my %netsettings=();
70 &General::readhash("${General::swroot}/ethernet/settings", \%netsettings);
71
72 # output cgi query arrguments to browser on debug
73 if ( $debug ){
74 &Header::openbox('100%', 'center', 'DEBUG');
75 my $debugCount = 0;
76 foreach my $line (sort keys %cgiin) {
77 print "$line = '$cgiin{$line}'<br />\n";
78 $debugCount++;
79 }
80 print "&nbsp;Count: $debugCount\n";
81 &Header::closebox();
82 }
83
84 #workaround to suppress a warning when a variable is used only once
85 my @dummy = ( ${Header::table1colour} );
86 undef (@dummy);
87
88 # check sorting arguments
89 if ( $cgiin{'sort_field'} ~~ [ '1','2','3','4','5','6','7','8','9' ] ) {
90 $SORT_FIELD = $cgiin{'sort_field'};
91
92 if ( $cgiin{'sort_order'} ~~ [ 'a','d','A','D' ] ) {
93 $SORT_ORDER = lc($cgiin{'sort_order'});
94 }
95 }
96
97 # Read and sort the connection tracking table
98 # do sorting
99 if ($SORT_FIELD and $SORT_ORDER) {
100 # field sorting when sorting arguments are sane
101 open(CONNTRACK, "/usr/local/bin/getconntracktable | /usr/local/bin/consort.sh $SORT_FIELD $SORT_ORDER |") or die "Unable to read conntrack table";
102 } else {
103 # default sorting with no query arguments
104 open(CONNTRACK, "/usr/local/bin/getconntracktable | sort -k 5,5 --numeric-sort --reverse |") or die "Unable to read conntrack table";
105 }
106 my @conntrack = <CONNTRACK>;
107 close(CONNTRACK);
108
109 # Collect data for the @network array.
110
111 # Add Firewall Localhost 127.0.0.1
112 push(@network, '127.0.0.1');
113 push(@masklen, '255.255.255.255');
114 push(@colour, ${Header::colourfw});
115
116 if (open(IP, "${General::swroot}/red/local-ipaddress")) {
117 my $redip = <IP>;
118 close(IP);
119
120 chomp $redip;
121 push(@network, $redip);
122 push(@masklen, '255.255.255.255');
123 push(@colour, ${Header::colourfw});
124 }
125
126 # Add STATIC RED aliases
127 if ($netsettings{'RED_DEV'}) {
128 my $aliasfile = "${General::swroot}/ethernet/aliases";
129 open(ALIASES, $aliasfile) or die 'Unable to open aliases file.';
130 my @aliases = <ALIASES>;
131 close(ALIASES);
132
133 # We have a RED eth iface
134 if ($netsettings{'RED_TYPE'} eq 'STATIC') {
135 # We have a STATIC RED eth iface
136 foreach my $line (@aliases) {
137 chomp($line);
138 my @temp = split(/\,/,$line);
139 if ($temp[0]) {
140 push(@network, $temp[0]);
141 push(@masklen, $netsettings{'RED_NETMASK'} );
142 push(@colour, ${Header::colourfw} );
143 }
144 }
145 }
146 }
147
148 # Add Green Firewall Interface
149 push(@network, $netsettings{'GREEN_ADDRESS'});
150 push(@masklen, "255.255.255.255" );
151 push(@colour, ${Header::colourfw} );
152
153 # Add Green Network to Array
154 push(@network, $netsettings{'GREEN_NETADDRESS'});
155 push(@masklen, $netsettings{'GREEN_NETMASK'} );
156 push(@colour, ${Header::colourgreen} );
157
158 # Add Green Routes to Array
159 my @routes = `/sbin/route -n | /bin/grep $netsettings{'GREEN_DEV'}`;
160 foreach my $route (@routes) {
161 chomp($route);
162 my @temp = split(/[\t ]+/, $route);
163 push(@network, $temp[0]);
164 push(@masklen, $temp[2]);
165 push(@colour, ${Header::colourgreen} );
166 }
167
168 # Add Blue Firewall Interface
169 push(@network, $netsettings{'BLUE_ADDRESS'});
170 push(@masklen, "255.255.255.255" );
171 push(@colour, ${Header::colourfw} );
172
173 # Add Blue Network
174 if ($netsettings{'BLUE_DEV'}) {
175 push(@network, $netsettings{'BLUE_NETADDRESS'});
176 push(@masklen, $netsettings{'BLUE_NETMASK'} );
177 push(@colour, ${Header::colourblue} );
178
179 # Add Blue Routes to Array
180 @routes = `/sbin/route -n | /bin/grep $netsettings{'BLUE_DEV'}`;
181 foreach my $route (@routes) {
182 chomp($route);
183 my @temp = split(/[\t ]+/, $route);
184 push(@network, $temp[0]);
185 push(@masklen, $temp[2]);
186 push(@colour, ${Header::colourblue} );
187 }
188 }
189
190 # Add Orange Firewall Interface
191 push(@network, $netsettings{'ORANGE_ADDRESS'});
192 push(@masklen, "255.255.255.255" );
193 push(@colour, ${Header::colourfw} );
194
195 # Add Orange Network
196 if ($netsettings{'ORANGE_DEV'}) {
197 push(@network, $netsettings{'ORANGE_NETADDRESS'});
198 push(@masklen, $netsettings{'ORANGE_NETMASK'} );
199 push(@colour, ${Header::colourorange} );
200 # Add Orange Routes to Array
201 @routes = `/sbin/route -n | /bin/grep $netsettings{'ORANGE_DEV'}`;
202 foreach my $route (@routes) {
203 chomp($route);
204 my @temp = split(/[\t ]+/, $route);
205 push(@network, $temp[0]);
206 push(@masklen, $temp[2]);
207 push(@colour, ${Header::colourorange} );
208 }
209 }
210
211 # Highlight multicast connections.
212 push(@network, "224.0.0.0");
213 push(@masklen, "239.0.0.0");
214 push(@colour, $colour_multicast);
215
216 # Add OpenVPN net and RED/BLUE/ORANGE entry (when appropriate)
217 if (-e "${General::swroot}/ovpn/settings") {
218 my %ovpnsettings = ();
219 &General::readhash("${General::swroot}/ovpn/settings", \%ovpnsettings);
220 my @tempovpnsubnet = split("\/",$ovpnsettings{'DOVPN_SUBNET'});
221
222 # add OpenVPN net
223 push(@network, $tempovpnsubnet[0]);
224 push(@masklen, $tempovpnsubnet[1]);
225 push(@colour, ${Header::colourovpn} );
226
227 # add BLUE:port / proto
228 if (($ovpnsettings{'ENABLED_BLUE'} eq 'on') && $netsettings{'BLUE_DEV'}) {
229 push(@network, $netsettings{'BLUE_ADDRESS'} );
230 push(@masklen, '255.255.255.255' );
231 push(@colour, ${Header::colourovpn});
232 }
233
234 # add ORANGE:port / proto
235 if (($ovpnsettings{'ENABLED_ORANGE'} eq 'on') && $netsettings{'ORANGE_DEV'}) {
236 push(@network, $netsettings{'ORANGE_ADDRESS'} );
237 push(@masklen, '255.255.255.255' );
238 push(@colour, ${Header::colourovpn} );
239 }
240 }
241
242 # Add OpenVPN net for custom OVPNs
243 if (-e "${General::swroot}/ovpn/ccd.conf") {
244 open(OVPNSUB, "${General::swroot}/ovpn/ccd.conf");
245 my @ovpnsub = <OVPNSUB>;
246 close(OVPNSUB);
247
248 foreach (@ovpnsub) {
249 my ($network, $mask) = split '/', (split ',', $_)[2];
250
251 $mask = ipv4_cidr2msk($mask) unless &General::validip($mask);
252
253 push(@network, $network);
254 push(@masklen, $mask);
255 push(@colour, ${Header::colourovpn});
256 }
257 }
258
259 open(IPSEC, "${General::swroot}/vpn/config");
260 my @ipsec = <IPSEC>;
261 close(IPSEC);
262
263 foreach my $line (@ipsec) {
264 my @vpn = split(',', $line);
265
266 my @subnets = split(/\|/, $vpn[12]);
267 for my $subnet (@subnets) {
268 my ($network, $mask) = split("/", $subnet);
269
270 if (!&General::validip($mask)) {
271 $mask = ipv4_cidr2msk($mask);
272 }
273
274 push(@network, $network);
275 push(@masklen, $mask);
276 push(@colour, ${Header::colourvpn});
277 }
278 }
279
280 if (-e "${General::swroot}/ovpn/n2nconf") {
281 open(OVPNN2N, "${General::swroot}/ovpn/ovpnconfig");
282 my @ovpnn2n = <OVPNN2N>;
283 close(OVPNN2N);
284
285 foreach my $line (@ovpnn2n) {
286 my @ovpn = split(',', $line);
287 next if ($ovpn[4] ne 'net');
288
289 my ($network, $mask) = split("/", $ovpn[12]);
290 if (!&General::validip($mask)) {
291 $mask = ipv4_cidr2msk($mask);
292 }
293
294 push(@network, $network);
295 push(@masklen, $mask);
296 push(@colour, ${Header::colourovpn});
297 }
298 }
299
300 # Show the page.
301 &Header::openpage($Lang::tr{'connections'}, 1, '');
302 &Header::openbigbox('100%', 'left');
303 &Header::openbox('100%', 'left', $Lang::tr{'connection tracking'});
304
305 # Print legend.
306 print <<END;
307 <table style='width:100%'>
308 <tr>
309 <td style='text-align:center;'>
310 <b>$Lang::tr{'legend'} :</b>
311 </td>
312 <td style='text-align:center; color:#FFFFFF; background-color:${Header::colourgreen}; font-weight:bold;'>
313 <b>$Lang::tr{'lan'}</b>
314 </td>
315 <td style='text-align:center; color:#FFFFFF; background-color:${Header::colourred};'>
316 <b>$Lang::tr{'internet'}</b>
317 </td>
318 <td style='text-align:center; color:#FFFFFF; background-color:${Header::colourorange};'>
319 <b>$Lang::tr{'dmz'}</b>
320 </td>
321 <td style='text-align:center; color:#FFFFFF; background-color:${Header::colourblue};'>
322 <b>$Lang::tr{'wireless'}</b>
323 </td>
324 <td style='text-align:center; color:#FFFFFF; background-color:${Header::colourfw};'>
325 <b>IPFire</b>
326 </td>
327 <td style='text-align:center; color:#FFFFFF; background-color:${Header::colourvpn};'>
328 <b>$Lang::tr{'vpn'}</b>
329 </td>
330 <td style='text-align:center; color:#FFFFFF; background-color:${Header::colourovpn};'>
331 <b>$Lang::tr{'OpenVPN'}</b>
332 </td>
333 <td style='text-align:center; color:#FFFFFF; background-color:$colour_multicast;'>
334 <b>Multicast</b>
335 </td>
336 </tr>
337 </table>
338 <br>
339 END
340
341 if ($SORT_FIELD and $SORT_ORDER) {
342 my @sort_field_name = (
343 $Lang::tr{'source ip'},
344 $Lang::tr{'destination ip'},
345 $Lang::tr{'source port'},
346 $Lang::tr{'destination port'},
347 $Lang::tr{'protocol'},
348 $Lang::tr{'connection'}.' '.$Lang::tr{'status'},
349 $Lang::tr{'expires'}.' ('.$Lang::tr{'seconds'}.')',
350 $Lang::tr{'download'},
351 $Lang::tr{'upload'}
352 );
353 my $sort_order_name;
354 if (lc($SORT_ORDER) eq "a") {
355 $sort_order_name = $Lang::tr{'sort ascending'};
356 } else {
357 $sort_order_name = $Lang::tr{'sort descending'};
358 }
359
360 print <<END
361 <div style="font-weight:bold;margin:10px;font-size: 70%">
362 $sort_order_name: $sort_field_name[$SORT_FIELD-1]
363 </div>
364 END
365 ;
366 }
367
368 # Print table header.
369 print <<END;
370 <table style='width:100%'>
371 <tr>
372 <th style='text-align:center'>
373 <a href="?sort_field=5&amp;sort_order=d"><img style="width:10px" src="/images/up.gif" alt=""></a>
374 <a href="?sort_field=5&amp;sort_order=a"><img style="width:10px" src="/images/down.gif" alt=""></a>
375 </th>
376 <th style='text-align:center' colspan='2'>
377 <a href="?sort_field=1&amp;sort_order=d"><img style="width:10px" src="/images/up.gif" alt=""></a>
378 <a href="?sort_field=1&amp;sort_order=a"><img style="width:10px" src="/images/down.gif" alt=""></a>
379 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
380 <a href="?sort_field=3&amp;sort_order=d"><img style="width:10px" src="/images/up.gif" alt=""></a>
381 <a href="?sort_field=3&amp;sort_order=a"><img style="width:10px" src="/images/down.gif" alt=""></a>
382 </th>
383 <th>&nbsp;</th>
384 <th style='text-align:center' colspan='2'>
385 <a href="?sort_field=2&amp;sort_order=d"><img style="width:10px" src="/images/up.gif" alt=""></a>
386 <a href="?sort_field=2&amp;sort_order=a"><img style="width:10px" src="/images/down.gif" alt=""></a>
387 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
388 <a href="?sort_field=4&amp;sort_order=d"><img style="width:10px" src="/images/up.gif" alt=""></a>
389 <a href="?sort_field=4&amp;sort_order=a"><img style="width:10px" src="/images/down.gif" alt=""></a>
390 </th>
391 <th>&nbsp;</th>
392 <th style='text-align:center'>
393 <a href="?sort_field=8&amp;sort_order=d"><img style="width:10px" src="/images/up.gif" alt=""></a>
394 <a href="?sort_field=8&amp;sort_order=a"><img style="width:10px" src="/images/down.gif" alt=""></a>
395 &nbsp;&nbsp;&nbsp;&nbsp;
396 <a href="?sort_field=9&amp;sort_order=d"><img style="width:10px" src="/images/up.gif" alt=""></a>
397 <a href="?sort_field=9&amp;sort_order=a"><img style="width:10px" src="/images/down.gif" alt=""></a>
398 </th>
399 <th style='text-align:center'>
400 <a href="?sort_field=6&amp;sort_order=d"><img style="width:10px" src="/images/up.gif" alt=""></a>
401 <a href="?sort_field=6&amp;sort_order=a"><img style="width:10px" src="/images/down.gif" alt=""></a>
402 </th>
403 <th style='text-align:center'>
404 <a href="?sort_field=7&amp;sort_order=d"><img style="width:10px" src="/images/up.gif" alt=""></a>
405 <a href="?sort_field=7&amp;sort_order=a"><img style="width:10px" src="/images/down.gif" alt=""></a>
406 </th>
407 </tr>
408 <tr>
409 <th style='text-align:center'>
410 $Lang::tr{'protocol'}
411 </th>
412 <th style='text-align:center' colspan='2'>
413 $Lang::tr{'source ip and port'}
414 </th>
415 <th style='text-align:center'>
416 $Lang::tr{'country'}
417 </th>
418 <th style='text-align:center' colspan='2'>
419 $Lang::tr{'dest ip and port'}
420 </th>
421 <th style='text-align:center'>
422 $Lang::tr{'country'}
423 </th>
424 <th style='text-align:center'>
425 $Lang::tr{'download'} /
426 <br>$Lang::tr{'upload'}
427 </th>
428 <th style='text-align:center'>
429 $Lang::tr{'connection'}<br>$Lang::tr{'status'}
430 </th>
431 <th style='text-align:center'>
432 $Lang::tr{'expires'}<br>($Lang::tr{'seconds'})
433 </th>
434 </tr>
435 END
436
437 foreach my $line (@conntrack) {
438 my @conn = split(' ', $line);
439
440 # The first bit is the l3 protocol.
441 my $l3proto = $conn[0];
442
443 # Skip everything that is not IPv4.
444 if ($l3proto ne 'ipv4') {
445 next;
446 }
447
448 # L4 protocol (tcp, udp, ...).
449 my $l4proto = $conn[2];
450
451 # Translate unknown protocols.
452 if ($l4proto eq 'unknown') {
453 my $l4protonum = $conn[3];
454 if ($l4protonum eq '2') {
455 $l4proto = 'IGMP';
456 } elsif ($l4protonum eq '4') {
457 $l4proto = 'IPv4 Encap';
458 } elsif ($l4protonum eq '33') {
459 $l4proto = 'DCCP';
460 } elsif ($l4protonum eq '41') {
461 $l4proto = 'IPv6 Encap';
462 } elsif ($l4protonum eq '50') {
463 $l4proto = 'ESP';
464 } elsif ($l4protonum eq '51') {
465 $l4proto = 'AH';
466 } elsif ($l4protonum eq '132') {
467 $l4proto = 'SCTP';
468 } else {
469 $l4proto = $l4protonum;
470 }
471 } else {
472 $l4proto = uc($l4proto);
473 }
474
475 # Source and destination.
476 my $sip;
477 my $sip_ret;
478 my $dip;
479 my $dip_ret;
480 my $sport;
481 my $sport_ret;
482 my $dport;
483 my $dport_ret;
484 my @packets;
485 my @bytes;
486
487 my $ttl = $conn[4];
488 my $state;
489 if ($l4proto eq 'TCP') {
490 $state = $conn[5];
491 }
492
493 # Kick out everything that is not IPv4.
494 foreach my $item (@conn) {
495 my ($key, $val) = split('=', $item);
496
497 switch ($key) {
498 case "src" {
499 if ($sip == "") {
500 $sip = $val;
501 } else {
502 $dip_ret = $val;
503 }
504 }
505 case "dst" {
506 if ($dip == "") {
507 $dip = $val;
508 } else {
509 $sip_ret = $val;
510 }
511 }
512 case "sport" {
513 if ($sport == "") {
514 $sport = $val;
515 } else {
516 $dport_ret = $val;
517 }
518 }
519 case "dport" {
520 if ($dport == "") {
521 $dport = $val;
522 } else {
523 $sport_ret = $val;
524 }
525 }
526 case "packets" {
527 push(@packets, $val);
528 }
529 case "bytes" {
530 push(@bytes, $val);
531 }
532 }
533 }
534
535 my $sip_colour = ipcolour($sip);
536 # use colour of destination network for DNAT
537 my $dip_colour = $dip ne $dip_ret ? ipcolour($dip_ret) : ipcolour($dip);
538
539 my $sserv = '';
540 if ($sport < 1024) {
541 $sserv = uc(getservbyport($sport, lc($l4proto)));
542 }
543
544 my $dserv = '';
545 if ($dport < 1024) {
546 $dserv = uc(getservbyport($dport, lc($l4proto)));
547 }
548
549 my $bytes_in = format_bytes($bytes[0]);
550 my $bytes_out = format_bytes($bytes[1]);
551
552 # enumerate GeoIP information
553 my $srcccode = &GeoIP::lookup($sip_ret);
554 my $src_flag_icon = &GeoIP::get_flag_icon($srcccode);
555 my $dstccode = &GeoIP::lookup($dip_ret);
556 my $dst_flag_icon = &GeoIP::get_flag_icon($dstccode);
557
558 # Format TTL
559 $ttl = format_time($ttl);
560
561 my $sip_extra;
562 if ($sip_ret && $sip ne $sip_ret) {
563 $sip_extra = "<span style='color:#FFFFFF;'>&gt;</span> ";
564 $sip_extra .= "<a href='/cgi-bin/ipinfo.cgi?ip=$sip_ret'>";
565 $sip_extra .= " <span style='color:#FFFFFF;'>$sip_ret</span>";
566 $sip_extra .= "</a>";
567 }
568
569 my $dip_extra;
570 if ($dip_ret && $dip ne $dip_ret) {
571 $dip_extra = "<span style='color:#FFFFFF;'>&gt;</span> ";
572 $dip_extra .= "<a href='/cgi-bin/ipinfo.cgi?ip=$dip_ret'>";
573 $dip_extra .= " <span style='color:#FFFFFF;'>$dip_ret</span>";
574 $dip_extra .= "</a>";
575 }
576
577
578 my $sport_extra;
579 if ($sport ne $sport_ret) {
580 my $sserv_ret = '';
581 if ($sport_ret < 1024) {
582 $sserv_ret = uc(getservbyport($sport_ret, lc($l4proto)));
583 }
584
585 $sport_extra = "<span style='color:#FFFFFF;'>&gt;</span> ";
586 $sport_extra .= "<a href='http://isc.sans.org/port_details.php?port=$sport_ret' target='top' title='$sserv_ret'>";
587 $sport_extra .= " <span style='color:#FFFFFF;'>$sport_ret</span>";
588 $sport_extra .= "</a>";
589 }
590
591 my $dport_extra;
592 if ($dport ne $dport_ret) {
593 my $dserv_ret = '';
594 if ($dport_ret < 1024) {
595 $dserv_ret = uc(getservbyport($dport_ret, lc($l4proto)));
596 }
597
598 $dport_extra = "<span style='color:#FFFFFF;'>&gt;</span> ";
599 $dport_extra .= "<a href='http://isc.sans.org/port_details.php?port=$dport_ret' target='top' title='$dserv_ret'>";
600 $dport_extra .= " <span style='color:#FFFFFF;'>$dport_ret</span>";
601 $dport_extra .= "</a>";
602 }
603
604 print <<END;
605 <tr>
606 <td style='text-align:center'>$l4proto</td>
607 <td style='text-align:center; background-color:$sip_colour;'>
608 <a href='/cgi-bin/ipinfo.cgi?ip=$sip'>
609 <span style='color:#FFFFFF;'>$sip</span>
610 </a>
611 $sip_extra
612 </td>
613 <td style='text-align:center; background-color:$sip_colour;'>
614 <a href='http://isc.sans.org/port_details.php?port=$sport' target='top' title='$sserv'>
615 <span style='color:#FFFFFF;'>$sport</span>
616 </a>
617 $sport_extra
618 </td>
619 <td style='text-align:center; background-color:$sip_colour;'>
620 <a href='country.cgi#$srcccode'><img src='$src_flag_icon' border='0' align='absmiddle' alt='$srcccode' title='$srcccode' /></a>
621 </td>
622 <td style='text-align:center; background-color:$dip_colour;'>
623 <a href='/cgi-bin/ipinfo.cgi?ip=$dip'>
624 <span style='color:#FFFFFF;'>$dip</span>
625 </a>
626 $dip_extra
627 </td>
628 <td style='text-align:center; background-color:$dip_colour;'>
629 <a href='http://isc.sans.org/port_details.php?port=$dport' target='top' title='$dserv'>
630 <span style='color:#FFFFFF;'>$dport</span>
631 </a>
632 $dport_extra
633 </td>
634 <td style='text-align:center; background-color:$sip_colour;'>
635 <a href='country.cgi#$dstccode'><img src='$dst_flag_icon' border='0' align='absmiddle' alt='$dstccode' title='$dstccode' /></a>
636 </td>
637 <td style='text-align:center'>
638 $bytes_in / $bytes_out
639 </td>
640 <td style='text-align:center'>$state</td>
641 <td style='text-align:center'>$ttl</td>
642 </tr>
643 END
644 }
645
646 # Close the main table.
647 print "</table>";
648
649 &Header::closebox();
650 &Header::closebigbox();
651 &Header::closepage();
652
653 sub format_bytes($) {
654 my $bytes = shift;
655 my @units = ("B", "k", "M", "G", "T");
656
657 foreach my $unit (@units) {
658 if ($bytes < 1024) {
659 return sprintf("%d%s", $bytes, $unit);
660 }
661
662 $bytes /= 1024;
663 }
664
665 return sprintf("%d%s", $bytes, $units[$#units]);
666 }
667
668 sub format_time($) {
669 my $time = shift;
670
671 my $seconds = $time % 60;
672 my $minutes = $time / 60;
673
674 my $hours = 0;
675 if ($minutes >= 60) {
676 $hours = $minutes / 60;
677 $minutes %= 60;
678 }
679
680 return sprintf("%3d:%02d:%02d", $hours, $minutes, $seconds);
681 }
682
683 sub ipcolour($) {
684 my $id = 0;
685 my $colour = ${Header::colourred};
686 my ($ip) = $_[0];
687 my $found = 0;
688
689 if ($ip) {
690 foreach my $line (@network) {
691 if ($network[$id] eq '') {
692 $id++;
693 } else {
694 if (!$found && ipv4_in_network($network[$id], $masklen[$id], $ip) ) {
695 $found = 1;
696 $colour = $colour[$id];
697 }
698 $id++;
699 }
700 }
701 }
702
703 return $colour;
704 }
705
706 1;