2 # Show a list of free IP addresses, within the configured ranges
4 require './bind8-lib.pl';
6 # Go through all zones to find IPs in use, and networks
8 @views = &find("view", $conf);
10 @vz = &find("zone", $v->{'members'});
11 map { $view{$_} = $v } @vz;
14 push(@zones, &find("zone", $conf));
16 $type = &find_value("type", $z->{'members'});
17 next if ($type ne "master");
18 $file = &find_value("file", $z->{'members'});
19 @recs = &read_zone_file($file, $z->{'value'});
21 if ($r->{'type'} eq 'A') {
22 $taken{$r->{'values'}->[0]}++;
23 $net = $r->{'values'}->[0];
25 if ($net ne "127.0.0.0") {
29 elsif ($r->{'type'} eq 'PTR') {
30 $taken{&arpa_to_ip($r->{'values'}->[0])}++;
35 # Use configured networks, if any
36 if ($config{'free_nets'}) {
37 @nets = split(/\s+/, $config{'free_nets'});
42 @nets = sort { $a cmp $b } @nets;
44 # display list of free IPs in the nets
45 &popup_header($text{'free_title'});
47 print "function select(f)\n";
49 print "top.opener.ifield.value = f;\n";
50 print "top.close();\n";
51 print "return false;\n";
54 print &ui_columns_start([ $text{'free_ip'} ], 100);
55 foreach $net (@nets) {
56 @netip = split(/\./, $net);
57 if ($netip[3] eq "0") {
61 elsif ($netip[3] =~ /^(\d+)\-(\d+)$/) {
66 $start = $end = $netip[3];
68 for($d=$start; $d<=$end; $d++) {
69 $ip = "$netip[0].$netip[1].$netip[2].$d";
71 print &ui_columns_row([ "<a href=\"\" onClick='return select(\"$ip\")'>$ip</a>" ]);
75 print &ui_columns_end();