#!/usr/local/bin/perl
# master_form.cgi
# Form for creating a new master zone

require './bind8-lib.pl';
&ReadParse();
%access = &get_module_acl();
$access{'master'} || &error($text{'mcreate_ecannot'});
&ui_print_header(undef, $text{'mcreate_title'}, "");

print "<form action=create_master.cgi>\n";
print "<table border width=100%>\n";
print "<tr> <td $tb><b>$text{'mcreate_opts'}</b></td> </tr>\n";
print "<tr> <td $cb><table width=100%>\n";

print "<tr> <td><b>$text{'mcreate_type'}</b></td>\n";
print "<td colspan=3><input type=radio name=rev value=0 checked>\n";
print "$text{'mcreate_fwd'}\n";
print "&nbsp;&nbsp;<input type=radio name=rev value=1>\n";
print "$text{'mcreate_rev'}</td> </tr>\n";

print "<tr> <td><b>$text{'mcreate_dom'}</b></td>\n";
print "<td colspan=3><input name=zone size=40></td> </tr>\n";

$conf = &get_config();
@views = &find("view", $conf);
if (@views) {
	print "<tr> <td><b>$text{'mcreate_view'}</b></td>\n";
	print "<td colspan=3><select name=view>\n";
	foreach $v (grep { &can_edit_view(\%access, $_) } @views) {
		printf "<option value=%d>%s\n",
			$v->{'index'}, $v->{'value'};
		}
	print "</select></td> </tr>\n";
	}

print "<tr> <td><b>$text{'mcreate_file'}</b></td> <td colspan=3>\n";
print "<input type=radio name=file_def value=1 checked> ",
      "$text{'mcreate_auto'}\n";
print "<input type=radio name=file_def value=0>\n";
print "<input name=file size=30>",&file_chooser_button("file"),"</td> </tr>\n";

print "<tr> <td><b>$text{'master_server'}</b></td>\n";
printf "<td colspan=3><input name=master size=30 value=\"%s\">\n",
	$config{'default_prins'} || &get_system_hostname();
printf "<input type=checkbox name=master_ns value=1 checked> %s</td> </tr>\n",
	$text{'master_ns'};

&foreign_require("servers", "servers-lib.pl");
@servers = grep { $_->{'user'} } &servers::list_servers();
if (@servers && $access{'remote'}) {
	print "<tr> <td valign=top><b>$text{'master_slave'}</b></td>\n";
	print "<td colspan=3><select name=slave>\n";
	print "<option value=''>&nbsp;\n";
	foreach $s (@servers) {
		printf "<option value=%s %s>%s\n",
		    $s->{'host'},
		    $s->{'host'} eq $config{'default_slave'} ? 'selected' : '',
		    $s->{'desc'} ? $s->{'desc'} : $s->{'host'};
		}
	print "</select> $text{'master_mip'}\n";
	printf "<input name=mip size=30 value='%s'><br>\n",
		$config{'this_ip'} || &to_ipaddress(&get_system_hostname());

	print "<b>$text{'slave_file'}</b>\n";
	print "<input type=radio name=sfile_def value=1> $text{'slave_none'}\n";
	print "<input type=radio name=sfile_def value=2 checked> ",
	      "$text{'slave_auto'}\n";
	print "<input type=radio name=sfile_def value=0>\n";
	print "<input name=sfile size=30></td> </tr>\n";
	}

print "<tr> <td><b>$text{'master_email'}</b></td>\n";
printf "<td colspan=3><input name=email size=40 value='%s'></td> </tr>\n",
	$config{'tmpl_email'};

print "<tr> <td><b>$text{'master_tmpl'}</b></td>\n";
printf "<td><input type=radio name=tmpl value=1 %s> $text{'yes'}\n",
	$config{'tmpl_0'} || $config{'tmpl_include'} ? 'checked' : '';
printf "<input type=radio name=tmpl value=0 %s> $text{'no'}</td>\n",
	$config{'tmpl_0'} || $config{'tmpl_include'} ? '' : 'checked';
print "<td><b>$text{'master_ip'}</b></td>\n";
print "<td><input name=ip size=15></td> </tr>\n";

&get_zone_defaults(\%zd);
print "<tr> <td><b>$text{'master_refresh'}</b></td>\n";
print "<td><input name=refresh size=8 value=$zd{'refresh'}>\n";
&time_unit_choice("refunit", $zd{'refunit'});
print "</td>\n";

print "<td><b>$text{'master_retry'}</b></td>\n";
print "<td><input name=retry size=8 value=$zd{'retry'}>\n";
&time_unit_choice("retunit", $zd{'retunit'});
print "</td> </tr>\n";

print "<tr> <td><b>$text{'master_expiry'}</b></td>\n";
print "<td><input name=expiry size=8 value=$zd{'expiry'}>\n";
&time_unit_choice("expunit", $zd{'expunit'});
print "</td>\n";

print "<td><b>$text{'master_minimum'}</b></td>\n";
print "<td><input name=minimum size=8 value=$zd{'minimum'}>\n";
&time_unit_choice("minunit", $zd{'minunit'});
print "</td> </tr>\n";

print "</table></td></tr></table>\n";
print "<input type=submit value=\"$text{'create'}\"></form>\n";

&ui_print_footer("", $text{'index_return'});

