mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-11-29 08:25:10 +00:00
matrixsynapse: Add let's encrypt component for certficiates
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org> Reviewed-by: Joseph Nuthalapati <njoseph@thoughtworks.com>
This commit is contained in:
1 parent
c47a99b25e
commit
9fd1b95244
4 files changed
+43
-117
No files matched your search
@@ -20,6 +20,7 @@ FreedomBox app to configure matrix-synapse server.
|
||||
|
||||
import logging
|
||||
import os
|
||||
import pathlib
|
||||
|
||||
from django.urls import reverse_lazy
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
@@ -31,6 +32,7 @@ from plinth import frontpage, menu
|
||||
from plinth.daemon import Daemon
|
||||
from plinth.modules.apache.components import Webserver
|
||||
from plinth.modules.firewall.components import Firewall
|
||||
from plinth.modules.letsencrypt.components import LetsEncrypt
|
||||
|
||||
from .manifest import backup, clients
|
||||
|
||||
@@ -40,6 +42,8 @@ managed_services = ['matrix-synapse']
|
||||
|
||||
managed_packages = ['matrix-synapse', 'matrix-synapse-ldap3']
|
||||
|
||||
managed_paths = [pathlib.Path('/etc/matrix-synapse/')]
|
||||
|
||||
name = _('Matrix Synapse')
|
||||
|
||||
short_description = _('Chat Server')
|
||||
@@ -101,6 +105,16 @@ class MatrixSynapseApp(app_module.App):
|
||||
'matrix-synapse-plinth')
|
||||
self.add(webserver)
|
||||
|
||||
letsencrypt = LetsEncrypt(
|
||||
'letsencrypt-matrixsynapse', domains=get_domains, daemons=[
|
||||
managed_services[0]
|
||||
], should_copy_certificates=True,
|
||||
private_key_path='/etc/matrix-synapse/homeserver.tls.key',
|
||||
certificate_path='/etc/matrix-synapse/homeserver.tls.crt',
|
||||
user_owner='matrix-synapse', group_owner='nogroup',
|
||||
managing_app='matrixsynapse')
|
||||
self.add(letsencrypt)
|
||||
|
||||
daemon = Daemon('daemon-matrixsynapse', managed_services[0])
|
||||
self.add(daemon)
|
||||
|
||||
@@ -121,6 +135,15 @@ def setup(helper, old_version=None):
|
||||
helper.call('post', actions.superuser_run, 'matrixsynapse',
|
||||
['post-install'])
|
||||
helper.call('post', app.enable)
|
||||
app.get_component('letsencrypt-matrixsynapse').setup_certificates()
|
||||
|
||||
|
||||
def setup_domain(domain_name):
|
||||
"""Configure a domain name for matrixsynapse."""
|
||||
app.get_component('letsencrypt-matrixsynapse').setup_certificates(
|
||||
[domain_name])
|
||||
actions.superuser_run('matrixsynapse',
|
||||
['setup', '--domain-name', domain_name])
|
||||
|
||||
|
||||
def is_setup():
|
||||
@@ -141,6 +164,15 @@ def diagnose():
|
||||
return results
|
||||
|
||||
|
||||
def get_domains():
|
||||
"""Return a list of domains this app is interested in."""
|
||||
domain = get_configured_domain_name()
|
||||
if domain:
|
||||
return [domain]
|
||||
|
||||
return []
|
||||
|
||||
|
||||
def get_configured_domain_name():
|
||||
"""Return the currently configured domain name."""
|
||||
if not is_setup():
|
||||
@@ -159,8 +191,10 @@ def get_public_registration_status():
|
||||
return output.strip() == 'enabled'
|
||||
|
||||
|
||||
def has_valid_certificate():
|
||||
"""Return whether the configured domain name has a valid certificate."""
|
||||
status = actions.superuser_run('matrixsynapse',
|
||||
['letsencrypt', 'get-status'])
|
||||
return status.startswith('valid')
|
||||
def get_certificate_status():
|
||||
"""Return the status of certificate for the configured domain."""
|
||||
status = app.get_component('letsencrypt-matrixsynapse').get_status()
|
||||
if not status:
|
||||
return 'no-domains'
|
||||
|
||||
return list(status.values())[0]
|
||||
@@ -39,7 +39,7 @@
|
||||
{% endblocktrans %}
|
||||
</p>
|
||||
|
||||
{% if not has_valid_certificate %}
|
||||
{% if certificate_status != "valid" %}
|
||||
<div class="alert alert-warning" role="alert">
|
||||
{% url 'letsencrypt:index' as letsencrypt_url %}
|
||||
{% blocktrans %}
|
||||
|
||||
@@ -30,7 +30,7 @@ from plinth.modules import matrixsynapse
|
||||
from plinth.utils import get_domain_names
|
||||
from plinth.views import AppView
|
||||
|
||||
from . import get_public_registration_status, has_valid_certificate
|
||||
from . import get_public_registration_status
|
||||
from .forms import MatrixSynapseForm
|
||||
|
||||
|
||||
@@ -42,10 +42,7 @@ class SetupView(FormView):
|
||||
|
||||
def form_valid(self, form):
|
||||
"""Handle valid form submission."""
|
||||
domain_name = form.cleaned_data['domain_name']
|
||||
actions.superuser_run('matrixsynapse',
|
||||
['setup', '--domain-name', domain_name])
|
||||
|
||||
matrixsynapse.setup_domain(form.cleaned_data['domain_name'])
|
||||
return super().form_valid(form)
|
||||
|
||||
def get_context_data(self, *args, **kwargs):
|
||||
@@ -82,7 +79,7 @@ class MatrixSynapseAppView(AppView):
|
||||
context['domain_name'] = matrixsynapse.get_configured_domain_name()
|
||||
context['clients'] = matrixsynapse.clients
|
||||
context['manual_page'] = matrixsynapse.manual_page
|
||||
context['has_valid_certificate'] = has_valid_certificate()
|
||||
context['certificate_status'] = matrixsynapse.get_certificate_status()
|
||||
return context
|
||||
|
||||
def get_initial(self):
|
||||
|
||||
Reference in new issue
Block a user