mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-09-19 04:59:01 +00:00
names: Implement a diagnostic check for checking name resolution
- Use deb.debian.org because it is already contacted regularly for checking/downloading packages and updates. Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org> Reviewed-by: Veiko Aasa <veiko17@disroot.org>
This commit is contained in:
parent
a124681083
commit
1eb578fdb5
@ -4,12 +4,16 @@ FreedomBox app to configure name services.
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
import subprocess
|
||||||
|
|
||||||
from django.utils.translation import gettext_lazy as _
|
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 app as app_module
|
||||||
from plinth import cfg, menu, network
|
from plinth import cfg, menu, network
|
||||||
from plinth.daemon import Daemon
|
from plinth.daemon import Daemon
|
||||||
|
from plinth.diagnostic_check import (DiagnosticCheck,
|
||||||
|
DiagnosticCheckParameters, Result)
|
||||||
from plinth.modules.backups.components import BackupRestore
|
from plinth.modules.backups.components import BackupRestore
|
||||||
from plinth.package import Packages
|
from plinth.package import Packages
|
||||||
from plinth.privileged import service as service_privileged
|
from plinth.privileged import service as service_privileged
|
||||||
@ -70,6 +74,12 @@ class NamesApp(app_module.App):
|
|||||||
domain_added.connect(on_domain_added)
|
domain_added.connect(on_domain_added)
|
||||||
domain_removed.connect(on_domain_removed)
|
domain_removed.connect(on_domain_removed)
|
||||||
|
|
||||||
|
def diagnose(self) -> list[DiagnosticCheck]:
|
||||||
|
"""Run diagnostics and return the results."""
|
||||||
|
results = super().diagnose()
|
||||||
|
results.append(diagnose_resolution('deb.debian.org'))
|
||||||
|
return results
|
||||||
|
|
||||||
def setup(self, old_version):
|
def setup(self, old_version):
|
||||||
"""Install and configure the app."""
|
"""Install and configure the app."""
|
||||||
super().setup(old_version)
|
super().setup(old_version)
|
||||||
@ -94,6 +104,22 @@ class NamesApp(app_module.App):
|
|||||||
self.enable()
|
self.enable()
|
||||||
|
|
||||||
|
|
||||||
|
def diagnose_resolution(domain: str) -> DiagnosticCheck:
|
||||||
|
"""Perform a diagnostic check for whether a domain can be resolved."""
|
||||||
|
result = Result.NOT_DONE
|
||||||
|
try:
|
||||||
|
subprocess.run(['resolvectl', 'query', '--cache=no', domain],
|
||||||
|
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL,
|
||||||
|
check=True)
|
||||||
|
result = Result.PASSED
|
||||||
|
except subprocess.CalledProcessError:
|
||||||
|
result = Result.FAILED
|
||||||
|
|
||||||
|
description = gettext_noop('Resolve domain name: {domain}')
|
||||||
|
parameters: DiagnosticCheckParameters = {'domain': domain}
|
||||||
|
return DiagnosticCheck('names-resolve', description, result, parameters)
|
||||||
|
|
||||||
|
|
||||||
def on_domain_added(sender, domain_type, name='', description='',
|
def on_domain_added(sender, domain_type, name='', description='',
|
||||||
services=None, **kwargs):
|
services=None, **kwargs):
|
||||||
"""Add domain to global list."""
|
"""Add domain to global list."""
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user