Merge pull request #2 from Junker/master

Made python3.4 compatible. added subdomains support.
This commit is contained in:
Erik C. Thauvin 2020-04-14 09:15:56 -07:00 committed by GitHub
commit e0fc2e71fa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 11 deletions

View file

@ -1,7 +1,7 @@
# NameSilo Let's Encrypt # 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) [![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, 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 using [Certbot](https://certbot.eff.org/) DNS-01 challenge validation for domains DNS hosted on
@ -9,10 +9,12 @@ using [Certbot](https://certbot.eff.org/) DNS-01 challenge validation for domain
## Setup ## 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 untangle
pip install tldextract
``` ```
Download the [latest release](https://github.com/ethauvin/namesilo-letsencrypt/releases) archive and expand it in the desired directory. 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 \
</pre> </pre>
Please note that NameSilo DNS propagation takes up to **15 minutes**. The scripts will wait **20 minutes** before completing, just to be safe. Please note that NameSilo DNS propagation takes up to **15 minutes**. The scripts will wait **20 minutes** before completing, just to be safe.
q

18
authenticator.py Normal file → Executable file
View file

@ -1,4 +1,4 @@
#!/usr/bin/env python3.8 #!/usr/bin/env python3
# authenticator.py # authenticator.py
# #
@ -37,6 +37,7 @@ import tempfile
import time import time
import urllib.request import urllib.request
import tldextract
import untangle import untangle
from config import apikey, wait from config import apikey, wait
@ -51,14 +52,21 @@ def sleep(minutes):
domain = os.environ['CERTBOT_DOMAIN'] domain = os.environ['CERTBOT_DOMAIN']
validation = os.environ['CERTBOT_VALIDATION'] validation = os.environ['CERTBOT_VALIDATION']
tmpdir = os.path.join(tempfile.gettempdir(), f"CERTBOT_{domain}") tmpdir = os.path.join(tempfile.gettempdir(), "CERTBOT_"+domain)
rrhost = "_acme-challenge"
if "NAMESILO_API" in os.environ: if "NAMESILO_API" in os.environ:
apikey = os.environ['NAMESILO_API'] apikey = os.environ['NAMESILO_API']
url = f"https://www.namesilo.com/api/dnsAddRecord?\
version=1&type=xml&key={apikey}&domain={domain}&rrtype=TXT\ tld = tldextract.extract(domain)
&rrhost=_acme-challenge&rrvalue={validation}&rrttl=3600" 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="+nsdomain+"&rrtype=TXT\
&rrhost="+rrhost+"&rrvalue="+validation+"&rrttl=3600"
req = urllib.request.Request( req = urllib.request.Request(
url, url,

12
cleanup.py Normal file → Executable file
View file

@ -1,4 +1,4 @@
#!/usr/bin/env python3.8 #!/usr/bin/env python3
# cleanup.py # cleanup.py
# #
@ -36,19 +36,23 @@ import sys
import tempfile import tempfile
import urllib.request import urllib.request
import tldextract
import untangle import untangle
from config import apikey from config import apikey
domain = os.environ['CERTBOT_DOMAIN'] 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: if "NAMESILO_API" in os.environ:
apikey = os.environ['NAMESILO_API'] apikey = os.environ['NAMESILO_API']
url = f"https://www.namesilo.com/api/dnsDeleteRecord\ tld = tldextract.extract(domain)
?version=1&type=xml&key={apikey}&domain={domain}&rrid=" 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): def getrequest(record_id):
return urllib.request.Request( return urllib.request.Request(