diff --git a/plinth/modules/diagnostics/__init__.py b/plinth/modules/diagnostics/__init__.py index 33ad68431..42b5652b6 100644 --- a/plinth/modules/diagnostics/__init__.py +++ b/plinth/modules/diagnostics/__init__.py @@ -11,24 +11,31 @@ import threading from copy import deepcopy import psutil +from django.urls import reverse_lazy from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_noop from plinth import app as app_module -from plinth import daemon, glib, kvstore, menu +from plinth import cfg, glib, kvstore, menu from plinth import operation as operation_module +from plinth.daemon import RelatedDaemon, diagnose_port_listening from plinth.diagnostic_check import (CheckJSONDecoder, CheckJSONEncoder, DiagnosticCheck, Result) from plinth.modules.apache.components import diagnose_url_on_all from plinth.modules.backups.components import BackupRestore from plinth.setup import run_repair_on_app +from plinth.utils import format_lazy from . import manifest _description = [ _('The system diagnostic test will run a number of checks on your ' 'system to confirm that applications and services are working as ' - 'expected.') + 'expected.'), + format_lazy( + _('This app also shows the logs for ' + '{box_name} services.'), box_name=_(cfg.box_name), + logs_url=reverse_lazy('logs', args=['diagnostics'])) ] logger = logging.Logger(__name__) @@ -61,6 +68,14 @@ class DiagnosticsApp(app_module.App): order=30) self.add(menu_item) + # Add FreedomBox daemons to show logs for them. + daemon = RelatedDaemon('related-daemon-plinth', 'plinth') + self.add(daemon) + + daemon = RelatedDaemon('related-daemon-freedombox-privileged', + 'freedombox-privileged') + self.add(daemon) + backup_restore = BackupRestore('backup-restore-diagnostics', **manifest.backup) self.add(backup_restore) @@ -82,7 +97,7 @@ class DiagnosticsApp(app_module.App): def diagnose(self) -> list[DiagnosticCheck]: """Run diagnostics and return the results.""" results = super().diagnose() - results.append(daemon.diagnose_port_listening(8000, 'tcp4')) + results.append(diagnose_port_listening(8000, 'tcp4')) results.extend( diagnose_url_on_all('http://{host}/plinth/', check_certificate=False)) diff --git a/plinth/modules/help/privileged.py b/plinth/modules/help/privileged.py deleted file mode 100644 index a1e6447e8..000000000 --- a/plinth/modules/help/privileged.py +++ /dev/null @@ -1,14 +0,0 @@ -# SPDX-License-Identifier: AGPL-3.0-or-later -"""Actions for help module.""" - -import subprocess - -from plinth.actions import privileged - - -@privileged -def get_logs() -> str: - """Get latest FreedomBox logs.""" - command = ['journalctl', '--no-pager', '--lines=100', '--unit=plinth'] - process = subprocess.run(command, check=True, stdout=subprocess.PIPE) - return process.stdout.decode() diff --git a/plinth/modules/help/templates/statuslog.html b/plinth/modules/help/templates/statuslog.html deleted file mode 100644 index 6542300bc..000000000 --- a/plinth/modules/help/templates/statuslog.html +++ /dev/null @@ -1,38 +0,0 @@ -{% extends 'help_base.html' %} -{% comment %} -# SPDX-License-Identifier: AGPL-3.0-or-later -{% endcomment %} - -{% load i18n %} - -{% block content %} - -

{% trans "Status Log" %}

- -

- {% blocktrans trimmed %} - These are the last {{ num_lines }} lines of the status log for this web - interface. If you want to report a bug, please use the bug - tracker and attach this status log to the bug report. - {% endblocktrans %} -

- -
-
- - {% trans "Caution:" %} -
-
- {% blocktrans trimmed %} - Please remove any personal information from the log before submitting - the bug report. - {% endblocktrans %} -
-
- -

-

{{ data }}
-

- -{% endblock %} diff --git a/plinth/modules/help/tests/test_functional.py b/plinth/modules/help/tests/test_functional.py deleted file mode 100644 index 3658648de..000000000 --- a/plinth/modules/help/tests/test_functional.py +++ /dev/null @@ -1,38 +0,0 @@ -# SPDX-License-Identifier: AGPL-3.0-or-later -""" -Functional, browser based tests for help app. -""" - -import pytest - -from plinth.tests import functional - -pytestmark = [pytest.mark.system, pytest.mark.essential, pytest.mark.help] - -# TODO Scenario: Visit the wiki -# TODO Scenario: Visit the mailing list -# TODO Scenario: Visit the IRC channel -# TODO Scenario: View the manual -# TODO Scenario: View the about page - - -@pytest.fixture(scope='module', autouse=True) -def fixture_background(session_browser): - """Login.""" - functional.login(session_browser) - - -def test_view_status_logs(session_browser): - """Test viewing the status logs.""" - _go_to_status_logs(session_browser) - assert _are_status_logs_shown(session_browser) - - -def _go_to_status_logs(browser): - functional.visit(browser, '/plinth/help/status-log/') - - -def _are_status_logs_shown(browser): - status_log = browser.find_by_css('.status-log').first.text - return ('-- No entries --' in status_log - or status_log.strip().splitlines()) diff --git a/plinth/modules/help/urls.py b/plinth/modules/help/urls.py index 4f91d1d6f..001f1b953 100644 --- a/plinth/modules/help/urls.py +++ b/plinth/modules/help/urls.py @@ -25,6 +25,4 @@ urlpatterns = [ non_admin_view(views.manual), name='manual-page'), re_path(r'^help/manual-download/$', non_admin_view(views.download_manual), name='download-manual'), - re_path(r'^help/status-log/$', non_admin_view(views.status_log), - name='status-log'), ] diff --git a/plinth/modules/help/views.py b/plinth/modules/help/views.py index a5638bc40..da13242cd 100644 --- a/plinth/modules/help/views.py +++ b/plinth/modules/help/views.py @@ -19,8 +19,6 @@ from django.utils.translation import gettext as _ from plinth import __version__, cfg, menu from plinth.modules.upgrades import views as upgrades_views -from . import privileged - def index(request): """Serve the index page""" @@ -164,10 +162,3 @@ def download_manual(request): response['Content-Encoding'] = encoding return response - - -def status_log(request): - """Serve the last 100 lines of plinth's status log.""" - logs = privileged.get_logs() - context = {'num_lines': 100, 'data': logs} - return TemplateResponse(request, 'statuslog.html', context) diff --git a/plinth/templates/500.html b/plinth/templates/500.html index df90448d8..a87930b0d 100644 --- a/plinth/templates/500.html +++ b/plinth/templates/500.html @@ -10,13 +10,13 @@

{% trans "500" %}

- {% url 'help:status-log' as status_log_url %} + {% url 'logs' app_id='diagnostics' as logs_url %} {% blocktrans trimmed %} This is an internal error and not something you caused or can fix. Please report the error on the bug tracker so we can fix it. Also, please attach the status log to the bug report. + href="{{ logs_url }}">logs to the bug report. {% endblocktrans %}