Yet more ui-lib conversion, plus button cleanups and re-factoring

This commit is contained in:
Jamie Cameron
2008-08-29 22:14:30 +00:00
parent 861eb08963
commit b06a89bad1
14 changed files with 169 additions and 191 deletions

View File

@@ -312,7 +312,7 @@ else {
}
}
# save_directive(&parent, name|&old, &values, indent, [structonly])
# save_directive(&parent, name|&olds, &values, indent, [structonly])
# Given a structure containing a directive name, type, values and members
# add, update or remove that directive in config structure and data files.
# Updating of files assumes that there is no overlap between directives -
@@ -328,11 +328,9 @@ for($i=0; $i<@oldv || $i<@newv; $i++) {
# a new directive is being added.. put it at the end of
# the parent
if (!$_[4]) {
local $parent = &get_config_parent($newv[$i]->{'file'} ||
$_[0]->{'file'});
$lref = &read_file_lines(
&make_chroot($newv[$i]->{'file'} ||
$_[0]->{'file'}));
local $addfile = $newv[$i]->{'file'} || $_[0]->{'file'};
local $parent = &get_config_parent($addfile);
$lref = &read_file_lines(&make_chroot($addfile));
@nl = &directive_lines($newv[$i], $_[3]);
splice(@$lref, $_[0]->{'eline'}, 0, @nl);
$newv[$i]->{'file'} = $_[0]->{'file'};
@@ -2432,5 +2430,45 @@ local $out = &backquote_command(
return $? ? split(/\r?\n/, $out) : ( );
}
# delete_records_file(file)
# Given a file (chroot-relative), delete it with locking, and any associated
# journal or log files
sub delete_records_file
{
local ($file) = @_;
local $zonefile = &make_chroot(&absolute_path($file));
&lock_file($zonefile);
unlink($zonefile);
local $logfile = $zonefile.".log";
if (-r $logfile) {
&lock_file($logfile);
unlink($logfile);
}
local $jnlfile = $zonefile.".jnl";
if (-r $jnlfile) {
&lock_file($jnlfile);
unlink($jnlfile);
}
}
# move_zone_button(&config, current-view, zone-index)
# If possible, returns a button row for moving this zone to another view
sub move_zone_button
{
local ($conf, $view, $index) = @_;
local @views = grep { &can_edit_view($_) } &find("view", $conf);
if ($view eq '' && @views || $view ne '' && @views > 1) {
return &ui_buttons_row("move_zone.cgi",
$text{'master_move'},
$text{'master_movedesc'},
&ui_hidden("index", $index).
&ui_hidden("view", $view),
&ui_select("newview", undef,
[ map { [ $_->{'index'}, $_->{'value'} ] }
grep { $_->{'index'} ne $view } @views ]));
}
return undef;
}
1;

View File

@@ -4,8 +4,8 @@
require './bind8-lib.pl';
&ReadParse();
$pconf = &get_config_parent();
$conf = $pconf->{'members'};
$parent = &get_config_parent();
$conf = $parent->{'members'};
$vconf = $conf->[$in{'index'}];
$access{'views'} || &error($text{'view_ecannot'});
@@ -13,34 +13,31 @@ if (!$in{'confirm'}) {
# Ask the user if he is sure ..
&ui_print_header(undef, $text{'vdelete_title'}, "");
# Build input for moving zones to another view
@zones = &find("zone", $vconf->{'members'});
print "<center><p>",&text(@zones ? 'vdelete_mesg' : 'vdelete_mesg2',
"<tt>$vconf->{'value'}</tt>"),"<p>\n";
print "<form action=delete_view.cgi>\n";
print "<input type=hidden name=index value=$in{'index'}>\n";
print "<input type=submit name=confirm value='$text{'delete'}'><br>\n";
if (@zones) {
print "<b>$text{'vdelete_newview'}</b>\n";
print "<input type=radio name=mode value=0> ",
"$text{'vdelete_delete'}\n";
print "<input type=radio name=mode value=1 checked> ",
"$text{'vdelete_root'}\n";
@moveopts = ( [ 0, $text{'vdelete_delete'} ],
[ 1, $text{'vdelete_root'} ] );
@views = &find("view", $conf);
if (@views > 1) {
print "<input type=radio name=mode value=2> ",
"$text{'vdelete_move'}\n";
print "<select name=newview>\n";
foreach $v (@views) {
if ($v->{'index'} != $in{'index'}) {
printf "<option value=%d>%s\n",
$v->{'index'}, $v->{'value'};
}
}
print "</select>\n";
push(@moveopts, [ 2, $text{'vdelete_move'}." ".
&ui_select("newview", undef,
[ map { [ $_->{'index'}, $_->{'value'} ] }
grep { $_->{'index'} != $in{'index'} }
@views ]) ]);
}
print "<br>\n";
$movefield = "<b>$text{'vdelete_newview'}</b> ".
&ui_radio("mode", 1, \@moveopts);
}
print "</form></center>\n";
# Show confirm form
print &ui_confirmation_form("delete_view.cgi",
&text(@zones ? 'vdelete_mesg' : 'vdelete_mesg2',
"<tt>$vconf->{'value'}</tt>"),
[ [ 'index', $in{'index'} ] ],
[ [ 'confirm', $text{'view_delete'} ] ],
$movefield);
&ui_print_footer("", $text{'index_return'});
exit;
}
@@ -48,9 +45,11 @@ if (!$in{'confirm'}) {
# deal with the zones in this view
@zones = &find("zone", $vconf->{'members'});
if ($in{'mode'} == 1) {
$dest = $pconf;
# Adding to top level
$dest = &get_config_parent(&add_to_file());
}
else {
# Adding to some other view
$dest = $conf->[$in{'newview'}];
}
&lock_file(&make_chroot($dest->{'file'}));
@@ -58,24 +57,23 @@ foreach $z (@zones) {
local $type = &find_value("type", $z->{'members'});
next if (!$type || $type eq 'hint');
if ($in{'mode'} == 0) {
# Delete the records file
local $file = &find_value("file", $z->{'members'});
if ($file) {
&lock_file(&make_chroot(&absolute_path($file)));
unlink(&make_chroot(&absolute_path($file)));
# Delete the records file, and perhaps journal
local $f = &find_value("file", $z->{'members'});
if ($f) {
&delete_records_file($f->{'value'});
}
}
else {
# Move to another view or the top level
# Move to another view or the top level.
# File may change
delete($z->{'file'});
&save_directive($dest, undef, [ $z ], $in{'mode'} == 2 ? 1 : 0);
}
}
&flush_file_lines();
# remove the view directive
&lock_file(&make_chroot($vconf->{'file'}));
$lref = &read_file_lines(&make_chroot($vconf->{'file'}));
splice(@$lref, $vconf->{'line'}, $vconf->{'eline'} - $vconf->{'line'} + 1);
&save_directive($parent, [ $vconf ], [ ]);
&flush_file_lines();
&unlock_all_files();
&webmin_log("delete", "view", $vconf->{'value'}, \%in);

View File

@@ -5,10 +5,12 @@
require './bind8-lib.pl';
&ReadParse();
$conf = &get_config();
$parent = &get_config_parent();
if ($in{'view'} ne '') {
$view = $conf->[$in{'view'}];
$conf = $view->{'members'};
$viewname = $view->{'values'}->[0];
$parent = $view;
}
else {
$viewname = undef;
@@ -41,7 +43,7 @@ if (!$in{'confirm'} && $config{'confirm_zone'}) {
&text('delete_mesg3', $zdesc),
[ [ 'index', $in{'index'} ],
[ 'view', $in{'view'} ] ],
[ [ 'confirm', $text{'delete'} ] ],
[ [ 'confirm', $text{'master_del'} ] ],
($type eq 'master' ?
$text{$rev ? 'delete_fwd' : 'delete_rev'}." ".
&ui_yesno_radio("rev", 1)."<br>" : "").
@@ -106,21 +108,12 @@ elsif ($rev && $in{'rev'} && $type eq 'master') {
# delete the records file
$f = &find("file", $zconf->{'members'});
if ($f && $type ne 'hint') {
local $zonefile = &make_chroot(&absolute_path($f->{'value'}));
&lock_file($zonefile);
unlink($zonefile);
local $logfile = $zonefile.".log";
if (!-r $logfile) { $logfile = $zonefile.".jnl"; }
if (-r $logfile) {
&lock_file($logfile);
unlink($logfile);
}
&delete_records_file($f->{'value'});
}
# remove the zone directive
&lock_file(&make_chroot($zconf->{'file'}));
$lref = &read_file_lines(&make_chroot($zconf->{'file'}));
splice(@$lref, $zconf->{'line'}, $zconf->{'eline'} - $zconf->{'line'} + 1);
&save_directive($parent, [ $zconf ], [ ]);
&flush_file_lines();
&unlock_all_files();
&webmin_log("delete", &find("type", $zconf->{'members'})->{'value'},

View File

@@ -23,17 +23,7 @@ if (!$access{'ro'}) {
print &ui_buttons_start();
# Move to another view
@views = &find("view", $bconf);
if ($in{'view'} eq '' && @views || $in{'view'} ne '' && @views > 1) {
print &ui_buttons_row("move_zone.cgi",
$text{'master_move'},
$text{'master_movedesc'},
&ui_hidden("index", $in{'index'}).
&ui_hidden("view", $in{'view'}),
&ui_select("newview", undef,
map { [ $_->{'index'}, $_->{'view'} ] }
grep { $_->{'index'} ne $in{'view'} } @views));
}
print &move_zone_button($bconf, $in{'view'}, $in{'index'});
# Delete zone
if ($access{'delete'}) {

View File

@@ -44,17 +44,7 @@ else {
print &ui_buttons_start();
# Move to another view
@views = &find("view", $bconf);
if ($in{'view'} eq '' && @views || $in{'view'} ne '' && @views > 1) {
print &ui_buttons_row("move_zone.cgi",
$text{'master_move'},
$text{'master_movedesc'},
&ui_hidden("index", $in{'index'}).
&ui_hidden("view", $in{'view'}),
&ui_select("newview", undef,
map { [ $_->{'index'}, $_->{'view'} ] }
grep { $_->{'index'} ne $in{'view'} } @views));
}
print &move_zone_button($bconf, $in{'view'}, $in{'index'});
# Delete zone
if ($access{'delete'}) {

View File

@@ -147,16 +147,29 @@ if (!$access{'ro'} && ($access{'delete'} || $apply)) {
&ui_hidden("index", $in{'index'}).
&ui_hidden("view", $in{'view'})
);
}
# Show button to check records
if (&supports_check_zone()) {
print &ui_buttons_row(
"check_zone.cgi", $text{'master_checkzone'},
$text{'master_checkzonemsg'},
&ui_hidden("index", $in{'index'}).
&ui_hidden("view", $in{'view'})
);
}
# Show button to check records
if (&supports_check_zone()) {
print &ui_buttons_row(
"check_zone.cgi", $text{'master_checkzone'},
$text{'master_checkzonemsg'},
&ui_hidden("index", $in{'index'}).
&ui_hidden("view", $in{'view'})
);
}
# Move zone button
$conf = &get_config();
print &move_zone_button($conf, $in{'view'}, $in{'index'});
# Convert to slave zone
if ($access{'slave'}) {
print &ui_buttons_row("convert_master.cgi",
$text{'master_convert'},
$text{'master_convertdesc'},
&ui_hidden("index", $in{'index'}).
&ui_hidden("view", $in{'view'}));
}
print &ui_buttons_end();

View File

@@ -39,34 +39,6 @@ print &address_input($text{'master_notify2'}, "also-notify", $zconf);
print &ui_table_end();
print &ui_form_end([ [ undef, $text{'save'} ] ]);
# Buttons at end of page
print &ui_hr();
print &ui_buttons_start();
# Move to another view
@views = grep { &can_edit_view($_) } &find("view", $bconf);
if ($in{'view'} eq '' && @views || $in{'view'} ne '' && @views > 1) {
print &ui_buttons_row("move_zone.cgi",
$text{'master_move'},
$text{'master_movedesc'},
&ui_hidden("index", $in{'index'}).
&ui_hidden("view", $in{'view'}),
&ui_select("newview", undef,
map { [ $_->{'index'}, $_->{'view'} ] }
grep { $_->{'index'} ne $in{'view'} } @views));
}
# Convert to slave zone
if ($access{'slave'}) {
print &ui_buttons_row("convert_master.cgi",
$text{'master_convert'},
$text{'master_convertdesc'},
&ui_hidden("index", $in{'index'}).
&ui_hidden("view", $in{'view'}));
}
print &ui_buttons_end();
&ui_print_footer("edit_master.cgi?index=$in{'index'}&view=$in{'view'}",
$text{'master_return'});

View File

@@ -98,8 +98,8 @@ if (!$access{'ro'} && ($access{'delete'} || $apply)) {
&ui_hidden("view", $in{'view'}));
}
# Show button to do an NDC reload
if ($apply) {
# Show button to do an NDC reload
print &ui_buttons_row("restart_zone.cgi",
$text{'slave_apply'},
$text{'slave_applymsg2'},
@@ -107,6 +107,19 @@ if (!$access{'ro'} && ($access{'delete'} || $apply)) {
&ui_hidden("view", $in{'view'}));
}
# Move to other view
$conf = &get_config();
print &move_zone_button($conf, $in{'view'}, $in{'index'});
# Convert to master zone
if ($access{'master'} && $st[7]) {
print &ui_buttons_row("convert_slave.cgi",
$text{'slave_convert'},
$text{'slave_convertdesc'},
&ui_hidden("index", $in{'index'}).
&ui_hidden("view", $in{'view'}));
}
print &ui_buttons_end();
}

View File

@@ -58,34 +58,6 @@ print &address_input($text{'slave_notify2'}, "also-notify", $zconf);
print &ui_table_end();
print &ui_form_end([ [ undef, $text{'save'} ] ]);
# Buttons at end of page
print &ui_hr();
print &ui_buttons_start();
# Move to a new view
@views = &find("view", $bconf);
if ($in{'view'} eq '' && @views || $in{'view'} ne '' && @views > 1) {
print &ui_buttons_row("move_zone.cgi",
$text{'master_move'},
$text{'master_movedesc'},
&ui_hidden("index", $in{'index'}).
&ui_hidden("view", $in{'view'}),
&ui_select("newview", undef,
map { [ $_->{'index'}, $_->{'view'} ] }
grep { $_->{'index'} ne $in{'view'} } @views));
}
# Convert to master zone
if ($access{'master'} && -s &make_chroot($file)) {
print &ui_buttons_row("convert_slave.cgi",
$text{'slave_convert'},
$text{'slave_convertdesc'},
&ui_hidden("index", $in{'index'}).
&ui_hidden("view", $in{'view'}));
}
print &ui_buttons_end();
&ui_print_footer("edit_slave.cgi?index=$in{'index'}&view=$in{'view'}",
$text{'master_return'});

View File

@@ -12,40 +12,39 @@ $access{'views'} || &error($text{'view_ecannot'});
&ui_print_header(undef, $text{'view_title'}, "");
print "<form action=save_view.cgi>\n";
print "<input type=hidden name=index value=\"$in{'index'}\">\n";
print "<table border width=100%>\n";
print "<tr $tb> <td><b>$text{'view_opts'}</b></td> </tr>\n";
print "<tr $cb> <td><table width=100%>\n";
# Form header
print &ui_form_start("save_view.cgi");
print &ui_hidden("index", $in{'index'});
print &ui_table_start($text{'view_opts'}, "width=100%", 4);
# View name
@v = @{$view->{'values'}};
print "<tr> <td><b>$text{'view_name'}</b></td>\n";
print "<td><tt>$v[0]</tt></td>\n";
print &ui_table_row($text{'view_name'}, "<tt>$v[0]</tt>");
print "<td><b>$text{'view_class'}</b></td>\n";
printf "<td>%s</td> </tr>\n",
$v[1] ? "<tt>$v[1]</tt>" : "$text{'default'} (<tt>IN</tt>)";
# Class (not editable)
print &ui_table_row($text{'view_class'},
$v[1] ? "<tt>$v[1]</tt>" : "$text{'default'} (<tt>IN</tt>)");
print "<tr>\n";
print &addr_match_input($text{'view_match'}, "match-clients", $vconf);
print &choice_input($text{'view_recursion'}, 'recursion', $vconf,
$text{'yes'}, 'yes', $text{'no'}, 'no',
$text{'default'}, undef);
print "</tr>\n";
print "</table></td></tr> </table>\n";
print &ui_table_end();
if ($access{'ro'}) {
print "</form>\n";
print &ui_form_end();
}
else {
print "<table width=100%><tr><td align=left>\n";
print "<input type=submit value=\"$text{'save'}\"></td></form>\n";
print &ui_form_end([ [ undef, $text{'save'} ] ]);
print "<form action=delete_view.cgi>\n";
print "<input type=hidden name=index value=\"$in{'index'}\">\n";
print "<td align=right><input type=submit ",
"value=\"$text{'delete'}\"></td></form>\n";
print "</tr></table>\n";
# Delete button
print &ui_hr();
print &ui_buttons_start();
print &ui_buttons_row("delete_view.cgi",
$text{'view_delete'}, $text{'view_deletemsg'},
&ui_hidden("index", $in{'index'}));
print &ui_buttons_end();
}
&ui_print_footer("", $text{'index_return'});

View File

@@ -71,13 +71,14 @@ $chroot = &get_chroot();
if ($need_create) {
print &text('index_eempty',
"<tt>".&make_chroot($config{'named_conf'})."</tt>"),"<p>\n";
print "<form action=\"dns_boot.cgi\">\n";
print "<input type=radio name=real value=0> $text{'index_local'}<p>\n";
print "<input type=radio name=real value=1 checked> ",
"$text{'index_download'}<p>\n";
print "<input type=radio name=real value=2> $text{'index_webmin'}<p>\n";
print "<center><input type=submit value=\"$text{'index_create'}\">",
"</center></form>\n";
print &ui_form_start("dns_boot.cgi");
print &ui_radio("real", 1,
[ [ 0, $text{'index_local'}."<br>" ],
[ 1, $text{'index_download'}."<br>" ],
[ 2, $text{'index_webmin'}."<br>" ] ]);
print &ui_form_end([ [ undef, $text{'index_create'} ] ]);
&ui_print_footer("/", $text{"index"});
exit;
}

View File

@@ -113,7 +113,7 @@ master_edeletecannot=You are not allowed to delete zones
master_etaken=This zone already exists
master_include=Additional template file
master_noinclude=Just use records above
master_convert=Convert to slave zone
master_convert=Convert to Slave Zone
master_convertdesc=Turns this master zone into a slave, so that it will receive records from another master server instead of serving them locally.
master_whois=Lookup WHOIS Information
master_move=Move to view:
@@ -178,7 +178,7 @@ slave_efile=Missing records file
slave_efile2='$1' is not an allowable records file
slave_mins=minutes
slave_master_port=port
slave_convert=Convert to master zone
slave_convert=Convert to Master Zone
slave_convertdesc=Click this button to convert this slave zone into a master, with all the records that were last transferred from the original master system.
slave_manual=View Records File
slave_delmsg=Click this button to delete this zone from your DNS server. The source master zone will be un-touched.
@@ -748,10 +748,12 @@ view_class=DNS records class
view_match=Apply this view to clients
view_recursion=Do full recursive lookups for clients?
view_ecannot=You are not allowed to edit this view
view_delete=Delete View
view_deletemsg=Click this button to delete the view. You will have a choice of moving zones it contains to another view, or deleting them as well.
vcreate_title=Create Client View
vcreate_match_all=All clients
vcreate_match_sel=Selected addresses, networks and ACLs
vcreate_match_sel=Listed addresses, networks and ACLs..
vcreate_err=Failed to create view
vcreate_ename=Missing or invalid view name
vcreate_etaken=View name is already taken

View File

@@ -66,8 +66,7 @@ else {
# delete the records file
$f = &find("file", $zconf->{'members'});
if ($f && $type ne 'hint') {
&lock_file(&make_chroot(&absolute_path($f->{'value'})));
unlink(&make_chroot(&absolute_path($f->{'value'})));
&delete_records_file($f->{'value'});
}
# remove the zone directive

View File

@@ -10,28 +10,26 @@ $access{'ro'} && &error($text{'vcreate_ecannot'});
&ui_print_header(undef, $text{'vcreate_title'}, "");
print "<form action=create_view.cgi>\n";
print "<table border width=100%>\n";
print "<tr $tb> <td><b>$text{'view_opts'}</b></td> </tr>\n";
print "<tr $cb> <td><table width=100%>\n";
# Form header
print &ui_form_start("create_view.cgi");
print &ui_table_start($text{'view_opts'}, "width=100%", 4);
print "<tr> <td><b>$text{'view_name'}</b></td>\n";
print "<td><input name=name size=25></td>\n";
# View name
print &ui_table_row($text{'view_name'},
&ui_textbox("name", undef, 25));
print "<td><b>$text{'view_class'}</b></td>\n";
print "<td><input type=radio name=class_def value=1 checked> ",
"$text{'default'}\n";
print "<input type=radio name=class_def value=0>\n";
print "<input name=class size=4></td> </tr>\n";
# Custom class
print &ui_table_row($text{'view_class'},
&ui_opt_textbox("class", undef, 4, "$text{'default'} (<tt>IN</tt>)"));
print "<tr> <td valign=top><b>$text{'view_match'}</b></td> <td colspan=3>\n";
print "<input type=radio name=match_def value=1> $text{'vcreate_match_all'}\n";
print "<input type=radio name=match_def value=0 checked> ",
"$text{'vcreate_match_sel'}<br>\n";
print "<textarea name=match rows=5 cols=40></textarea></td> </tr>\n";
# Clients to match
print &ui_table_row($text{'view_match'},
&ui_radio("match_def", 0, [ [ 1, $text{'vcreate_match_all'} ],
[ 0, $text{'vcreate_match_sel'} ] ])."<br>".
&ui_textarea("match", undef, 5, 40));
print "</table></td></tr> </table>\n";
print "<input type=submit value=\"$text{'create'}\"></form>\n";
print &ui_table_end();
print &ui_form_end([ [ undef, $text{'create'} ] ]);
&ui_print_footer("", $text{'index_return'});