diff --git a/src/coulobre/hosting/domain_policies.py b/src/coulobre/hosting/domain_policies.py index 5a936cb..7d87953 100644 --- a/src/coulobre/hosting/domain_policies.py +++ b/src/coulobre/hosting/domain_policies.py @@ -7,7 +7,29 @@ def policy_for(account, domain): policy = DomainServicePolicy.objects.filter( account=account, domain=domain ).first() - return policy or DomainServicePolicy(account=account, domain=domain) + if policy is not None: + return policy + return DomainServicePolicy( + account=account, + domain=domain, + mail_managed=( + domain == account.primary_domain + or account.mail_domains.filter(domain=domain).exists() + ), + ) + + +def managed_mail_domains(account): + domains = {account.primary_domain} + domains.update(account.mail_domains.values_list("domain", flat=True)) + for domain, enabled in account.domainservicepolicy_set.values_list( + "domain", "mail_managed" + ): + if enabled: + domains.add(domain) + else: + domains.discard(domain) + return sorted(domains) def require_managed(account, domain, field): diff --git a/src/coulobre/hosting/domain_services.py b/src/coulobre/hosting/domain_services.py index 3104c1a..fcb6ada 100644 --- a/src/coulobre/hosting/domain_services.py +++ b/src/coulobre/hosting/domain_services.py @@ -1,4 +1,5 @@ from django import forms +from django.conf import settings from django.contrib import messages from django.core.exceptions import PermissionDenied, ValidationError from django.db import transaction @@ -14,15 +15,17 @@ from .access import customer_for_user from .account_setup import website_records from .dns_defaults import zone_defaults from .dns_forms import zone_record_rows -from .domain_policies import policy_for +from .domain_policies import managed_mail_domains, policy_for from .independent_websites import account_websites from .installation_features import panel_feature_allowed from .models import DomainServicePolicy, HostingAccount from .resource_requests import lock_hosting_account, require_open_account +from .service_credentials import CredentialKind, show_credential_action from .sftp import site_is_active DNS_PUBLISHING = "LOCAL_DNS_PUBLISHING" MAIL_PROVISIONING = "LOCAL_MAILBOX_PROVISIONING" +MAIL_PAGES = {"email", "forwarders", "replies", "spam"} class DomainServicesForm(forms.Form): @@ -111,14 +114,30 @@ def domain_workspace(request, pk, page): account = get_object_or_404( HostingAccount, pk=pk, customer=customer, retired_at__isnull=True ) - domains = allowed_domains(account) + if page == "dns": + domains = list( + account.dns_zones.order_by("domain").values_list( + "domain", flat=True + ) + ) + elif page in MAIL_PAGES: + domains = sorted( + set(managed_mail_domains(account)) & set(allowed_domains(account)) + ) + else: + domains = allowed_domains(account) + + default = account.primary_domain + if domains and default not in domains: + default = domains[0] + selection = request.GET.get("domain") try: - domain = canonical_domain( - request.GET.get("domain", account.primary_domain) + domain = ( + canonical_domain(selection) if selection is not None else default ) except ValueError as error: raise Http404 from error - if domain not in domains: + if selection is not None and domain not in domains: raise Http404 policy = policy_for(account, domain) initial = { @@ -167,7 +186,7 @@ def domain_workspace(request, pk, page): ) mail_domain = ( account.mail_domains.filter(domain=domain).first() - if page in {"dns", "email", "forwarders", "replies", "spam"} + if page == "dns" or page in MAIL_PAGES else None ) titles = { @@ -184,6 +203,9 @@ def domain_workspace(request, pk, page): from .roundcube import roundcube_available defaults = zone_defaults() if page == "dns" else None + show_mailbox_credentials = show_credential_action( + request, CredentialKind.MAILBOX + ) return render( request, "hosting/domain_workspace.html", @@ -205,14 +227,18 @@ def domain_workspace(request, pk, page): ) if page == "dns" and not policy.dns_managed else (), - "zone_defaults": defaults, "mail_domain": mail_domain, "mail_enabled": panel_feature_allowed( "LOCAL_MAILBOX_PROVISIONING" ), "can_edit_routing": mail_policy_available("routing"), "can_edit_mailbox": mail_policy_available("vacation"), - "roundcube_enabled": roundcube_available(request), + "show_mailbox_credentials": show_mailbox_credentials, + "roundcube_enabled": ( + show_mailbox_credentials and roundcube_available(request) + ), + "mail_imap_host": settings.MAIL_IMAP_HOST, + "mail_submission_host": settings.MAIL_SUBMISSION_HOST, "mailboxes": mail_domain.mailboxes.select_related("provisioning") if mail_domain else (), diff --git a/src/coulobre/hosting/service_credentials.py b/src/coulobre/hosting/service_credentials.py index e8bb723..9a1db24 100644 --- a/src/coulobre/hosting/service_credentials.py +++ b/src/coulobre/hosting/service_credentials.py @@ -103,6 +103,14 @@ def can_rotate_credentials(user, kind): ) +def show_credential_action(request, kind): + return ( + getattr(request, "impersonation", None) is None + and enabled_credential_access(request, kind) + and can_reveal_credentials(request.user, kind) + ) + + @transaction.atomic @sensitive_variables() def verify_credential_access( diff --git a/src/coulobre/hosting/static/hosting/dns-record-editor.js b/src/coulobre/hosting/static/hosting/dns-record-editor.js index 5a59453..67c137d 100644 --- a/src/coulobre/hosting/static/hosting/dns-record-editor.js +++ b/src/coulobre/hosting/static/hosting/dns-record-editor.js @@ -39,6 +39,8 @@ function appendRecord(record) { priority.required = usesPriority; priority.disabled = !usesPriority; value.required = type.value !== "TXT"; + value.rows = type.value === "TXT" ? 4 : 1; + value.classList.toggle("dns-txt-value", type.value === "TXT"); valueLabel.textContent = valueLabels[type.value]; }; type.addEventListener("change", updateFields); diff --git a/src/coulobre/hosting/static/hosting/panel.css b/src/coulobre/hosting/static/hosting/panel.css index e27f72a..4738634 100644 --- a/src/coulobre/hosting/static/hosting/panel.css +++ b/src/coulobre/hosting/static/hosting/panel.css @@ -1043,9 +1043,9 @@ dd { } .dns-edit-row { - display: flex; - flex-wrap: wrap; - align-items: end; + display: grid; + grid-template-columns: minmax(0, 30%) 5rem minmax(0, 1fr) auto; + align-items: start; gap: 0.5rem; min-width: 0; margin: 0; @@ -1054,12 +1054,44 @@ dd { border-radius: 0.5rem; } -.dns-edit-row label { flex: 1 1 8rem; margin: 0; } +.dns-edit-row label { min-width: 0; margin: 0; } .dns-edit-row label[hidden] { display: none; } -.dns-edit-row label:has(select, input[type="number"]) { flex: 0 1 6rem; } -.dns-edit-row label:has(textarea) { flex: 2 1 12rem; } -.dns-edit-row textarea { display: block; min-height: 2.45rem; resize: vertical; } -.dns-record-table code { white-space: pre-wrap; overflow-wrap: anywhere; } +.dns-edit-row > button { margin-top: 1.4em; } +.dns-edit-value { + display: flex; + gap: 0.5rem; +} +.dns-edit-value > label { flex: 1; } +.dns-edit-value > [data-priority-label] { flex: 0 0 5rem; } +.dns-edit-row textarea { + display: block; + min-height: 2.45rem; + overflow-wrap: anywhere; + resize: vertical; +} +.dns-edit-row .dns-txt-value { field-sizing: content; min-height: 5rem; } + +.dns-record-table { table-layout: fixed; } +.dns-record-table .dns-record-name { width: 30%; } +.dns-record-table .dns-record-type { width: 5rem; } +.dns-record-table th, .dns-record-table code { overflow-wrap: anywhere; } +.dns-record-table code { white-space: pre-wrap; } + +.usage-table code, .usage-table th, .usage-error-log { + overflow-wrap: anywhere; +} + +.usage-error-log { + padding: 0 1.2rem 1rem; + white-space: pre-wrap; +} + +@media (max-width: 720px) { + .dns-edit-row { grid-template-columns: minmax(0, 1fr) 5rem; } + .dns-edit-value { grid-column: 1 / -1; } + .dns-edit-row > button { margin-top: 0; justify-self: start; } + .dns-record-table .dns-record-type { width: 3.5rem; } +} .reseller-editor fieldset { min-width: 0; diff --git a/src/coulobre/hosting/templates/hosting/dns_record_editor.html b/src/coulobre/hosting/templates/hosting/dns_record_editor.html index 0a5362f..f134600 100644 --- a/src/coulobre/hosting/templates/hosting/dns_record_editor.html +++ b/src/coulobre/hosting/templates/hosting/dns_record_editor.html @@ -11,8 +11,10 @@ - - +
| Name | Type | Value |
|---|---|---|
| {{ record.name }} | {{ record.type }} | {{ record.value }} |
| {{ record.name }} | {{ record.type }} | {{ record.value }} |
| Name | Type | Value |
|---|---|---|
| {{ record.name }} | {{ record.type }} | {{ record.value }} |
This domain has no saved Coulobre DNS zone.
{% endif %} {% if not policy.dns_managed %} @@ -28,8 +28,8 @@{{ record.name }} {{ record.record_type }} {{ record.address }}Check MX, SPF, DKIM and DMARC records
{% endif %} - {% elif zone_defaults.nameservers %} -Mailbox passwords cannot be viewed in this panel. Use your full email address as your username.
+ {% if mail_imap_host or mail_submission_host %} +Last checked {{ snapshot.observed_at }}
{% if snapshot.report.error %} -{{ snapshot.report.error }}
+{{ snapshot.report.error }}
{% else %} -{{ line }}{% empty %}No entries.
{% endfor %} -{{ line }}{% empty %}No entries.
{% endfor %} +| Time (UTC) | Method | Status | Path | Size |
|---|---|---|---|---|
| {{ entry.time|utc|date:"j M Y, H:i:s" }} | {{ entry.method }} | {{ entry.status }} | {{ entry.path }} | {{ entry.bytes|filesizeformat }} |
{{ entry.raw }} | ||||
No entries.
{% endif %} +{% for line in snapshot.report.error_lines %}{{ line }}{% if not forloop.last %}
+{% endif %}{% endfor %}{% else %}No entries.
{% endif %} {% endif %} {% else %} -No measurement yet.
+No measurement yet.
{% endif %}No active websites.
{% endfor %} {% if mailboxes is not None %} -No mailboxes.
{% endfor %} -| Mailbox | Storage used | Limit |
|---|---|---|
| {{ mailbox }} | {% if mailbox.usage_bytes is not None %}{{ mailbox.usage_bytes|filesizeformat }}{% else %}Unavailable{% endif %} | {{ mailbox.quota_mib|default_if_none:"Unlimited" }}{% if mailbox.quota_mib %} MiB{% endif %} |
No mailboxes.
{% endif %}