From 85a694f20f2126785d02278f9c7153440683a4da Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Sat, 18 Jan 2025 16:34:49 -0800 Subject: [PATCH] names: Retrieve the most important domain in a more generic way - The get_domain_name() has some problem. It returns only static domain names but not a dynamic domain name. It may not always return the same domain when multiple static domains are configured. It may return return an empty string. Tests: - JSXC page shows the alphabetically first static domain. If no static domain is configured, first dynamic domain is shown, next pagekite domain, next pagekite domain, next tor onion domain, and finally .local domain. - Downloading profile from OpenVPN will set the first domain in it. - When ejabberd is installed, the first domain is configured by default. Signed-off-by: Sunil Mohan Adapa Reviewed-by: James Valleroy --- plinth/modules/ejabberd/__init__.py | 4 ++-- plinth/modules/jsxc/views.py | 6 +++--- plinth/modules/names/__init__.py | 6 ------ plinth/modules/openvpn/views.py | 7 ++----- 4 files changed, 7 insertions(+), 16 deletions(-) diff --git a/plinth/modules/ejabberd/__init__.py b/plinth/modules/ejabberd/__init__.py index 965fa22b8..7e25752ce 100644 --- a/plinth/modules/ejabberd/__init__.py +++ b/plinth/modules/ejabberd/__init__.py @@ -11,12 +11,12 @@ from plinth import app as app_module from plinth import cfg, frontpage, menu from plinth.config import DropinConfigs from plinth.daemon import Daemon -from plinth.modules import names from plinth.modules.apache.components import Webserver from plinth.modules.backups.components import BackupRestore from plinth.modules.coturn.components import TurnConfiguration, TurnConsumer from plinth.modules.firewall.components import Firewall from plinth.modules.letsencrypt.components import LetsEncrypt +from plinth.modules.names.components import DomainName from plinth.modules.users.components import UsersAndGroups from plinth.package import Packages from plinth.signals import (domain_added, post_hostname_change, @@ -136,7 +136,7 @@ class EjabberdApp(app_module.App): def setup(self, old_version): """Install and configure the app.""" - domain_name = names.get_domain_name() + domain_name = DomainName.list_names()[0] logger.info('ejabberd service domain name - %s', domain_name) privileged.pre_install(domain_name) diff --git a/plinth/modules/jsxc/views.py b/plinth/modules/jsxc/views.py index 145420294..1e51bb416 100644 --- a/plinth/modules/jsxc/views.py +++ b/plinth/modules/jsxc/views.py @@ -5,7 +5,7 @@ from django.http import Http404 from django.views.generic import TemplateView import plinth.app as app_module -from plinth.modules import names +from plinth.modules.names.components import DomainName class JsxcView(TemplateView): @@ -21,8 +21,8 @@ class JsxcView(TemplateView): return super().dispatch(request, *args, **kwargs) - def get_context_data(self, *args, **kwargs): + def get_context_data(self, *args, **kwargs) -> dict[str, object]: """Add domain information to view context.""" context = super().get_context_data(*args, **kwargs) - context['domain_name'] = names.get_domain_name() + context['domain_name'] = DomainName.list_names()[0] return context diff --git a/plinth/modules/names/__init__.py b/plinth/modules/names/__init__.py index 3f17192fb..a085d974b 100644 --- a/plinth/modules/names/__init__.py +++ b/plinth/modules/names/__init__.py @@ -239,12 +239,6 @@ def on_domain_removed(sender: str, domain_type: str, name: str = '', **kwargs): ###################################################### -def get_domain_name() -> str | None: - """Return the currently set static domain name.""" - domains = privileged.get_domains() - return domains[0] if domains else '' - - def get_hostname(): """Return the hostname.""" process = subprocess.run(['hostnamectl', 'hostname', '--static'], diff --git a/plinth/modules/openvpn/views.py b/plinth/modules/openvpn/views.py index 1c83bd998..63cdd5189 100644 --- a/plinth/modules/openvpn/views.py +++ b/plinth/modules/openvpn/views.py @@ -5,7 +5,7 @@ import logging from django.http import HttpResponse -from plinth.modules import names +from plinth.modules.names.components import DomainName from plinth.views import AppView from . import privileged @@ -23,10 +23,7 @@ class OpenVPNAppView(AppView): def profile(request): """Provide the user's profile for download.""" username = request.user.username - domain_name = names.get_domain_name() - - if not domain_name: - domain_name = names.get_hostname() + domain_name = DomainName.list_names()[0] profile_string = privileged.get_profile(username, domain_name) response = HttpResponse(profile_string,