diff --git a/actions/ldap b/actions/ldap index cf0dc75eb..fd06bce54 100755 --- a/actions/ldap +++ b/actions/ldap @@ -121,6 +121,17 @@ remove_user_from_group() } +diagnose() +{ + result="failed" + if lsldap | grep 'dn: dc=thisbox' > /dev/null; then + result="passed" + fi + + echo "[[\"Access LDAP server locally\", \"$result\"]]" +} + + setup() { # XXX: Password setting on users is disabled as changing passwords @@ -163,6 +174,9 @@ case $command in remove-user-from-group) remove_user_from_group "$@" ;; + diagnose) + diagnose "$@" + ;; *) echo "Invalid sub-command" exit -1 diff --git a/plinth/module_loader.py b/plinth/module_loader.py index 6834e3b5f..7b1443134 100644 --- a/plinth/module_loader.py +++ b/plinth/module_loader.py @@ -144,14 +144,14 @@ def get_modules_to_load(): module_directory = os.path.join(cfg.config_dir, 'modules-enabled') # Omit hidden files - file_names = [file - for file in os.listdir(module_directory) - if not file.startswith('.') and '.dpkg' not in file] + file_names = [file_name + for file_name in os.listdir(module_directory) + if not file_name.startswith('.') and '.dpkg' not in file_name] for file_name in file_names: full_file_name = os.path.join(module_directory, file_name) - with open(full_file_name, 'r') as file: - for line in file: + with open(full_file_name, 'r') as file_handle: + for line in file_handle: line = re.sub('#.*', '', line) line = line.strip() if line: diff --git a/plinth/modules/diagnostics/diagnostics.py b/plinth/modules/diagnostics/diagnostics.py index 01d487d0f..ab9f8b303 100644 --- a/plinth/modules/diagnostics/diagnostics.py +++ b/plinth/modules/diagnostics/diagnostics.py @@ -19,11 +19,14 @@ Plinth module for running diagnostics """ +from django.http import Http404 from django.template.response import TemplateResponse from gettext import gettext as _ +import importlib from plinth import actions from plinth import cfg +from plinth import module_loader from plinth.errors import ActionError @@ -55,3 +58,24 @@ def test(request): {'title': _('Diagnostic Test'), 'diagnostics_output': output, 'diagnostics_error': error}) + +def module(request, module_name): + """Return diagnostics for a particular module.""" + found = False + for module_import_path in module_loader.loaded_modules: + if module_name == module_import_path.split('.')[-1]: + found = True + break + + if not found: + raise Http404('Module does not exist or not loaded') + + loaded_module = importlib.import_module(module_import_path) + results = [] + if hasattr(loaded_module, 'diagnose'): + results = loaded_module.diagnose() + + return TemplateResponse(request, 'diagnostics_module.html', + {'title': _('Diagnostic Test'), + 'module_name': module_name, + 'results': results}) diff --git a/plinth/modules/diagnostics/templates/diagnostics_module.html b/plinth/modules/diagnostics/templates/diagnostics_module.html new file mode 100644 index 000000000..8e9ac2462 --- /dev/null +++ b/plinth/modules/diagnostics/templates/diagnostics_module.html @@ -0,0 +1,52 @@ +{% extends 'base.html' %} +{% comment %} +# +# This file is part of Plinth. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +{% endcomment %} + +{% block content %} + +

Diagnostic Results

+ +

Module: {{ module_name }}

+ +{% if results %} +
+
+ + + + + + + + + {% for test, result in results %} + + + + + {% endfor %} + +
TestResult
{{ test }}{{ result }}
+
+
+{% else %} +

This module does not support diagnostics

+{% endif %} + +{% endblock %} diff --git a/plinth/modules/diagnostics/urls.py b/plinth/modules/diagnostics/urls.py index c1797c716..afb7025e5 100644 --- a/plinth/modules/diagnostics/urls.py +++ b/plinth/modules/diagnostics/urls.py @@ -26,4 +26,6 @@ urlpatterns = patterns( # pylint: disable-msg=C0103 'plinth.modules.diagnostics.diagnostics', url(r'^sys/diagnostics/$', 'index', name='index'), url(r'^sys/diagnostics/test/$', 'test', name='test'), + url(r'^sys/diagnostics/module/(?P[a-z\-]+)/$', 'module', + name='module'), ) diff --git a/plinth/modules/users/__init__.py b/plinth/modules/users/__init__.py index 6a68e6bac..45b7a9906 100644 --- a/plinth/modules/users/__init__.py +++ b/plinth/modules/users/__init__.py @@ -20,10 +20,10 @@ Plinth module to manage users """ from gettext import gettext as _ +import json from plinth import cfg - -__all__ = ['init'] +from plinth import actions depends = ['plinth.modules.system'] @@ -33,3 +33,9 @@ def init(): menu = cfg.main_menu.get('system:index') menu.add_urlname(_('Users and Groups'), 'glyphicon-user', 'users:index', 15) + + +def diagnose(): + """Run diagnostics and result the results.""" + output = actions.superuser_run('ldap', ['diagnose']) + return json.loads(output) diff --git a/plinth/modules/users/templates/users_list.html b/plinth/modules/users/templates/users_list.html index f4040c66e..29933d5aa 100644 --- a/plinth/modules/users/templates/users_list.html +++ b/plinth/modules/users/templates/users_list.html @@ -59,6 +59,9 @@ {% endfor %} + + Run Diagnostics