mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-07-22 11:59:33 +00:00
Tests:
- Visit the names app. New 'Domains' heading and configuration section appear.
- DNS-over-TLS configuration option is as expected.
- When the configuration file does not exist, the option selected is 'no'.
- When the configuration option is changed, 'resolvectl' shows the newly set
configuration. Using 'resolvectl query {domain}' does not work when DoT is on
and server does not support DoT. 'opportunistic' and 'no' work on those cases.
- When a DNS server supporting DoT (such as 1.1.1.1) is manually set, resolution
with all three settings works.
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Veiko Aasa <veiko17@disroot.org>
58 lines
1.7 KiB
Python
58 lines
1.7 KiB
Python
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
"""
|
|
FreedomBox app for name services.
|
|
"""
|
|
|
|
from django.contrib import messages
|
|
from django.utils.translation import gettext_lazy as _
|
|
|
|
from plinth.views import AppView
|
|
|
|
from . import components, privileged
|
|
from .forms import NamesConfigurationForm
|
|
|
|
|
|
class NamesAppView(AppView):
|
|
"""Show names app main page."""
|
|
|
|
app_id = 'names'
|
|
template_name = 'names.html'
|
|
prefix = 'names'
|
|
form_class = NamesConfigurationForm
|
|
|
|
def get_initial(self):
|
|
"""Return the values to fill in the form."""
|
|
initial = super().get_initial()
|
|
initial.update(privileged.get_resolved_configuration())
|
|
return initial
|
|
|
|
def get_context_data(self, *args, **kwargs):
|
|
"""Add additional context data for template."""
|
|
context = super().get_context_data(*args, **kwargs)
|
|
context['status'] = get_status()
|
|
return context
|
|
|
|
def form_valid(self, form):
|
|
"""Apply the changes submitted in the form."""
|
|
old_data = form.initial
|
|
form_data = form.cleaned_data
|
|
|
|
if old_data['dns_over_tls'] != form_data['dns_over_tls']:
|
|
privileged.set_resolved_configuration(
|
|
dns_over_tls=form_data['dns_over_tls'])
|
|
messages.success(self.request, _('Configuration updated'))
|
|
|
|
return super().form_valid(form)
|
|
|
|
|
|
def get_status():
|
|
"""Get configured services per name."""
|
|
domains = components.DomainName.list()
|
|
used_domain_types = {domain.domain_type for domain in domains}
|
|
unused_domain_types = [
|
|
domain_type for domain_type in components.DomainType.list().values()
|
|
if domain_type not in used_domain_types
|
|
]
|
|
|
|
return {'domains': domains, 'unused_domain_types': unused_domain_types}
|