Move zone apply into a function
authorJamie Cameron <jcameron@webmin.com>
Thu, 30 Dec 2010 05:36:45 +0000 (21:36 -0800)
committerJamie Cameron <jcameron@webmin.com>
Thu, 30 Dec 2010 05:36:45 +0000 (21:36 -0800)
bind8/bind8-lib.pl
bind8/restart_zone.cgi

index b77883f..3ccfadc 100755 (executable)
@@ -1739,11 +1739,11 @@ sub save_master_zone_records
 local ($name, $records) = @_;
 local $filename = &get_master_zone_file($name, 0);
 return 0 if (!$filename);
-&open_tempfile(ZONE, ">".&make_chroot($file), 1, 1) || return 0;
+&open_tempfile(ZONE, ">".&make_chroot($filename), 1, 1) || return 0;
 &close_tempfile(ZONE);
 foreach my $r (@$records) {
-       &create_record($file, $r->{'name'}, $r->{'ttl'}, $r->{'class'},
-                             $r->{'type'}, $r->{'values'}, $r->{'comment'});
+       &create_record($filename, $r->{'name'}, $r->{'ttl'}, $r->{'class'},
+                      $r->{'type'}, &join_record_values($r), $r->{'comment'});
        }
 return 1;
 }
@@ -1880,6 +1880,45 @@ else {
 return undef;
 }
 
+# restart_zone(domain, [view])
+# Call ndc or rndc to apply a single zone. Returns undef on success or an error
+# message on failure.
+sub restart_zone
+{
+local ($dom, $view) = @_;
+local $out;
+if ($view) {
+       # Reload a zone in a view
+       $out = &try_cmd("reload ".quotemeta($dom)." IN ".quotemeta($view).
+                       " 2>&1 </dev/null");
+       }
+else {
+       # Just reload one top-level zone
+       $out = &try_cmd("reload ".quotemeta($dom)." 2>&1 </dev/null");
+       }
+if ($out =~ /not found/i) {
+       # Zone is not known to BIND yet - do a total reload
+       local $err = &restart_bind();
+       return $err if ($err);
+       if ($access{'remote'}) {
+               # Restart all slaves too
+               &error_setup();
+               local @slaveerrs = &restart_on_slaves();
+               if (@slaveerrs) {
+                       return &text('restart_errslave',
+                            "<p>".join("<br>",
+                                       map { "$_->[0]->{'host'} : $_->[1]" }
+                                           @slaveerrs));
+                       }
+               }
+       }
+elsif ($? || $out =~ /failed|not found|error/i) {
+       return &text('restart_endc', "<tt>".&html_escape($out)."</tt>");
+       }
+&refresh_nscd();
+return undef;
+}
+
 # start_bind()
 # Attempts to start the BIND DNS server, and returns undef on success or an
 # error message on failure
index 47a728d..06e9fd6 100755 (executable)
@@ -7,39 +7,10 @@ require './bind8-lib.pl';
 $access{'ro'} && &error($text{'restart_ecannot'});
 $access{'apply'} || &error($text{'restart_ecannot'});
 $zone = &get_zone_name($in{'index'}, $in{'view'});
-if ($zone->{'view'}) {
-       # Reload a zone in a view
-       $dom = $zone->{'name'};
-       &can_edit_zone($zone) || &error($text{'restart_ecannot'});
-       $out = &try_cmd("reload '$dom' IN '$zone->{'view'}'");
-       }
-else {
-       # Just reload one top-level zone
-       $dom = $zone->{'name'};
-       &can_edit_zone($zone) || &error($text{'restart_ecannot'});
-       $out = &try_cmd("reload '$dom' 2>&1 </dev/null");
-       }
-if ($out =~ /not found/i) {
-       # Zone is not known to BIND yet - do a total reload
-       $err = &restart_bind();
-       &error($err) if ($err);
-       if ($access{'remote'}) {
-               # Restart all slaves too
-               &error_setup();
-               @slaveerrs = &restart_on_slaves();
-               if (@slaveerrs) {
-                       &error(&text('restart_errslave',
-                            "<p>".join("<br>",
-                                       map { "$_->[0]->{'host'} : $_->[1]" }
-                                           @slaveerrs)));
-                       }
-               }
-       }
-elsif ($? || $out =~ /failed|not found|error/i) {
-       &error(&text('restart_endc', "<tt>$out</tt>"));
-       }
-&refresh_nscd();
-&webmin_log("apply", $dom);
+&can_edit_zone($zone) || &error($text{'restart_ecannot'});
+$err = &restart_zone($zone->{'name'}, $zone->{'view'});
+&error($err) if ($err);
+&webmin_log("apply", $zone->{'name'});
 
 $tv = $zone->{'type'};
 if ($in{'return'}) {