ubuntuusers.de

ddclient für cloudflare

Status: Ungelöst | Ubuntu-Version: Xubuntu 12.04 (Precise Pangolin)
Antworten |

glaskugel

Anmeldungsdatum:
8. Juli 2010

Beiträge: 3613

Ich blicke da mit den Versionen nicht ganz durch. Installiert habe ich ddclient 3.8.0-11.4ubuntu1

https://www.cloudflare.com/resources-downloads

Dynamic DNS Client: ddclient Description A port of ddclient, this includes support for using the CloudFlare dynamic DNS updating system. Requirements Perl 5.004 or later (you need the IO::Socket::SSL perl library for ssl-support)

Der Download für den Patch ist weiter unten und führt zu http://blog.peter-r.co.uk/cloudflare-ddclient-patch.html und baut auf 3.8.0 auf, die bei Precise installiert ist.

Gibt es da vielleicht ein Repo für Precise mit einer neueren Version, das "protocol=cloudflare" unterstützt? Wenn nein, was mache ich am einfachsten?

Das ist der Download von http://blog.peter-r.co.uk/uploads/ddclient-3.8.0-cloudflare-26-09-2013.patch

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
--- ddclient.orig	2013-09-26 01:06:12.399990673 +0100
+++ ddclient	2013-09-26 06:25:36.768189452 +0100
@@ -13,12 +13,17 @@
 # Support for multiple IP numbers added by
 # Astaro AG, Ingo Schwarze <ischwarze-OOs/4mkCeqbQT0dZR+AlfA@public.gmane.org> September 16, 2008
 #
+# Modified to work with Cloudflare by Robert Ian Hawdon 2012-07-16: http://robertianhawdon.me.uk/
+#
+# Further modified to work with Cloudflare by Peter Roberts 2013-09-26: blog.peter-r.co.uk
+#
 ######################################################################
-require 5.004;
+require 5.014;
 use strict;
 use Getopt::Long;
 use Sys::Hostname;
 use IO::Socket;
+use JSON::Any;
 
 my $version  = "3.8.0";
 my $programd  = $0; 
@@ -416,6 +421,14 @@
 	'warned-min-interval'       => setv(T_ANY,    0, 1, 0, 0,             undef),
 	'warned-min-error-interval' => setv(T_ANY,    0, 1, 0, 0,             undef),
     },
+    'cloudflare-common-defaults'       => {
+	'server'	          => setv(T_FQDNP,  1, 0, 1, 'www.cloudflare.com', undef),
+        'zone'                => setv(T_FQDN,   1, 0, 1, '',                  undef),
+	'static'              => setv(T_BOOL,   0, 1, 1, 0,                   undef),
+	'wildcard'            => setv(T_BOOL,   0, 1, 1, 0,                   undef),
+	'mx'	              => setv(T_OFQDN,  0, 1, 1, '',                  undef),
+	'backupmx'            => setv(T_BOOL,   0, 1, 1, 0,                   undef),
+    },
 );
 my %services = (
     'dyndns1' => {
@@ -529,6 +542,17 @@
                           $variables{'service-common-defaults'},
                         ),
     },
+    'cloudflare' => {
+        'updateable' => undef,
+        'update'     => \&nic_cloudflare_update,
+        'examples'   => \&nic_cloudflare_examples,
+        'variables'  => merge(
+            { 'server'       => setv(T_FQDNP,  1, 0, 1, 'www.cloudflare.com', undef)          },
+            { 'min-interval' => setv(T_DELAY,  0, 0, 1, interval('5m'), 0),},
+            $variables{'cloudflare-common-defaults'},
+            $variables{'service-common-defaults'},
+            ),
+    },
 );
 $variables{'merged'} = merge($variables{'global-defaults'},
 			     $variables{'service-common-defaults'},
@@ -3386,7 +3410,128 @@
 }
 
 ######################################################################
-# vim: ai ts=4 sw=4 tw=78 :
 
