users: Improve diagnostics

- Move diagnostics into main module instead of action script.

- Ability run diagnostics as non-root user (because it runs in Plinth
  instead of action).

- Diagnose whether LDAP server is listening.

- Diagnose directory entities created during setup.
This commit is contained in:
Sunil Mohan Adapa 2015-08-21 20:01:05 +05:30 committed by James Valleroy
parent 0febeb7244
commit 4210332bf6
3 changed files with 31 additions and 19 deletions

View File

@ -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

View File

@ -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]

View File

@ -60,8 +60,7 @@
{% endfor %}
</div>
<a href="{% url 'diagnostics:module' 'users' %}"
class="btn btn-default">Run Diagnostics</a>
{% include "diagnostics_button.html" with module="users" %}
</div>
</div>