]>
Commit | Line | Data |
---|---|---|
1 | #!/usr/bin/perl | |
2 | # | |
3 | # (c) 2001 Jack Beglinger <jackb_guppy@yahoo.com> | |
4 | # | |
5 | # (c) 2003 Dave Roberts <countzerouk@hotmail.com> - colour coded netfilter/iptables rewrite for 1.3 | |
6 | # | |
7 | # (c) 2006 Franck - add sorting+filtering capability | |
8 | # | |
9 | # $Id: connections.cgi,v 1.6.2.12 2006/02/27 19:48:46 franck78 Exp $ | |
10 | # | |
11 | ||
12 | # Setup GREEN, ORANGE, IPCOP, VPN CIDR networks, masklengths and colours only once | |
13 | ||
14 | my @network=(); | |
15 | my @masklen=(); | |
16 | my @colour=(); | |
17 | ||
18 | use Net::IPv4Addr qw( :all ); | |
19 | ||
20 | use strict; | |
21 | ||
22 | # enable only the following on debugging purpose | |
23 | #use warnings; | |
24 | #use CGI::Carp 'fatalsToBrowser'; | |
25 | ||
26 | require 'CONFIG_ROOT/general-functions.pl'; | |
27 | require "${General::swroot}/lang.pl"; | |
28 | require "${General::swroot}/header.pl"; | |
29 | ||
30 | #workaround to suppress a warning when a variable is used only once | |
31 | my @dummy = ( ${Header::table1colour} ); | |
32 | undef (@dummy); | |
33 | ||
34 | # Read various files | |
35 | ||
36 | my %netsettings=(); | |
37 | &General::readhash("${General::swroot}/ethernet/settings", \%netsettings); | |
38 | ||
39 | open (ACTIVE, "/proc/net/ip_conntrack") or die 'Unable to open ip_conntrack'; | |
40 | my @active = <ACTIVE>; | |
41 | close (ACTIVE); | |
42 | ||
43 | my @vpn = ('none'); | |
44 | open (ACTIVE, "/proc/net/ipsec_eroute") and @vpn = <ACTIVE>; | |
45 | close (ACTIVE); | |
46 | ||
47 | my $aliasfile = "${General::swroot}/ethernet/aliases"; | |
48 | open(ALIASES, $aliasfile) or die 'Unable to open aliases file.'; | |
49 | my @aliases = <ALIASES>; | |
50 | close(ALIASES); | |
51 | ||
52 | # Add Green Firewall Interface | |
53 | push(@network, $netsettings{'GREEN_ADDRESS'}); | |
54 | push(@masklen, "255.255.255.255" ); | |
55 | push(@colour, ${Header::colourfw} ); | |
56 | ||
57 | # Add Green Network to Array | |
58 | push(@network, $netsettings{'GREEN_NETADDRESS'}); | |
59 | push(@masklen, $netsettings{'GREEN_NETMASK'} ); | |
60 | push(@colour, ${Header::colourgreen} ); | |
61 | ||
62 | # Add Green Routes to Array | |
63 | my @routes = `/sbin/route -n | /bin/grep $netsettings{'GREEN_DEV'}`; | |
64 | foreach my $route (@routes) { | |
65 | chomp($route); | |
66 | my @temp = split(/[\t ]+/, $route); | |
67 | push(@network, $temp[0]); | |
68 | push(@masklen, $temp[2]); | |
69 | push(@colour, ${Header::colourgreen} ); | |
70 | } | |
71 | ||
72 | # Add Firewall Localhost 127.0.0.1 | |
73 | push(@network, '127.0.0.1'); | |
74 | push(@masklen, '255.255.255.255' ); | |
75 | push(@colour, ${Header::colourfw} ); | |
76 | ||
77 | # Add OpenVPN net and RED/BLUE/ORANGE entry (when appropriate) | |
78 | if (-e "${General::swroot}/ovpn/settings") { | |
79 | my %ovpnsettings = (); | |
80 | &General::readhash("${General::swroot}/ovpn/settings", \%ovpnsettings); | |
81 | my @tempovpnsubnet = split("\/",$ovpnsettings{'DOVPN_SUBNET'}); | |
82 | ||
83 | # add OpenVPN net | |
84 | push(@network, $tempovpnsubnet[0]); | |
85 | push(@masklen, $tempovpnsubnet[1]); | |
86 | push(@colour, ${Header::colourovpn} ); | |
87 | push(@ports, '0' ); | |
88 | push(@protocols, '' ); | |
89 | ||
90 | if ( ($ovpnsettings{'ENABLED'} eq 'on') && open(IP, "${General::swroot}/red/local-ipaddress") ) { | |
91 | # add RED:port / proto | |
92 | my $redip = <IP>; | |
93 | close(IP); | |
94 | chomp $redip; | |
95 | push(@network, $redip ); | |
96 | push(@masklen, '255.255.255.255' ); | |
97 | push(@colour, ${Header::colourovpn} ); | |
98 | push(@ports, $ovpnsettings{'DDEST_PORT'} ); | |
99 | push(@protocols, $ovpnsettings{'DPROTOCOL'} ); | |
100 | } | |
101 | if ( ($ovpnsettings{'ENABLED_BLUE'} eq 'on') && $netsettings{'BLUE_DEV'} ) { | |
102 | # add BLUE:port / proto | |
103 | push(@network, $netsettings{'BLUE_ADDRESS'} ); | |
104 | push(@masklen, '255.255.255.255' ); | |
105 | push(@colour, ${Header::colourovpn} ); | |
106 | push(@ports, $ovpnsettings{'DDEST_PORT'} ); | |
107 | push(@protocols, $ovpnsettings{'DPROTOCOL'} ); | |
108 | } | |
109 | if ( ($ovpnsettings{'ENABLED_ORANGE'} eq 'on') && $netsettings{'ORANGE_DEV'} ) { | |
110 | # add ORANGE:port / proto | |
111 | push(@network, $netsettings{'ORANGE_ADDRESS'} ); | |
112 | push(@masklen, '255.255.255.255' ); | |
113 | push(@colour, ${Header::colourovpn} ); | |
114 | push(@ports, $ovpnsettings{'DDEST_PORT'} ); | |
115 | push(@protocols, $ovpnsettings{'DPROTOCOL'} ); | |
116 | } | |
117 | } | |
118 | ||
119 | # Add Orange Network | |
120 | if ($netsettings{'ORANGE_DEV'}) { | |
121 | push(@network, $netsettings{'ORANGE_NETADDRESS'}); | |
122 | push(@masklen, $netsettings{'ORANGE_NETMASK'} ); | |
123 | push(@colour, ${Header::colourorange} ); | |
124 | # Add Orange Routes to Array | |
125 | @routes = `/sbin/route -n | /bin/grep $netsettings{'ORANGE_DEV'}`; | |
126 | foreach my $route (@routes) { | |
127 | chomp($route); | |
128 | my @temp = split(/[\t ]+/, $route); | |
129 | push(@network, $temp[0]); | |
130 | push(@masklen, $temp[2]); | |
131 | push(@colour, ${Header::colourorange} ); | |
132 | } | |
133 | } | |
134 | ||
135 | # Add Blue Network | |
136 | if ($netsettings{'BLUE_DEV'}) { | |
137 | push(@network, $netsettings{'BLUE_NETADDRESS'}); | |
138 | push(@masklen, $netsettings{'BLUE_NETMASK'} ); | |
139 | push(@colour, ${Header::colourblue} ); | |
140 | # Add Blue Routes to Array | |
141 | @routes = `/sbin/route -n | /bin/grep $netsettings{'BLUE_DEV'}`; | |
142 | foreach my $route (@routes) { | |
143 | chomp($route); | |
144 | my @temp = split(/[\t ]+/, $route); | |
145 | push(@network, $temp[0]); | |
146 | push(@masklen, $temp[2]); | |
147 | push(@colour, ${Header::colourblue} ); | |
148 | } | |
149 | } | |
150 | ||
151 | # Add STATIC RED aliases | |
152 | if ($netsettings{'RED_DEV'}) { | |
153 | # We have a RED eth iface | |
154 | if ($netsettings{'RED_TYPE'} eq 'STATIC') { | |
155 | # We have a STATIC RED eth iface | |
156 | foreach my $line (@aliases) | |
157 | { | |
158 | chomp($line); | |
159 | my @temp = split(/\,/,$line); | |
160 | if ( $temp[0] ) { | |
161 | push(@network, $temp[0]); | |
162 | push(@masklen, $netsettings{'RED_NETMASK'} ); | |
163 | push(@colour, ${Header::colourfw} ); | |
164 | } | |
165 | } | |
166 | } | |
167 | } | |
168 | ||
169 | # Add VPNs | |
170 | if ( $vpn[0] ne 'none' ) { | |
171 | foreach my $line (@vpn) { | |
172 | my @temp = split(/[\t ]+/,$line); | |
173 | my @temp1 = split(/[\/:]+/,$temp[3]); | |
174 | push(@network, $temp1[0]); | |
175 | push(@masklen, ipv4_cidr2msk($temp1[1])); | |
176 | push(@colour, ${Header::colourvpn} ); | |
177 | } | |
178 | } | |
179 | if (open(IP, "${General::swroot}/red/local-ipaddress")) { | |
180 | my $redip = <IP>; | |
181 | close(IP); | |
182 | chomp $redip; | |
183 | push(@network, $redip); | |
184 | push(@masklen, '255.255.255.255' ); | |
185 | push(@colour, ${Header::colourfw} ); | |
186 | } | |
187 | ||
188 | ||
189 | #Establish simple filtering&sorting boxes on top of table | |
190 | ||
191 | our %cgiparams; | |
192 | &Header::getcgihash(\%cgiparams); | |
193 | ||
194 | my @list_proto = ($Lang::tr{'all'}, 'icmp', 'udp', 'tcp'); | |
195 | my @list_state = ($Lang::tr{'all'}, 'SYN_SENT', 'SYN_RECV', 'ESTABLISHED', 'FIN_WAIT', | |
196 | 'CLOSE_WAIT', 'LAST_ACK', 'TIME_WAIT', 'CLOSE', 'LISTEN'); | |
197 | my @list_mark = ($Lang::tr{'all'}, '[ASSURED]', '[UNREPLIED]'); | |
198 | my @list_sort = ('orgsip','protocol', 'expires', 'status', 'orgdip', 'orgsp', | |
199 | 'orgdp', 'exsip', 'exdip', 'exsp', 'exdp'); | |
200 | ||
201 | # init or silently correct unknown value... | |
202 | if ( ! grep ( /^$cgiparams{'SEE_PROTO'}$/ , @list_proto )) { $cgiparams{'SEE_PROTO'} = $list_proto[0] }; | |
203 | if ( ! grep ( /^$cgiparams{'SEE_STATE'}$/ , @list_state )) { $cgiparams{'SEE_STATE'} = $list_state[0] }; | |
204 | if ( ! grep ( /^$cgiparams{'SEE_MARK'}$/ , @list_mark )) { $cgiparams{'SEE_MARK'} = $list_mark[0] }; | |
205 | if ( ! grep ( /^$cgiparams{'SEE_SORT'}$/ , @list_sort )) { $cgiparams{'SEE_SORT'} = $list_sort[0] }; | |
206 | # *.*.*.* or a valid IP | |
207 | if ( $cgiparams{'SEE_SRC'} !~ /^(\*\.\*\.\*\.\*\.|\d+\.\d+\.\d+\.\d+)$/) { $cgiparams{'SEE_SRC'} = '*.*.*.*' }; | |
208 | if ( $cgiparams{'SEE_DEST'} !~ /^(\*\.\*\.\*\.\*\.|\d+\.\d+\.\d+\.\d+)$/) { $cgiparams{'SEE_DEST'} = '*.*.*.*' }; | |
209 | ||
210 | ||
211 | our %entries = (); # will hold the lines analyzed correctly | |
212 | my $unknownlines = ''; # should be empty all the time... | |
213 | my $index = 0; # just a counter to make unique entryies in entries | |
214 | ||
215 | foreach my $line (@active) { | |
216 | my $protocol=''; | |
217 | my $expires=''; | |
218 | my $status=''; | |
219 | my $orgsip=''; | |
220 | my $orgdip=''; | |
221 | my $orgsp=''; | |
222 | my $orgdp=''; | |
223 | my $exsip=''; | |
224 | my $exdip=''; | |
225 | my $exsp=''; | |
226 | my $exdp=''; | |
227 | my $marked=''; | |
228 | my $use=''; | |
229 | ||
230 | chomp($line); | |
231 | my @temp = split(' ',$line); | |
232 | ||
233 | if ($temp[0] eq 'icmp') { | |
234 | $protocol = $temp[0]; | |
235 | $status = $Lang::tr{'all'}; | |
236 | $orgsip = substr $temp[3], 4; | |
237 | $orgdip = substr $temp[4], 4; | |
238 | $marked = $temp[8] eq '[UNREPLIED]' ? '[UNREPLIED]' : ' '; | |
239 | } | |
240 | if ($temp[0] eq 'udp') { | |
241 | $protocol = $temp[0]; | |
242 | $status = $Lang::tr{'all'}; | |
243 | $orgsip = substr $temp[3], 4; | |
244 | $orgdip = substr $temp[4], 4; | |
245 | $marked = $temp[7] eq '[UNREPLIED]' ? '[UNREPLIED]' : defined ($temp[12]) ? $temp[11] : ' '; | |
246 | } | |
247 | if ($temp[0] eq 'tcp') { | |
248 | $protocol = $temp[0]; | |
249 | $status = $temp[3]; | |
250 | $orgsip = substr $temp[4], 4; | |
251 | $orgdip = substr $temp[5], 4; | |
252 | $marked = $temp[8] eq '[UNREPLIED]' ? '[UNREPLIED]' : defined ($temp[13]) ? $temp[12] : ' '; | |
253 | } | |
254 | ||
255 | # filter the line if we found a known proto | |
256 | next if( !( | |
257 | (($cgiparams{'SEE_PROTO'} eq $Lang::tr{'all'}) || ($protocol eq $cgiparams{'SEE_PROTO'} )) | |
258 | && (($cgiparams{'SEE_STATE'} eq $Lang::tr{'all'}) || ($status eq $cgiparams{'SEE_STATE'} )) | |
259 | && (($cgiparams{'SEE_MARK'} eq $Lang::tr{'all'}) || ($marked eq $cgiparams{'SEE_MARK'} )) | |
260 | && (($cgiparams{'SEE_SRC'} eq "*.*.*.*") || ($orgsip eq $cgiparams{'SEE_SRC'} )) | |
261 | && (($cgiparams{'SEE_DEST'} eq "*.*.*.*") || ($orgdip eq $cgiparams{'SEE_DEST'} )) | |
262 | )); | |
263 | ||
264 | if ($temp[0] eq 'icmp') { | |
265 | my $offset = 0; | |
266 | $protocol = $temp[0] . " (" . $temp[1] . ")"; | |
267 | $expires = $temp[2]; | |
268 | $status = ' '; | |
269 | if ($temp[8] eq '[UNREPLIED]' ) { | |
270 | $offset = +1; | |
271 | } | |
272 | $orgsip = substr $temp[3], 4; | |
273 | $orgdip = substr $temp[4], 4; | |
274 | $orgsp = &General::GetIcmpDescription(substr( $temp[5], 5)) . "/" . substr( $temp[6], 5);; | |
275 | $orgdp = 'id=' . substr( $temp[7], 3); | |
276 | $exsip = substr $temp[8 + $offset], 4; | |
277 | $exdip = substr $temp[9 + $offset], 4; | |
278 | $exsp = &General::GetIcmpDescription(substr( $temp[10 + $offset], 5)). "/" . substr( $temp[11 + $offset], 5); | |
279 | $exdp = 'id=' . substr( $temp[11 + $offset], 5); | |
280 | $marked = $temp[8] eq '[UNREPLIED]' ? '[UNREPLIED]' : ' '; | |
281 | $use = substr( $temp[13 + $offset], 4 ); | |
282 | } | |
283 | if ($temp[0] eq 'udp') { | |
284 | my $offset = 0; | |
285 | $marked = ''; | |
286 | $protocol = $temp[0] . " (" . $temp[1] . ")"; | |
287 | $expires = $temp[2]; | |
288 | $status = ' '; | |
289 | $orgsip = substr $temp[3], 4; | |
290 | $orgdip = substr $temp[4], 4; | |
291 | $orgsp = substr $temp[5], 6; | |
292 | $orgdp = substr $temp[6], 6; | |
293 | if ($temp[7] eq '[UNREPLIED]') { | |
294 | $offset = 1; | |
295 | $marked = $temp[7]; | |
296 | $use = substr $temp[12], 4; | |
297 | } else { | |
298 | if ((substr $temp[11], 0, 3) eq 'use' ) { | |
299 | $marked = ''; | |
300 | $use = substr $temp[11], 4; | |
301 | } else { | |
302 | $marked = $temp[11]; | |
303 | $use = substr $temp[12], 4; | |
304 | } | |
305 | } | |
306 | $exsip = substr $temp[7 + $offset], 4; | |
307 | $exdip = substr $temp[8 + $offset], 4; | |
308 | $exsp = substr $temp[9 + $offset], 6; | |
309 | $exdp = substr $temp[10 + $offset], 6; | |
310 | } | |
311 | if ($temp[0] eq 'tcp') { | |
312 | my $offset = 0; | |
313 | $protocol = $temp[0] . " (" . $temp[1] . ")"; | |
314 | $expires = $temp[2]; | |
315 | $status = $temp[3]; | |
316 | $orgsip = substr $temp[4], 4; | |
317 | $orgdip = substr $temp[5], 4; | |
318 | $orgsp = substr $temp[6], 6; | |
319 | $orgdp = substr $temp[7], 6; | |
320 | if ($temp[8] eq '[UNREPLIED]') { | |
321 | $marked = $temp[8]; | |
322 | $offset = 1; | |
323 | } else { | |
324 | $marked = $temp[12]; | |
325 | } | |
326 | $exsip = substr $temp[8 + $offset], 4; | |
327 | $exdip = substr $temp[9 + $offset], 4; | |
328 | $exsp = substr $temp[10 + $offset], 6; | |
329 | $exdp = substr $temp[11 + $offset], 6; | |
330 | $use = substr $temp[13], 4; | |
331 | } | |
332 | if ($temp[0] eq 'unknown') { | |
333 | my $offset = 0; | |
334 | $protocol = "??? (" . $temp[1] . ")"; | |
335 | $protocol = "esp (" . $temp[1] . ")" if ($temp[1] == 50); | |
336 | $protocol = "ah (" . $temp[1] . ")" if ($temp[1] == 51); | |
337 | $expires = $temp[2]; | |
338 | $status = ' '; | |
339 | $orgsip = substr $temp[3], 4; | |
340 | $orgdip = substr $temp[4], 4; | |
341 | $orgsp = ' '; | |
342 | $orgdp = ' '; | |
343 | $exsip = substr $temp[5], 4; | |
344 | $exdip = substr $temp[6], 4; | |
345 | $exsp = ' '; | |
346 | $exdp = ' '; | |
347 | $marked = ' '; | |
348 | $use = ' '; | |
349 | } | |
350 | if ($temp[0] eq 'gre') { | |
351 | my $offset = 0; | |
352 | $protocol = $temp[0] . " (" . $temp[1] . ")"; | |
353 | $expires = $temp[2]; | |
354 | $orgsip = substr $temp[5], 4; | |
355 | $orgdip = substr $temp[6], 4; | |
356 | $orgsp = ' '; | |
357 | $orgdp = ' '; | |
358 | $exsip = substr $temp[11], 4; | |
359 | $exdip = substr $temp[12], 4; | |
360 | $exsp = ' '; | |
361 | $exdp = ' '; | |
362 | $marked = $temp[17]; | |
363 | $use = $temp[18]; | |
364 | } | |
365 | # Only from this point, lines have the same known format/field | |
366 | # The floating fields [UNREPLIED] [ASSURED] etc are ok. | |
367 | ||
368 | # Store the line in a hash array for sorting | |
369 | if ( $protocol ) { # line is decoded ? | |
370 | my @record = ( 'index', $index++, | |
371 | 'protocol', $protocol, | |
372 | 'expires', $expires, | |
373 | 'status', $status, | |
374 | 'orgsip', $orgsip, | |
375 | 'orgdip', $orgdip, | |
376 | 'orgsp', $orgsp, | |
377 | 'orgdp', $orgdp, | |
378 | 'exsip', $exsip, | |
379 | 'exdip', $exdip, | |
380 | 'exsp', $exsp, | |
381 | 'exdp', $exdp, | |
382 | 'marked', $marked, | |
383 | 'use', $use); | |
384 | my $record = {}; # create a reference to empty hash | |
385 | %{$record} = @record; # populate that hash with @record | |
386 | $entries{$record->{index}} = $record; # add this to a hash of hashes | |
387 | } else { # it was not a known line | |
388 | $unknownlines .= "<tr bgcolor='${Header::table1colour}'>"; | |
389 | $unknownlines .= "<td colspan='9'> unknown:$line></td></tr>"; | |
390 | } | |
391 | } | |
392 | ||
393 | # Build listbox objects | |
394 | my $menu_proto = &make_select ('SEE_PROTO', $cgiparams{'SEE_PROTO'}, @list_proto); | |
395 | my $menu_state = &make_select ('SEE_STATE', $cgiparams{'SEE_STATE'}, @list_state); | |
396 | my $menu_src = &make_select ('SEE_SRC', $cgiparams{'SEE_SRC'}, &get_known_ips('orgsip')); | |
397 | my $menu_dest = &make_select ('SEE_DEST', $cgiparams{'SEE_DEST'}, &get_known_ips('orgdip')); | |
398 | my $menu_mark = &make_select ('SEE_MARK', $cgiparams{'SEE_MARK'}, @list_mark); | |
399 | my $menu_sort = &make_select ('SEE_SORT', $cgiparams{'SEE_SORT'}, @list_sort); | |
400 | ||
401 | &Header::showhttpheaders(); | |
402 | &Header::openpage($Lang::tr{'connections'}, 1, ''); | |
403 | &Header::openbigbox('100%', 'left'); | |
404 | &Header::openbox('100%', 'left', $Lang::tr{'connection tracking'}); | |
405 | ||
406 | print <<END | |
407 | <table width='60%'> | |
408 | <tr><td align='center'><b>$Lang::tr{'legend'} : </b></td> | |
409 | <td align='center' bgcolor='${Header::colourgreen}'><b><font color='#FFFFFF'>$Lang::tr{'lan'}</font></b></td> | |
410 | <td align='center' bgcolor='${Header::colourred}'><b><font color='#FFFFFF'>$Lang::tr{'internet'}</font></b></td> | |
411 | <td align='center' bgcolor='${Header::colourorange}'><b><font color='#FFFFFF'>$Lang::tr{'dmz'}</font></b></td> | |
412 | <td align='center' bgcolor='${Header::colourblue}'><b><font color='#FFFFFF'>$Lang::tr{'wireless'}</font></b></td> | |
413 | <td align='center' bgcolor='${Header::colourfw}'><b><font color='#FFFFFF'>IPFire</font></b></td> | |
414 | <td align='center' bgcolor='${Header::colourvpn}'><b><font color='#FFFFFF'>$Lang::tr{'vpn'}</font></b></td> | |
415 | <td align='center' bgcolor='${Header::colourovpn}'><b><font color='#FFFFFF'>$Lang::tr{'OpenVPN'}</font></b></td> | |
416 | </tr> | |
417 | </table> | |
418 | <br /> | |
419 | <table cellpadding='2'> | |
420 | <tr><td align='center'><b>$Lang::tr{'protocol'}</b></td> | |
421 | <td align='center'><b>$Lang::tr{'expires'}<br />($Lang::tr{'seconds'})</b></td> | |
422 | <td align='center'><b>$Lang::tr{'connection'}<br />$Lang::tr{'status'}</b></td> | |
423 | <td align='center'><b>$Lang::tr{'original'}<br />$Lang::tr{'source ip and port'}</b></td> | |
424 | <td align='center'><b>$Lang::tr{'original'}<br />$Lang::tr{'dest ip and port'}</b></td> | |
425 | <td align='center'><b>$Lang::tr{'expected'}<br />$Lang::tr{'source ip and port'}</b></td> | |
426 | <td align='center'><b>$Lang::tr{'expected'}<br />$Lang::tr{'dest ip and port'}</b></td> | |
427 | <td align='center'><b>$Lang::tr{'marked'}</b></td> | |
428 | <td align='center'><b>$Lang::tr{'use'}</b></td> | |
429 | </tr> | |
430 | <tr><form method='post' action='$ENV{'SCRIPT_NAME'}'> | |
431 | <td align='center'>$menu_proto</td> | |
432 | <td></td> | |
433 | <td align='center'>$menu_state</td> | |
434 | <td align='center'>$menu_src</td> | |
435 | <td align='center'>$menu_dest</td> | |
436 | <td align='center'colspan='2'>$Lang::tr{'sort ascending'}:$menu_sort </td> | |
437 | <td align='center'>$menu_mark</td> | |
438 | <td align='center'><input type='submit' value='!' /></td> | |
439 | </form> | |
440 | </tr> | |
441 | END | |
442 | ; | |
443 | ||
444 | foreach my $entry (sort sort_entries keys %entries) { | |
445 | ||
446 | print "<tr bgcolor='${Header::table1colour}'>"; | |
447 | my $orgsipcolour = &ipcolour( $entries{$entry}->{orgsip} ); | |
448 | my $orgdipcolour = &ipcolour( $entries{$entry}->{orgdip} ); | |
449 | my $exsipcolour = &ipcolour( $entries{$entry}->{exsip} ); | |
450 | my $exdipcolour = &ipcolour( $entries{$entry}->{exdip} ); | |
451 | print <<END | |
452 | <td align='center'>$entries{$entry}->{protocol}</td> | |
453 | <td align='center'>$entries{$entry}->{expires}</td> | |
454 | <td align='center'>$entries{$entry}->{status}</td> | |
455 | <td align='center' bgcolor='$orgsipcolour'> | |
456 | <a href='/cgi-bin/ipinfo.cgi?ip=$entries{$entry}->{orgsip}'> | |
457 | <font color='#FFFFFF'>$entries{$entry}->{orgsip}</font> | |
458 | </a><font color='#FFFFFF'>:$entries{$entry}->{orgsp}</font></td> | |
459 | <td align='center' bgcolor='$orgdipcolour'> | |
460 | <a href='/cgi-bin/ipinfo.cgi?ip=$entries{$entry}->{orgdip}'> | |
461 | <font color='#FFFFFF'>$entries{$entry}->{orgdip}</font> | |
462 | </a><font color='#FFFFFF'>:$entries{$entry}->{orgdp}</font></td> | |
463 | <td align='center' bgcolor='$exsipcolour'> | |
464 | <a href='/cgi-bin/ipinfo.cgi?ip=$entries{$entry}->{exsip}'> | |
465 | <font color='#FFFFFF'>$entries{$entry}->{exsip}</font> | |
466 | </a><font color='#FFFFFF'>:$entries{$entry}->{exsp}</font></td> | |
467 | <td align='center' bgcolor='$exdipcolour'> | |
468 | <a href='/cgi-bin/ipinfo.cgi?ip=$entries{$entry}->{exdip}'> | |
469 | <font color='#FFFFFF'>$entries{$entry}->{exdip}</font> | |
470 | </a><font color='#FFFFFF'>:$entries{$entry}->{exdp}</font></td> | |
471 | <td align='center'>$entries{$entry}->{marked}</td> | |
472 | <td align='center'>$entries{$entry}->{use}</td> | |
473 | </tr> | |
474 | END | |
475 | ; | |
476 | } | |
477 | ||
478 | print "$unknownlines</table>"; | |
479 | ||
480 | &Header::closebox(); | |
481 | &Header::closebigbox(); | |
482 | &Header::closepage(); | |
483 | ||
484 | sub ipcolour($) { | |
485 | my $id = 0; | |
486 | my $line; | |
487 | my $colour = ${Header::colourred}; | |
488 | my ($ip) = $_[0]; | |
489 | my $found = 0; | |
490 | foreach $line (@network) { | |
491 | if (!$found && ipv4_in_network( $network[$id] , $masklen[$id], $ip) ) { | |
492 | $found = 1; | |
493 | $colour = $colour[$id]; | |
494 | } | |
495 | $id++; | |
496 | } | |
497 | return $colour | |
498 | } | |
499 | ||
500 | # Create a string containing a complete SELECT html object | |
501 | # param1: name | |
502 | # param2: current value selected | |
503 | # param3: field list | |
504 | sub make_select ($,$,$) { | |
505 | my $select_name = shift; | |
506 | my $selected = shift; | |
507 | my $select = "<select name='$select_name'>"; | |
508 | ||
509 | foreach my $value (@_) { | |
510 | my $check = $selected eq $value ? "selected='selected'" : ''; | |
511 | $select .= "<option $check value='$value'>$value"; | |
512 | } | |
513 | $select .= "</select>"; | |
514 | return $select; | |
515 | } | |
516 | ||
517 | # Build a list of IP obtained from the %entries hash | |
518 | # param1: IP field name | |
519 | sub get_known_ips ($) { | |
520 | my $field = shift; | |
521 | my $qs = $cgiparams{'SEE_SORT'}; # switch the sort order | |
522 | $cgiparams{'SEE_SORT'} = $field; | |
523 | ||
524 | my @liste=('*.*.*.*'); | |
525 | foreach my $entry ( sort sort_entries keys %entries) { | |
526 | push (@liste, $entries{$entry}->{$field}) if (! grep (/^$entries{$entry}->{$field}$/,@liste) ); | |
527 | } | |
528 | ||
529 | $cgiparams{'SEE_SORT'} = $qs; #restore sort order | |
530 | return @liste; | |
531 | } | |
532 | ||
533 | # Used to sort the table containing the lines displayed. | |
534 | sub sort_entries { #Reverse is not implemented | |
535 | my $qs=$cgiparams{'SEE_SORT'}; | |
536 | if ($qs =~ /orgsip|orgdip|exsip|exdip/) { | |
537 | my @a = split(/\./,$entries{$a}->{$qs}); | |
538 | my @b = split(/\./,$entries{$b}->{$qs}); | |
539 | ($a[0]<=>$b[0]) || | |
540 | ($a[1]<=>$b[1]) || | |
541 | ($a[2]<=>$b[2]) || | |
542 | ($a[3]<=>$b[3]); | |
543 | } elsif ($qs =~ /expire|orgsp|orgdp|exsp|exdp/) { | |
544 | $entries{$a}->{$qs} <=> $entries{$b}->{$qs}; | |
545 | } else { | |
546 | $entries{$a}->{$qs} cmp $entries{$b}->{$qs}; | |
547 | } | |
548 | } | |
549 | ||
550 | 1; |