diff --git a/actions/ldap b/actions/ldap index fd06bce54..cf0dc75eb 100755 --- a/actions/ldap +++ b/actions/ldap @@ -121,17 +121,6 @@ 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 @@ -174,9 +163,6 @@ case $command in remove-user-from-group) remove_user_from_group "$@" ;; - diagnose) - diagnose "$@" - ;; *) echo "Invalid sub-command" exit -1 diff --git a/plinth/modules/users/__init__.py b/plinth/modules/users/__init__.py index 45b7a9906..6977066c2 100644 --- a/plinth/modules/users/__init__.py +++ b/plinth/modules/users/__init__.py @@ -21,9 +21,11 @@ Plinth module to manage users from gettext import gettext as _ import json +import subprocess from plinth import cfg from plinth import actions +from plinth import action_utils depends = ['plinth.modules.system'] @@ -36,6 +38,31 @@ def init(): def diagnose(): - """Run diagnostics and result the results.""" - output = actions.superuser_run('ldap', ['diagnose']) - return json.loads(output) + """Run diagnostics and return the results.""" + results = [] + + results.append(action_utils.diagnose_port_listening(389, 'tcp4')) + results.append(action_utils.diagnose_port_listening(389, 'tcp6')) + + results.append(_diagnose_ldap_entry('dc=thisbox')) + results.append(_diagnose_ldap_entry('ou=people')) + results.append(_diagnose_ldap_entry('ou=groups')) + + return results + + +def _diagnose_ldap_entry(search_item): + """Diagnose that an LDAP entry exists.""" + result = 'failed' + + try: + subprocess.check_output(['ldapsearch', '-x', '-b', 'dc=thisbox', + search_item]) + result = 'passed' + except subprocess.CalledProcessError: + pass + + return [_('Check LDAP entry "{search_item}"') + .format(search_item=search_item), result] + + diff --git a/plinth/modules/users/templates/users_list.html b/plinth/modules/users/templates/users_list.html index 29933d5aa..5bec38ef8 100644 --- a/plinth/modules/users/templates/users_list.html +++ b/plinth/modules/users/templates/users_list.html @@ -60,8 +60,7 @@ {% endfor %} - Run Diagnostics + {% include "diagnostics_button.html" with module="users" %}