+######################################################################
+## nic_cloudflare_examples
+##
+## written by Ian Pye
+##
+######################################################################
+sub nic_cloudflare_examples {
+    return <<EoEXAMPLE;
+o 'cloudflare'
+
+The 'cloudflare' protocol is used by DNS service offered by www.cloudflare.com.
+
+Configuration variables applicable to the 'cloudflare' protocol are:
+  protocol=cloudflare          ## 
+  server=fqdn.of.service       ## defaults to www.cloudflare.com
+  zone=dns.zone		       ## your domain
+  login=service-login          ## login name and password  registered with the service
+  password=service-password    ##
+  fully.qualified.host         ## the host registered with the service.
+
+Example ${program}.conf file entries:
+  ## single host update
+  protocol=cloudflare,
+  zone=dns-zone,                                                \\
+  login=my-cloudflare.com-login,                                \\
+  password=my-cloudflare.com-api-key                            \\
+  myhost.com 
+
+  ## multiple host update to the custom DNS service
+  protocol=cloudflare,
+  zone=dns.zone                                                 \\
+  login=my-cloudflare.com-login,                                \\
+  password=my-cloudflare.com-api-key                            \\
+  my-toplevel-domain.com,my-other-domain.com
+EoEXAMPLE
+}
+######################################################################
+## nic_cloudflare_update
+######################################################################
+sub nic_cloudflare_update {
+    debug("\nnic_cloudflare_update -------------------");
+
+    ## group hosts with identical attributes together 
+    my %groups = group_hosts_by([ @_ ], [ qw(ssh login password server wildcard mx backupmx) ]);
+
+    ## update each set of hosts that had similar configurations
+    foreach my $sig (keys %groups) {
+    	my @hosts = @{$groups{$sig}};
+    	my $hosts = join(',', @hosts);
+    	my $key   = $hosts[0];
+    	my $ip    = $config{$key}{'wantip'};
+    	
+    	# FQDNs
+    	for my $domain (@hosts) {
+	    my $hostname = $domain =~ s/\.$config{$key}{zone}$//r;
+	    delete $config{$domain}{'wantip'};
+	    
+	    info("setting IP address to %s for %s", $ip, $domain);
+	    verbose("UPDATE:","updating %s", $domain);
+
+	    # Get domain ID
+	    my $url = "https://$config{$key}{'server'}/api_json.html?a=rec_load_all";
+	    $url   .= "&z=".$config{$key}{'zone'};
+	    $url   .= "&email=".$config{$key}{'login'};	
+	    $url   .= "&tkn=".$config{$key}{'password'};
+	    
+	    my $reply = geturl(opt('proxy'), $url);
+	    unless ($reply) {
+		failed("updating %s: Could not connect to %s.", $domain, $config{$key}{'server'});
+		last;
+	    }
+	    last if !header_ok($domain, $reply);
+	    
+	    # Strip header
+	    $reply =~ s/^.*?\n\n//s;
+	    my $response = JSON::Any->jsonToObj($reply);
+	    if ($response->{result} eq 'error') {
+		failed ("%s", $response->{msg});
+		next; 
+	    }
+	    
+	    # Pull the ID out of the json, messy
+	    my ($id) = map { $_->{name} eq $domain ? $_->{rec_id} : () } @{ $response->{response}->{recs}->{objs} };
+	    unless($id) {
+		failed("updating %s: No domain ID found.", $domain);
+		next;
+	    }
+	    
+	    # Set domain
+	    $url   = "https://$config{$key}{'server'}/api_json.html?a=rec_edit&type=A&ttl=1";
+	    $url     .= "&name=$hostname";
+	    $url     .= "&z=".$config{$key}{'zone'};
+	    $url     .= "&id=".$id;	
+	    $url     .= "&email=".$config{$key}{'login'};	
+	    $url     .= "&tkn=".$config{$key}{'password'};    
+	    $url     .= "&content=";
+	    $url     .= "$ip"       if $ip;
+	    
+	    $reply = geturl(opt('proxy'), $url);
+	    unless ($reply) {
+		failed("updating %s: Could not connect to %s.", $domain, $config{$domain}{'server'});
+		last;
+	    }
+	    last if !header_ok($domain, $reply);
+	    
+	    # Strip header
+	    $reply =~ s/^.*?\n\n//s;
+	    $response = JSON::Any->jsonToObj($reply);
+	    if ($response->{result} eq 'error') {
+		failed ("%s", $response->{msg});	
+	    } else {
+		success ("%s -- Updated Successfully to %s", $domain, $ip);
+		 
+	    }
+	    
+	    # Cache
+	    $config{$key}{'ip'}     = $ip;
+	    $config{$key}{'mtime'}  = $now;
+	    $config{$key}{'status'} = 'good';
+	}
+    }
+}
 
 __END__
Antworten |