Index: /trunk/DNSDB/ExportBIND.pm
===================================================================
--- /trunk/DNSDB/ExportBIND.pm	(revision 869)
+++ /trunk/DNSDB/ExportBIND.pm	(revision 870)
@@ -43,5 +43,5 @@
   # Fetch active zone list
   my $revsth = $dnsdb->{dbh}->prepare("SELECT rdns_id,revnet,status,changed,default_location FROM revzones WHERE status=1 ".
-	"ORDER BY masklen(revnet) DESC, rdns_id");
+	"ORDER BY masklen(revnet),revnet DESC, rdns_id");
   # Unflag changed zones, so we can maybe cache the export and not redo everything every time
   my $zonesth = $dnsdb->{dbh}->prepare("UPDATE revzones SET changed='n' WHERE rdns_id=?");
@@ -105,6 +105,8 @@
           open $zonefiles{$loc}, ">", $zfilepath;
           printf {$zonefiles{$loc}} "; %s in view %s exported %s\n", $arpazone, $loc, scalar(localtime)
-            or die "Error writing SOA [$zone, '$loc']: $!\n";;
-        }
+            or die "Error writing header [$zone, '$loc']: $!\n";;
+          # tag the zonefile for publication in the view
+          push @{$viewzones{$loc}}, $arpazone;
+        } # foreach @loclist
 
         # need to fetch this separately since the rest of the records all (should) have real IPs in val
@@ -198,5 +200,5 @@
     open BINDCONF, ">", $tmpconf;
 
-    foreach my $view (@{$viewlist}) {
+    foreach my $view (@{$viewlist}, 'common') {
 #print Dumper($view);
       print BINDCONF "view $view->{location} {\n";
@@ -207,5 +209,5 @@
       # same as a BIND view with match-clients { any; };
       if ($view->{iplist}) {
-         print BINDCONF "  match-clients { ".join("; ", $view->iplist)."; };\n";
+         print BINDCONF "  match-clients { ".join("; ", $view->{iplist})."; };\n";
 #         print "  match-clients { ".join("; ", split(/[\s,]+/, $view->{iplist}))."; };\n";
       } else {
@@ -217,4 +219,5 @@
         print qq(  zone "$zone" IN {\n\ttype master;\n\tnotify no;\n\tfile "db.$zone";\n  };\n);
       }
+      print BINDCONF "};\n\n";
       print "};\n\n";
     } # foreach @$viewlist
