Handle hostnames with upper-case letters
[webmin.git] / bind8 / delete_view.cgi
1 #!/usr/local/bin/perl
2 # delete_zone.cgi
3 # Delete an existing view and all its zones
4
5 require './bind8-lib.pl';
6 &ReadParse();
7 $parent = &get_config_parent();
8 $conf = $parent->{'members'};
9 $vconf = $conf->[$in{'index'}];
10 $access{'views'} || &error($text{'view_ecannot'});
11
12 if (!$in{'confirm'}) {
13         # Ask the user if he is sure ..
14         &ui_print_header(undef, $text{'vdelete_title'}, "");
15
16         # Build input for moving zones to another view
17         @zones = &find("zone", $vconf->{'members'});
18         if (@zones) {
19                 @moveopts = ( [ 0, $text{'vdelete_delete'} ],
20                               [ 1, $text{'vdelete_root'} ] );
21                 @views = &find("view", $conf);
22                 if (@views > 1) {
23                         push(@moveopts, [ 2, $text{'vdelete_move'}." ".
24                                 &ui_select("newview", undef,
25                                    [ map { [ $_->{'index'}, $_->{'value'} ] }
26                                          grep { $_->{'index'} != $in{'index'} }
27                                               @views ]) ]);
28                         }
29                 $movefield = "<b>$text{'vdelete_newview'}</b> ".
30                              &ui_radio("mode", 1, \@moveopts);
31                 }
32
33         # Show confirm form
34         print &ui_confirmation_form("delete_view.cgi",
35                 &text(@zones ? 'vdelete_mesg' : 'vdelete_mesg2',
36                       "<tt>$vconf->{'value'}</tt>"),
37                 [ [ 'index', $in{'index'} ] ],
38                 [ [ 'confirm', $text{'view_delete'} ] ],
39                 $movefield);
40
41         &ui_print_footer("", $text{'index_return'});
42         exit;
43         }
44
45 # deal with the zones in this view
46 @zones = &find("zone", $vconf->{'members'});
47 if ($in{'mode'} == 1) {
48         # Adding to top level
49         $dest = &get_config_parent(&add_to_file());
50         }
51 else {
52         # Adding to some other view
53         $dest = $conf->[$in{'newview'}];
54         }
55 &lock_file(&make_chroot($dest->{'file'}));
56 foreach $z (@zones) {
57         local $type = &find_value("type", $z->{'members'});
58         next if (!$type || $type eq 'hint');
59         if ($in{'mode'} == 0) {
60                 # Delete the records file, and perhaps journal
61                 local $f = &find_value("file", $z->{'members'});
62                 if ($f) {
63                         &delete_records_file($f->{'value'});
64                         }
65                 }
66         else {
67                 # Move to another view or the top level.
68                 # File may change 
69                 delete($z->{'file'});
70                 &save_directive($dest, undef, [ $z ], $in{'mode'} == 2 ? 1 : 0);
71                 }
72         }
73
74 # remove the view directive
75 &lock_file(&make_chroot($vconf->{'file'}));
76 &save_directive($parent, [ $vconf ], [ ]);
77 &flush_file_lines();
78 &unlock_all_files();
79 &webmin_log("delete", "view", $vconf->{'value'}, \%in);
80 &redirect("");
81