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