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 <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
Sunil Mohan Adapa 2025-01-18 16:34:49 -08:00 committed by James Valleroy
parent eeeec6710f
commit 85a694f20f
No known key found for this signature in database
GPG Key ID: 77C0C75E7B650808
4 changed files with 7 additions and 16 deletions

View File

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

View File

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

View File

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

View File

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