mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-09-19 04:59:01 +00:00
Merge remote-tracking branch 'sunil/diagnostics'
This commit is contained in:
commit
2879c9cedb
14
actions/ldap
14
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()
|
setup()
|
||||||
{
|
{
|
||||||
# XXX: Password setting on users is disabled as changing passwords
|
# 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)
|
||||||
remove_user_from_group "$@"
|
remove_user_from_group "$@"
|
||||||
;;
|
;;
|
||||||
|
diagnose)
|
||||||
|
diagnose "$@"
|
||||||
|
;;
|
||||||
*)
|
*)
|
||||||
echo "Invalid sub-command"
|
echo "Invalid sub-command"
|
||||||
exit -1
|
exit -1
|
||||||
|
|||||||
@ -144,14 +144,14 @@ def get_modules_to_load():
|
|||||||
module_directory = os.path.join(cfg.config_dir, 'modules-enabled')
|
module_directory = os.path.join(cfg.config_dir, 'modules-enabled')
|
||||||
|
|
||||||
# Omit hidden files
|
# Omit hidden files
|
||||||
file_names = [file
|
file_names = [file_name
|
||||||
for file in os.listdir(module_directory)
|
for file_name in os.listdir(module_directory)
|
||||||
if not file.startswith('.') and '.dpkg' not in file]
|
if not file_name.startswith('.') and '.dpkg' not in file_name]
|
||||||
|
|
||||||
for file_name in file_names:
|
for file_name in file_names:
|
||||||
full_file_name = os.path.join(module_directory, file_name)
|
full_file_name = os.path.join(module_directory, file_name)
|
||||||
with open(full_file_name, 'r') as file:
|
with open(full_file_name, 'r') as file_handle:
|
||||||
for line in file:
|
for line in file_handle:
|
||||||
line = re.sub('#.*', '', line)
|
line = re.sub('#.*', '', line)
|
||||||
line = line.strip()
|
line = line.strip()
|
||||||
if line:
|
if line:
|
||||||
|
|||||||
@ -19,11 +19,14 @@
|
|||||||
Plinth module for running diagnostics
|
Plinth module for running diagnostics
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from django.http import Http404
|
||||||
from django.template.response import TemplateResponse
|
from django.template.response import TemplateResponse
|
||||||
from gettext import gettext as _
|
from gettext import gettext as _
|
||||||
|
import importlib
|
||||||
|
|
||||||
from plinth import actions
|
from plinth import actions
|
||||||
from plinth import cfg
|
from plinth import cfg
|
||||||
|
from plinth import module_loader
|
||||||
from plinth.errors import ActionError
|
from plinth.errors import ActionError
|
||||||
|
|
||||||
|
|
||||||
@ -55,3 +58,24 @@ def test(request):
|
|||||||
{'title': _('Diagnostic Test'),
|
{'title': _('Diagnostic Test'),
|
||||||
'diagnostics_output': output,
|
'diagnostics_output': output,
|
||||||
'diagnostics_error': error})
|
'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})
|
||||||
|
|||||||
52
plinth/modules/diagnostics/templates/diagnostics_module.html
Normal file
52
plinth/modules/diagnostics/templates/diagnostics_module.html
Normal file
@ -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 <http://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
{% endcomment %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
|
||||||
|
<h2>Diagnostic Results</h2>
|
||||||
|
|
||||||
|
<h3>Module: {{ module_name }}</h3>
|
||||||
|
|
||||||
|
{% if results %}
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-sm-3">
|
||||||
|
<table class="table table-bordered table-striped">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Test</th>
|
||||||
|
<th>Result</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{% for test, result in results %}
|
||||||
|
<tr>
|
||||||
|
<td>{{ test }}</td>
|
||||||
|
<td>{{ result }}</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% else %}
|
||||||
|
<p>This module does not support diagnostics</p>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% endblock %}
|
||||||
@ -26,4 +26,6 @@ urlpatterns = patterns( # pylint: disable-msg=C0103
|
|||||||
'plinth.modules.diagnostics.diagnostics',
|
'plinth.modules.diagnostics.diagnostics',
|
||||||
url(r'^sys/diagnostics/$', 'index', name='index'),
|
url(r'^sys/diagnostics/$', 'index', name='index'),
|
||||||
url(r'^sys/diagnostics/test/$', 'test', name='test'),
|
url(r'^sys/diagnostics/test/$', 'test', name='test'),
|
||||||
|
url(r'^sys/diagnostics/module/(?P<module_name>[a-z\-]+)/$', 'module',
|
||||||
|
name='module'),
|
||||||
)
|
)
|
||||||
|
|||||||
@ -20,10 +20,10 @@ Plinth module to manage users
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
from gettext import gettext as _
|
from gettext import gettext as _
|
||||||
|
import json
|
||||||
|
|
||||||
from plinth import cfg
|
from plinth import cfg
|
||||||
|
from plinth import actions
|
||||||
__all__ = ['init']
|
|
||||||
|
|
||||||
depends = ['plinth.modules.system']
|
depends = ['plinth.modules.system']
|
||||||
|
|
||||||
@ -33,3 +33,9 @@ def init():
|
|||||||
menu = cfg.main_menu.get('system:index')
|
menu = cfg.main_menu.get('system:index')
|
||||||
menu.add_urlname(_('Users and Groups'), 'glyphicon-user', 'users:index',
|
menu.add_urlname(_('Users and Groups'), 'glyphicon-user', 'users:index',
|
||||||
15)
|
15)
|
||||||
|
|
||||||
|
|
||||||
|
def diagnose():
|
||||||
|
"""Run diagnostics and result the results."""
|
||||||
|
output = actions.superuser_run('ldap', ['diagnose'])
|
||||||
|
return json.loads(output)
|
||||||
|
|||||||
@ -59,6 +59,9 @@
|
|||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<a href="{% url 'diagnostics:module' 'users' %}"
|
||||||
|
class="btn btn-default">Run Diagnostics</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user