From cbfaee85b508765a5abe3356cdbb13e7c07a3c74 Mon Sep 17 00:00:00 2001
From: Sunil Mohan Adapa
Date: Fri, 6 Sep 2024 12:02:25 -0700
Subject: [PATCH] networks: Show current global value of DNS-over-TLS and link
to it
So that when users select 'Default' they understand what value applies and how
to change it.
Signed-off-by: Sunil Mohan Adapa
Reviewed-by: Veiko Aasa
---
plinth/modules/networks/forms.py | 25 +++++++++++++++++++++++--
1 file changed, 23 insertions(+), 2 deletions(-)
diff --git a/plinth/modules/networks/forms.py b/plinth/modules/networks/forms.py
index 7b6fa384c..d16059e51 100644
--- a/plinth/modules/networks/forms.py
+++ b/plinth/modules/networks/forms.py
@@ -2,6 +2,8 @@
from django import forms
from django.core import validators
+from django.urls import reverse_lazy
+from django.utils.functional import lazy
from django.utils.translation import gettext_lazy as _
from plinth import cfg, network
@@ -10,6 +12,22 @@ from plinth.utils import format_lazy, import_from_gi
nm = import_from_gi('NM', '1.0')
+def _get_dns_over_tls():
+ """Return the value of DNS over TLS."""
+ try:
+ from plinth.modules.names import privileged
+ dns_over_tls = privileged.get_resolved_configuration()['dns_over_tls']
+ except Exception:
+ return _('unknown')
+
+ value_map = {
+ 'yes': _('yes'),
+ 'opportunistic': _('opportunistic'),
+ 'no': _('no')
+ }
+ return str(value_map.get(dns_over_tls, dns_over_tls))
+
+
class ConnectionTypeSelectForm(forms.Form):
"""Form to select type for new connection."""
connection_type = forms.ChoiceField(
@@ -35,8 +53,11 @@ class ConnectionForm(forms.Form):
('default',
format_lazy(
'Default. Unspecified for this connection. Use the global preference.
',
- allow_markup=True)),
+ 'class="help-block">Use the global '
+ 'preference. Current value is "{global_value}".
',
+ names_app=reverse_lazy('names:index'),
+ global_value=lazy(_get_dns_over_tls,
+ str)(), allow_markup=True)),
('yes',
format_lazy(
'Yes. Encrypt connections to the DNS server.