Neue Hardwareerkennung im Installer...
[people/teissler/ipfire-2.x.git] / html / cgi-bin / connections.cgi
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 # (c) 2006 Peter Schälchli -inetwork (bug)
10 #
11
12 # Setup GREEN, ORANGE, IPFIRE, 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 '/var/ipfire/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 Orange Network
78 if ($netsettings{'ORANGE_DEV'}) {
79 push(@network, $netsettings{'ORANGE_NETADDRESS'});
80 push(@masklen, $netsettings{'ORANGE_NETMASK'} );
81 push(@colour, ${Header::colourorange} );
82 # Add Orange Routes to Array
83 @routes = `/sbin/route -n | /bin/grep $netsettings{'ORANGE_DEV'}`;
84 foreach my $route (@routes) {
85 chomp($route);
86 my @temp = split(/[\t ]+/, $route);
87 push(@network, $temp[0]);
88 push(@masklen, $temp[2]);
89 push(@colour, ${Header::colourorange} );
90 }
91 }
92
93 # Add Blue Firewall Interface
94 push(@network, $netsettings{'BLUE_ADDRESS'});
95 push(@masklen, "255.255.255.255" );
96 push(@colour, ${Header::colourfw} );
97
98 # Add Blue Network
99 if ($netsettings{'BLUE_DEV'}) {
100 push(@network, $netsettings{'BLUE_NETADDRESS'});
101 push(@masklen, $netsettings{'BLUE_NETMASK'} );
102 push(@colour, ${Header::colourblue} );
103 # Add Blue Routes to Array
104 @routes = `/sbin/route -n | /bin/grep $netsettings{'BLUE_DEV'}`;
105 foreach my $route (@routes) {
106 chomp($route);
107 my @temp = split(/[\t ]+/, $route);
108 push(@network, $temp[0]);
109 push(@masklen, $temp[2]);
110 push(@colour, ${Header::colourblue} );
111 }
112 }
113
114 # Add OpenVPN net and RED/BLUE/ORANGE entry (when appropriate)
115 if (-e "${General::swroot}/ovpn/settings") {
116 my %ovpnsettings = ();
117 &General::readhash("${General::swroot}/ovpn/settings", \%ovpnsettings);
118 my @tempovpnsubnet = split("\/",$ovpnsettings{'DOVPN_SUBNET'});
119
120 # add OpenVPN net
121 push(@network, $tempovpnsubnet[0]);
122 push(@masklen, $tempovpnsubnet[1]);
123 push(@colour, ${Header::colourovpn} );
124
125 if ( ($ovpnsettings{'ENABLED'} eq 'on') && open(IP, "${General::swroot}/red/local-ipaddress") ) {
126 # add RED:port / proto
127 my $redip = <IP>;
128 close(IP);
129 chomp $redip;
130 push(@network, $redip );
131 push(@masklen, '255.255.255.255' );
132 push(@colour, ${Header::colourovpn} );
133 }
134 if ( ($ovpnsettings{'ENABLED_BLUE'} eq 'on') && $netsettings{'BLUE_DEV'} ) {
135 # add BLUE:port / proto
136 push(@network, $netsettings{'BLUE_ADDRESS'} );
137 push(@masklen, '255.255.255.255' );
138 push(@colour, ${Header::colourovpn} );
139 }
140 if ( ($ovpnsettings{'ENABLED_ORANGE'} eq 'on') && $netsettings{'ORANGE_DEV'} ) {
141 # add ORANGE:port / proto
142 push(@network, $netsettings{'ORANGE_ADDRESS'} );
143 push(@masklen, '255.255.255.255' );
144 push(@colour, ${Header::colourovpn} );
145 }
146 }
147
148 # Add STATIC RED aliases
149 if ($netsettings{'RED_DEV'}) {
150 # We have a RED eth iface
151 if ($netsettings{'RED_TYPE'} eq 'STATIC') {
152 # We have a STATIC RED eth iface
153 foreach my $line (@aliases)
154 {
155 chomp($line);
156 my @temp = split(/\,/,$line);
157 if ( $temp[0] ) {
158 push(@network, $temp[0]);
159 push(@masklen, $netsettings{'RED_NETMASK'} );
160 push(@colour, ${Header::colourfw} );
161 }
162 }
163 }
164 }
165
166 # Add VPNs
167 if ( $vpn[0] ne 'none' ) {
168 foreach my $line (@vpn) {
169 my @temp = split(/[\t ]+/,$line);
170 my @temp1 = split(/[\/:]+/,$temp[3]);
171 push(@network, $temp1[0]);
172 push(@masklen, ipv4_cidr2msk($temp1[1]));
173 push(@colour, ${Header::colourvpn} );
174 }
175 }
176 if (open(IP, "${General::swroot}/red/local-ipaddress")) {
177 my $redip = <IP>;
178 close(IP);
179 chomp $redip;
180 push(@network, $redip);
181 push(@masklen, '255.255.255.255' );
182 push(@colour, ${Header::colourfw} );
183 }
184
185
186 #Establish simple filtering&sorting boxes on top of table
187
188 our %cgiparams;
189 &Header::getcgihash(\%cgiparams);
190
191 my @list_proto = ($Lang::tr{'all'}, 'icmp', 'udp', 'tcp');
192 my @list_state = ($Lang::tr{'all'}, 'SYN_SENT', 'SYN_RECV', 'ESTABLISHED', 'FIN_WAIT',
193 'CLOSE_WAIT', 'LAST_ACK', 'TIME_WAIT', 'CLOSE', 'LISTEN');
194 my @list_mark = ($Lang::tr{'all'}, '[ASSURED]', '[UNREPLIED]');
195 my @list_sort = ('orgsip','protocol', 'expires', 'status', 'orgdip', 'orgsp',
196 'orgdp', 'exsip', 'exdip', 'exsp', 'exdp', 'marked');
197
198 # init or silently correct unknown value...
199 if ( ! grep ( /^$cgiparams{'SEE_PROTO'}$/ , @list_proto )) { $cgiparams{'SEE_PROTO'} = $list_proto[0] };
200 if ( ! grep ( /^$cgiparams{'SEE_STATE'}$/ , @list_state )) { $cgiparams{'SEE_STATE'} = $list_state[0] };
201 if ( ($cgiparams{'SEE_MARK'} ne $Lang::tr{'all'}) && # ok the grep should work but it doesn't because of
202 ($cgiparams{'SEE_MARK'} ne '[ASSURED]') && # the '[' & ']' interpreted as list separator.
203 ($cgiparams{'SEE_MARK'} ne '[UNREPLIED]') # So, explicitly enumerate items.
204 ) { $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[16];
325 }
326 $exsip = substr $temp[10 + $offset], 4;
327 $exdip = substr $temp[11 + $offset], 4;
328 $exsp = substr $temp[12 + $offset], 6;
329 $exdp = substr $temp[13 + $offset], 6;
330 $use = substr $temp[18], 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 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
408 <table width='100%'>
409 <tr><td align='center'><b>$Lang::tr{'legend'} : </b></td>
410 <td align='center' bgcolor='${Header::colourgreen}'><b><font color='#FFFFFF'>$Lang::tr{'lan'}</font></b></td>
411 <td align='center' bgcolor='${Header::colourred}'><b><font color='#FFFFFF'>$Lang::tr{'internet'}</font></b></td>
412 <td align='center' bgcolor='${Header::colourorange}'><b><font color='#FFFFFF'>$Lang::tr{'dmz'}</font></b></td>
413 <td align='center' bgcolor='${Header::colourblue}'><b><font color='#FFFFFF'>$Lang::tr{'wireless'}</font></b></td>
414 <td align='center' bgcolor='${Header::colourfw}'><b><font color='#FFFFFF'>IPFire</font></b></td>
415 <td align='center' bgcolor='${Header::colourvpn}'><b><font color='#FFFFFF'>$Lang::tr{'vpn'}</font></b></td>
416 <td align='center' bgcolor='${Header::colourovpn}'><b><font color='#FFFFFF'>$Lang::tr{'OpenVPN'}</font></b></td>
417 </tr>
418 </table>
419 <br></br>
420 <table width='100%'>
421 <tr><td align='center'><font size=2>$Lang::tr{'protocol'}</font></td>
422 <td align='center'><font size=2>$Lang::tr{'expires'}<br></br>($Lang::tr{'seconds'})</font></td>
423 <td align='center'><font size=2>$Lang::tr{'connection'}<br></br>$Lang::tr{'status'}</font></td>
424 <td align='center'><font size=2>$Lang::tr{'original'}<br></br>$Lang::tr{'source ip and port'}</font></td>
425 <td align='center'><font size=2>$Lang::tr{'original'}<br></br>$Lang::tr{'dest ip and port'}</font></td>
426 <td align='center'><font size=2>$Lang::tr{'expected'}<br></br>$Lang::tr{'source ip and port'}</font></td>
427 <td align='center'><font size=2>$Lang::tr{'expected'}<br></br>$Lang::tr{'dest ip and port'}</font></td>
428 <td align='center'><font size=2>$Lang::tr{'marked'}</font></td>
429 </tr>
430 <tr>
431 <td align='center'>$menu_proto</td>
432 <td>&nbsp;</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'></td>
437 <td align='center'>$menu_mark</td>
438 </tr>
439 <tr>
440 <td align='center' colspan='8'></td>
441 </tr>
442 <tr>
443 <td align='center' colspan='8'><input type='submit' value='Aktualisieren' /></td>
444 </tr>
445
446 END
447 ;
448
449 foreach my $entry (sort sort_entries keys %entries) {
450 my $orgsipcolour = &ipcolour( $entries{$entry}->{orgsip} );
451 my $orgdipcolour = &ipcolour( $entries{$entry}->{orgdip} );
452 my $exsipcolour = &ipcolour( $entries{$entry}->{exsip} );
453 my $exdipcolour = &ipcolour( $entries{$entry}->{exdip} );
454 print <<END
455 <tr bgcolor='${Header::table1colour}'>
456 <td align='center'><font size=2>$entries{$entry}->{protocol}</font></td>
457 <td align='center'><font size=2>$entries{$entry}->{expires}</font></td>
458 <td align='center'><font size=2>$entries{$entry}->{status}</font></td>
459 <td align='center' bgcolor='$orgsipcolour'>
460 <a href='/cgi-bin/ipinfo.cgi?ip=$entries{$entry}->{orgsip}'>
461 <font color='#FFFFFF' size=2>$entries{$entry}->{orgsip}</font>
462 </a><font color='#FFFFFF' size=2>:$entries{$entry}->{orgsp}</font></td>
463 <td align='center' bgcolor='$orgdipcolour'>
464 <a href='/cgi-bin/ipinfo.cgi?ip=$entries{$entry}->{orgdip}'>
465 <font color='#FFFFFF' size=2>$entries{$entry}->{orgdip}</font>
466 </a><font color='#FFFFFF' size=2>:$entries{$entry}->{orgdp}</font></td>
467 <td align='center' bgcolor='$exsipcolour'>
468 <a href='/cgi-bin/ipinfo.cgi?ip=$entries{$entry}->{exsip}'>
469 <font color='#FFFFFF' size=2>$entries{$entry}->{exsip}</font>
470 </a><font color='#FFFFFF' size=2>:$entries{$entry}->{exsp}</font></td>
471 <td align='center' bgcolor='$exdipcolour'>
472 <a href='/cgi-bin/ipinfo.cgi?ip=$entries{$entry}->{exdip}'>
473 <font color='#FFFFFF' size=2>$entries{$entry}->{exdip}</font>
474 </a><font color='#FFFFFF' size=2>:$entries{$entry}->{exdp}</font></td>
475 <td align='center'><font size=2>$entries{$entry}->{marked}</font></td>
476 </tr>
477 END
478 ;
479 }
480
481 print "$unknownlines</table></form>";
482
483 &Header::closebox();
484 &Header::closebigbox();
485 &Header::closepage();
486
487 sub ipcolour($) {
488 my $id = 0;
489 my $line;
490 my $colour = ${Header::colourred};
491 my ($ip) = $_[0];
492 my $found = 0;
493 foreach $line (@network) {
494 if ($network[$id] eq '') {
495 $id++;
496 } else {
497 if (!$found && ipv4_in_network( $network[$id] , $masklen[$id], $ip) ) {
498 $found = 1;
499 $colour = $colour[$id];
500 }
501 $id++;
502 }
503 }
504 return $colour
505 }
506
507 # Create a string containing a complete SELECT html object
508 # param1: name
509 # param2: current value selected
510 # param3: field list
511 sub make_select ($,$,$) {
512 my $select_name = shift;
513 my $selected = shift;
514 my $select = "<select name='$select_name'>";
515
516 foreach my $value (@_) {
517 my $check = $selected eq $value ? "selected='selected'" : '';
518 $select .= "<option $check value='$value'>$value</option>";
519 }
520 $select .= "</select>";
521 return $select;
522 }
523
524 # Build a list of IP obtained from the %entries hash
525 # param1: IP field name
526 sub get_known_ips ($) {
527 my $field = shift;
528 my $qs = $cgiparams{'SEE_SORT'}; # switch the sort order
529 $cgiparams{'SEE_SORT'} = $field;
530
531 my @liste=('*.*.*.*');
532 foreach my $entry ( sort sort_entries keys %entries) {
533 push (@liste, $entries{$entry}->{$field}) if (! grep (/^$entries{$entry}->{$field}$/,@liste) );
534 }
535
536 $cgiparams{'SEE_SORT'} = $qs; #restore sort order
537 return @liste;
538 }
539
540 # Used to sort the table containing the lines displayed.
541 sub sort_entries { #Reverse is not implemented
542 my $qs=$cgiparams{'SEE_SORT'};
543 if ($qs =~ /orgsip|orgdip|exsip|exdip/) {
544 my @a = split(/\./,$entries{$a}->{$qs});
545 my @b = split(/\./,$entries{$b}->{$qs});
546 ($a[0]<=>$b[0]) ||
547 ($a[1]<=>$b[1]) ||
548 ($a[2]<=>$b[2]) ||
549 ($a[3]<=>$b[3]);
550 } elsif ($qs =~ /expire|orgsp|orgdp|exsp|exdp/) {
551 $entries{$a}->{$qs} <=> $entries{$b}->{$qs};
552 } else {
553 $entries{$a}->{$qs} cmp $entries{$b}->{$qs};
554 }
555 }
556
557 1;