From patchwork Thu Jul 9 15:10:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Schantl X-Patchwork-Id: 3250 Return-Path: Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384 client-signature ECDSA (P-384) client-digest SHA384) (Client CN "mail01.haj.ipfire.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by web04.haj.ipfire.org (Postfix) with ESMTPS id 4B2fkF0G5yz3xGZ for ; Thu, 9 Jul 2020 15:10:28 +0000 (UTC) Received: from mail02.haj.ipfire.org (mail02.haj.ipfire.org [172.28.1.201]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail02.haj.ipfire.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mail01.ipfire.org (Postfix) with ESMTPS id 4B2fkD2H0fz1YK; Thu, 9 Jul 2020 15:10:28 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4B2fkC5ypXz2y3k; Thu, 9 Jul 2020 15:10:27 +0000 (UTC) Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384 client-signature ECDSA (P-384) client-digest SHA384) (Client CN "mail01.haj.ipfire.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mail02.haj.ipfire.org (Postfix) with ESMTPS id 4B2fkB3DR4z2xZt; Thu, 9 Jul 2020 15:10:26 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (Client did not present a certificate) by mail01.ipfire.org (Postfix) with ESMTPSA id 4B2fk84b59z1TJ; Thu, 9 Jul 2020 15:10:24 +0000 (UTC) DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003ed25519; t=1594307425; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=crAzMuCoPnfsElw/vpBrofc9i3ijq1EmMpHIaKomZJA=; b=d1K3sM1EXaHgjVSyepw4bh08LES4kzJ5vTum8BjsMihGkPVjdh2MFzRlZpGmQlwt4k/diU 3BQysUcECpNt4IAg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003rsa; t=1594307425; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=crAzMuCoPnfsElw/vpBrofc9i3ijq1EmMpHIaKomZJA=; b=dgdPuujU97OYBitJV9vxu57OpgHxIqLWuC0/Sq1ERaBPKxdp3xJ63AP/btCh196fSunSsv uud6Cd7XcKEctjorHIgGzujckXNWaXNTJRsuI/53o78DRRU1olJqF4p/uFxJlk/mp4tD8X L8Pb7Q8idaxPWLYgJZnMQezKmAsQmT+RxH0lcv7mf+cKxS7urshmfUC3UdjC6X+HgTAnbq ey+PHajTTlOKQWfYaUHr6WV3j7WrAqp545fzVzD0rm2KLKGSjXdJjkmRYgEpL5jVCVrIkT H5QaF0Gyqh1+qQUIhMfCQ2LxFWMCVtOCpqd9qf5I6DN5zVNByycdpnogizCAdg== From: Stefan Schantl To: development@lists.ipfire.org Subject: [PATCH] duckdns.org: Support new update API Date: Thu, 9 Jul 2020 17:10:09 +0200 Message-Id: <20200709151009.9217-1-stefan.schantl@ipfire.org> MIME-Version: 1.0 Authentication-Results: mail01.ipfire.org; auth=pass smtp.mailfrom=stefan.schantl@ipfire.org X-BeenThere: ddns@lists.ipfire.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List for the IPFire dynamic DNS client List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ddns@lists.ipfire.org Errors-To: ddns-bounces@lists.ipfire.org Sender: "ddns" The provider entirely changed the update API, which now is not longer DynDNS2 compatible, but supports IPv6 and cleaning records. Sadly they do not provide any detailed return codes in case an update fails. Signed-off-by: Stefan Schantl Acked-by: Michael Tremer --- src/ddns/providers.py | 46 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 4 deletions(-) diff --git a/src/ddns/providers.py b/src/ddns/providers.py index 46d8a67..690516f 100644 --- a/src/ddns/providers.py +++ b/src/ddns/providers.py @@ -802,16 +802,54 @@ class DDNSProviderDtDNS(DDNSProvider): raise DDNSUpdateError -class DDNSProviderDuckDNS(DDNSProtocolDynDNS2, DDNSProvider): +class DDNSProviderDuckDNS(DDNSProvider): handle = "duckdns.org" name = "Duck DNS" website = "http://www.duckdns.org/" - protocols = ("ipv4",) + protocols = ("ipv6", "ipv4",) # Information about the format of the request is to be found - # https://www.duckdns.org/install.jsp + # https://www.duckdns.org/spec.jsp + + # ipv4 / ipv6 records are automatically removed during the update + # process ( clear=true ) and the ipv4 / ipv6 addresses appended. + url = "https://www.duckdns.org/update" + + def update(self): + # Raise an error if no auth details are given. + if not self.token: + raise DDNSConfigurationError + + data = { + "domains" : self.hostname, + "token" : self.token, + "ipv6" : self.get_address("ipv6", "-"), + "ip" : self.get_address("ipv4", "-"), + "clear" : "true", + } + + # Send update to the server. + response = self.send_request(self.url, data=data) + + # Get the full response message. + output = response.read().decode() + + # Remove all leading and trailing whitespace. + output = output.strip() - url = "https://www.duckdns.org/nic/update" + print(output) + + # Handle success messages. + if output == "OK": + return + + # The provider does not give detailed information + # if the update fails. Only a "KO" will be sent back. + if output == "KO": + raise DDNSUpdateError + + # If we got here, some other update error happened. + raise DDNSUpdateError class DDNSProviderDyFi(DDNSProtocolDynDNS2, DDNSProvider):