From ff5aec2d5dbff6e7ed313b44520f3e9c303c0f83 Mon Sep 17 00:00:00 2001 From: Luis Daniel Lucio Quiroz Date: Thu, 23 Jan 2020 03:19:09 -0500 Subject: [PATCH] Not mine (#3) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Update README.md Replaced a leftover dns-netcup with dns-ispconfig in Named arguments section. Also added a ISPConfig 3.1 path to the Credentials file, that is required, I found it to fail when not included. * Update dns_ispconfig.py Added the `stamp` parameter to API JSON that is required by ISPConfig * Allow full name zones Add the original record name (full domain including _acme-challenge bit) to the list of domain guesses to check with ISPConfig. Now the full record is tried first and so if there is a zone named _acme-challenge.example.com it will be used instead of example.com. The actual record name is then empty. * Update sutup.py Removed encoding parameter as it is not known to python 2.7 and default in python 3 Co-authored-by: Michal Krejčí --- README.rst | 4 ++-- certbot_dns_ispconfig/dns_ispconfig.py | 10 ++++++---- setup.py | 2 +- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/README.rst b/README.rst index 318756e..3e0e870 100644 --- a/README.rst +++ b/README.rst @@ -34,7 +34,7 @@ To start using DNS authentication for ispconfig, pass the following arguments on certbot's command line: ============================================================= ============================================== -``--authenticator certbot-dns-ispconfig:dns-netcup`` select the authenticator plugin (Required) +``--authenticator certbot-dns-ispconfig:dns-ispconfig`` select the authenticator plugin (Required) ``--certbot-dns-ispconfig:dns-ispconfig-credentials`` ispconfig Remote User credentials INI file. (Required) @@ -57,7 +57,7 @@ An example ``credentials.ini`` file: certbot_dns_ispconfig:dns_ispconfig_username = myremoteuser certbot_dns_ispconfig:dns_ispconfig_password = verysecureremoteuserpassword - certbot_dns_ispconfig:dns_ispconfig_endpoint = https://localhost:8080 + certbot_dns_ispconfig:dns_ispconfig_endpoint = https://localhost:8080/remote/json.php The path to this file can be provided interactively or using the ``--certbot-dns-ispconfig:dns-ispconfig-credentials`` command-line argument. Certbot diff --git a/certbot_dns_ispconfig/dns_ispconfig.py b/certbot_dns_ispconfig/dns_ispconfig.py index 4d64c52..61d11a1 100644 --- a/certbot_dns_ispconfig/dns_ispconfig.py +++ b/certbot_dns_ispconfig/dns_ispconfig.py @@ -1,6 +1,7 @@ """DNS Authenticator for ISPConfig.""" import json import logging +import time import requests import zope.interface @@ -133,7 +134,7 @@ class _ISPConfigClient(object): :raises certbot.errors.PluginError: if an error occurs communicating with the ISPConfig API """ self._login() - zone_id, zone_name = self._find_managed_zone_id(domain) + zone_id, zone_name = self._find_managed_zone_id(domain, record_name) if zone_id is None: raise errors.PluginError("Domain not known") logger.debug("domain found: %s with id: %s", zone_name, zone_id) @@ -167,7 +168,7 @@ class _ISPConfigClient(object): :raises certbot.errors.PluginError: if an error occurs communicating with the ISPConfig API """ self._login() - zone_id, zone_name = self._find_managed_zone_id(domain) + zone_id, zone_name = self._find_managed_zone_id(domain, record_name) if zone_id is None: raise errors.PluginError("Domain not known") logger.debug("domain found: %s with id: %s", zone_name, zone_id) @@ -196,6 +197,7 @@ class _ISPConfigClient(object): "zone": zone_id, "ttl": record_ttl, "update_serial": False, + "stamp": time.strftime('%Y-%m-%d %H:%M:%S'), }, } return data @@ -218,7 +220,7 @@ class _ISPConfigClient(object): logger.debug("delete with data: %s", data) result = self._api_request("dns_txt_delete", data) - def _find_managed_zone_id(self, domain): + def _find_managed_zone_id(self, domain, record_name): """ Find the managed zone for a given domain. @@ -228,7 +230,7 @@ class _ISPConfigClient(object): :raises certbot.errors.PluginError: if the managed zone cannot be found. """ - zone_dns_name_guesses = dns_common.base_domain_name_guesses(domain) + zone_dns_name_guesses = [record_name] + dns_common.base_domain_name_guesses(domain) for zone_name in zone_dns_name_guesses: # get the zone id diff --git a/setup.py b/setup.py index bffd7c6..f100835 100644 --- a/setup.py +++ b/setup.py @@ -16,7 +16,7 @@ install_requires = [ from os import path this_directory = path.abspath(path.dirname(__file__)) -with open(path.join(this_directory, "README.rst"), encoding="utf-8") as f: +with open(path.join(this_directory, "README.rst")) as f: long_description = f.read() setup(