From 1867401b359d4f0abdb7fe150e00426ad5457c3a Mon Sep 17 00:00:00 2001 From: Junker Date: Tue, 14 Apr 2020 18:51:52 +0700 Subject: [PATCH 1/2] make python3.4 compatible --- README.md | 2 +- authenticator.py | 11 ++++++----- cleanup.py | 9 +++++---- 3 files changed, 12 insertions(+), 10 deletions(-) mode change 100644 => 100755 authenticator.py mode change 100644 => 100755 cleanup.py diff --git a/README.md b/README.md index 79ab273..855985e 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # NameSilo Let's Encrypt [![License (3-Clause BSD)](https://img.shields.io/badge/license-BSD%203--Clause-blue.svg?style=flat-square)](http://opensource.org/licenses/BSD-3-Clause) -[![Python 3.8](https://img.shields.io/badge/python-3.8-blue.svg)](https://www.python.org/) +[![Python 3.4](https://img.shields.io/badge/python-3.4-blue.svg)](https://www.python.org/) Python scripts (hook) to automate obtaining [Let's Encrypt](https://letsencrypt.org/) certificates, using [Certbot](https://certbot.eff.org/) DNS-01 challenge validation for domains DNS hosted on diff --git a/authenticator.py b/authenticator.py old mode 100644 new mode 100755 index c6fb9bd..1db6e8d --- a/authenticator.py +++ b/authenticator.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python3.8 +#!/usr/bin/env python3 # authenticator.py # @@ -51,14 +51,15 @@ def sleep(minutes): domain = os.environ['CERTBOT_DOMAIN'] validation = os.environ['CERTBOT_VALIDATION'] -tmpdir = os.path.join(tempfile.gettempdir(), f"CERTBOT_{domain}") +tmpdir = os.path.join(tempfile.gettempdir(), "CERTBOT_"+domain) if "NAMESILO_API" in os.environ: apikey = os.environ['NAMESILO_API'] -url = f"https://www.namesilo.com/api/dnsAddRecord?\ -version=1&type=xml&key={apikey}&domain={domain}&rrtype=TXT\ -&rrhost=_acme-challenge&rrvalue={validation}&rrttl=3600" + +url = "https://www.namesilo.com/api/dnsAddRecord?\ +version=1&type=xml&key="+apikey+"&domain="+domain+"&rrtype=TXT\ +&rrhost=_acme-challenge&rrvalue="+validation+"&rrttl=3600" req = urllib.request.Request( url, diff --git a/cleanup.py b/cleanup.py old mode 100644 new mode 100755 index 627560a..37aebf5 --- a/cleanup.py +++ b/cleanup.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python3.8 +#!/usr/bin/env python3 # cleanup.py # @@ -41,13 +41,14 @@ import untangle from config import apikey domain = os.environ['CERTBOT_DOMAIN'] -tmpdir = os.path.join(tempfile.gettempdir(), f"CERTBOT_{domain}") +tmpdir = os.path.join(tempfile.gettempdir(), "CERTBOT_"+domain) + if "NAMESILO_API" in os.environ: apikey = os.environ['NAMESILO_API'] -url = f"https://www.namesilo.com/api/dnsDeleteRecord\ -?version=1&type=xml&key={apikey}&domain={domain}&rrid=" +url = "https://www.namesilo.com/api/dnsDeleteRecord\ +?version=1&type=xml&key="+apikey+"&domain="+domain+"&rrid=" def getrequest(record_id): From d680a58068f8fd08468ce46e07a2f93e84d23210 Mon Sep 17 00:00:00 2001 From: Junker <1144095+Junker@users.noreply.github.com> Date: Tue, 14 Apr 2020 19:21:09 +0700 Subject: [PATCH 2/2] add subdomains support --- README.md | 5 ++++- authenticator.py | 11 +++++++++-- cleanup.py | 7 +++++-- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 855985e..d93e2ba 100644 --- a/README.md +++ b/README.md @@ -9,10 +9,12 @@ using [Certbot](https://certbot.eff.org/) DNS-01 challenge validation for domain ## Setup -The scripts use the [untangle](https://untangle.readthedocs.io/en/latest/) library, if not already installed on your system: +The scripts use the [untangle](https://untangle.readthedocs.io/en/latest/) and tldextract libraries, if not already installed on your system: ``` pip install untangle + +pip install tldextract ``` Download the [latest release](https://github.com/ethauvin/namesilo-letsencrypt/releases) archive and expand it in the desired directory. @@ -44,3 +46,4 @@ certbot certonly --manual --email you@example.com \ Please note that NameSilo DNS propagation takes up to **15 minutes**. The scripts will wait **20 minutes** before completing, just to be safe. +q diff --git a/authenticator.py b/authenticator.py index 1db6e8d..8098b0c 100755 --- a/authenticator.py +++ b/authenticator.py @@ -37,6 +37,7 @@ import tempfile import time import urllib.request +import tldextract import untangle from config import apikey, wait @@ -52,14 +53,20 @@ def sleep(minutes): domain = os.environ['CERTBOT_DOMAIN'] validation = os.environ['CERTBOT_VALIDATION'] tmpdir = os.path.join(tempfile.gettempdir(), "CERTBOT_"+domain) +rrhost = "_acme-challenge" if "NAMESILO_API" in os.environ: apikey = os.environ['NAMESILO_API'] +tld = tldextract.extract(domain) +nsdomain = tld.domain+"."+tld.suffix +if tld.subdomain: + rrhost += "."+tld.subdomain + url = "https://www.namesilo.com/api/dnsAddRecord?\ -version=1&type=xml&key="+apikey+"&domain="+domain+"&rrtype=TXT\ -&rrhost=_acme-challenge&rrvalue="+validation+"&rrttl=3600" +version=1&type=xml&key="+apikey+"&domain="+nsdomain+"&rrtype=TXT\ +&rrhost="+rrhost+"&rrvalue="+validation+"&rrttl=3600" req = urllib.request.Request( url, diff --git a/cleanup.py b/cleanup.py index 37aebf5..e95a369 100755 --- a/cleanup.py +++ b/cleanup.py @@ -36,6 +36,7 @@ import sys import tempfile import urllib.request +import tldextract import untangle from config import apikey @@ -47,9 +48,11 @@ tmpdir = os.path.join(tempfile.gettempdir(), "CERTBOT_"+domain) if "NAMESILO_API" in os.environ: apikey = os.environ['NAMESILO_API'] -url = "https://www.namesilo.com/api/dnsDeleteRecord\ -?version=1&type=xml&key="+apikey+"&domain="+domain+"&rrid=" +tld = tldextract.extract(domain) +nsdomain = tld.domain+"."+tld.suffix +url = "https://www.namesilo.com/api/dnsDeleteRecord\ +?version=1&type=xml&key="+apikey+"&domain="+nsdomain+"&rrid=" def getrequest(record_id): return urllib.request.Request(