mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-03-11 09:04:54 +00:00
email_server: Drop showing diagnostics/repair and roundcube config
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org> Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
parent
affffddf36
commit
14c6541dfb
@ -147,7 +147,6 @@ class EmailServerApp(plinth.app.App):
|
||||
results = super().diagnose()
|
||||
results.extend([r.summarize() for r in audit.ldap.get()])
|
||||
results.extend([r.summarize() for r in audit.spam.get()])
|
||||
results.extend([r.summarize() for r in audit.rcube.get()])
|
||||
return results
|
||||
|
||||
|
||||
@ -179,7 +178,6 @@ def setup(helper, old_version=None):
|
||||
helper.call('post', audit.domain.set_domains)
|
||||
helper.call('post', audit.ldap.repair)
|
||||
helper.call('post', audit.spam.repair)
|
||||
helper.call('post', audit.rcube.repair)
|
||||
|
||||
# Reload
|
||||
actions.superuser_run('service', ['reload', 'postfix'])
|
||||
|
||||
@ -3,8 +3,6 @@
|
||||
Provides diagnosis and repair of email server configuration issues
|
||||
"""
|
||||
|
||||
from . import aliases, domain, home, ldap, models, rcube, spam, tls
|
||||
from . import aliases, domain, home, ldap, models, spam, tls
|
||||
|
||||
__all__ = [
|
||||
'aliases', 'domain', 'home', 'ldap', 'models', 'rcube', 'spam', 'tls'
|
||||
]
|
||||
__all__ = ['aliases', 'domain', 'home', 'ldap', 'models', 'spam', 'tls']
|
||||
|
||||
@ -1,90 +0,0 @@
|
||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from plinth import actions
|
||||
from plinth.modules.email_server.lock import Mutex
|
||||
from plinth.modules.email_server.modconf import ConfigInjector
|
||||
|
||||
from . import models
|
||||
|
||||
config_path = '/etc/roundcube/config.inc.php'
|
||||
boundary_pattern = '//[ ]*--[ ]*(BEGIN|END)[ ]+FREEDOMBOX CONFIG$'
|
||||
boundary_format = '//-- {} FREEDOMBOX CONFIG'
|
||||
|
||||
rconf_template = """//
|
||||
// The following section is managed by FreedomBox
|
||||
// Be careful not to edit
|
||||
include_once("/etc/roundcube/freedombox_mail.inc.php");
|
||||
"""
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
rcube_mutex = Mutex('rcube-config')
|
||||
|
||||
|
||||
def get():
|
||||
translation = {
|
||||
'rc_installed': _('RoundCube availability'),
|
||||
'rc_config_header': _('RoundCube configured for FreedomBox email'),
|
||||
}
|
||||
|
||||
output = actions.superuser_run('email_server', ['rcube', 'check'])
|
||||
results = json.loads(output)
|
||||
for i in range(0, len(results)):
|
||||
results[i] = models.Diagnosis.from_json(results[i], translation.get)
|
||||
|
||||
return results
|
||||
|
||||
|
||||
def repair():
|
||||
actions.superuser_run('email_server', ['rcube', 'set_up'])
|
||||
|
||||
|
||||
def repair_component(action):
|
||||
action_to_services = {'set_up': []}
|
||||
if action not in action_to_services:
|
||||
return
|
||||
actions.superuser_run('email_server', ['rcube', action])
|
||||
return action_to_services[action]
|
||||
|
||||
|
||||
def action_check():
|
||||
results = _action_check()
|
||||
for i in range(0, len(results)):
|
||||
results[i] = results[i].to_json()
|
||||
print(json.dumps(results))
|
||||
|
||||
|
||||
def _action_check():
|
||||
results = []
|
||||
if not os.path.exists(config_path):
|
||||
diagnosis = models.Diagnosis('rc_installed')
|
||||
diagnosis.error('Config file was missing')
|
||||
diagnosis.error('Check that RoundCube has been installed')
|
||||
results.append(diagnosis)
|
||||
return results
|
||||
|
||||
diagnosis = models.Diagnosis('rc_config_header', action='set_up')
|
||||
injector = ConfigInjector(boundary_pattern, boundary_format)
|
||||
if not injector.has_header_line(config_path):
|
||||
diagnosis.error('FreedomBox header line was missing')
|
||||
results.append(diagnosis)
|
||||
return results
|
||||
|
||||
|
||||
def action_set_up():
|
||||
with rcube_mutex.lock_all():
|
||||
_inject_rcube_config()
|
||||
|
||||
|
||||
def _inject_rcube_config():
|
||||
if not os.path.exists(config_path):
|
||||
logger.warning('Roundcube has not been installed')
|
||||
return
|
||||
logger.info('Opening rcube config file %s', config_path)
|
||||
injector = ConfigInjector(boundary_pattern, boundary_format)
|
||||
injector.do_template_string(rconf_template, config_path)
|
||||
@ -1,8 +0,0 @@
|
||||
<?php
|
||||
$config['default_host'] = 'localhost';
|
||||
$config['mail_domain'] = '%n';
|
||||
|
||||
$config['smtp_server'] = 'localhost';
|
||||
$config['smtp_port'] = 25;
|
||||
$config['smtp_helo_host'] = 'localhost';
|
||||
?>
|
||||
@ -5,11 +5,6 @@
|
||||
|
||||
{% load i18n %}
|
||||
|
||||
{% block content %}
|
||||
{{ tabs|safe }}
|
||||
{{ block.super }}
|
||||
{% endblock %}
|
||||
|
||||
{% block subsubmenu %}
|
||||
<a class="btn btn-default" role="button" href="/rspamd/">
|
||||
{% trans "Manage Spam" %}
|
||||
@ -20,46 +15,3 @@
|
||||
{% trans "Manage Aliases" %}
|
||||
</a>
|
||||
{% endblock %}
|
||||
|
||||
{% block extra_content %}
|
||||
{% if related_diagnostics %}
|
||||
<h3>{% trans "Service Alert" %}</h3>
|
||||
<ul class="list-group">
|
||||
{% for model in related_diagnostics %}
|
||||
<li class="list-group-item clearfix">
|
||||
|
||||
<span>{{ model.title }}</span>
|
||||
{% if model.critical_errors %}
|
||||
<span class="badge badge-danger">{% trans "error" %}</span>
|
||||
{% elif model.errors %}
|
||||
<span class="badge badge-warning">{% trans "failed" %}</span>
|
||||
{% else %}
|
||||
<span class="badge badge-success">{% trans "passed" %}</span>
|
||||
{% endif %}
|
||||
|
||||
{% if model.has_failed and model.action %}
|
||||
<form method="post" class="float-right"
|
||||
action="{{ request.path }}" >
|
||||
{% csrf_token %}
|
||||
<button type="submit" class="btn btn-sm btn-outline-primary"
|
||||
name="repair" value="{{ model.action }}">
|
||||
{% trans "Repair" %}
|
||||
</button>
|
||||
</form>
|
||||
{% endif %}
|
||||
|
||||
<ul>
|
||||
{% for message in model.critical_errors %}
|
||||
<li>{{ message }}</li>
|
||||
{% endfor %}
|
||||
{% for message in model.errors %}
|
||||
<li>{{ message }}</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% endif %}
|
||||
{{ block.super }}
|
||||
{% endblock %}
|
||||
|
||||
@ -4,49 +4,22 @@ Views for the email app.
|
||||
"""
|
||||
|
||||
from django.contrib import messages
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.http import HttpResponseBadRequest
|
||||
from django.shortcuts import redirect
|
||||
from django.urls import reverse_lazy
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.views.generic.base import TemplateView, View
|
||||
from django.views.generic.base import TemplateView
|
||||
from django.views.generic.edit import FormView
|
||||
|
||||
import plinth.actions
|
||||
import plinth.utils
|
||||
from plinth.views import AppView
|
||||
|
||||
from . import aliases as aliases_module
|
||||
from . import audit, forms
|
||||
|
||||
|
||||
class ExceptionsMixin(View):
|
||||
|
||||
def render_validation_error(self, validation_error, status=400):
|
||||
context = self.get_context_data()
|
||||
context['error'] = validation_error
|
||||
return self.render_to_response(context, status=status)
|
||||
|
||||
def render_exception(self, exception, status=500):
|
||||
context = self.get_context_data()
|
||||
context['error'] = [str(exception)]
|
||||
return self.render_to_response(context, status=status)
|
||||
|
||||
def catch_exceptions(self, function, request):
|
||||
try:
|
||||
return function(request)
|
||||
except ValidationError as validation_error:
|
||||
return self.render_validation_error(validation_error)
|
||||
except Exception as error:
|
||||
return self.render_exception(error)
|
||||
|
||||
|
||||
class EmailServerView(ExceptionsMixin, AppView):
|
||||
class EmailServerView(AppView):
|
||||
"""Server configuration page"""
|
||||
app_id = 'email_server'
|
||||
form_class = forms.DomainForm
|
||||
template_name = 'email_server.html'
|
||||
audit_modules = ('rcube', )
|
||||
|
||||
def get_initial(self):
|
||||
"""Return the initial values to populate in the form."""
|
||||
@ -55,45 +28,6 @@ class EmailServerView(ExceptionsMixin, AppView):
|
||||
initial['primary_domain'] = domains['primary_domain']
|
||||
return initial
|
||||
|
||||
def get_context_data(self, *args, **kwargs):
|
||||
context = super().get_context_data(*args, **kwargs)
|
||||
|
||||
dlist = []
|
||||
for module_name in self.audit_modules:
|
||||
self._get_audit_results(module_name, dlist)
|
||||
dlist.sort(key=audit.models.Diagnosis.sorting_key)
|
||||
|
||||
context['related_diagnostics'] = dlist
|
||||
return context
|
||||
|
||||
def _get_audit_results(self, module_name, dlist):
|
||||
try:
|
||||
results = getattr(audit, module_name).get()
|
||||
except Exception as e:
|
||||
title = _('Internal error in {0}').format('audit.' + module_name)
|
||||
diagnosis = audit.models.Diagnosis(title)
|
||||
diagnosis.critical(str(e))
|
||||
diagnosis.critical(_('Check syslog for more information'))
|
||||
results = [diagnosis]
|
||||
|
||||
for diagnosis in results:
|
||||
if diagnosis.action:
|
||||
diagnosis.action = '%s.%s' % (module_name, diagnosis.action)
|
||||
if diagnosis.has_failed:
|
||||
dlist.append(diagnosis)
|
||||
|
||||
def post(self, request):
|
||||
repair_field = request.POST.get('repair')
|
||||
if repair_field:
|
||||
module_name, sep, action_name = repair_field.partition('.')
|
||||
if not sep or module_name not in self.audit_modules:
|
||||
return HttpResponseBadRequest('Bad post data')
|
||||
|
||||
self._repair(module_name, action_name)
|
||||
return redirect(request.path)
|
||||
|
||||
return super().post(request)
|
||||
|
||||
def form_valid(self, form):
|
||||
"""Update the settings for changed domain values."""
|
||||
old_data = form.initial
|
||||
@ -103,27 +37,11 @@ class EmailServerView(ExceptionsMixin, AppView):
|
||||
audit.domain.set_domains(new_data['primary_domain'])
|
||||
messages.success(self.request, _('Configuration updated'))
|
||||
except Exception:
|
||||
messages.success(self.request,
|
||||
_('An error occurred during configuration.'))
|
||||
messages.error(self.request,
|
||||
_('An error occurred during configuration.'))
|
||||
|
||||
return super().form_valid(form)
|
||||
|
||||
def _repair(self, module_name, action_name):
|
||||
"""Repair the configuration of the given audit module."""
|
||||
module = getattr(audit, module_name)
|
||||
if not hasattr(module, 'repair_component'):
|
||||
return
|
||||
|
||||
reload_list = []
|
||||
try:
|
||||
reload_list = module.repair_component(action_name)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
for service in reload_list:
|
||||
# plinth.action_utils.service_reload(service)
|
||||
plinth.actions.superuser_run('service', ['reload', service])
|
||||
|
||||
|
||||
class AliasView(FormView):
|
||||
"""View to create, list, enable, disable and delete aliases.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user