]> git.openstreetmap.org Git - dns.git/blobdiff - bin/mkgeo
Escape colon in TLSRPT record
[dns.git] / bin / mkgeo
index 873fbf830d834ab89527b9476045fc9afff922b0..f23d0c56c5d02c752aff6a17187f733e1e4ac8a5 100755 (executable)
--- a/bin/mkgeo
+++ b/bin/mkgeo
@@ -1,5 +1,7 @@
 #!/usr/bin/perl
 
+use v5.12;
+
 use strict;
 use warnings;
 
@@ -269,6 +271,11 @@ foreach my $cluster (sort { $a->{name} cmp $b->{name} } values %$clusters)
     my $name = $cluster->{name};
 
     output_server($zonefile, "${name}.${zone}", $cluster);
+
+    if (@{$cluster->{servers}} > 1)
+    {
+        output_server($zonefile, "${name}-%02d.${zone}", $cluster);
+    }
 }
 
 # Output the GeoJSON text
@@ -283,10 +290,11 @@ if (defined($gdnsname))
 {
     my $gdnsmapfile = IO::File->new("> gdns/${gdnsname}.map") || die "$!";
     my $gdnsresourcefile = IO::File->new("> gdns/${gdnsname}.resource") || die "$!";
+    my $gdnsweightedfile = IO::File->new("> gdns/${gdnsname}.weighted") || die "$!";
     my $continent = "";
 
     $gdnsmapfile->print("${gdnsname} => {\n");
-    $gdnsmapfile->print("  geoip2_db => /var/lib/GeoIP/GeoLite2-Country.mmdb\n");
+    $gdnsmapfile->print("  geoip2_db => /usr/share/GeoIP/GeoLite2-Country.mmdb\n");
     $gdnsmapfile->print("  datacenters => [" . join(",", sort(keys(%$clusters))) . "]\n");
     $gdnsmapfile->print("  map => {\n");
     $gdnsmapfile->print("    default => [" . join(",", sort(map { $_->{name} } grep { $_->{default} } values(%$clusters))) . "]\n");
@@ -323,12 +331,35 @@ if (defined($gdnsname))
     {
         my $name = $cluster->{name};
 
-        $gdnsresourcefile->print("    ${name} => ${name}.tile.openstreetmap.org.\n");
+        if (@{$cluster->{servers}} > 1)
+        {
+            $gdnsweightedfile->print("${name} => {\n");
+
+            while (my($index,$server) = each @{$cluster->{servers}})
+            {
+                if ($server->{status} eq "up")
+                {
+                    my $number = sprintf("%02d", $index + 1);
+                    my $bandwidth = $server->{bandwidth};
+                
+                    $gdnsweightedfile->print("  ${name}-${number} = [ ${name}-${number}.${zone}., ${bandwidth} ]\n");
+                }
+            }
+
+            $gdnsweightedfile->print("}\n");
+
+            $gdnsresourcefile->print("    ${name} => %weighted!${name}\n");
+        }
+        else
+        {
+            $gdnsresourcefile->print("    ${name} => ${name}.${zone}.\n");
+        }
     }
 
     $gdnsresourcefile->print("  }\n");
     $gdnsresourcefile->print("}\n");
 
+    $gdnsweightedfile->close();
     $gdnsresourcefile->close();
     $gdnsmapfile->close();
 }
@@ -489,15 +520,15 @@ sub output_server
     my $name = shift;
     my $cluster = shift;
 
-    foreach my $server (@{$cluster->{servers}})
+    while (my($index,$server) = each @{$cluster->{servers}})
     {
         if ($server->{status} eq "up")
         {
-            $zonefile->print("+${name}:$server->{ipv4}:600\n");
+            $zonefile->printf("+${name}:$server->{ipv4}:600\n", $index + 1);
 
             if ($server->{ipv6})
             {
-#                $zonefile->print("3${name}:$server->{ipv6}:600\n");
+                $zonefile->printf("3${name}:$server->{ipv6}:600\n", $index + 1);
             }
         }
     }