Handle hostnames with upper-case letters
[webmin.git] / bind8 / edit_slave.cgi
1 #!/usr/local/bin/perl
2 # edit_slave.cgi
3 # Display records and other info for an existing slave or stub 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) ||
17         &error($text{'slave_ecannot'});
18
19 $desc = &ip6int_to_net(&arpa_to_ip($dom));
20 if ($zone->{'file'}) {
21         @st = stat(&make_chroot(&absolute_path($zone->{'file'})));
22         $lasttrans = &text('slave_last', @st && $st[7] ? &make_date($st[9])
23                                                        : $text{'slave_never'});
24         }
25 &ui_print_header($desc, $0 =~ /edit_slave/ ? $text{'slave_title'}
26                                            : $text{'stub_title'},
27                  "", undef, 0, 0, 0, &restart_links($zone),
28                  undef, undef, $lasttrans);
29
30 if ($zone->{'file'}) {
31         print "<p>\n";
32         @recs = &read_zone_file($zone->{'file'}, $dom);
33         if ($dom =~ /in-addr\.arpa/i || $dom =~ /\.$ipv6revzone/i) {
34                 @rcodes = &get_reverse_record_types();
35                 }
36         else {
37                 @rcodes = &get_forward_record_types();
38                 }
39         foreach $c (@rcodes) { $rnum{$c} = 0; }
40         foreach $r (@recs) {
41                 $rnum{$r->{'type'}}++;
42                 if ($r->{'type'} eq "SOA") { $soa = $r; }
43                 }
44         if ($config{'show_list'}) {
45                 # display as list
46                 $mid = int((@rcodes+1)/2);
47                 @grid = ( );
48                 push(@grid, &types_table(@rcodes[0..$mid-1]));
49                 push(@grid, &types_table(@rcodes[$mid..$#rcodes]));
50                 print &ui_grid_table(\@grid, 2, 100,
51                         [ "width=50%", "width=50%" ]);
52                 }
53         else {
54                 # display as icons
55                 for($i=0; $i<@rcodes; $i++) {
56                         push(@rlinks, "edit_recs.cgi?index=$in{'index'}".
57                                       "&view=$in{'view'}&type=$rcodes[$i]");
58                         push(@rtitles, $text{"type_$rcodes[$i]"}.
59                                        " ($rnum{$rcodes[$i]})");
60                         push(@ricons, "images/$rcodes[$i].gif");
61                         }
62                 &icons_table(\@rlinks, \@rtitles, \@ricons);
63                 }
64         $done_recs = 1;
65         }
66
67 # Shut buttons for editing, options and whois
68 if ($access{'file'} && $zone->{'file'}) {
69         push(@links, "view_text.cgi?index=$in{'index'}&view=$in{'view'}");
70         push(@titles, $text{'slave_manual'});
71         push(@images, "images/text.gif");
72         }
73 if ($access{'opts'}) {
74         push(@links, "edit_soptions.cgi?index=$in{'index'}&view=$in{'view'}");
75         push(@titles, $text{'master_options'});
76         push(@images, "images/options.gif");
77         }
78 if ($access{'whois'} && &has_command($config{'whois_cmd'}) &&
79     $dom !~ /in-addr\.arpa/i) {
80         push(@links, "whois.cgi?index=$in{'index'}&view=$in{'view'}");
81         push(@titles, $text{'master_whois'});
82         push(@images, "images/whois.gif");
83         }
84 push(@links, "xfer.cgi?index=$in{'index'}&view=$in{'view'}");
85 push(@titles, $text{'slave_xfer'});
86 push(@images, "images/xfer.gif");
87 if (@links) {
88         print &ui_hr() if ($done_recs);
89         &icons_table(\@links, \@titles, \@images);
90         }
91
92 $apply = $access{'apply'} && &has_ndc();
93 if (!$access{'ro'} && ($access{'delete'} || $apply)) {
94         print &ui_hr();
95         print &ui_buttons_start();
96
97         # Move to other view
98         $conf = &get_config();
99         print &move_zone_button($conf, $in{'view'}, $in{'index'});
100
101         # Convert to master zone
102         if ($access{'master'} && $st[7]) {
103                 print &ui_buttons_row("convert_slave.cgi",
104                         $text{'slave_convert'},
105                         $text{'slave_convertdesc'},
106                         &ui_hidden("index", $in{'index'}).
107                         &ui_hidden("view", $in{'view'}));
108                 }
109
110         # Delete zone
111         if ($access{'delete'}) {
112                 print &ui_buttons_row("delete_zone.cgi",
113                         $text{'master_del'}, $text{'slave_delmsg'},
114                         &ui_hidden("index", $in{'index'}).
115                         &ui_hidden("view", $in{'view'}));
116                 }
117
118         print &ui_buttons_end();
119         }
120
121 &ui_print_footer("", $text{'index_return'});
122
123 sub types_table
124 {
125 my $rv;
126 if ($_[0]) {
127         $rv .= &ui_columns_start([
128                 $text{'master_type'},
129                 $text{'master_records'},
130                 ], 100);
131         for(my $i=0; $_[$i]; $i++) {
132                 local @cols = ( "<a href=\"edit_recs.cgi?".
133                       "index=$in{'index'}&view=$in{'view'}&type=$_[$i]\">".
134                       ($text{"recs_$_[$i]"} || $_[$i])."</a>",
135                       $rnum{$_[$i]} );
136                 $rv .= &ui_columns_row(\@cols);
137                 }
138         $rv .= &ui_columns_end();
139         }
140 return $rv;
141 }
142