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