#!/usr/local/bin/perl
# save_text.cgi
# Save a manually edit zone file

require './bind8-lib.pl';
&ReadParseMime();
$conf = &get_config();
if ($in{'view'} ne '') {
	$view = $conf->[$in{'view'}];
	$conf = $view->{'members'};
	}
$zconf = $conf->[$in{'index'}]->{'members'};
$file = &absolute_path(&find("file", $zconf)->{'value'});
%access = &get_module_acl();
&can_edit_zone(\%access, $conf->[$in{'index'}], $view) ||
	&error($text{'master_ecannot'});
$access{'file'} || &error($text{'text_ecannot'});
$access{'ro'} && &error($text{'master_ero'});

&lock_file(&make_chroot($file));
$in{'text'} =~ s/\r//g;
$in{'text'} .= "\n" if ($in{'text'} !~ /\n$/);
open(FILE, ">".&make_chroot($file));
print FILE $in{'text'};
close(FILE);
&unlock_file(&make_chroot($file));
&webmin_log("text", undef, $conf->[$in{'index'}]->{'value'},
	    { 'file' => $file });
&redirect("edit_master.cgi?index=$in{'index'}&view=$in{'view'}");

