Handle hostnames with upper-case letters
[webmin.git] / bind8 / edit_master.cgi
1 #!/usr/local/bin/perl
2 # edit_master.cgi
3 # Display options and directives in an existing master zone
4
5 require './bind8-lib.pl';
6 &ReadParse();
7 if ($in{'zone'}) {
8         $zone = &get_zone_name($in{'zone'}, 'any');
9         $in{'index'} = $zone->{'index'};
10         $in{'view'} = $zone->{'viewindex'};
11         }
12 else {
13         $zone = &get_zone_name($in{'index'}, $in{'view'});
14         }
15 $dom = $zone->{'name'};
16 &can_edit_zone($zone) || &error($text{'master_ecannot'});
17 $desc = &ip6int_to_net(&arpa_to_ip($dom));
18 &ui_print_header($desc, $text{'master_title'}, "",
19                  undef, undef, undef, undef, &restart_links($zone));
20
21 # Find the record types
22 if (!$config{'largezones'}) {
23         @recs = grep { !$_->{'generate'} && !$_->{'defttl'} }
24                      &read_zone_file($zone->{'file'}, $dom);
25         }
26 if ($dom =~ /in-addr\.arpa/i || $dom =~ /\.$ipv6revzone/i) {
27         @rcodes = &get_reverse_record_types();
28         }
29 else {
30         @rcodes = &get_forward_record_types();
31         }
32 push(@rcodes, "ALL");
33 @rcodes = grep { &can_edit_type($_, \%access) } @rcodes;
34
35 if (!$config{'largezones'}) {
36         # See what record type we have
37         foreach $c (@rcodes) { $rnum{$c} = 0; }
38         foreach $r (@recs) {
39                 $rnum{$r->{'type'}}++;
40                 $rnum{"ALL"}++ if ($r->{'type'} ne "SOA");
41                 if ($r->{'type'} eq "SOA") { $soa = $r; }
42                 }
43         }
44 else {
45         # Just assume that we have all types
46         $soa = 1;
47         }
48
49 if ($config{'show_list'}) {
50         # display as list
51         $mid = int((@rcodes+1)/2);
52         @grid = ( );
53         push(@grid, &types_table(@rcodes[0..$mid-1]));
54         push(@grid, &types_table(@rcodes[$mid..$#rcodes]));
55         print &ui_grid_table(\@grid, 2, 100, [ "width=50%", "width=50%" ]);
56         }
57 else {
58         # display as icons
59         for($i=0; $i<@rcodes; $i++) {
60                 push(@rlinks, "edit_recs.cgi?index=$in{'index'}&".
61                               "view=$in{'view'}&type=$rcodes[$i]");
62                 push(@rtitles, ($text{"type_$rcodes[$i]"} || $rcodes[$i]).
63                                (defined(%rnum) ? " ($rnum{$rcodes[$i]})" : ""));
64                 push(@ricons, $is_extra{$rcodes[$i]} ?
65                                 "images/extra.gif" : "images/$rcodes[$i].gif");
66                 }
67         &icons_table(\@rlinks, \@rtitles, \@ricons);
68         }
69
70 # links to forms editing text, soa and zone options
71 if ($access{'file'}) {
72         # Manually edit zone
73         push(@links, "edit_text.cgi?index=$in{'index'}&view=$in{'view'}");
74         push(@titles, $text{'master_manual'});
75         push(@images, "images/text.gif");
76         }
77 if ($access{'params'}) {
78         # SOA values
79         push(@links, "edit_soa.cgi?index=$in{'index'}&view=$in{'view'}");
80         push(@titles, $text{'master_soa'});
81         push(@images, "images/soa.gif");
82         }
83 if ($access{'opts'}) {
84         # Zone options in named.conf
85         push(@links, "edit_options.cgi?index=$in{'index'}&view=$in{'view'}");
86         push(@titles, $text{'master_options'});
87         push(@images, "images/options.gif");
88         }
89 if ($access{'findfree'}) {
90         # Find free IPs
91         push(@links, "find_free.cgi?index=$in{'index'}&view=$in{'view'}");
92         push(@titles, $text{'findfree_desc'});
93         push(@images, "images/findfree.gif");
94         }
95 if ($access{'gen'}) {
96         # Generators
97         push(@links, "list_gen.cgi?index=$in{'index'}&view=$in{'view'}");
98         push(@titles, $text{'gen_title'});
99         push(@images, "images/gen.gif");
100         }
101 if ($access{'whois'} && &has_command($config{'whois_cmd'}) &&
102     $dom !~ /in-addr\.arpa/i) {
103         # Whois lookup
104         push(@links, "whois.cgi?index=$in{'index'}&view=$in{'view'}");
105         push(@titles, $text{'master_whois'});
106         push(@images, "images/whois.gif");
107         }
108 if (&supports_dnssec()) {
109         # Zone key
110         push(@links, "edit_zonekey.cgi?index=$in{'index'}&view=$in{'view'}");
111         push(@titles, $text{'zonekey_title'});
112         push(@images, "images/zonekey.gif");
113         }
114
115 if (@links) {
116         print &ui_hr();
117         &icons_table(\@links, \@titles, \@images);
118         }
119
120 $apply = $access{'apply'} && &has_ndc();
121 if (!$access{'ro'} && ($access{'delete'} || $apply)) {
122         print &ui_hr();
123         print &ui_buttons_start();
124
125         if ($apply) {
126                 # Show button to freeze
127                 print &ui_buttons_row(
128                         "freeze_zone.cgi", $text{'master_freeze'},
129                         $text{'master_freezemsg2'},
130                         &ui_hidden("index", $in{'index'}).
131                         &ui_hidden("view", $in{'view'})
132                         );
133
134                 # Show button to un-freeze
135                 print &ui_buttons_row(
136                         "unfreeze_zone.cgi", $text{'master_unfreeze'},
137                         $text{'master_unfreezemsg2'},
138                         &ui_hidden("index", $in{'index'}).
139                         &ui_hidden("view", $in{'view'})
140                         );
141                 }
142
143         # Show button to check records
144         if (&supports_check_zone()) {
145                 print &ui_buttons_row(
146                         "check_zone.cgi", $text{'master_checkzone'},
147                         $text{'master_checkzonemsg'},
148                         &ui_hidden("index", $in{'index'}).
149                         &ui_hidden("view", $in{'view'})
150                         );
151                 }
152
153         # Move zone button
154         $conf = &get_config();
155         print &move_zone_button($conf, $in{'view'}, $in{'index'});
156
157         # Convert to slave zone
158         if ($access{'slave'}) {
159                 print &ui_buttons_row("convert_master.cgi",
160                         $text{'master_convert'},
161                         $text{'master_convertdesc'},
162                         &ui_hidden("index", $in{'index'}).
163                         &ui_hidden("view", $in{'view'}));
164                 }
165
166         if ($access{'delete'}) {
167                 # Show button to delete zome
168                 print &ui_buttons_row(
169                         "delete_zone.cgi", $text{'master_del'},
170                         $text{'master_delmsg'}." ".
171                         ($dom !~ /in-addr\.arpa/i &&
172                          $dom !~ /\.$ipv6revzone/i ? $text{'master_delrev'}
173                                                    : ""),
174                         &ui_hidden("index", $in{'index'}).
175                         &ui_hidden("view", $in{'view'})
176                         );
177                 }
178
179         print &ui_buttons_end();
180         }
181
182 &ui_print_footer("", $text{'index_return'});
183
184 sub types_table
185 {
186 my $rv;
187 if ($_[0]) {
188         $rv .= &ui_columns_start([
189                 $text{'master_type'},
190                 defined(%rnum) ? ( $text{'master_records'} ) : ( )
191                 ], 100);
192         for(my $i=0; $_[$i]; $i++) {
193                 local @cols = ( "<a href=\"edit_recs.cgi?".
194                       "index=$in{'index'}&view=$in{'view'}&type=$_[$i]\">".
195                       ($text{"recs_$_[$i]"} || $_[$i])."</a>" );
196                 if (defined(%rnum)) {
197                         push(@cols, $rnum{$_[$i]});
198                         }
199                 $rv .= &ui_columns_row(\@cols);
200                 }
201         $rv .= &ui_columns_end();
202         }
203 return $rv;
204 }
205