Add ipv6 support.
authorAndré Frimberger <github@frimberger.de>
Sat, 18 Oct 2014 16:01:31 +0000 (18:01 +0200)
committerAndré Frimberger <github@frimberger.de>
Sat, 18 Oct 2014 16:01:31 +0000 (18:01 +0200)
src/Dyndns/Helper.php [changed mode: 0644->0755]
src/Dyndns/Hosts.php [changed mode: 0644->0755]

old mode 100644 (file)
new mode 100755 (executable)
index 12adaf9..8c2b316
@@ -15,7 +15,7 @@ class Helper
      */
     public static function checkValidIp($ip)
     {
-        return (ip2long($ip) !== false);
+        return filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) || filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6);
     }
 
     /**
old mode 100644 (file)
new mode 100755 (executable)
index d448ed7..d06dcc7
@@ -171,8 +171,17 @@ class Hosts
         fwrite($fh, "server $server\n");
         fwrite($fh, "zone $zone\n");
         foreach ($this->updates as $host => $ip) {
-            fwrite($fh, "update delete $host A\n");
-            fwrite($fh, "update add $host $ttl A $ip\n");
+           $recType = "unknown record type";
+           
+           if( filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) ){
+               $recType = "A";
+           }
+           
+           if( filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) ){
+               $recType = "AAAA";
+           }
+           fwrite($fh, "update delete $host $recType\n");
+           fwrite($fh, "update add $host $ttl $recType $ip\n");
         }
         fwrite($fh, "send\n");
         fclose($fh);