2 # Display a list of domains, views, and icons for global options.
4 require './bind8-lib.pl';
7 $need_create = !-r &make_chroot($config{'named_conf'}) ||
10 # Check if bind is installed
11 if (!-x $config{'named_path'}) {
12 &ui_print_header(undef, $text{'index_title'}, "", undef, 1, 1, 0,
13 &help_search_link("bind", "doc", "google"));
14 print "<p>",&text('index_enamed', "<tt>$config{'named_path'}</tt>",
15 "$gconfig{'webprefix'}/config.cgi?$module_name"),"<p>\n";
17 &foreign_require("software", "software-lib.pl");
18 $lnk = &software::missing_install_link("bind", $text{'index_bind'},
19 "../$module_name/", $text{'index_title'});
20 print $lnk,"<p>\n" if ($lnk);
22 &ui_print_footer("/", $text{"index"});
26 # Check if BIND is the right version.. Only BIND 8/9 offers the -f option
27 # Is there a better way to do this?
28 if ($out = &check_bind_8()) {
29 &ui_print_header(undef, $text{'index_title'}, "", undef, 1, 1, 0,
30 &help_search_link("bind", "doc", "google"));
31 print "<p>",&text('index_eversion', "<tt>$config{'named_path'}</tt>",
32 "/dnsadmin/", "<tt>$config{'named_path'} -help</tt>",
33 "<pre>$out</pre>"),"<p>\n";
34 &ui_print_footer("/", $text{"index"});
38 # Try to get the version number, and save for later calls
39 $bind_version = &get_bind_version();
40 &open_tempfile(VERSION, ">$module_config_directory/version");
41 &print_tempfile(VERSION, "$bind_version\n");
42 &close_tempfile(VERSION);
44 # Get the list of zones
45 @allzones = &list_zone_names();
46 @zones = grep { $_->{'type'} ne 'view' &&
48 (!$access{'ro'} || $_->{'name'} ne '.') } @allzones;
49 @views = grep { $_->{'type'} eq 'view' } @allzones;
50 @hashint = grep { $_->{'type'} ne 'view' &&
51 $_->{'name'} eq '.' } @allzones;
53 if (@zones == 1 && $access{'zones'} ne '*' && !$access{'defaults'} &&
54 !$access{'views'} && $access{'apply'} != 1 && !$access{'master'} &&
55 !$access{'slave'} && !$access{'forward'} && $access{'noconfig'}) {
56 # Only one zone, so go direct to it
58 &redirect("edit_master.cgi?index=$z->{'index'}".
59 ($z->{'viewindex'} eq '' ? '' : '&view='.$z->{'viewindex'}));
63 $chroot = &get_chroot();
64 &ui_print_header(undef, $text{'index_title'}, "", undef, 1, 1, 0,
65 &restart_links().'<br>'.
66 &help_search_link("bind", "doc", "google"), undef, undef,
67 &text($chroot eq "/" || !$chroot ? 'index_version' : 'index_chroot',
68 $bind_version, "<tt>$chroot</tt>"));
70 # If the named.conf file does not exist, offer to create it
72 print &text('index_eempty',
73 "<tt>".&make_chroot($config{'named_conf'})."</tt>"),"<p>\n";
75 print &ui_form_start("dns_boot.cgi");
76 print &ui_radio("real", 1,
77 [ [ 0, $text{'index_local'}."<br>" ],
78 [ 1, $text{'index_download'}."<br>" ],
79 [ 2, $text{'index_webmin'}."<br>" ] ]);
80 print &ui_form_end([ [ undef, $text{'index_create'} ] ]);
82 &ui_print_footer("/", $text{"index"});
86 if ($access{'defaults'}) {
87 # display global options
88 print &ui_subheading($text{'index_opts'});
89 @olinks = ("conf_servers.cgi", "conf_logging.cgi", "conf_acls.cgi",
90 "conf_files.cgi", "conf_forwarding.cgi", "conf_net.cgi",
91 "conf_misc.cgi", "conf_controls.cgi", "conf_keys.cgi",
92 "conf_zonedef.cgi", "list_slaves.cgi",
93 $bind_version >= 9 ? ( "conf_rndc.cgi" ) : ( ),
94 &supports_dnssec_client() ? ( "conf_trusted.cgi" ) : ( ),
95 &supports_dnssec() ? ( "conf_dnssec.cgi" ) : ( ),
96 &supports_check_conf() ? ( "conf_ncheck.cgi" ) : ( ),
98 @otitles = map { /(conf|list)_(\S+).cgi/; $text{$2."_title"} } @olinks;
99 @oicons = map { /^(conf|list)_(\S+).cgi/; "images/$2.gif"; } @olinks;
100 &icons_table(\@olinks, \@otitles, \@oicons, 6);
104 # Work out what creation links we have
106 if ($access{'master'} && !$access{'ro'}) {
108 "<a href=\"master_form.cgi\">$text{'index_addmaster'}</a>");
110 if ($access{'slave'} && !$access{'ro'}) {
112 "<a href=\"slave_form.cgi\">$text{'index_addslave'}</a>");
114 "<a href=\"stub_form.cgi\">$text{'index_addstub'}</a>");
116 if ($access{'forward'} && !$access{'ro'}) {
118 "<a href=\"forward_form.cgi\">$text{'index_addfwd'}</a>");
120 if ($access{'delegation'} && !$access{'ro'} && &version_atleast(9, 2, 1)) {
122 "<a href=\"delegation_form.cgi\">$text{'index_adddele'}</a>");
124 if ($access{'master'} && !$access{'ro'} &&
125 scalar(@hashint) < (@views ? scalar(@views) : 1)) {
127 "<a href=\"hint_form.cgi\">$text{'index_addhint'}</a>");
131 "<a href=\"mass_form.cgi\">$text{'index_addmass'}</a>");
134 if (@zones > $config{'max_zones'}) {
135 # Too many zones, show search form
136 print &ui_subheading($text{'index_zones'});
137 print "$text{'index_toomany'}<p>\n";
138 print &ui_form_start("find_zones.cgi");
139 print "<b>$text{'index_find'}</b>\n";
140 print &ui_textbox("search", undef, 20);
141 print &ui_form_end([ [ undef, $text{'index_search'} ] ]);
142 print &ui_links_row(\@crlinks);
144 elsif (@zones && (!@views || !$config{'by_view'})) {
146 print &ui_subheading($text{'index_zones'});
147 foreach $z (@zones) {
151 $t = "delegation" if ($t eq "delegation-only");
152 local $zn = $v eq "." ? "<i>$text{'index_root'}</i>"
153 : &ip6int_to_net(&arpa_to_ip($v));
155 local $vw = $z->{'viewindex'};
156 push(@zlinks, "edit_$t.cgi?index=$z->{'index'}".
158 push(@ztitles, $zn." ".
159 &text('index_view', "<tt>$z->{'view'}</tt>"));
160 push(@zdels, &can_edit_zone($z, $vw) ?
161 $z->{'index'}." ".$z->{'viewindex'} : undef);
164 push(@zlinks, "edit_$t.cgi?index=$z->{'index'}");
166 push(@zdels, &can_edit_zone($z) ?
167 $z->{'index'} : undef);
169 push(@zsort, $t eq 'hint' ? undef : $ztitles[$#ztitles]);
170 push(@zicons, "images/$t.gif");
171 push(@ztypes, $text{"index_$t"});
173 $ztitlehash{$zn} = $ztitles[$#ztitles];
174 $zlinkhash{$zn} = $zlinks[$#zlinks];
175 $ztypeshash{$zn} = $ztypes[$#ztypes];
176 $zdelhash{$zn} = $zdels[$#ztypes];
181 @zorder = sort { &compare_zones($zsort[$a], $zsort[$b]) } (0 .. $len-1);
182 @zlinks = map { $zlinks[$_] } @zorder;
183 @ztitles = map { $ztitles[$_] } @zorder;
184 @zicons = map { $zicons[$_] } @zorder;
185 @ztypes = map { $ztypes[$_] } @zorder;
186 @zdels = map { $zdels[$_] } @zorder;
188 print &ui_form_start("mass_delete.cgi", "post");
189 @links = ( &select_all_link("d", 0),
190 &select_invert_link("d", 0),
192 print &ui_links_row(\@links);
194 if ($config{'show_list'} == 1) {
196 $mid = int((@zlinks+1)/2);
198 push(@grid, &zones_table([ @zlinks[0 .. $mid-1] ],
199 [ @ztitles[0 .. $mid-1] ],
200 [ @ztypes[0 .. $mid-1] ],
201 [ @zdels[0 .. $mid-1] ] ));
202 if ($mid < @zlinks) {
203 push(@grid, &zones_table([ @zlinks[$mid .. $#zlinks] ],
204 [ @ztitles[$mid .. $#ztitles] ],
205 [ @ztypes[$mid .. $#ztypes] ],
206 [ @zdels[$mid .. $#zdels] ]));
208 print &ui_grid_table(\@grid, 2, 100,
209 [ "width=50%", "width=50%" ]);
211 elsif ($config{'show_list'} == 2) {
212 # Show as collapsible tree, broken down by domain parts
213 %heiropen = map { $_, 1 } &get_heiropen();
215 foreach $z (grep { $_->{'type'} } @zones) {
216 local $v = $z->{'name'};
217 local @p = split(/\./, &ip6int_to_net(&arpa_to_ip($v)));
218 for($i=1; $i<=@p; $i++) {
219 local $ch = join(".", @p[$i-1 .. $#p]);
220 local $par = $i == @p ?
221 "" : join(".", @p[$i .. $#p]);
222 @{$ztree{$par}} = &unique(@{$ztree{$par}}, $ch);
231 @befores = map { $_ ? &ui_checkbox("d", $_, "", 0) : "" }
233 &icons_table(\@zlinks, \@ztitles, \@zicons, 5, undef,
234 undef, undef, \@befores);
236 print &ui_links_row(\@links);
237 print &ui_form_end([ $access{'delete'} ?
238 ( [ "delete", $text{'index_massdelete'} ] ) : ( ),
239 [ "update", $text{'index_massupdate'} ],
240 [ "create", $text{'index_masscreate'} ],
241 [ "rdelete", $text{'index_massrdelete'} ] ]);
244 # Show zones under views
245 print &ui_subheading($text{'index_zones'});
246 foreach $vw (@views) {
247 local (@zorder, @zlinks, @ztitles, @zicons, @ztypes, @zsort, @zdels, $len);
248 local @zv = grep { $_->{'view'} eq $vw->{'name'} } @zones;
250 print "<b>",&text('index_inview',
251 "<tt>$vw->{'name'}</tt>"),"</b><br>\n";
255 local $zn = $v eq "." ? "<i>$text{'index_root'}</i>"
256 : &ip6int_to_net(&arpa_to_ip($v));
257 push(@zlinks, "edit_$t.cgi?index=$z->{'index'}".
258 "&view=$z->{'viewindex'}");
260 push(@zsort, $t eq 'hint' ? undef : $ztitles[$#ztitles]);
261 push(@zicons, "images/$t.gif");
262 push(@ztypes, $text{"index_$t"});
263 push(@zdels, $z->{'index'}." ".$z->{'viewindex'});
268 @zorder = sort { &compare_zones($zsort[$a], $zsort[$b]) }
270 @zlinks = map { $zlinks[$_] } @zorder;
271 @ztitles = map { $ztitles[$_] } @zorder;
272 @zicons = map { $zicons[$_] } @zorder;
273 @ztypes = map { $ztypes[$_] } @zorder;
274 @zdels = map { $zdels[$_] } @zorder;
276 print &ui_form_start("mass_delete.cgi", "post");
277 print &ui_links_row(\@crlinks);
278 if ($config{'show_list'}) {
280 $mid = int((@zlinks+1)/2);
282 push(@grid, &zones_table([ @zlinks[0 .. $mid-1] ],
283 [ @ztitles[0 .. $mid-1] ],
284 [ @ztypes[0 .. $mid-1] ],
285 [ @zdels[0 .. $mid-1] ]));
286 if ($mid < @zlinks) {
287 push(@grid, &zones_table(
288 [ @zlinks[$mid .. $#zlinks] ],
289 [ @ztitles[$mid .. $#ztitles] ],
290 [ @ztypes[$mid .. $#ztypes] ],
291 [ @zdels[$mid .. $#zdels] ]));
293 print &ui_grid_table(\@grid, 2, 100,
294 [ "width=50%", "width=50%" ]);
298 @befores = map { $_ ? &ui_checkbox("d", $_, "", 0) : "" }
300 &icons_table(\@zlinks, \@ztitles, \@zicons, 5, undef,
301 undef, undef, \@befores);
303 print &ui_links_row(\@crlinks);
306 ( [ "delete", $text{'index_massdelete'} ] ) : ( ),
307 [ "update", $text{'index_massupdate'} ],
308 [ "create", $text{'index_masscreate'} ],
309 [ "rdelete", $text{'index_massrdelete'} ], ]);
313 print "<b>$text{'index_none'}</b><p>\n";
314 print &ui_links_row(\@crlinks);
317 if ($access{'views'} && $bind_version >= 9) {
318 # Display list of views
320 print &ui_subheading($text{'index_views'});
322 # Show a warning if any zones are not in a view
323 @notinview = grep { $_->{'viewindex'} eq '' } @zones;
324 if (@notinview && @views) {
325 print "<b>",&text('index_viewwarn',
326 join(" , ", map { "<tt>".&ip6int_to_net(
327 &arpa_to_ip($_->{'name'}))."</tt>" }
328 @notinview)),"</b><p>\n";
329 print "<b>$text{'index_viewwarn2'}</b><p>\n";
332 @views = grep { &can_edit_view($_) } @views;
333 foreach $v (@views) {
334 push(@vlinks, "edit_view.cgi?index=$v->{'index'}");
335 push(@vtitles, $v->{'name'});
336 push(@vicons, "images/view.gif");
339 push(@links, "<a href=\"view_form.cgi\">$text{'index_addview'}</a>")
340 if (!$access{'ro'} && $access{'views'} != 2);
342 print &ui_links_row(\@links);
343 &icons_table(\@vlinks, \@vtitles, \@vicons, 5);
346 print "<b>$text{'index_vnone'}</b><p>\n";
348 print &ui_links_row(\@links);
351 &ui_print_footer("/", $text{"index"});
356 foreach $c (@{$_[0]}) {
357 print "$_[1]$c->{'name'} ",
358 join(',', @{$c->{'values'}});
361 &dump_config($c->{'members'}, "$_[1]\t");
370 local @sp0 = split(/\./, lc($_[0]));
371 local @sp1 = split(/\./, lc($_[1]));
372 for($i=0; $i<@sp0 || $i<@sp1; $i++) {
373 if ($sp0[$i] =~ /^\d+$/ && $sp1[$i] =~ /^\d+$/) {
374 return -1 if ($sp0[$i] < $sp1[$i]);
375 return 1 if ($sp0[$i] > $sp1[$i]);
378 local $c = $sp0[$i] cmp $sp1[$i];
387 local ($name, $depth) = @_;
388 print "<tr> <td>", " " x $depth;
390 print "<a name=\"$name\"></a>\n";
391 $name =~ /^([^\.]+)/;
392 if (!$ztree{$name}) {
394 print "<img border=0 src=images/smallicon.gif> $1</td>\n",
398 local $act = $heiropen{$name} ? "close" : "open";
399 print "<a href=\"$act.cgi?what=",&urlize($name),"\">";
400 print "<img border=0 src=images/$act.gif></a> $1</td>\n",
405 print "<img src=images/close.gif> <i>$text{'index_all'}</i></td>\n";
408 local $cb = $zdelhash{$name} ?
409 &ui_checkbox("d", $zdelhash{$name}, "", 0)." " : "";
410 print "<td>$cb<a href='$zlinkhash{$name}'>$ztitlehash{$name} ($ztypeshash{$name})</a></td> </tr>\n";
413 print "<td><br></td> </tr>\n";
415 if ($heiropen{$name}) {
416 foreach $sz (@{$ztree{$name}}) {
417 &recursive_tree($sz, $depth+1);