]>
git.ipfire.org Git - ipfire-2.x.git/blob - html/cgi-bin/connections.cgi
3 # (c) 2001 Jack Beglinger <jackb_guppy@yahoo.com>
5 # (c) 2003 Dave Roberts <countzerouk@hotmail.com> - colour coded netfilter/iptables rewrite for 1.3
7 # $Id: connections.cgi,v 1.6.2.11 2005/02/24 07:44:35 gespinasse Exp $
10 # Setup GREEN, ORANGE, IPCOP, VPN CIDR networks, masklengths and colours only once
16 use Net
::IPv4Addr
qw( :all );
20 # enable only the following on debugging purpose
22 #use CGI::Carp 'fatalsToBrowser';
24 require 'CONFIG_ROOT/general-functions.pl';
25 require "${General::swroot}/lang.pl";
26 require "${General::swroot}/header.pl";
28 #workaround to suppress a warning when a variable is used only once
29 my @dummy = ( ${Header
::table1colour
} );
35 &General
::readhash
("${General::swroot}/ethernet/settings", \
%netsettings);
37 open (ACTIVE
, "/proc/net/ip_conntrack") or die 'Unable to open ip_conntrack';
38 my @active = <ACTIVE
>;
42 open (ACTIVE
, "/proc/net/ipsec_eroute") and @vpn = <ACTIVE
>; close (ACTIVE
);
44 my $aliasfile = "${General::swroot}/ethernet/aliases";
45 open(ALIASES
, $aliasfile) or die 'Unable to open aliases file.';
46 my @aliases = <ALIASES
>;
49 # Add Green Firewall Interface
50 push(@network, $netsettings{'GREEN_ADDRESS'});
51 push(@masklen, "255.255.255.255" );
52 push(@colour, ${Header
::colourfw
} );
54 # Add Green Network to Array
55 push(@network, $netsettings{'GREEN_NETADDRESS'});
56 push(@masklen, $netsettings{'GREEN_NETMASK'} );
57 push(@colour, ${Header
::colourgreen
} );
59 # Add Green Routes to Array
60 my @routes = `/sbin/route -n | /bin/grep $netsettings{'GREEN_DEV'}`;
61 foreach my $route (@routes) {
63 my @temp = split(/[\t ]+/, $route);
64 push(@network, $temp[0]);
65 push(@masklen, $temp[2]);
66 push(@colour, ${Header
::colourgreen
} );
69 # Add Firewall Localhost 127.0.0.1
70 push(@network, '127.0.0.1');
71 push(@masklen, '255.255.255.255' );
72 push(@colour, ${Header
::colourfw
} );
75 if ($netsettings{'ORANGE_DEV'}) {
76 push(@network, $netsettings{'ORANGE_NETADDRESS'});
77 push(@masklen, $netsettings{'ORANGE_NETMASK'} );
78 push(@colour, ${Header
::colourorange
} );
79 # Add Orange Routes to Array
80 @routes = `/sbin/route -n | /bin/grep $netsettings{'ORANGE_DEV'}`;
81 foreach my $route (@routes) {
83 my @temp = split(/[\t ]+/, $route);
84 push(@network, $temp[0]);
85 push(@masklen, $temp[2]);
86 push(@colour, ${Header
::colourorange
} );
91 if ($netsettings{'BLUE_DEV'}) {
92 push(@network, $netsettings{'BLUE_NETADDRESS'});
93 push(@masklen, $netsettings{'BLUE_NETMASK'} );
94 push(@colour, ${Header
::colourblue
} );
95 # Add Blue Routes to Array
96 @routes = `/sbin/route -n | /bin/grep $netsettings{'BLUE_DEV'}`;
97 foreach my $route (@routes) {
99 my @temp = split(/[\t ]+/, $route);
100 push(@network, $temp[0]);
101 push(@masklen, $temp[2]);
102 push(@colour, ${Header
::colourblue
} );
106 # Add STATIC RED aliases
107 if ($netsettings{'RED_DEV'}) {
108 # We have a RED eth iface
109 if ($netsettings{'RED_TYPE'} eq 'STATIC') {
110 # We have a STATIC RED eth iface
111 foreach my $line (@aliases)
114 my @temp = split(/\,/,$line);
116 push(@network, $temp[0]);
117 push(@masklen, $netsettings{'RED_NETMASK'} );
118 push(@colour, ${Header
::colourfw
} );
125 if ( $vpn[0] ne 'none' ) {
126 foreach my $line (@vpn) {
127 my @temp = split(/[\t ]+/,$line);
128 my @temp1 = split(/[\/:]+/,$temp[3]);
129 push(@network, $temp1[0]);
130 push(@masklen, ipv4_cidr2msk
($temp1[1]));
131 push(@colour, ${Header
::colourvpn
} );
134 if (open(IP
, "${General::swroot}/red/local-ipaddress")) {
138 push(@network, $redip);
139 push(@masklen, '255.255.255.255' );
140 push(@colour, ${Header
::colourfw
} );
143 &Header
::showhttpheaders
();
144 &Header
::openpage
($Lang::tr
{'connections'}, 1, '');
145 &Header
::openbigbox
('100%', 'left');
146 &Header
::openbox
('100%', 'left', $Lang::tr
{'connection tracking'});
150 <tr><td align='center'><b>$Lang::tr{'legend'} : </b></td>
151 <td align='center' bgcolor='${Header::colourgreen}'><b><font color='#FFFFFF'>$Lang::tr{'lan'}</font></b></td>
152 <td align='center' bgcolor='${Header::colourred}'><b><font color='#FFFFFF'>$Lang::tr{'internet'}</font></b></td>
153 <td align='center' bgcolor='${Header::colourorange}'><b><font color='#FFFFFF'>$Lang::tr{'dmz'}</font></b></td>
154 <td align='center' bgcolor='${Header::colourblue}'><b><font color='#FFFFFF'>$Lang::tr{'wireless'}</font></b></td>
155 <td align='center' bgcolor='${Header::colourfw}'><b><font color='#FFFFFF'>IPCop</font></b></td>
156 <td align='center' bgcolor='${Header::colourvpn}'><b><font color='#FFFFFF'>$Lang::tr{'vpn'}</font></b></td>
160 <table cellpadding='2'>
161 <tr><td align='center'><b>$Lang::tr{'protocol'}</b></td>
162 <td align='center'><b>$Lang::tr{'expires'}<br />($Lang::tr{'seconds'})</b></td>
163 <td align='center'><b>$Lang::tr{'connection'}<br />$Lang::tr{'status'}</b></td>
164 <td align='center'><b>$Lang::tr{'original'}<br />$Lang::tr{'source ip and port'}</b></td>
165 <td align='center'><b>$Lang::tr{'original'}<br />$Lang::tr{'dest ip and port'}</b></td>
166 <td align='center'><b>$Lang::tr{'expected'}<br />$Lang::tr{'source ip and port'}</b></td>
167 <td align='center'><b>$Lang::tr{'expected'}<br />$Lang::tr{'dest ip and port'}</b></td>
168 <td align='center'><b>$Lang::tr{'marked'}</b></td>
169 <td align='center'><b>$Lang::tr{'use'}</b></td>
174 foreach my $line (@active)
195 my @temp = split(' ',$line);
196 print "<tr bgcolor='${Header::table1colour}'>\n";
197 if ($temp[0] eq 'udp') {
200 $protocol = $temp[0] . " (" . $temp[1] . ")";
203 $orgsip = substr $temp[3], 4;
204 $orgdip = substr $temp[4], 4;
205 $orgsp = substr $temp[5], 6;
206 $orgdp = substr $temp[6], 6;
207 if ($temp[7] eq '[UNREPLIED]') {
215 $exsip = substr $temp[7 + $offset], 4;
216 $exdip = substr $temp[8 + $offset], 4;
217 $exsp = substr $temp[9 + $offset], 6;
218 $exdp = substr $temp[10 + $offset], 6;
219 if ($marked eq '[UNREPLIED]') {
220 $use = substr $temp[11 + $offset], 4;
223 $marked = $temp[11 + $offset];
224 $use = substr $marked, 0, 3;
225 if ($use eq 'use' ) {
227 $use = substr $temp[11 + $offset], 4;
230 $use = substr $temp[12 + $offset], 4;
234 if ($temp[0] eq 'tcp') {
236 $protocol = $temp[0] . " (" . $temp[1] . ")";
238 $connstatus = $temp[3];
239 $orgsip = substr $temp[4], 4;
240 $orgdip = substr $temp[5], 4;
241 $orgsp = substr $temp[6], 6;
242 $orgdp = substr $temp[7], 6;
243 if ($temp[8] eq '[UNREPLIED]') {
246 $use = substr $temp[13], 4;
250 $use = substr $temp[13], 4;
253 $exsip = substr $temp[8 + $offset], 4;
254 $exdip = substr $temp[9 + $offset], 4;
255 $exsp = substr $temp[10 + $offset], 6;
256 $exdp = substr $temp[11 + $offset], 6;
258 if ($temp[0] eq 'unknown') {
260 $protocol = "??? (" . $temp[1] . ")";
261 $protocol = "esp (" . $temp[1] . ")" if ($temp[1] == 50);
262 $protocol = " ah (" . $temp[1] . ")" if ($temp[1] == 51);
265 $orgsip = substr $temp[3], 4;
266 $orgdip = substr $temp[4], 4;
269 $exsip = substr $temp[5], 4;
270 $exdip = substr $temp[6], 4;
276 if ($temp[0] eq 'gre') {
278 $protocol = $temp[0] . " (" . $temp[1] . ")";
280 $orgsip = substr $temp[5], 4;
281 $orgdip = substr $temp[6], 4;
284 $exsip = substr $temp[11], 4;
285 $exdip = substr $temp[12], 4;
291 $orgsipcolour = &ipcolour
($orgsip);
292 $orgdipcolour = &ipcolour
($orgdip);
293 $exsipcolour = &ipcolour
($exsip);
294 $exdipcolour = &ipcolour
($exdip);
296 <td align='center'>$protocol</td>
297 <td align='center'>$expires</td>
298 <td align='center'>$connstatus</td>
299 <td align='center' bgcolor='$orgsipcolour'><a href='/cgi-bin/ipinfo.cgi?ip=$orgsip'><font color='#FFFFFF'>$orgsip</font></a><font color='#FFFFFF'>:$orgsp</font></td>
300 <td align='center' bgcolor='$orgdipcolour'><a href='/cgi-bin/ipinfo.cgi?ip=$orgdip'><font color='#FFFFFF'>$orgdip</font></a><font color='#FFFFFF'>:$orgdp</font></td>
301 <td align='center' bgcolor='$exsipcolour'><a href='/cgi-bin/ipinfo.cgi?ip=$exsip'><font color='#FFFFFF'>$exsip</font></a><font color='#FFFFFF'>:$exsp</font></td>
302 <td align='center' bgcolor='$exdipcolour'><a href='/cgi-bin/ipinfo.cgi?ip=$exdip'><font color='#FFFFFF'>$exdip</font></a><font color='#FFFFFF'>:$exdp</font></td>
303 <td align='center'>$marked</td><td align='center'>$use</td>
311 &Header
::closebigbox
();
312 &Header
::closepage
();
317 my $colour = ${Header
::colourred
};
320 foreach $line (@network)
322 if (!$found && ipv4_in_network
( $network[$id] , $masklen[$id], $ip) ) {
324 $colour = $colour[$id];