#!/usr/local/bin/perl
# convert_master.cgi
# Convert a master zone into a slave

require './bind8-lib.pl';
&ReadParse();
%access = &get_module_acl();
$conf = &get_config();
if ($in{'view'} ne '') {
	$conf = $conf->[$in{'view'}]->{'members'};
	}
$zconf = $conf->[$in{'index'}];
&error_setup($text{'convert_err'});
$access{'slave'} || &error($text{'screate_ecannot1'});

&lock_file($config{'chroot'}.$zconf->{'file'});
&save_directive($zconf, 'type', [ { 'name' => 'type',
				    'values' => [ 'slave' ] } ], 1);
if ($config{'default_master'}) {
	@mdirs = map { { 'name' => $_ } } split(/\s+/, $config{'default_master'});
	&save_directive($zconf, 'masters', [ { 'name' => 'masters',
					       'type' => 1,
					       'members' => \@mdirs } ], 1);
	}
&flush_file_lines();
&unlock_file($config{'chroot'}.$zconf->{'file'});
&redirect("");

