From 933c2e8ed1b9ac06fd4d9411a08a2e4458ee113a Mon Sep 17 00:00:00 2001 From: Markus Hauschild Date: Sun, 10 Jan 2016 15:48:16 +0100 Subject: [PATCH] Minor code and documentation improvements --- README.md | 3 +++ acertmgr.py | 24 ++++++++++++++---------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 46777da..61efd95 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,7 @@ All configuration files use yaml syntax. --- mode: webdir +#mode: standalone webdir: /var/www/challenges/ ``` @@ -32,7 +33,9 @@ mail.example.com: - user: postfix group: postfix perm: '400' + notify: '/etc/init.d/postfix reload' - user: dovecot group: dovecot perm: '400' + notify: '/etc/init.d/dovecot reload' ``` diff --git a/acertmgr.py b/acertmgr.py index 62f2d04..29f6e98 100755 --- a/acertmgr.py +++ b/acertmgr.py @@ -51,6 +51,7 @@ def cert_isValid(domain, settings): def cert_get(domain, settings): key_file = ACME_DIR + "server.key" + csr_file = "/tmp/%s.csr" % domain print("Getting certificate for %s." % domain) @@ -58,28 +59,31 @@ def cert_get(domain, settings): # TODO run acme_tiny # TODO check if resulting certificate is valid + # TODO delete temporary files # TODO copy cert w/ correct permissions # TODO restart/reload service(s) if __name__ == "__main__": - # load configuration - with open(ACME_CONF) as config_fd: - config = yaml.load(config_fd) - if not config: - config = {} - if 'domains' not in config: - config['domains'] = {} + # load global configuration + if os.path.isfile(ACME_CONF): + with open(ACME_CONF) as config_fd: + config = yaml.load(config_fd) + if not config: + config = {} + if 'domains' not in config: + config['domains'] = {} + + # load domain configuration for config_file in os.listdir(ACME_CONFD): if config_file.endswith(".conf"): with open(ACME_CONFD + config_file) as config_fd: config['domains'].update(yaml.load(config_fd)) #print(str(config)) - # fill up configuration with defaults - # TODO + # TODO fill up configuration with defaults - # check certificate validity + # check certificate validity and obtain/renew certificates if needed for domain in config['domains']: if not cert_isValid(domain, config['domains'][domain]): cert_get(domain, config['domains'][domain])