]>
git.ipfire.org Git - people/teissler/ipfire-2.x.git/blob - html/cgi-bin/connections.cgi
2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2007-2012 IPFire Team <info@ipfire.org> #
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. #
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. #
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/>. #
20 ###############################################################################
24 use Net
::IPv4Addr
qw( :all );
27 # enable only the following on debugging purpose
29 #use CGI::Carp 'fatalsToBrowser';
31 require '/var/ipfire/general-functions.pl';
32 require "${General::swroot}/lang.pl";
33 require "${General::swroot}/header.pl";
35 &Header
::showhttpheaders
();
42 &General
::readhash
("${General::swroot}/ethernet/settings", \
%netsettings);
44 #workaround to suppress a warning when a variable is used only once
45 my @dummy = ( ${Header
::table1colour
} );
48 # Read the connection tracking table.
49 open(CONNTRACK
, "/usr/local/bin/getconntracktable | sort -k 5,5 --numeric-sort --reverse |") or die "Unable to read conntrack table";
50 my @conntrack = <CONNTRACK
>;
53 # Collect data for the @network array.
55 # Add Firewall Localhost 127.0.0.1
56 push(@network, '127.0.0.1');
57 push(@masklen, '255.255.255.255');
58 push(@colour, ${Header
::colourfw
});
60 if (open(IP
, "${General::swroot}/red/local-ipaddress")) {
65 push(@network, $redip);
66 push(@masklen, '255.255.255.255');
67 push(@colour, ${Header
::colourfw
});
70 # Add STATIC RED aliases
71 if ($netsettings{'RED_DEV'}) {
72 my $aliasfile = "${General::swroot}/ethernet/aliases";
73 open(ALIASES
, $aliasfile) or die 'Unable to open aliases file.';
74 my @aliases = <ALIASES
>;
77 # We have a RED eth iface
78 if ($netsettings{'RED_TYPE'} eq 'STATIC') {
79 # We have a STATIC RED eth iface
80 foreach my $line (@aliases) {
82 my @temp = split(/\,/,$line);
84 push(@network, $temp[0]);
85 push(@masklen, $netsettings{'RED_NETMASK'} );
86 push(@colour, ${Header
::colourfw
} );
92 # Add Green Firewall Interface
93 push(@network, $netsettings{'GREEN_ADDRESS'});
94 push(@masklen, "255.255.255.255" );
95 push(@colour, ${Header
::colourfw
} );
97 # Add Green Network to Array
98 push(@network, $netsettings{'GREEN_NETADDRESS'});
99 push(@masklen, $netsettings{'GREEN_NETMASK'} );
100 push(@colour, ${Header
::colourgreen
} );
102 # Add Green Routes to Array
103 my @routes = `/sbin/route -n | /bin/grep $netsettings{'GREEN_DEV'}`;
104 foreach my $route (@routes) {
106 my @temp = split(/[\t ]+/, $route);
107 push(@network, $temp[0]);
108 push(@masklen, $temp[2]);
109 push(@colour, ${Header
::colourgreen
} );
112 # Add Blue Firewall Interface
113 push(@network, $netsettings{'BLUE_ADDRESS'});
114 push(@masklen, "255.255.255.255" );
115 push(@colour, ${Header
::colourfw
} );
118 if ($netsettings{'BLUE_DEV'}) {
119 push(@network, $netsettings{'BLUE_NETADDRESS'});
120 push(@masklen, $netsettings{'BLUE_NETMASK'} );
121 push(@colour, ${Header
::colourblue
} );
123 # Add Blue Routes to Array
124 @routes = `/sbin/route -n | /bin/grep $netsettings{'BLUE_DEV'}`;
125 foreach my $route (@routes) {
127 my @temp = split(/[\t ]+/, $route);
128 push(@network, $temp[0]);
129 push(@masklen, $temp[2]);
130 push(@colour, ${Header
::colourblue
} );
135 if ($netsettings{'ORANGE_DEV'}) {
136 push(@network, $netsettings{'ORANGE_NETADDRESS'});
137 push(@masklen, $netsettings{'ORANGE_NETMASK'} );
138 push(@colour, ${Header
::colourorange
} );
139 # Add Orange Routes to Array
140 @routes = `/sbin/route -n | /bin/grep $netsettings{'ORANGE_DEV'}`;
141 foreach my $route (@routes) {
143 my @temp = split(/[\t ]+/, $route);
144 push(@network, $temp[0]);
145 push(@masklen, $temp[2]);
146 push(@colour, ${Header
::colourorange
} );
150 # Add OpenVPN net and RED/BLUE/ORANGE entry (when appropriate)
151 if (-e
"${General::swroot}/ovpn/settings") {
152 my %ovpnsettings = ();
153 &General
::readhash
("${General::swroot}/ovpn/settings", \
%ovpnsettings);
154 my @tempovpnsubnet = split("\/",$ovpnsettings{'DOVPN_SUBNET'});
157 push(@network, $tempovpnsubnet[0]);
158 push(@masklen, $tempovpnsubnet[1]);
159 push(@colour, ${Header
::colourovpn
} );
161 # add BLUE:port / proto
162 if (($ovpnsettings{'ENABLED_BLUE'} eq 'on') && $netsettings{'BLUE_DEV'}) {
163 push(@network, $netsettings{'BLUE_ADDRESS'} );
164 push(@masklen, '255.255.255.255' );
165 push(@colour, ${Header
::colourovpn
});
168 # add ORANGE:port / proto
169 if (($ovpnsettings{'ENABLED_ORANGE'} eq 'on') && $netsettings{'ORANGE_DEV'}) {
170 push(@network, $netsettings{'ORANGE_ADDRESS'} );
171 push(@masklen, '255.255.255.255' );
172 push(@colour, ${Header
::colourovpn
} );
176 open(IPSEC
, "${General::swroot}/var/ipfire/vpn/config");
180 foreach my $line (@ipsec) {
181 my @vpn = split(',', $line);
182 my ($network, $mask) = split("/", $vpn[12]);
184 if (!&General
::validip
($mask)) {
185 $mask = ipv4_cidr2msk
($mask);
188 push(@network, $network);
189 push(@masklen, $mask);
190 push(@colour, ${Header
::colourvpn
});
193 if (-e
"${General::swroot}/ovpn/n2nconf") {
194 open(OVPNN2N
, "${General::swroot}/ovpn/ovpnconfig");
195 my @ovpnn2n = <OVPNN2N
>;
198 foreach my $line (@ovpnn2n) {
199 my @ovpn = split(',', $line);
200 next if ($ovpn[4] ne 'net');
202 my ($network, $mask) = split("/", $ovpn[12]);
203 if (!&General
::validip
($mask)) {
204 $mask = ipv4_cidr2msk
($mask);
207 push(@network, $network);
208 push(@masklen, $mask);
209 push(@colour, ${Header
::colourovpn
});
214 &Header
::openpage
($Lang::tr
{'connections'}, 1, '');
215 &Header
::openbigbox
('100%', 'left');
216 &Header
::openbox
('100%', 'left', $Lang::tr
{'connection tracking'});
223 <b>$Lang::tr{'legend'} : </b>
225 <td align='center' bgcolor='${Header::colourgreen}'>
226 <b><font color='#FFFFFF'>$Lang::tr{'lan'}</font></b>
228 <td align='center' bgcolor='${Header::colourred}'>
229 <b><font color='#FFFFFF'>$Lang::tr{'internet'}</font></b>
231 <td align='center' bgcolor='${Header::colourorange}'>
232 <b><font color='#FFFFFF'>$Lang::tr{'dmz'}</font></b>
234 <td align='center' bgcolor='${Header::colourblue}'>
235 <b><font color='#FFFFFF'>$Lang::tr{'wireless'}</font></b>
237 <td align='center' bgcolor='${Header::colourfw}'>
238 <b><font color='#FFFFFF'>IPFire</font></b>
240 <td align='center' bgcolor='${Header::colourvpn}'>
241 <b><font color='#FFFFFF'>$Lang::tr{'vpn'}</font></b>
243 <td align='center' bgcolor='${Header::colourovpn}'>
244 <b><font color='#FFFFFF'>$Lang::tr{'OpenVPN'}</font></b>
251 # Print table header.
256 $Lang::tr{'protocol'}
259 $Lang::tr{'source ip and port'}
263 $Lang::tr{'dest ip and port'}
267 $Lang::tr{'download'} /
268 <br>$Lang::tr{'upload'}
271 $Lang::tr{'connection'}<br>$Lang::tr{'status'}
274 $Lang::tr{'expires'}<br>($Lang::tr{'seconds'})
279 foreach my $line (@conntrack) {
280 my @conn = split(' ', $line);
282 # The first bit is the l3 protocol.
283 my $l3proto = $conn[0];
285 # Skip everything that is not IPv4.
286 if ($l3proto ne 'ipv4') {
290 # L4 protocol (tcp, udp, ...).
291 my $l4proto = $conn[2];
293 if ($l4proto eq 'unknown') {
297 # Source and destination.
307 if ($l4proto eq 'tcp') {
311 # Kick out everything that is not IPv4.
312 foreach my $item (@conn) {
313 my ($key, $val) = split('=', $item);
329 push(@packets, $val);
337 my $sip_colour = ipcolour
($sip);
338 my $dip_colour = ipcolour
($dip);
342 $sserv = uc(getservbyport($sport, lc($l4proto)));
344 $sserv = " ($sserv)";
350 $dserv = uc(getservbyport($dport, lc($l4proto)));
352 $dserv = " ($dserv)";
356 my $bytes_in = format_bytes
($bytes[0]);
357 my $bytes_out = format_bytes
($bytes[1]);
360 $ttl = format_time
($ttl);
364 <td align='center'>$l4proto</td>
365 <td align='center' bgcolor='$sip_colour'>
366 <a href='/cgi-bin/ipinfo.cgi?ip=$sip'>
367 <font color='#FFFFFF'>$sip</font>
370 <td align='center' bgcolor='$sip_colour'>
371 <a href='http://isc.sans.org/port_details.php?port=$sport' target='top'>
372 <font color='#FFFFFF'>$sport$sserv</font>
375 <td align='center' bgcolor='$dip_colour'>
376 <a href='/cgi-bin/ipinfo.cgi?ip=$dip'>
377 <font color='#FFFFFF'>$dip</font>
380 <td align='center' bgcolor='$dip_colour'>
381 <a href='http://isc.sans.org/port_details.php?port=$dport' target='top'>
382 <font color='#FFFFFF'>$dport$dserv</font>
386 $bytes_in / $bytes_out
388 <td align='center'>$state</td>
389 <td align='center'>$ttl</td>
394 # Close the main table.
398 &Header
::closebigbox
();
399 &Header
::closepage
();
401 sub format_bytes
($) {
403 my @units = ("B", "k", "M", "G", "T");
405 foreach my $unit (@units) {
407 return sprintf("%d%s", $bytes, $unit);
413 return sprintf("%d%s", $bytes, $units[$#units]);
419 my $seconds = $time % 60;
420 my $minutes = $time / 60;
423 if ($minutes >= 60) {
424 $hours = $minutes / 60;
428 return sprintf("%3d:%02d:%02d", $hours, $minutes, $seconds);
433 my $colour = ${Header
::colourred
};
437 foreach my $line (@network) {
438 if ($network[$id] eq '') {
441 if (!$found && ipv4_in_network
($network[$id], $masklen[$id], $ip) ) {
443 $colour = $colour[$id];