]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - html/cgi-bin/connections.cgi
suricata: Change midstream policy to "pass-flow"
[people/pmueller/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}/location-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 # Call safe system_output function to get all available routes.
150 my @all_routes = &General::system_output("/sbin/route", "-n");
151
152 # Add Green Firewall Interface
153 push(@network, $netsettings{'GREEN_ADDRESS'});
154 push(@masklen, "255.255.255.255" );
155 push(@colour, ${Header::colourfw} );
156
157 # Add Green Network to Array
158 push(@network, $netsettings{'GREEN_NETADDRESS'});
159 push(@masklen, $netsettings{'GREEN_NETMASK'} );
160 push(@colour, ${Header::colourgreen} );
161
162 # Add Green Routes to Array
163 my @routes = grep (/$netsettings{'GREEN_DEV'}/, @all_routes);
164 foreach my $route (@routes) {
165 chomp($route);
166 my @temp = split(/[\t ]+/, $route);
167 push(@network, $temp[0]);
168 push(@masklen, $temp[2]);
169 push(@colour, ${Header::colourgreen} );
170 }
171
172 # Add Blue Firewall Interface
173 push(@network, $netsettings{'BLUE_ADDRESS'});
174 push(@masklen, "255.255.255.255" );
175 push(@colour, ${Header::colourfw} );
176
177 # Add Blue Network
178 if ($netsettings{'BLUE_DEV'}) {
179 push(@network, $netsettings{'BLUE_NETADDRESS'});
180 push(@masklen, $netsettings{'BLUE_NETMASK'} );
181 push(@colour, ${Header::colourblue} );
182
183 # Add Blue Routes to Array
184 @routes = grep(/$netsettings{'BLUE_DEV'}/, @all_routes);
185 foreach my $route (@routes) {
186 chomp($route);
187 my @temp = split(/[\t ]+/, $route);
188 push(@network, $temp[0]);
189 push(@masklen, $temp[2]);
190 push(@colour, ${Header::colourblue} );
191 }
192 }
193
194 # Add Orange Firewall Interface
195 push(@network, $netsettings{'ORANGE_ADDRESS'});
196 push(@masklen, "255.255.255.255" );
197 push(@colour, ${Header::colourfw} );
198
199 # Add Orange Network
200 if ($netsettings{'ORANGE_DEV'}) {
201 push(@network, $netsettings{'ORANGE_NETADDRESS'});
202 push(@masklen, $netsettings{'ORANGE_NETMASK'} );
203 push(@colour, ${Header::colourorange} );
204 # Add Orange Routes to Array
205 @routes = grep(/$netsettings{'ORANGE_DEV'}/, @all_routes);
206 foreach my $route (@routes) {
207 chomp($route);
208 my @temp = split(/[\t ]+/, $route);
209 push(@network, $temp[0]);
210 push(@masklen, $temp[2]);
211 push(@colour, ${Header::colourorange} );
212 }
213 }
214
215 # Highlight multicast connections.
216 push(@network, "224.0.0.0");
217 push(@masklen, "239.0.0.0");
218 push(@colour, $colour_multicast);
219
220 # Add OpenVPN net and RED/BLUE/ORANGE entry (when appropriate)
221 if (-e "${General::swroot}/ovpn/settings") {
222 my %ovpnsettings = ();
223 &General::readhash("${General::swroot}/ovpn/settings", \%ovpnsettings);
224 my @tempovpnsubnet = split("\/",$ovpnsettings{'DOVPN_SUBNET'});
225
226 # add OpenVPN net
227 push(@network, $tempovpnsubnet[0]);
228 push(@masklen, $tempovpnsubnet[1]);
229 push(@colour, ${Header::colourovpn} );
230
231 # add BLUE:port / proto
232 if (($ovpnsettings{'ENABLED_BLUE'} eq 'on') && $netsettings{'BLUE_DEV'}) {
233 push(@network, $netsettings{'BLUE_ADDRESS'} );
234 push(@masklen, '255.255.255.255' );
235 push(@colour, ${Header::colourovpn});
236 }
237
238 # add ORANGE:port / proto
239 if (($ovpnsettings{'ENABLED_ORANGE'} eq 'on') && $netsettings{'ORANGE_DEV'}) {
240 push(@network, $netsettings{'ORANGE_ADDRESS'} );
241 push(@masklen, '255.255.255.255' );
242 push(@colour, ${Header::colourovpn} );
243 }
244 }
245
246 # Add OpenVPN net for custom OVPNs
247 if (-e "${General::swroot}/ovpn/ccd.conf") {
248 open(OVPNSUB, "${General::swroot}/ovpn/ccd.conf");
249 my @ovpnsub = <OVPNSUB>;
250 close(OVPNSUB);
251
252 foreach (@ovpnsub) {
253 my ($network, $mask) = split '/', (split ',', $_)[2];
254
255 $mask = ipv4_cidr2msk($mask) unless &General::validip($mask);
256
257 push(@network, $network);
258 push(@masklen, $mask);
259 push(@colour, ${Header::colourovpn});
260 }
261 }
262
263 open(IPSEC, "${General::swroot}/vpn/config");
264 my @ipsec = <IPSEC>;
265 close(IPSEC);
266
267 foreach my $line (@ipsec) {
268 my @vpn = split(',', $line);
269
270 my @subnets = split(/\|/, $vpn[12]);
271 for my $subnet (@subnets) {
272 my ($network, $mask) = split("/", $subnet);
273
274 if (!&General::validip($mask)) {
275 $mask = ipv4_cidr2msk($mask);
276 }
277
278 push(@network, $network);
279 push(@masklen, $mask);
280 push(@colour, ${Header::colourvpn});
281 }
282 }
283
284 if (-e "${General::swroot}/ovpn/n2nconf") {
285 open(OVPNN2N, "${General::swroot}/ovpn/ovpnconfig");
286 my @ovpnn2n = <OVPNN2N>;
287 close(OVPNN2N);
288
289 foreach my $line (@ovpnn2n) {
290 my @ovpn = split(',', $line);
291 next if ($ovpn[4] ne 'net');
292
293 my ($network, $mask) = split("/", $ovpn[12]);
294 if (!&General::validip($mask)) {
295 $mask = ipv4_cidr2msk($mask);
296 }
297
298 push(@network, $network);
299 push(@masklen, $mask);
300 push(@colour, ${Header::colourovpn});
301 }
302 }
303
304 # Show the page.
305 &Header::openpage($Lang::tr{'connections'}, 1, '');
306 &Header::openbigbox('100%', 'left');
307 &Header::openbox('100%', 'left', $Lang::tr{'connection tracking'});
308
309 # Print legend.
310 print <<END;
311 <table style='width:100%'>
312 <tr>
313 <td style='text-align:center;'>
314 <b>$Lang::tr{'legend'} :</b>
315 </td>
316 <td style='text-align:center; color:#FFFFFF; background-color:${Header::colourgreen}; font-weight:bold;'>
317 <b>$Lang::tr{'lan'}</b>
318 </td>
319 <td style='text-align:center; color:#FFFFFF; background-color:${Header::colourred};'>
320 <b>$Lang::tr{'internet'}</b>
321 </td>
322 <td style='text-align:center; color:#FFFFFF; background-color:${Header::colourorange};'>
323 <b>$Lang::tr{'dmz'}</b>
324 </td>
325 <td style='text-align:center; color:#FFFFFF; background-color:${Header::colourblue};'>
326 <b>$Lang::tr{'wireless'}</b>
327 </td>
328 <td style='text-align:center; color:#FFFFFF; background-color:${Header::colourfw};'>
329 <b>IPFire</b>
330 </td>
331 <td style='text-align:center; color:#FFFFFF; background-color:${Header::colourvpn};'>
332 <b>$Lang::tr{'vpn'}</b>
333 </td>
334 <td style='text-align:center; color:#FFFFFF; background-color:${Header::colourovpn};'>
335 <b>$Lang::tr{'OpenVPN'}</b>
336 </td>
337 <td style='text-align:center; color:#FFFFFF; background-color:$colour_multicast;'>
338 <b>Multicast</b>
339 </td>
340 </tr>
341 </table>
342 <br>
343 END
344
345 if ($SORT_FIELD and $SORT_ORDER) {
346 my @sort_field_name = (
347 $Lang::tr{'source ip'},
348 $Lang::tr{'destination ip'},
349 $Lang::tr{'source port'},
350 $Lang::tr{'destination port'},
351 $Lang::tr{'protocol'},
352 $Lang::tr{'connection'}.' '.$Lang::tr{'status'},
353 $Lang::tr{'expires'}.' ('.$Lang::tr{'seconds'}.')',
354 $Lang::tr{'download'},
355 $Lang::tr{'upload'}
356 );
357 my $sort_order_name;
358 if (lc($SORT_ORDER) eq "a") {
359 $sort_order_name = $Lang::tr{'sort ascending'};
360 } else {
361 $sort_order_name = $Lang::tr{'sort descending'};
362 }
363
364 print <<END
365 <div style="font-weight:bold;margin:10px;font-size: 70%">
366 $sort_order_name: $sort_field_name[$SORT_FIELD-1]
367 </div>
368 END
369 ;
370 }
371
372 # Print table header.
373 print <<END;
374 <table style='width:100%'>
375 <tr>
376 <th style='text-align:center'>
377 <a href="?sort_field=5&amp;sort_order=d"><img style="width:10px" src="/images/up.gif" alt=""></a>
378 <a href="?sort_field=5&amp;sort_order=a"><img style="width:10px" src="/images/down.gif" alt=""></a>
379 </th>
380 <th style='text-align:center' colspan='2'>
381 <a href="?sort_field=1&amp;sort_order=d"><img style="width:10px" src="/images/up.gif" alt=""></a>
382 <a href="?sort_field=1&amp;sort_order=a"><img style="width:10px" src="/images/down.gif" alt=""></a>
383 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
384 <a href="?sort_field=3&amp;sort_order=d"><img style="width:10px" src="/images/up.gif" alt=""></a>
385 <a href="?sort_field=3&amp;sort_order=a"><img style="width:10px" src="/images/down.gif" alt=""></a>
386 </th>
387 <th>&nbsp;</th>
388 <th style='text-align:center' colspan='2'>
389 <a href="?sort_field=2&amp;sort_order=d"><img style="width:10px" src="/images/up.gif" alt=""></a>
390 <a href="?sort_field=2&amp;sort_order=a"><img style="width:10px" src="/images/down.gif" alt=""></a>
391 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
392 <a href="?sort_field=4&amp;sort_order=d"><img style="width:10px" src="/images/up.gif" alt=""></a>
393 <a href="?sort_field=4&amp;sort_order=a"><img style="width:10px" src="/images/down.gif" alt=""></a>
394 </th>
395 <th>&nbsp;</th>
396 <th style='text-align:center'>
397 <a href="?sort_field=8&amp;sort_order=d"><img style="width:10px" src="/images/up.gif" alt=""></a>
398 <a href="?sort_field=8&amp;sort_order=a"><img style="width:10px" src="/images/down.gif" alt=""></a>
399 &nbsp;&nbsp;&nbsp;&nbsp;
400 <a href="?sort_field=9&amp;sort_order=d"><img style="width:10px" src="/images/up.gif" alt=""></a>
401 <a href="?sort_field=9&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=6&amp;sort_order=d"><img style="width:10px" src="/images/up.gif" alt=""></a>
405 <a href="?sort_field=6&amp;sort_order=a"><img style="width:10px" src="/images/down.gif" alt=""></a>
406 </th>
407 <th style='text-align:center'>
408 <a href="?sort_field=7&amp;sort_order=d"><img style="width:10px" src="/images/up.gif" alt=""></a>
409 <a href="?sort_field=7&amp;sort_order=a"><img style="width:10px" src="/images/down.gif" alt=""></a>
410 </th>
411 </tr>
412 <tr>
413 <th style='text-align:center'>
414 $Lang::tr{'protocol'}
415 </th>
416 <th style='text-align:center' colspan='2'>
417 $Lang::tr{'source ip and port'}
418 </th>
419 <th style='text-align:center'>
420 $Lang::tr{'country'}
421 </th>
422 <th style='text-align:center' colspan='2'>
423 $Lang::tr{'dest ip and port'}
424 </th>
425 <th style='text-align:center'>
426 $Lang::tr{'country'}
427 </th>
428 <th style='text-align:center'>
429 $Lang::tr{'download'} /
430 <br>$Lang::tr{'upload'}
431 </th>
432 <th style='text-align:center'>
433 $Lang::tr{'connection'}<br>$Lang::tr{'status'}
434 </th>
435 <th style='text-align:center'>
436 $Lang::tr{'expires'}<br>($Lang::tr{'seconds'})
437 </th>
438 </tr>
439 END
440
441 foreach my $line (@conntrack) {
442 my @conn = split(' ', $line);
443
444 # The first bit is the l3 protocol.
445 my $l3proto = $conn[0];
446
447 # Skip everything that is not IPv4.
448 if ($l3proto ne 'ipv4') {
449 next;
450 }
451
452 # L4 protocol (tcp, udp, ...).
453 my $l4proto = $conn[2];
454
455 # Translate unknown protocols.
456 if ($l4proto eq 'unknown') {
457 my $l4protonum = $conn[3];
458 if ($l4protonum eq '2') {
459 $l4proto = 'IGMP';
460 } elsif ($l4protonum eq '4') {
461 $l4proto = 'IPv4 Encap';
462 } elsif ($l4protonum eq '33') {
463 $l4proto = 'DCCP';
464 } elsif ($l4protonum eq '41') {
465 $l4proto = 'IPv6 Encap';
466 } elsif ($l4protonum eq '50') {
467 $l4proto = 'ESP';
468 } elsif ($l4protonum eq '51') {
469 $l4proto = 'AH';
470 } elsif ($l4protonum eq '132') {
471 $l4proto = 'SCTP';
472 } else {
473 $l4proto = $l4protonum;
474 }
475 } else {
476 $l4proto = uc($l4proto);
477 }
478
479 # Source and destination.
480 my $sip;
481 my $sip_ret;
482 my $dip;
483 my $dip_ret;
484 my $sport;
485 my $sport_ret;
486 my $dport;
487 my $dport_ret;
488 my @packets;
489 my @bytes;
490
491 my $ttl = $conn[4];
492 my $state;
493 if ($l4proto eq 'TCP') {
494 $state = $conn[5];
495 }
496
497 # Kick out everything that is not IPv4.
498 foreach my $item (@conn) {
499 my ($key, $val) = split('=', $item);
500
501 switch ($key) {
502 case "src" {
503 if ($sip == "") {
504 $sip = $val;
505 } else {
506 $dip_ret = $val;
507 }
508 }
509 case "dst" {
510 if ($dip == "") {
511 $dip = $val;
512 } else {
513 $sip_ret = $val;
514 }
515 }
516 case "sport" {
517 if ($sport == "") {
518 $sport = $val;
519 } else {
520 $dport_ret = $val;
521 }
522 }
523 case "dport" {
524 if ($dport == "") {
525 $dport = $val;
526 } else {
527 $sport_ret = $val;
528 }
529 }
530 case "packets" {
531 push(@packets, $val);
532 }
533 case "bytes" {
534 push(@bytes, $val);
535 }
536 }
537 }
538
539 my $sip_colour = ipcolour($sip);
540 # use colour of destination network for DNAT
541 my $dip_colour = $dip ne $dip_ret ? ipcolour($dip_ret) : ipcolour($dip);
542
543 my $sserv = '';
544 if ($sport < 1024) {
545 $sserv = uc(getservbyport($sport, lc($l4proto)));
546 }
547
548 my $dserv = '';
549 if ($dport < 1024) {
550 $dserv = uc(getservbyport($dport, lc($l4proto)));
551 }
552
553 my $bytes_in = format_bytes($bytes[0]);
554 my $bytes_out = format_bytes($bytes[1]);
555
556 # enumerate location information
557 my $srcccode = &Location::Functions::lookup_country_code($sip_ret);
558 my $src_flag_icon = &Location::Functions::get_flag_icon($srcccode);
559 my $dstccode = &Location::Functions::lookup_country_code($dip_ret);
560 my $dst_flag_icon = &Location::Functions::get_flag_icon($dstccode);
561
562 # Format TTL
563 $ttl = format_time($ttl);
564
565 my $sip_extra;
566 if ($sip_ret && $sip ne $sip_ret) {
567 $sip_extra = "<span style='color:#FFFFFF;'>&gt;</span> ";
568 $sip_extra .= "<a href='/cgi-bin/ipinfo.cgi?ip=$sip_ret'>";
569 $sip_extra .= " <span style='color:#FFFFFF;'>$sip_ret</span>";
570 $sip_extra .= "</a>";
571 }
572
573 my $dip_extra;
574 if ($dip_ret && $dip ne $dip_ret) {
575 $dip_extra = "<span style='color:#FFFFFF;'>&gt;</span> ";
576 $dip_extra .= "<a href='/cgi-bin/ipinfo.cgi?ip=$dip_ret'>";
577 $dip_extra .= " <span style='color:#FFFFFF;'>$dip_ret</span>";
578 $dip_extra .= "</a>";
579 }
580
581
582 my $sport_extra;
583 if ($sport ne $sport_ret) {
584 my $sserv_ret = '';
585 if ($sport_ret < 1024) {
586 $sserv_ret = uc(getservbyport($sport_ret, lc($l4proto)));
587 }
588
589 $sport_extra = "<span style='color:#FFFFFF;'>&gt;</span> ";
590 $sport_extra .= "<a href='http://isc.sans.org/port_details.php?port=$sport_ret' target='top' title='$sserv_ret'>";
591 $sport_extra .= " <span style='color:#FFFFFF;'>$sport_ret</span>";
592 $sport_extra .= "</a>";
593 }
594
595 my $dport_extra;
596 if ($dport ne $dport_ret) {
597 my $dserv_ret = '';
598 if ($dport_ret < 1024) {
599 $dserv_ret = uc(getservbyport($dport_ret, lc($l4proto)));
600 }
601
602 $dport_extra = "<span style='color:#FFFFFF;'>&gt;</span> ";
603 $dport_extra .= "<a href='http://isc.sans.org/port_details.php?port=$dport_ret' target='top' title='$dserv_ret'>";
604 $dport_extra .= " <span style='color:#FFFFFF;'>$dport_ret</span>";
605 $dport_extra .= "</a>";
606 }
607
608 print <<END;
609 <tr>
610 <td style='text-align:center'>$l4proto</td>
611 <td style='text-align:center; background-color:$sip_colour;'>
612 <a href='/cgi-bin/ipinfo.cgi?ip=$sip'>
613 <span style='color:#FFFFFF;'>$sip</span>
614 </a>
615 $sip_extra
616 </td>
617 <td style='text-align:center; background-color:$sip_colour;'>
618 <a href='http://isc.sans.org/port_details.php?port=$sport' target='top' title='$sserv'>
619 <span style='color:#FFFFFF;'>$sport</span>
620 </a>
621 $sport_extra
622 </td>
623 <td style='text-align:center; background-color:$sip_colour;'>
624 <a href='country.cgi#$srcccode'><img src='$src_flag_icon' border='0' align='absmiddle' alt='$srcccode' title='$srcccode' /></a>
625 </td>
626 <td style='text-align:center; background-color:$dip_colour;'>
627 <a href='/cgi-bin/ipinfo.cgi?ip=$dip'>
628 <span style='color:#FFFFFF;'>$dip</span>
629 </a>
630 $dip_extra
631 </td>
632 <td style='text-align:center; background-color:$dip_colour;'>
633 <a href='http://isc.sans.org/port_details.php?port=$dport' target='top' title='$dserv'>
634 <span style='color:#FFFFFF;'>$dport</span>
635 </a>
636 $dport_extra
637 </td>
638 <td style='text-align:center; background-color:$sip_colour;'>
639 <a href='country.cgi#$dstccode'><img src='$dst_flag_icon' border='0' align='absmiddle' alt='$dstccode' title='$dstccode' /></a>
640 </td>
641 <td style='text-align:center'>
642 $bytes_in / $bytes_out
643 </td>
644 <td style='text-align:center'>$state</td>
645 <td style='text-align:center'>$ttl</td>
646 </tr>
647 END
648 }
649
650 # Close the main table.
651 print "</table>";
652
653 &Header::closebox();
654 &Header::closebigbox();
655 &Header::closepage();
656
657 sub format_bytes($) {
658 my $bytes = shift;
659 my @units = ("B", "k", "M", "G", "T");
660
661 foreach my $unit (@units) {
662 if ($bytes < 1024) {
663 return sprintf("%d%s", $bytes, $unit);
664 }
665
666 $bytes /= 1024;
667 }
668
669 return sprintf("%d%s", $bytes, $units[$#units]);
670 }
671
672 sub format_time($) {
673 my $time = shift;
674
675 my $seconds = $time % 60;
676 my $minutes = $time / 60;
677
678 my $hours = 0;
679 if ($minutes >= 60) {
680 $hours = $minutes / 60;
681 $minutes %= 60;
682 }
683
684 return sprintf("%3d:%02d:%02d", $hours, $minutes, $seconds);
685 }
686
687 sub ipcolour($) {
688 my $id = 0;
689 my $colour = ${Header::colourred};
690 my ($ip) = $_[0];
691 my $found = 0;
692
693 if ($ip) {
694 foreach my $line (@network) {
695 if ($network[$id] eq '') {
696 $id++;
697 } else {
698 if (!$found && ipv4_in_network($network[$id], $masklen[$id], $ip) ) {
699 $found = 1;
700 $colour = $colour[$id];
701 }
702 $id++;
703 }
704 }
705 }
706
707 return $colour;
708 }
709
710 1;