ui-lib conversion of Find Free IPs

This commit is contained in:
Jamie Cameron
2008-08-30 21:48:08 +00:00
parent b02946bcca
commit f45db2eef3
9 changed files with 58 additions and 228 deletions

View File

@@ -88,3 +88,4 @@ Converted all forms to use the Webmin UI library, for a more consistent look and
Moved buttons for deleting, moving and converting zones up to the page shown when you click on a zone name.
Switched to the new root zone file available from Internic.
Restrictions that apply to all zones in a view (such as allowed IPs for transfers and queries) can now be set on the Edit Client View page.
Made the Find Free IPs page visible, for finding addresses in a master zone that are not currently used.

View File

@@ -843,7 +843,8 @@ sub can_edit_reverse
return $access{'reverse'} || &can_edit_zone($_[0]);
}
# record_input(zoneindex, view, type, file, origin, [num], [record])
# record_input(zoneindex, view, type, file, origin, [num], [record],
# [new-name, new-value])
# Display a form for editing or creating a DNS record
sub record_input
{
@@ -855,16 +856,18 @@ print &ui_hidden("view", $_[1]);
print &ui_hidden("file", $_[3]);
print &ui_hidden("origin", $_[4]);
print &ui_hidden("sort", $in{'sort'});
if (@_ >= 6) {
if (defined($_[5])) {
print &ui_hidden("num", $_[5]);
%rec = %{$_[6]};
}
else {
print &ui_hidden("new", 1);
$rec{'name'} = $_[7] if ($_[7]);
$rec{'values'} = [ $_[8] ] if ($_[8]);
}
print &ui_hidden("type", $type);
print &ui_hidden("redirtype", $_[2]);
print &ui_table_start(&text(@_ >= 6 ? 'edit_edit' : 'edit_add',
print &ui_table_start(&text(defined($_[5]) ? 'edit_edit' : 'edit_add',
$text{"edit_".$type}));
# Record name field(s)
@@ -903,7 +906,7 @@ else {
}
# Show canonical name too, if not auto-converted
if ($config{'short_names'} && @_ > 6) {
if ($config{'short_names'} && defined($_[5])) {
print &ui_table_row($text{'edit_canon'}, "<tt>$rec{'canon'}</tt>");
}
@@ -923,8 +926,9 @@ print &ui_table_row($text{'edit_ttl'},
if ($type eq "A" || $type eq "AAAA") {
print &ui_table_row($text{'value_A1'},
&ui_textbox("value0", $v[0], 20)." ".
(@_ < 6 && $type eq "A" ? &free_address_button("value0") : ""), 3);
if (@_ >= 6) {
(!defined($_[5]) && $type eq "A" ?
&free_address_button("value0") : ""), 3);
if (defined($_[5])) {
print &ui_hidden("oldname", $rec{'name'});
print &ui_hidden("oldvalue0", $v[0]);
}
@@ -977,7 +981,7 @@ elsif ($type eq "PTR") {
# Reverse address
print &ui_table_row($text{'value_PTR1'},
&ui_textbox("value0", $v[0], 30), 3);
if (@_ >= 6) {
if (defined($_[5])) {
print &ui_hidden("oldname", $rec{'name'});
print &ui_hidden("oldvalue0", $v[0]);
}
@@ -1071,7 +1075,7 @@ if ($type eq "A" || $type eq "AAAA") {
&ui_radio("rev", $config{'rev_def'} == 0 ? 1 :
$config{'rev_def'} == 2 ? 2 : 0,
[ [ 1, $text{'yes'} ],
@_ < 6 ? ( [ 2, $text{'edit_over'} ] ) : ( ),
defined($_[5]) ? ( ) : ( [ 2, $text{'edit_over'} ] ),
[ 0, $text{'no'} ] ]));
}
elsif ($type eq "PTR") {
@@ -1084,7 +1088,7 @@ print &ui_table_end();
# End buttons
if (!$access{'ro'}) {
if (@_ >= 6) {
if (defined($_[5])) {
print &ui_form_end([ [ undef, $text{'save'} ],
[ "delete", $text{'delete'} ] ]);
}

View File

@@ -20,3 +20,4 @@ gen=1
vlist=*
delegation=1
slaves=1
findfree=1

View File

@@ -19,7 +19,8 @@ $type = $zone->{'type'};
$file = $zone->{'file'};
$form = 0;
if (!$access{'ro'} && $type eq 'master' && $in{'type'} ne 'ALL') {
&record_input($in{'index'}, $in{'view'}, $in{'type'}, $file, $dom);
&record_input($in{'index'}, $in{'view'}, $in{'type'}, $file, $dom,
undef, undef, $in{'newname'}, $in{'newvalue'});
$form++;
$shown_create_form = 1;
}

View File

@@ -17,23 +17,10 @@ if (!$access{'findfree'}) {&error($text{'findfree_nofind'})};
$desc = &text('findfree_header', &arpa_to_ip($dom));
&ui_print_header($desc, &text('findfree_title'), "");
my $cf=1;
if (@in == 2) {
&find_ips ($in{'index'}, $in{'from'});
}
elsif (@in == 3) {
&find_ips ($in{'index'}, $in{'from'}, $in{'to'});
}
elsif (@in == 4) {
$cf=$in{'cf'};
&find_ips ($in{'index'}, $in{'from'}, $in{'to'}, $in{'cf'});
}
else {
&find_ips ($in{'index'});
}
if (@in >= 3) { #we need to do the search!
&find_ips($in{'index'}, $in{'from'}, $in{'to'}, $in{'cf'});
if ($in{'from'} && $in{'to'}) {
# Do the search
@recs = &read_zone_file($file, $dom);
@recs = grep { ($_->{'type'} eq 'A') || ($_->{'type'} eq 'PTR')} @recs;
my $freeXXXcount=0;
@@ -57,7 +44,7 @@ if (@in >= 3) { #we need to do the search!
# print "evaluating ", $hip, " ", $hname, "...<BR>"; #debug
if($cf & ($hname=~ /^free.*/) & exists $frecs{$hip}) { # 'freeXXX' hostnames are free IP's!
if($in{'cf'} & ($hname=~ /^free.*/) & exists $frecs{$hip}) { # 'freeXXX' hostnames are free IP's!
# update
# print "&nbsp;&nbsp;updating: ",$hip, "... <BR>"; #debug
$frecs{$hip}->{'ttl'}=$recs[$i]->{'ttl'};
@@ -72,23 +59,16 @@ if (@in >= 3) { #we need to do the search!
}
# Show a message
my @frecs=sort ffree_ip_sort_func values %frecs;
my $mid = int((@frecs+1)/2);
print "<P align = \"center\"><STRONG>Found <BIG>" . @frecs . "</BIG> free IP number" . (@frecs==1?"\n":"s\n");
if ($cf) {
print " (<BIG>$freeXXXcount</BIG> ". ($freeXXXcount==1?" is":"are") .
" <EM>`freeXXX'</EM>" .
" of which <BIG>$freemaccount</BIG> ". ($freemaccount==1?" is":"are") .
" <EM>`freemac'</EM>)" ;
print "</STRONG></P>\n";
}
print "<table width=100%><tr><td width=50% valign=top>\n";
&frecs_table(@frecs[0 .. $mid-1]);
print "</td><td width=50% valign=top>\n";
if ($mid < @frecs) { &frecs_table(@frecs[$mid .. $#frecs]); }
print "</td></tr></table><p>\n";
print "<p>\n";
print "<b>",&text('findfree_msg', scalar(@frecs)),"\n";
if ($in{'cf'}) {
print &text('findfree_msg2', $freeXXXcount, $freemaccount),"\n";
}
print "...</b><p>\n";
# Show all the IPs
&frecs_table(@frecs);
} # if(@recs)
} # if(@in >= 3)
@@ -139,91 +119,40 @@ for ($byte0=$from[0]; $byte0<=$to[0]; $byte0++) {
return %frecs;
} # sub build_iprange
# find_ips (zoneindex, from_ip, to_ip, consider_freeXX_names)
# Display a form for searching for free IP nos
sub find_ips
{
print "<form action=find_free.cgi>\n";
print "<input type=hidden name=index value='$_[0]'>\n";
print "<input type=hidden name=view value='$in{'view'}'>\n";
print "<table border>\n";
print "<tr $tb><td><b>$text{'findfree_sopt'}</b></td> </tr>\n";
print "<tr $cb><td><table>\n";
print "<tr> <td><b>$text{'findfree_IPrange'}</b></td>\n";
print "<td><b>$text{'findfree_from'}</b></td>\n";
if (@_ >= 2) { # there is a "from" field on the URL
print "<td> <input name=from value=\"$_[1]\" size=30></td> </tr>\n";
}
else {
print "<td> <input name=from value=\"\" size=30></td> </tr>\n";
}
print "<tr> <td>&nbsp;</td>\n";
print "<td><b>$text{'findfree_to'}</b></td>\n";
if (@_ >= 3) { # there is a "to" field on the URL
print "<td> <input name=to value=\"$_[2]\" size=30></td> </tr>\n";
}
else {
print "<td> <input name=to value=\"\" size=30></td> </tr>\n";
}
print "<tr> <td colspan=3 nowrap><b>$text{'findfree_cf'}</b>\n";
$cfy=$cf?'checked':'';
$cfn=(!$cf)?'checked':'';
print " &nbsp; <input type=radio name=cf value=1 $cfy> $text{'yes'}\n";
print "<input type=radio name=cf value=0 $cfn> $text{'no'}</td></tr>\n";
print "<tr colspan=3><td><input type=submit value=\"$text{'findfree_search'}\"></td></tr>\n";
print "</table></td></tr></table></form>\n";
} # end of find_ips
print &ui_form_start("find_free.cgi");
print &ui_hidden("index", $_[0]);
print &ui_hidden("view", $in{'view'});
print &ui_table_start($text{'findfree_sopt'}, undef, 2);
# Range start
print &ui_table_row($text{'findfree_fromip'},
&ui_textbox("from", $_[1], 20));
# Range end
print &ui_table_row($text{'findfree_toip'},
&ui_textbox("to", $_[2], 20));
# Handle freeXXX hostnames?
print &ui_table_row($text{'findfree_cf'},
&ui_yesno_radio("cf", $_[3]));
print &ui_table_end();
print &ui_form_end([ [ undef, $text{'findfree_search'} ] ]);
}
# frecs_table(array_of_freerecords)
sub frecs_table
{
print "<table border width=100%>\n";
print "<tr $tb> <td><b>", $text{'recs_addr'},"</b></td>",
"<td><b>$text{'recs_ttl'}</b></td>\n",
"<td><b>$text{'recs_name'}</b></td>\n",
"</tr>\n";
for($i=0; $i<@_; $i++) {
$r = $_[$i];
print "<tr $cb> <td>$r->{'ip'}</td>\n",
"<td>",$r->{'ttl'} ? $r->{'ttl'} : $text{'default'},"</td>\n",
"<td>",$r->{'name'}?$r->{'name'}:'&nbsp;',"</td>\n",
"</tr>\n";
}
print "</table>\n";
print &ui_grid_table(
[ map { "<a href='edit_recs.cgi?index=$in{'index'}&view=$in{'view'}".
"&type=A&newvalue=$_->{'ip'}'>$_->{'ip'}</a>" } @_ ],
4, 100, [ "width=25%", "width=25%", "width=25%", "width=25%" ]);
}
sub ffree_ip_sort_func
{
$a->{'ip'} =~ /^(\d+)\.(\d+)\.(\d+)\.(\d+)/;

View File

@@ -679,11 +679,12 @@ findfree_desc=Find Free IPs
findfree_nofind=You cannot look for free IP's
findfree_header=In $1
findfree_sopt=Search options
findfree_IPrange=IP range
findfree_from=from
findfree_to=to
findfree_cf=Consider <em>`freeXXX'</em> hostnames as free IP's?
findfree_fromip=From IP address
findfree_toip=To IP address
findfree_cf=Consider <em>`freeXXX'</em> hostnames as free IPs?
findfree_search=Search
findfree_msg=Found $1 free IP addresses
findfree_msg2=(of which $1 are like <i>freeXXX</i>, $2 like <i>freemac</i>)
free_title=Free IP Addresses
free_ip=IP Address

View File

@@ -7,14 +7,14 @@ require './bind8-lib.pl';
@d = split(/\0/, $in{'d'});
@d || &error($text{'rmass_enone'});
&ui_print_header(undef, $text{'umass_title'}, "", [ "width=30%" ]);
&ui_print_header(undef, $text{'rmass_title'}, "");
print &ui_form_start("mass_rcreate.cgi", "post");
foreach $d (@d) {
print &ui_hidden("d", $d),"\n";
$dc++;
}
print &ui_table_start($text{'rmass_header'}, undef, 2, [ "width=30%" ]);
print &ui_table_start($text{'rmass_header'}, undef, 2);
# Number of domains selected
print &ui_table_row($text{'umass_sel'}, $dc);

View File

@@ -7,7 +7,7 @@ require './bind8-lib.pl';
@d = split(/\0/, $in{'d'});
@d || &error($text{'umass_enone'});
&ui_print_header(undef, $text{'umass_title'}, "", [ "width=30%" ]);
&ui_print_header(undef, $text{'umass_title'}, "");
print &ui_form_start("mass_update.cgi", "post");
foreach $d (@d) {

View File

@@ -1,107 +0,0 @@
#!/usr/local/bin/perl
# conf_controls.cgi
# Display controls options
require './bind8-lib.pl';
$access{'defaults'} || &error($text{'controls_ecannot'});
&ui_print_header(undef, $text{'controls_title'}, "");
&ReadParse();
$conf = &get_config();
$controls = &find("controls", $conf);
$mems = $controls->{'members'};
my ($inet, $unix, $addr, $port, $file, $perms, $owner, $group);
my @addrvals=();
foreach $mem ( @$mems ) {
if ($mem->{'name'} eq "inet") {
$inet=$mem;
# Directive reads
# INET ( ip_addr | * ) PORT ip_port ALLOW address_match_list
# the parser will see the address matchlist as a set of members
# everything else is a value.
my $v=$inet->{'values'};
$addr=$v->[0];
$port=$v->[2];
foreach $addrmatch (@{$inet->{'members'}}) {
push @addrvals, $addrmatch->{'name'};
}
} elsif ($mem->{'name'} eq "unix") {
$unix=$mem;
# Directive reads
# UNIX path_name PERM number OWNER number GROUP number;
my $v=$unix->{'values'};
$file=$v->[0];
$perms=$v->[2];
$owner=$v->[4];
$group=$v->[6];
}
}
$inetdefault=defined($inet)?"":" checked";
$inetset=defined($inet)?" checked":"";
$unixdefault=defined($unix)?"":" checked";
$unixset=defined($unix)?" checked":"";
print "<form action=save_controls.cgi>\n";
print "<table border width=100%>\n";
print "<tr $tb> <td><b>$text{'controls_header'}</b></td> </tr>\n";
print "<tr $cb> <td><table width=100%>\n";
print "<tr>\n";
print "<td valign=top><b>",
$text{'controls_inet'},
"</b></td>\n";
print "<td nowrap valign=top>\n";
print "<input type=radio name=inet_def value=1$inetdefault> ",
$text{'default'},
"\n";
print "<input type=radio name=inet_def value=0$inetset>\n";
print "<input name=inetaddr size=16 value=$addr></td>\n";
print "<td valign=top>",
$text{'controls_port'},
"</td>\n";
print "<td valign=top>",
"<input name=inetport size=6 value=$port></td>\n";
print "<td valign=top>",
$text{'controls_allow'},
"</td>\n";
print "<td valign=top>",
"<textarea name=inetallow rows=4 cols=40 wrap=auto>\n",
join(" ", @addrvals),
"</textarea>\n";
print "</td></tr>\n";
print "<tr>\n";
print "<td valign=top><b>",
$text{'controls_unix'},
"</b></td>\n";
print "<td nowrap valign=top>\n";
print "<input type=radio name=unix_def value=1$unixdefault> ",
$text{'default'},
"\n";
print "<input type=radio name=unix_def value=0$unixset>\n";
print "<input name=unixfile size=16 value=$file></td>\n";
print "<td valign=top>",
$text{'controls_permissions'},
"</td>\n";
print "<td valign=top>",
"<input name=unixperms size=6 value=$perms></td>\n";
print "<td valign=top>",
$text{'controls_owner'},
"</td>\n";
print "<td valign=top>",
"<input name=unixowner size=8 value=$owner>\n",
$text{'controls_group'},
"<input name=unixgroup size = 8 value=$group>\n";
print "</td></tr>\n";
print "</table></td></tr></table>\n";
print "<input type=submit value=\"$text{'save'}\"></form>\n";
&ui_print_footer("", $text{'index_return'});