From 5c810ed87faa8a110007ba984ea2a26d5d8188ab Mon Sep 17 00:00:00 2001 From: James Valleroy Date: Thu, 18 Feb 2016 18:05:48 -0500 Subject: [PATCH] monkeysphere: Add Let's Encrypt certificates Filter letsencrypt domains from snakeoil list. Rename views for snakeoil and letsencrypt. --- actions/monkeysphere | 49 +++++++++++++--- .../monkeysphere/templates/monkeysphere.html | 56 ++++++++++++++++++- plinth/modules/monkeysphere/urls.py | 6 +- plinth/modules/monkeysphere/views.py | 50 ++++++++++++++--- 4 files changed, 140 insertions(+), 21 deletions(-) diff --git a/actions/monkeysphere b/actions/monkeysphere index 89924a611..ef37de3f7 100755 --- a/actions/monkeysphere +++ b/actions/monkeysphere @@ -41,9 +41,14 @@ def parse_arguments(): host_import_ssh_key.add_argument( 'domain', help='Fully-qualified domain name') - host_import_https_key = subparsers.add_parser( - 'host-import-https-key', help='Import host HTTPS key') - host_import_https_key.add_argument( + host_import_snakeoil_key = subparsers.add_parser( + 'host-import-snakeoil-key', help='Import host snakeoil key') + host_import_snakeoil_key.add_argument( + 'domain', help='Fully-qualified domain name') + + host_import_letsencrypt_key = subparsers.add_parser( + 'host-import-letsencrypt-key', help="Import Let's Encrypt key") + host_import_letsencrypt_key.add_argument( 'domain', help='Fully-qualified domain name') host_publish_key = subparsers.add_parser( @@ -96,13 +101,41 @@ def subcommand_host_import_ssh_key(arguments): print(output.decode()) -def subcommand_host_import_https_key(arguments): - """Import host HTTPS key.""" - output = subprocess.check_output( +def subcommand_host_import_snakeoil_key(arguments): + """Import host snakeoil key.""" + proc = subprocess.Popen( ['monkeysphere-host', 'import-key', '/etc/ssl/private/ssl-cert-snakeoil.key', - 'https://' + arguments.domain]) - print(output.decode()) + 'https://' + arguments.domain], + stdout=subprocess.PIPE, stderr=subprocess.PIPE, + env=dict( + os.environ, + MONKEYSPHERE_PROMPT='false')) + output, error = proc.communicate() + output, error = output.decode(), error.decode() + if proc.returncode != 0: + raise Exception(output, error) + + print(output) + + +def subcommand_host_import_letsencrypt_key(arguments): + """Import Let's Encrypt key.""" + proc = subprocess.Popen( + ['monkeysphere-host', 'import-key', + os.path.join('/etc/letsencrypt/live', + arguments.domain, 'privkey.pem'), + 'https://' + arguments.domain], + stdout=subprocess.PIPE, stderr=subprocess.PIPE, + env=dict( + os.environ, + MONKEYSPHERE_PROMPT='false')) + output, error = proc.communicate() + output, error = output.decode(), error.decode() + if proc.returncode != 0: + raise Exception(output, error) + + print(output) def subcommand_host_publish_key(arguments): diff --git a/plinth/modules/monkeysphere/templates/monkeysphere.html b/plinth/modules/monkeysphere/templates/monkeysphere.html index c28bea719..1eaf2a94b 100644 --- a/plinth/modules/monkeysphere/templates/monkeysphere.html +++ b/plinth/modules/monkeysphere/templates/monkeysphere.html @@ -127,7 +127,7 @@ - {% for domain in status.https_domains %} + {% for domain in status.snakeoil_domains %} {{ domain.name }} @@ -143,7 +143,59 @@ {% if not domain.key %}
+ action="{% url 'monkeysphere:generate_snakeoil' domain.name %}"> + {% csrf_token %} + + +
+ {% elif not running %} +
+ {% csrf_token %} + + +
+ {% endif %} + + + {% endfor %} + + + + + +

{% trans "Let's Encrypt Certificates" %}

+ +
+
+ + + + + + + + + + {% for domain in status.letsencrypt_domains %} + + + +
{% trans "Domain" %}{% trans "OpenPGP Fingerprint" %}{% trans "Actions" %}
{{ domain.name }} + {% if domain.key %} + + {{ domain.key.pgp_fingerprint }} + + {% else %} + {% trans "Not Available" %} + {% endif %} + + {% if not domain.key %} +
{% csrf_token %}