From dbd8c41eebccbabeec1215aec97d4a8d1187ee09 Mon Sep 17 00:00:00 2001
From: Ludovico Cavedon <ludovico.cavedon@gmail.com>
Date: Fri, 25 Nov 2016 13:48:28 -0800
Subject: [PATCH] Add support for dnsmadeeasy

---
 ddclient | 95 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 95 insertions(+)

diff --git a/ddclient b/ddclient
index 439a9cb..03033fd 100755
--- a/ddclient
+++ b/ddclient
@@ -69,6 +69,7 @@ my %builtinweb = (
    'Current IP Address:', },
    'dnspark'      => { 'url' => 'http://ipdetect.dnspark.com/', 'skip' => 'Current Address:', },
    'loopia'       => { 'url' => 'http://dns.loopia.se/checkip/checkip.php', 'skip' => 'Current IP Address:', },
+   'dnsmadeeasy'  => { 'url' => 'http://www.dnsmadeeasy.com/myip.jsp', },
 );
 my %builtinfw = (
     'watchguard-soho'        => {
@@ -305,6 +306,7 @@ my %web_strategies = (
 	'dyndns'=> 1,
 	'dnspark'=> 1,
 	'loopia'=> 1,
+    'dnsmadeeasy'=> 1,
 );
 
 sub setv {
@@ -478,6 +480,10 @@ my %variables = (
         'warned-min-interval'       => setv(T_ANY,    0, 1, 0, 0,             undef),
         'warned-min-error-interval' => setv(T_ANY,    0, 1, 0, 0,             undef),
     },
+    'dnsmadeeasy-common-defaults' => {
+        'server' => setv(T_FQDNP,  1, 0, 1, 'cp.dnsmadeeasy.com', undef),
+        'web'    => setv(T_STRING, 0, 0, 1, 'dnsmadeeasy',        undef),
+    },
 );
 my %services = (
     'dyndns1' => {
@@ -671,6 +677,15 @@ my %services = (
             $variables{'woima-service-common-defaults'},
         ),
     },
+    'dnsmadeeasy' => {
+        'updateable' => undef,
+        'update'     => \&nic_dnsmadeeasy_update,
+        'examples'   => \&nic_dnsmadeeasy_examples,
+        'variables'  => merge(
+                          $variables{'dnsmadeeasy-common-defaults'},
+                          $variables{'service-common-defaults'},
+                        ),
+    },
 );
 $variables{'merged'} = merge($variables{'global-defaults'},
 			     $variables{'service-common-defaults'},
@@ -4551,6 +4566,86 @@ sub nic_woima_update {
 
 
 ######################################################################
+## nic_dnsmadeeasy_examples
+######################################################################
+sub nic_dnsmadeeasy_examples {
+    return <<EoEXAMPLE;
+o 'dnsmadeeasy'
+
+The 'dnsmadeeasy' protocol is used by the free
+dynamic DNS service offered by www.dnsmadeeasy.com.
+
+Configuration variables applicable to the 'dnsmadeeasy' protocol are:
+  protocol=dnsmadeeasy
+  login=<username>
+  password=<password>
+  <host-id>
+
+Example ${program}.conf file entries:
+  ## single host update
+  protocol=dnsmadeeasy,                                      \\
+  login=my-username,                                         \\
+  password=my-password                                       \\
+  1234567
+
+EoEXAMPLE
+}
+
+######################################################################
+## nic_dnsmadeeasy_update
+## by Ludovico Cavedon <k6lud@sbarc.org>
+######################################################################
+sub nic_dnsmadeeasy_update {
+    debug("\nnic_dnsmadeeasy_update -------------------");
+
+    ## update each configured host
+    ## should improve to update in one pass
+    foreach my $h (@_) {
+        my $ip = delete $config{$h}{'wantip'};
+        info("setting IP address to %s for %s", $ip, $h);
+        verbose("UPDATE:","updating %s", $h);
+
+        # Set the URL that we're going to to update
+        my $url;
+        $url  = "http://$config{$h}{'server'}/servlet/updateip";
+        $url .= "?username=";
+        $url .= $config{$h}{'login'};
+        $url .= "&password=";
+        $url .= $config{$h}{'password'};
+        $url .= "&id=";
+        $url .= $h;
+        $url .= "&ip=";
+        $url .= $ip;
+
+        # Try to get URL
+        my $reply = geturl(opt('proxy'), $url);
+
+        # No response, declare as failed
+        if (!defined($reply) || !$reply) {
+            failed("updating %s: Could not connect to %s.", $h, $config{$h}{'server'});
+            last;
+        }
+        last if !header_ok($h, $reply);
+
+        my @reply = split /\n/, $reply;
+        my $returned = pop(@reply);
+        if ($returned =~ /success/)
+        {
+            $config{$h}{'ip'}     = $ip;
+            $config{$h}{'mtime'}  = $now;
+            $config{$h}{'status'} = 'good';
+            success("updating %s: good: IP address set to %s", $h, $ip);
+        }
+        else
+        {
+            $config{$h}{'status'} = 'failed';
+            failed("updating %s: Server said: '$returned'", $h);
+        }
+    }
+}
+
+
+######################################################################
 # vim: ai ts=4 sw=4 tw=78 :
 
 
-- 
2.1.4

