Merge pull request 'Prepare Coulobre 1.0.0 RC4 with hosting fixes' (#215) from fix/rc4-hosting-regressions into main
Reviewed-on: #215
This commit is contained in:
commit
0c8e0e84a1
20 files changed
+495
-77
No files matched your search
@@ -1051,6 +1051,21 @@ credential and archive operations. The separate legacy SSH transports for
|
|||||||
those operations are unavailable on a scoped receiver. Local mail
|
those operations are unavailable on a scoped receiver. Local mail
|
||||||
delivery and IMAP keep using their existing configuration.
|
delivery and IMAP keep using their existing configuration.
|
||||||
|
|
||||||
|
#### Refresh an existing managed DKIM record
|
||||||
|
|
||||||
|
Upgrade the panels linked to a mail node before upgrading the mail node.
|
||||||
|
The updated panel accepts public keys from older mail nodes and publishes
|
||||||
|
the managed RSA key in SubjectPublicKeyInfo format. The existing private
|
||||||
|
key and selector stay in use.
|
||||||
|
|
||||||
|
Open **Mail DNS check** for a managed mail domain and select
|
||||||
|
**Refresh mail DNS setup**. If Coulobre publishes the zone and manages its
|
||||||
|
mail records, it replaces the previous encoding when the public key
|
||||||
|
matches. A different key at the same selector requires operator review.
|
||||||
|
For third-party DNS, copy the updated DKIM TXT value to the DNS provider.
|
||||||
|
Check the authoritative answer, allow cached records to expire, and
|
||||||
|
verify that a newly delivered message passes DKIM.
|
||||||
|
|
||||||
### Use SHA-2 for new managed database logins
|
### Use SHA-2 for new managed database logins
|
||||||
|
|
||||||
On a MariaDB build with `auth_mysql_sha2`, you can provision new managed
|
On a MariaDB build with `auth_mysql_sha2`, you can provision new managed
|
||||||
|
|||||||
+1
-1
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|||||||
|
|
||||||
[project]
|
[project]
|
||||||
name = "coulobre-panel"
|
name = "coulobre-panel"
|
||||||
version = "1.0.0rc3"
|
version = "1.0.0rc4"
|
||||||
description = "A web hosting control panel for hosting providers and resellers."
|
description = "A web hosting control panel for hosting providers and resellers."
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
requires-python = ">=3.12"
|
requires-python = ">=3.12"
|
||||||
|
|||||||
@@ -7,7 +7,29 @@ def policy_for(account, domain):
|
|||||||
policy = DomainServicePolicy.objects.filter(
|
policy = DomainServicePolicy.objects.filter(
|
||||||
account=account, domain=domain
|
account=account, domain=domain
|
||||||
).first()
|
).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):
|
def require_managed(account, domain, field):
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
from django import forms
|
from django import forms
|
||||||
|
from django.conf import settings
|
||||||
from django.contrib import messages
|
from django.contrib import messages
|
||||||
from django.core.exceptions import PermissionDenied, ValidationError
|
from django.core.exceptions import PermissionDenied, ValidationError
|
||||||
from django.db import transaction
|
from django.db import transaction
|
||||||
@@ -14,15 +15,17 @@ from .access import customer_for_user
|
|||||||
from .account_setup import website_records
|
from .account_setup import website_records
|
||||||
from .dns_defaults import zone_defaults
|
from .dns_defaults import zone_defaults
|
||||||
from .dns_forms import zone_record_rows
|
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 .independent_websites import account_websites
|
||||||
from .installation_features import panel_feature_allowed
|
from .installation_features import panel_feature_allowed
|
||||||
from .models import DomainServicePolicy, HostingAccount
|
from .models import DomainServicePolicy, HostingAccount
|
||||||
from .resource_requests import lock_hosting_account, require_open_account
|
from .resource_requests import lock_hosting_account, require_open_account
|
||||||
|
from .service_credentials import CredentialKind, show_credential_action
|
||||||
from .sftp import site_is_active
|
from .sftp import site_is_active
|
||||||
|
|
||||||
DNS_PUBLISHING = "LOCAL_DNS_PUBLISHING"
|
DNS_PUBLISHING = "LOCAL_DNS_PUBLISHING"
|
||||||
MAIL_PROVISIONING = "LOCAL_MAILBOX_PROVISIONING"
|
MAIL_PROVISIONING = "LOCAL_MAILBOX_PROVISIONING"
|
||||||
|
MAIL_PAGES = {"email", "forwarders", "replies", "spam"}
|
||||||
|
|
||||||
|
|
||||||
class DomainServicesForm(forms.Form):
|
class DomainServicesForm(forms.Form):
|
||||||
@@ -111,14 +114,30 @@ def domain_workspace(request, pk, page):
|
|||||||
account = get_object_or_404(
|
account = get_object_or_404(
|
||||||
HostingAccount, pk=pk, customer=customer, retired_at__isnull=True
|
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:
|
try:
|
||||||
domain = canonical_domain(
|
domain = (
|
||||||
request.GET.get("domain", account.primary_domain)
|
canonical_domain(selection) if selection is not None else default
|
||||||
)
|
)
|
||||||
except ValueError as error:
|
except ValueError as error:
|
||||||
raise Http404 from error
|
raise Http404 from error
|
||||||
if domain not in domains:
|
if selection is not None and domain not in domains:
|
||||||
raise Http404
|
raise Http404
|
||||||
policy = policy_for(account, domain)
|
policy = policy_for(account, domain)
|
||||||
initial = {
|
initial = {
|
||||||
@@ -167,7 +186,7 @@ def domain_workspace(request, pk, page):
|
|||||||
)
|
)
|
||||||
mail_domain = (
|
mail_domain = (
|
||||||
account.mail_domains.filter(domain=domain).first()
|
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
|
else None
|
||||||
)
|
)
|
||||||
titles = {
|
titles = {
|
||||||
@@ -184,6 +203,9 @@ def domain_workspace(request, pk, page):
|
|||||||
from .roundcube import roundcube_available
|
from .roundcube import roundcube_available
|
||||||
|
|
||||||
defaults = zone_defaults() if page == "dns" else None
|
defaults = zone_defaults() if page == "dns" else None
|
||||||
|
show_mailbox_credentials = show_credential_action(
|
||||||
|
request, CredentialKind.MAILBOX
|
||||||
|
)
|
||||||
return render(
|
return render(
|
||||||
request,
|
request,
|
||||||
"hosting/domain_workspace.html",
|
"hosting/domain_workspace.html",
|
||||||
@@ -205,14 +227,18 @@ def domain_workspace(request, pk, page):
|
|||||||
)
|
)
|
||||||
if page == "dns" and not policy.dns_managed
|
if page == "dns" and not policy.dns_managed
|
||||||
else (),
|
else (),
|
||||||
"zone_defaults": defaults,
|
|
||||||
"mail_domain": mail_domain,
|
"mail_domain": mail_domain,
|
||||||
"mail_enabled": panel_feature_allowed(
|
"mail_enabled": panel_feature_allowed(
|
||||||
"LOCAL_MAILBOX_PROVISIONING"
|
"LOCAL_MAILBOX_PROVISIONING"
|
||||||
),
|
),
|
||||||
"can_edit_routing": mail_policy_available("routing"),
|
"can_edit_routing": mail_policy_available("routing"),
|
||||||
"can_edit_mailbox": mail_policy_available("vacation"),
|
"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")
|
"mailboxes": mail_domain.mailboxes.select_related("provisioning")
|
||||||
if mail_domain
|
if mail_domain
|
||||||
else (),
|
else (),
|
||||||
|
|||||||
@@ -12,7 +12,12 @@ from coulobre.dns_node import (
|
|||||||
TxtRecord,
|
TxtRecord,
|
||||||
dns_name,
|
dns_name,
|
||||||
)
|
)
|
||||||
from coulobre.mail_dns import MANAGED_DKIM_SELECTOR, matches_version
|
from coulobre.mail_dns import (
|
||||||
|
MANAGED_DKIM_SELECTOR,
|
||||||
|
matches_version,
|
||||||
|
normalize_rsa_dkim_record,
|
||||||
|
same_rsa_dkim_key,
|
||||||
|
)
|
||||||
|
|
||||||
from .dns_publication import queue_zone_snapshot
|
from .dns_publication import queue_zone_snapshot
|
||||||
from .models import HostingDnsZone, HostingMailDomain, MailboxProvisioning
|
from .models import HostingDnsZone, HostingMailDomain, MailboxProvisioning
|
||||||
@@ -53,7 +58,8 @@ def mail_dns_proposal(domain, public_key):
|
|||||||
if public_key:
|
if public_key:
|
||||||
records.append(
|
records.append(
|
||||||
TxtRecord(
|
TxtRecord(
|
||||||
f"{MANAGED_DKIM_SELECTOR}._domainkey.{domain}", public_key
|
f"{MANAGED_DKIM_SELECTOR}._domainkey.{domain}",
|
||||||
|
normalize_rsa_dkim_record(public_key),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
return addresses, mx, tuple(records)
|
return addresses, mx, tuple(records)
|
||||||
@@ -104,7 +110,7 @@ def sync_mail_dns(mail_domain, *, public_key=None):
|
|||||||
if current is None or account.retired_at is not None:
|
if current is None or account.retired_at is not None:
|
||||||
return
|
return
|
||||||
if public_key is not None:
|
if public_key is not None:
|
||||||
current.dkim_record = public_key
|
current.dkim_record = normalize_rsa_dkim_record(public_key)
|
||||||
current.dns_sync_requested = True
|
current.dns_sync_requested = True
|
||||||
current.save(update_fields=["dkim_record", "dns_sync_requested"])
|
current.save(update_fields=["dkim_record", "dns_sync_requested"])
|
||||||
if not current.dns_sync_requested or account.services_suspended:
|
if not current.dns_sync_requested or account.services_suspended:
|
||||||
@@ -173,15 +179,23 @@ def publish_mail_records(zone, domain, public_key):
|
|||||||
|
|
||||||
existing = spec.txt_records
|
existing = spec.txt_records
|
||||||
new_txt = []
|
new_txt = []
|
||||||
|
replacements = {}
|
||||||
problem = ""
|
problem = ""
|
||||||
for record in txt:
|
for record in txt:
|
||||||
version = record.text.split(" ")[0].rstrip(";")
|
version = record.text.split(" ")[0].rstrip(";")
|
||||||
at_owner = tuple(item for item in existing if item.name == record.name)
|
at_owner = tuple(item for item in existing if item.name == record.name)
|
||||||
if version == "v=DKIM1":
|
if version == "v=DKIM1":
|
||||||
if at_owner and at_owner != (record,):
|
if at_owner and at_owner != (record,):
|
||||||
raise ValueError(
|
if len(at_owner) != 1 or not same_rsa_dkim_key(
|
||||||
"The Coulobre DKIM selector already has a record."
|
at_owner[0].text, record.text
|
||||||
)
|
):
|
||||||
|
raise ValueError(
|
||||||
|
"The Coulobre DKIM selector already has a record."
|
||||||
|
)
|
||||||
|
previous = at_owner[0]
|
||||||
|
converted = normalize_rsa_dkim_record(previous.text)
|
||||||
|
if converted != previous.text:
|
||||||
|
replacements[previous] = replace(previous, text=converted)
|
||||||
else:
|
else:
|
||||||
at_owner = tuple(
|
at_owner = tuple(
|
||||||
item
|
item
|
||||||
@@ -207,7 +221,9 @@ def publish_mail_records(zone, domain, public_key):
|
|||||||
spec.nameservers,
|
spec.nameservers,
|
||||||
(*spec.addresses, *spec.mx_records, *existing, *spec.extra_records),
|
(*spec.addresses, *spec.mx_records, *existing, *spec.extra_records),
|
||||||
)
|
)
|
||||||
changed = bool(additions or not current_mx or new_txt or alias)
|
changed = bool(
|
||||||
|
additions or not current_mx or new_txt or replacements or alias
|
||||||
|
)
|
||||||
if publication and publication.finished_at is None:
|
if publication and publication.finished_at is None:
|
||||||
if changed:
|
if changed:
|
||||||
raise MailDnsPublicationPendingError
|
raise MailDnsPublicationPendingError
|
||||||
@@ -219,7 +235,10 @@ def publish_mail_records(zone, domain, public_key):
|
|||||||
serial=(spec.serial + 1) % (MAX_SOA_SERIAL + 1),
|
serial=(spec.serial + 1) % (MAX_SOA_SERIAL + 1),
|
||||||
addresses=spec.addresses + additions,
|
addresses=spec.addresses + additions,
|
||||||
mx_records=spec.mx_records + (mx if not current_mx else ()),
|
mx_records=spec.mx_records + (mx if not current_mx else ()),
|
||||||
txt_records=spec.txt_records + tuple(new_txt),
|
txt_records=tuple(
|
||||||
|
replacements.get(record, record) for record in existing
|
||||||
|
)
|
||||||
|
+ tuple(new_txt),
|
||||||
extra_records=spec.extra_records + ((alias,) if alias else ()),
|
extra_records=spec.extra_records + ((alias,) if alias else ()),
|
||||||
)
|
)
|
||||||
manifest = spec.manifest()
|
manifest = spec.manifest()
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ from coulobre.account_restore_request import (
|
|||||||
RESTORE_TIMEOUT_SECONDS,
|
RESTORE_TIMEOUT_SECONDS,
|
||||||
)
|
)
|
||||||
from coulobre.linked_updates import ROLES, UNIT_DIR, read_probe
|
from coulobre.linked_updates import ROLES, UNIT_DIR, read_probe
|
||||||
from coulobre.mail_dns import dkim_key
|
from coulobre.mail_dns import dkim_key, normalize_rsa_dkim_record
|
||||||
from coulobre.mail_node import MailboxQuotaUpdate, MailboxSigningRequest
|
from coulobre.mail_node import MailboxQuotaUpdate, MailboxSigningRequest
|
||||||
from coulobre.node_probe import PROBE_BYTES, parse_status_probe
|
from coulobre.node_probe import PROBE_BYTES, parse_status_probe
|
||||||
from coulobre.php_pool_settings import PhpPoolSettings
|
from coulobre.php_pool_settings import PhpPoolSettings
|
||||||
@@ -180,7 +180,7 @@ def provision_signing_mailbox(mailbox):
|
|||||||
or dkim_key(public)[0] != "ok"
|
or dkim_key(public)[0] != "ok"
|
||||||
):
|
):
|
||||||
raise ValueError("The mail node returned an invalid DKIM public key.")
|
raise ValueError("The mail node returned an invalid DKIM public key.")
|
||||||
return public
|
return normalize_rsa_dkim_record(public)
|
||||||
|
|
||||||
|
|
||||||
def update_local_mailbox_quota(mailbox):
|
def update_local_mailbox_quota(mailbox):
|
||||||
|
|||||||
@@ -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
|
@transaction.atomic
|
||||||
@sensitive_variables()
|
@sensitive_variables()
|
||||||
def verify_credential_access(
|
def verify_credential_access(
|
||||||
|
|||||||
@@ -39,6 +39,8 @@ function appendRecord(record) {
|
|||||||
priority.required = usesPriority;
|
priority.required = usesPriority;
|
||||||
priority.disabled = !usesPriority;
|
priority.disabled = !usesPriority;
|
||||||
value.required = type.value !== "TXT";
|
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];
|
valueLabel.textContent = valueLabels[type.value];
|
||||||
};
|
};
|
||||||
type.addEventListener("change", updateFields);
|
type.addEventListener("change", updateFields);
|
||||||
|
|||||||
@@ -1043,9 +1043,9 @@ dd {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.dns-edit-row {
|
.dns-edit-row {
|
||||||
display: flex;
|
display: grid;
|
||||||
flex-wrap: wrap;
|
grid-template-columns: minmax(0, 30%) 5rem minmax(0, 1fr) auto;
|
||||||
align-items: end;
|
align-items: start;
|
||||||
gap: 0.5rem;
|
gap: 0.5rem;
|
||||||
min-width: 0;
|
min-width: 0;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
@@ -1054,12 +1054,44 @@ dd {
|
|||||||
border-radius: 0.5rem;
|
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[hidden] { display: none; }
|
||||||
.dns-edit-row label:has(select, input[type="number"]) { flex: 0 1 6rem; }
|
.dns-edit-row > button { margin-top: 1.4em; }
|
||||||
.dns-edit-row label:has(textarea) { flex: 2 1 12rem; }
|
.dns-edit-value {
|
||||||
.dns-edit-row textarea { display: block; min-height: 2.45rem; resize: vertical; }
|
display: flex;
|
||||||
.dns-record-table code { white-space: pre-wrap; overflow-wrap: anywhere; }
|
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 {
|
.reseller-editor fieldset {
|
||||||
min-width: 0;
|
min-width: 0;
|
||||||
|
|||||||
@@ -11,8 +11,10 @@
|
|||||||
<label>Type<select data-record-type>
|
<label>Type<select data-record-type>
|
||||||
<option>A</option><option>AAAA</option><option>CNAME</option><option>MX</option><option>TXT</option><option>SRV</option><option>CAA</option>
|
<option>A</option><option>AAAA</option><option>CNAME</option><option>MX</option><option>TXT</option><option>SRV</option><option>CAA</option>
|
||||||
</select></label>
|
</select></label>
|
||||||
<label data-priority-label hidden>Priority<input data-record-priority type="number" min="0" max="65535" inputmode="numeric"></label>
|
<div class="dns-edit-value">
|
||||||
<label><span data-record-value-label>Value</span><textarea rows="1" data-record-value required></textarea></label>
|
<label data-priority-label hidden>Priority<input data-record-priority type="number" min="0" max="65535" inputmode="numeric"></label>
|
||||||
|
<label><span data-record-value-label>Value</span><textarea rows="1" data-record-value required></textarea></label>
|
||||||
|
</div>
|
||||||
<button class="button secondary" type="button" data-remove-record>Remove</button>
|
<button class="button secondary" type="button" data-remove-record>Remove</button>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
{% if records %}
|
{% if records %}
|
||||||
<div class="table-scroll">
|
<div class="table-scroll">
|
||||||
<table class="dns-record-table">
|
<table class="dns-record-table">
|
||||||
|
<colgroup><col class="dns-record-name"><col class="dns-record-type"><col></colgroup>
|
||||||
<thead><tr><th scope="col">Name</th><th scope="col">Type</th><th scope="col">Value</th></tr></thead>
|
<thead><tr><th scope="col">Name</th><th scope="col">Type</th><th scope="col">Value</th></tr></thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{% for record in records %}
|
{% for record in records %}
|
||||||
<tr><th scope="row" class="domain">{{ record.name }}</th><td>{{ record.type }}</td><td><code>{{ record.value }}</code></td></tr>
|
<tr><th scope="row">{{ record.name }}</th><td>{{ record.type }}</td><td><code>{{ record.value }}</code></td></tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|||||||
@@ -1,12 +1,14 @@
|
|||||||
{% extends "hosting/workspace_page.html" %}
|
{% extends "hosting/workspace_page.html" %}
|
||||||
{% block title %}{{ title }} · Coulobre Panel{% endblock %}
|
{% block title %}{{ title }} · Coulobre Panel{% endblock %}
|
||||||
{% block page_title %}{{ title }}{% endblock %}
|
{% block page_title %}{{ title }}{% endblock %}
|
||||||
{% block page_metadata %}<p class="heading-meta">{{ account.primary_domain }}</p>{% endblock %}
|
{% block page_metadata %}<p class="heading-meta">{{ domain }}</p>{% endblock %}
|
||||||
{% block page_actions %}
|
{% block page_actions %}
|
||||||
{% if page == 'domains' and can_add_site %}<a class="button primary" href="{% url 'panel:independent_website_create' account.pk %}">Add domain</a>{% endif %}
|
{% if page == 'domains' and can_add_site %}<a class="button primary" href="{% url 'panel:independent_website_create' account.pk %}">Add domain</a>{% endif %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
{% block page_context %}
|
{% block page_context %}
|
||||||
{% include "hosting/workspace_domain_selector.html" with field_id="domain" domains=domains domain=domain only %}
|
{% if domains %}
|
||||||
|
{% include "hosting/workspace_domain_selector.html" with field_id="domain" domains=domains domain=domain only %}
|
||||||
|
{% endif %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
{% block page_content %}
|
{% block page_content %}
|
||||||
{% if page == 'domains' %}
|
{% if page == 'domains' %}
|
||||||
@@ -17,9 +19,7 @@
|
|||||||
{% if zone %}
|
{% if zone %}
|
||||||
<section class="surface" aria-label="DNS records">
|
<section class="surface" aria-label="DNS records">
|
||||||
<header class="section-heading"><div><h2>DNS records</h2>{% if zone.publication %}<p class="heading-meta">Publication {{ zone.publication.state }}</p>{% endif %}</div>{% if may_edit_dns %}<a class="button primary" href="{% url 'panel:dns_zone_edit' zone.pk %}">Edit zone</a>{% endif %}</header>
|
<header class="section-heading"><div><h2>DNS records</h2>{% if zone.publication %}<p class="heading-meta">Publication {{ zone.publication.state }}</p>{% endif %}</div>{% if may_edit_dns %}<a class="button primary" href="{% url 'panel:dns_zone_edit' zone.pk %}">Edit zone</a>{% endif %}</header>
|
||||||
<div class="table-scroll"><table><thead><tr><th scope="col">Name</th><th scope="col">Type</th><th scope="col">Value</th></tr></thead><tbody>
|
{% include "hosting/dns_record_table.html" %}
|
||||||
{% for record in records %}<tr><td>{{ record.name }}</td><td>{{ record.type }}</td><td><code>{{ record.value }}</code></td></tr>{% endfor %}
|
|
||||||
</tbody></table></div>
|
|
||||||
</section>
|
</section>
|
||||||
{% else %}<p class="empty">This domain has no saved Coulobre DNS zone.</p>{% endif %}
|
{% else %}<p class="empty">This domain has no saved Coulobre DNS zone.</p>{% endif %}
|
||||||
{% if not policy.dns_managed %}
|
{% if not policy.dns_managed %}
|
||||||
@@ -28,8 +28,8 @@
|
|||||||
<ul class="workspace-list">{% for record in external_website_records %}<li><code>{{ record.name }} {{ record.record_type }} {{ record.address }}</code></li>{% empty %}<li>Ask your hosting provider for the website addresses.</li>{% endfor %}</ul>
|
<ul class="workspace-list">{% for record in external_website_records %}<li><code>{{ record.name }} {{ record.record_type }} {{ record.address }}</code></li>{% empty %}<li>Ask your hosting provider for the website addresses.</li>{% endfor %}</ul>
|
||||||
{% if mail_domain and policy.mail_managed %}<p class="section-text"><a href="{% url 'panel:mail_dns_check' mail_domain.pk %}">Check MX, SPF, DKIM and DMARC records</a></p>{% endif %}
|
{% if mail_domain and policy.mail_managed %}<p class="section-text"><a href="{% url 'panel:mail_dns_check' mail_domain.pk %}">Check MX, SPF, DKIM and DMARC records</a></p>{% endif %}
|
||||||
</section>
|
</section>
|
||||||
{% elif zone_defaults.nameservers %}
|
{% elif zone %}
|
||||||
<section class="surface section-heading"><div><h2>Nameservers</h2><p class="heading-meta">{{ zone_defaults.nameservers|join:", " }}</p></div></section>
|
<section class="surface section-heading"><div><h2>Nameservers</h2><p class="heading-meta">{{ zone.spec.nameservers|join:", " }}</p></div></section>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% elif page == 'php' or page == 'files' %}
|
{% elif page == 'php' or page == 'files' %}
|
||||||
<section class="surface section-heading" aria-label="{{ title }}">
|
<section class="surface section-heading" aria-label="{{ title }}">
|
||||||
@@ -54,11 +54,22 @@
|
|||||||
<thead><tr><th scope="col">Email address</th><th scope="col">Quota</th><th scope="col">State</th><th scope="col">Actions</th></tr></thead>
|
<thead><tr><th scope="col">Email address</th><th scope="col">Quota</th><th scope="col">State</th><th scope="col">Actions</th></tr></thead>
|
||||||
<tbody>{% for mailbox in mailboxes %}<tr><th scope="row">{{ mailbox.spec.address }}</th><td>{{ mailbox.quota_mib|default_if_none:"Unlimited" }}{% if mailbox.quota_mib %} MiB{% endif %}</td><td>{{ mailbox.provisioning.state|default:"Requested"|capfirst }}</td>
|
<tbody>{% for mailbox in mailboxes %}<tr><th scope="row">{{ mailbox.spec.address }}</th><td>{{ mailbox.quota_mib|default_if_none:"Unlimited" }}{% if mailbox.quota_mib %} MiB{% endif %}</td><td>{{ mailbox.provisioning.state|default:"Requested"|capfirst }}</td>
|
||||||
<td>{% if mailbox.provisioning.state == 'configured' %}
|
<td>{% if mailbox.provisioning.state == 'configured' %}
|
||||||
<a href="{% url 'panel:mailbox_credentials' mailbox.pk %}">Credentials</a>
|
{% if show_mailbox_credentials %}
|
||||||
|
<a href="{% url 'panel:mailbox_credentials' mailbox.pk %}">Credentials</a>
|
||||||
|
{% else %}Use the current mailbox password{% endif %}
|
||||||
{% if roundcube_enabled %}<form class="inline-form" method="post" action="{% url 'panel:roundcube_launch' mailbox.pk %}">{% csrf_token %}<button class="button secondary" type="submit">Open webmail</button></form>{% endif %}
|
{% if roundcube_enabled %}<form class="inline-form" method="post" action="{% url 'panel:roundcube_launch' mailbox.pk %}">{% csrf_token %}<button class="button secondary" type="submit">Open webmail</button></form>{% endif %}
|
||||||
{% endif %}</td></tr>
|
{% endif %}</td></tr>
|
||||||
{% empty %}<tr><td colspan="4">No mailboxes on this domain.</td></tr>{% endfor %}</tbody>
|
{% empty %}<tr><td colspan="4">No mailboxes on this domain.</td></tr>{% endfor %}</tbody>
|
||||||
</table></div>
|
</table></div>
|
||||||
|
{% if not show_mailbox_credentials and mailboxes %}
|
||||||
|
<p class="section-text">Mailbox passwords cannot be viewed in this panel. Use your full email address as your username.</p>
|
||||||
|
{% if mail_imap_host or mail_submission_host %}
|
||||||
|
<dl class="details">
|
||||||
|
{% if mail_imap_host %}<div><dt>Incoming mail (IMAP over TLS)</dt><dd>{{ mail_imap_host }} · port 993</dd></div>{% endif %}
|
||||||
|
{% if mail_submission_host %}<div><dt>Outgoing mail (SMTP with STARTTLS)</dt><dd>{{ mail_submission_host }} · port 587</dd></div>{% endif %}
|
||||||
|
</dl>
|
||||||
|
{% endif %}
|
||||||
|
{% endif %}
|
||||||
{% if mail_domain %}<p class="section-text"><a href="{% url 'panel:mail_dns_check' mail_domain.pk %}">Check email DNS</a></p>{% endif %}
|
{% if mail_domain %}<p class="section-text"><a href="{% url 'panel:mail_dns_check' mail_domain.pk %}">Check email DNS</a></p>{% endif %}
|
||||||
</section>
|
</section>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
{% extends "hosting/workspace_page.html" %}
|
{% extends "hosting/workspace_page.html" %}
|
||||||
|
{% load tz %}
|
||||||
{% block title %}Usage · {{ account.name }}{% endblock %}
|
{% block title %}Usage · {{ account.name }}{% endblock %}
|
||||||
{% block page_title %}Usage for {{ account.name }}{% endblock %}
|
{% block page_title %}Usage for {{ account.name }}{% endblock %}
|
||||||
{% block page_actions %}
|
{% block page_actions %}
|
||||||
@@ -18,37 +19,58 @@
|
|||||||
{% if not complete and total_traffic is not None %} · Partial{% endif %}
|
{% if not complete and total_traffic is not None %} · Partial{% endif %}
|
||||||
</p>
|
</p>
|
||||||
</section>
|
</section>
|
||||||
{% for site, snapshot, quota in sites %}
|
{% for site, snapshot, quota, access_entries in sites %}
|
||||||
<section class="surface editor-surface">
|
<section class="surface">
|
||||||
<h2>{{ site.domain }}</h2>
|
<header class="section-heading">
|
||||||
|
<h2>{{ site.domain }}</h2>
|
||||||
|
{% if snapshot %}<p class="heading-meta">Last checked {{ snapshot.observed_at|utc|date:"j M Y, H:i:s" }} UTC</p>{% endif %}
|
||||||
|
</header>
|
||||||
{% if snapshot %}
|
{% if snapshot %}
|
||||||
<p>Last checked {{ snapshot.observed_at }}</p>
|
|
||||||
{% if snapshot.report.error %}
|
{% if snapshot.report.error %}
|
||||||
<p role="alert">{{ snapshot.report.error }}</p>
|
<p class="section-text" role="alert">{{ snapshot.report.error }}</p>
|
||||||
{% else %}
|
{% else %}
|
||||||
<dl>
|
<dl class="details">
|
||||||
<dt>Website storage used</dt><dd>{{ snapshot.report.storage_bytes|filesizeformat }}{% if quota is not None %} of {{ quota }} MiB{% endif %}</dd>
|
<div><dt>Website storage used</dt><dd>{{ snapshot.report.storage_bytes|filesizeformat }}{% if quota is not None %} of {{ quota }} MiB{% endif %}</dd></div>
|
||||||
<dt>HTTP response data for {{ snapshot.report.month }} (UTC)</dt>
|
<div><dt>HTTP response data for {{ snapshot.report.month }} (UTC)</dt>
|
||||||
<dd>{% if snapshot.report.traffic_bytes is not None %}{{ snapshot.report.traffic_bytes|filesizeformat }}{% else %}Unavailable{% endif %}{% if snapshot.report.partial %} · Partial{% endif %}</dd>
|
<dd>{% if snapshot.report.traffic_bytes is not None %}{{ snapshot.report.traffic_bytes|filesizeformat }}{% else %}Unavailable{% endif %}{% if snapshot.report.partial %} · Partial{% endif %}</dd></div>
|
||||||
</dl>
|
</dl>
|
||||||
<h3>Recent access log</h3>
|
<header class="section-heading"><h3>Recent access log</h3></header>
|
||||||
{% for line in snapshot.report.access_lines %}<pre>{{ line }}</pre>{% empty %}<p>No entries.</p>{% endfor %}
|
{% if access_entries %}
|
||||||
<h3>Recent error log</h3>
|
<div class="table-scroll">
|
||||||
{% for line in snapshot.report.error_lines %}<pre>{{ line }}</pre>{% empty %}<p>No entries.</p>{% endfor %}
|
<table class="usage-table">
|
||||||
|
<thead><tr><th scope="col">Time (UTC)</th><th scope="col">Method</th><th scope="col">Status</th><th scope="col">Path</th><th scope="col">Size</th></tr></thead>
|
||||||
|
<tbody>{% for entry in access_entries %}
|
||||||
|
{% if entry.time %}
|
||||||
|
<tr><td class="cell-date">{{ entry.time|utc|date:"j M Y, H:i:s" }}</td><td>{{ entry.method }}</td><td>{{ entry.status }}</td><td><code>{{ entry.path }}</code></td><td>{{ entry.bytes|filesizeformat }}</td></tr>
|
||||||
|
{% else %}<tr><td colspan="5"><code>{{ entry.raw }}</code></td></tr>{% endif %}
|
||||||
|
{% endfor %}</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
{% else %}<p class="empty">No entries.</p>{% endif %}
|
||||||
|
<header class="section-heading"><h3>Recent error log</h3></header>
|
||||||
|
{% if snapshot.report.error_lines %}<pre class="usage-error-log">{% for line in snapshot.report.error_lines %}{{ line }}{% if not forloop.last %}
|
||||||
|
{% endif %}{% endfor %}</pre>{% else %}<p class="empty">No entries.</p>{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% else %}
|
{% else %}
|
||||||
<p>No measurement yet.</p>
|
<p class="empty">No measurement yet.</p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</section>
|
</section>
|
||||||
|
{% empty %}
|
||||||
|
<p class="empty">No active websites.</p>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% if mailboxes is not None %}
|
{% if mailboxes is not None %}
|
||||||
<section class="surface editor-surface">
|
<section class="surface">
|
||||||
<h2>Mailbox storage</h2>
|
<header class="section-heading"><h2>Mailbox storage</h2></header>
|
||||||
<dl>
|
{% if mailboxes %}
|
||||||
{% for mailbox in mailboxes %}
|
<div class="table-scroll">
|
||||||
<dt>{{ mailbox }}</dt><dd>{% if mailbox.usage_bytes is not None %}{{ mailbox.usage_bytes|filesizeformat }} used · {% endif %}{{ mailbox.quota_mib|default_if_none:"Unlimited" }}{% if mailbox.quota_mib %} MiB{% endif %}</dd>
|
<table class="usage-table">
|
||||||
{% empty %}<p>No mailboxes.</p>{% endfor %}
|
<thead><tr><th scope="col">Mailbox</th><th scope="col">Storage used</th><th scope="col">Limit</th></tr></thead>
|
||||||
</dl>
|
<tbody>{% for mailbox in mailboxes %}
|
||||||
|
<tr><th scope="row">{{ mailbox }}</th><td>{% if mailbox.usage_bytes is not None %}{{ mailbox.usage_bytes|filesizeformat }}{% else %}Unavailable{% endif %}</td><td>{{ mailbox.quota_mib|default_if_none:"Unlimited" }}{% if mailbox.quota_mib %} MiB{% endif %}</td></tr>
|
||||||
|
{% endfor %}</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
{% else %}<p class="empty">No mailboxes.</p>{% endif %}
|
||||||
</section>
|
</section>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -214,6 +214,14 @@ class MailDnsPanelTests(TestCase):
|
|||||||
public_key.public_bytes(Encoding.DER, PublicFormat.PKCS1)
|
public_key.public_bytes(Encoding.DER, PublicFormat.PKCS1)
|
||||||
).decode()
|
).decode()
|
||||||
)
|
)
|
||||||
|
spki = (
|
||||||
|
"v=DKIM1; k=rsa; p="
|
||||||
|
+ base64.b64encode(
|
||||||
|
public_key.public_bytes(
|
||||||
|
Encoding.DER, PublicFormat.SubjectPublicKeyInfo
|
||||||
|
)
|
||||||
|
).decode()
|
||||||
|
)
|
||||||
with patch(
|
with patch(
|
||||||
"coulobre.hosting.tasks.provision_signing_mailbox",
|
"coulobre.hosting.tasks.provision_signing_mailbox",
|
||||||
return_value=dkim,
|
return_value=dkim,
|
||||||
@@ -223,8 +231,9 @@ class MailDnsPanelTests(TestCase):
|
|||||||
self.assertEqual(job.state, "configured")
|
self.assertEqual(job.state, "configured")
|
||||||
self.domain.refresh_from_db()
|
self.domain.refresh_from_db()
|
||||||
zone.refresh_from_db()
|
zone.refresh_from_db()
|
||||||
self.assertEqual(self.domain.dkim_record, dkim)
|
self.assertEqual(self.domain.dkim_record, spki)
|
||||||
self.assertEqual(dkim_key(dkim, expected=dkim)[0], "ok")
|
self.assertEqual(dkim_key(dkim, expected=spki)[0], "ok")
|
||||||
|
self.assertEqual(dkim_key(spki, expected=dkim)[0], "ok")
|
||||||
self.assertEqual(dkim_key(DKIM, expected=dkim)[0], "attention")
|
self.assertEqual(dkim_key(DKIM, expected=dkim)[0], "attention")
|
||||||
self.assertEqual(zone.serial, 6)
|
self.assertEqual(zone.serial, 6)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
@@ -246,7 +255,7 @@ class MailDnsPanelTests(TestCase):
|
|||||||
{
|
{
|
||||||
DOMAIN: f"v=spf1 ip4:{IP} ~all",
|
DOMAIN: f"v=spf1 ip4:{IP} ~all",
|
||||||
"_dmarc.example.net": "v=DMARC1; p=none",
|
"_dmarc.example.net": "v=DMARC1; p=none",
|
||||||
"coulobre._domainkey.example.net": dkim,
|
"coulobre._domainkey.example.net": spki,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
publication = DnsPublication.objects.get(zone=zone)
|
publication = DnsPublication.objects.get(zone=zone)
|
||||||
@@ -255,6 +264,54 @@ class MailDnsPanelTests(TestCase):
|
|||||||
zone.refresh_from_db()
|
zone.refresh_from_db()
|
||||||
self.assertEqual(zone.serial, 6)
|
self.assertEqual(zone.serial, 6)
|
||||||
|
|
||||||
|
def test_existing_dkim_is_reencoded_only_for_the_same_rsa_key(self):
|
||||||
|
prefix = "v=DKIM1; k=rsa; p="
|
||||||
|
selector = f"coulobre._domainkey.{DOMAIN}"
|
||||||
|
signer = generate_private_key(
|
||||||
|
public_exponent=65537, key_size=2048
|
||||||
|
).public_key()
|
||||||
|
previous = (
|
||||||
|
prefix
|
||||||
|
+ base64.b64encode(
|
||||||
|
signer.public_bytes(Encoding.DER, PublicFormat.PKCS1)
|
||||||
|
).decode()
|
||||||
|
)
|
||||||
|
other = {"name": DOMAIN, "text": "site-verification=unchanged"}
|
||||||
|
zone = self.zone(
|
||||||
|
manage_mail_dns=True,
|
||||||
|
txt_records=[
|
||||||
|
{"name": selector, "text": previous + "; s=email"},
|
||||||
|
other,
|
||||||
|
],
|
||||||
|
)
|
||||||
|
sync_mail_dns(self.domain, public_key=previous)
|
||||||
|
zone.refresh_from_db()
|
||||||
|
self.domain.refresh_from_db()
|
||||||
|
self.assertNotEqual(self.domain.dkim_record, previous)
|
||||||
|
self.assertIn(
|
||||||
|
{"name": selector, "text": self.domain.dkim_record + "; s=email"},
|
||||||
|
zone.txt_records,
|
||||||
|
)
|
||||||
|
self.assertIn(other, zone.txt_records)
|
||||||
|
conflicting_signer = generate_private_key(
|
||||||
|
public_exponent=65537, key_size=2048
|
||||||
|
).public_key()
|
||||||
|
different = (
|
||||||
|
prefix
|
||||||
|
+ base64.b64encode(
|
||||||
|
conflicting_signer.public_bytes(
|
||||||
|
Encoding.DER, PublicFormat.SubjectPublicKeyInfo
|
||||||
|
)
|
||||||
|
).decode()
|
||||||
|
)
|
||||||
|
records, serial = zone.txt_records, zone.serial
|
||||||
|
sync_mail_dns(self.domain, public_key=different)
|
||||||
|
zone.refresh_from_db()
|
||||||
|
self.domain.refresh_from_db()
|
||||||
|
self.assertEqual(zone.txt_records, records)
|
||||||
|
self.assertEqual(zone.serial, serial)
|
||||||
|
self.assertIn("already has a record", self.domain.dns_setup_problem)
|
||||||
|
|
||||||
def test_dns_sync_keeps_an_existing_mail_client_host_record(self):
|
def test_dns_sync_keeps_an_existing_mail_client_host_record(self):
|
||||||
address = {"name": f"mail.{DOMAIN}", "address": "192.0.2.43"}
|
address = {"name": f"mail.{DOMAIN}", "address": "192.0.2.43"}
|
||||||
zone = self.zone(manage_mail_dns=True, addresses=[address])
|
zone = self.zone(manage_mail_dns=True, addresses=[address])
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ from unittest.mock import patch
|
|||||||
from django.contrib.auth import get_user_model
|
from django.contrib.auth import get_user_model
|
||||||
from django.test import SimpleTestCase, TestCase, override_settings
|
from django.test import SimpleTestCase, TestCase, override_settings
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
|
from django.utils import timezone
|
||||||
|
|
||||||
from coulobre.dns_catalog import render_catalog
|
from coulobre.dns_catalog import render_catalog
|
||||||
from coulobre.mail_node import MailboxSpec, MailboxUsageRequest
|
from coulobre.mail_node import MailboxSpec, MailboxUsageRequest
|
||||||
@@ -14,7 +15,7 @@ from coulobre.mail_queue import QUEUE_NAMES, summarize_queue
|
|||||||
from coulobre.web_node import WebSite
|
from coulobre.web_node import WebSite
|
||||||
from coulobre.web_node_usage import read_site_log, without_usage_logs
|
from coulobre.web_node_usage import read_site_log, without_usage_logs
|
||||||
|
|
||||||
from .models import Customer, HostingAccount, HostingMailDomain
|
from .models import Customer, HostingAccount, HostingMailDomain, WebsiteUsage
|
||||||
|
|
||||||
|
|
||||||
class ServiceInspectionTests(SimpleTestCase):
|
class ServiceInspectionTests(SimpleTestCase):
|
||||||
@@ -136,6 +137,38 @@ class PublicOperationsAccessTests(TestCase):
|
|||||||
self.assertEqual(self.client.get(url).status_code, 404)
|
self.assertEqual(self.client.get(url).status_code, 404)
|
||||||
self.assertEqual(self.client.post(url).status_code, 404)
|
self.assertEqual(self.client.post(url).status_code, 404)
|
||||||
|
|
||||||
|
def test_usage_formats_access_entries_and_preserves_saved_log_text(self):
|
||||||
|
long_path = "/" + "directory-" * 20
|
||||||
|
url = reverse("panel:website_usage", args=[self.account.pk])
|
||||||
|
site = WebSite(self.account.pk, self.account.primary_domain)
|
||||||
|
WebsiteUsage.objects.create(
|
||||||
|
account=self.account,
|
||||||
|
node_key=site.node_key,
|
||||||
|
domain=site.domain,
|
||||||
|
observed_at=timezone.now(),
|
||||||
|
report={
|
||||||
|
"month": timezone.now().strftime("%Y-%m"),
|
||||||
|
"storage_bytes": 2048,
|
||||||
|
"traffic_bytes": 1024,
|
||||||
|
"access_lines": [
|
||||||
|
f"1735689600 1024 200 GET {long_path}",
|
||||||
|
"unrecognised access entry",
|
||||||
|
],
|
||||||
|
"error_lines": ["<log message>"],
|
||||||
|
"partial": False,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
self.client.force_login(self.customer)
|
||||||
|
with patch(
|
||||||
|
"coulobre.hosting.website_usage_views.managed_sites",
|
||||||
|
return_value=[site],
|
||||||
|
):
|
||||||
|
response = self.client.get(url)
|
||||||
|
self.assertContains(response, "1 Jan 2025, 00:00:00")
|
||||||
|
self.assertContains(response, long_path)
|
||||||
|
self.assertContains(response, "unrecognised access entry")
|
||||||
|
self.assertContains(response, "<log message>")
|
||||||
|
|
||||||
def test_queue_is_visible_to_operators_only(self):
|
def test_queue_is_visible_to_operators_only(self):
|
||||||
url = reverse("panel:mail_queue", args=[self.domain.pk])
|
url = reverse("panel:mail_queue", args=[self.domain.pk])
|
||||||
self.client.force_login(self.customer)
|
self.client.force_login(self.customer)
|
||||||
|
|||||||
@@ -10,10 +10,17 @@ from django_otp.plugins.otp_totp.models import TOTPDevice
|
|||||||
|
|
||||||
from .models import (
|
from .models import (
|
||||||
Customer,
|
Customer,
|
||||||
|
DomainServicePolicy,
|
||||||
HostingAccount,
|
HostingAccount,
|
||||||
|
HostingDnsZone,
|
||||||
|
HostingMailbox,
|
||||||
|
HostingMailDomain,
|
||||||
HostingPlan,
|
HostingPlan,
|
||||||
|
MailboxProvisioning,
|
||||||
PanelInvitation,
|
PanelInvitation,
|
||||||
Reseller,
|
Reseller,
|
||||||
|
WebsiteAlias,
|
||||||
|
WebsiteDomain,
|
||||||
WebsiteScheduledJob,
|
WebsiteScheduledJob,
|
||||||
WebsiteUsage,
|
WebsiteUsage,
|
||||||
)
|
)
|
||||||
@@ -126,6 +133,103 @@ class UserDeletionTests(TestCase):
|
|||||||
|
|
||||||
|
|
||||||
class WorkspaceTests(TestCase):
|
class WorkspaceTests(TestCase):
|
||||||
|
def test_domain_selectors_list_only_domains_managed_by_the_service(self):
|
||||||
|
user = get_user_model().objects.create_user("customer")
|
||||||
|
account = HostingAccount.objects.create(
|
||||||
|
name="Example",
|
||||||
|
primary_domain="example.test",
|
||||||
|
customer=Customer.objects.create(user=user),
|
||||||
|
)
|
||||||
|
self.client.force_login(user)
|
||||||
|
alias = "www.example.test"
|
||||||
|
for name in (alias, "mailing.example.test"):
|
||||||
|
WebsiteAlias.objects.create(
|
||||||
|
reservation=WebsiteDomain.objects.create(
|
||||||
|
account=account, domain=name
|
||||||
|
),
|
||||||
|
primary_domain=account.primary_domain,
|
||||||
|
)
|
||||||
|
DomainServicePolicy.objects.create(
|
||||||
|
account=account, domain="mailing.example.test", mail_managed=True
|
||||||
|
)
|
||||||
|
HostingMailDomain.objects.create(
|
||||||
|
account=account, domain="existing.example.test"
|
||||||
|
)
|
||||||
|
for name in (account.primary_domain, "delegated.example.test"):
|
||||||
|
HostingDnsZone.objects.create(
|
||||||
|
account=account,
|
||||||
|
domain=name,
|
||||||
|
nameservers=["ns.provider.test"],
|
||||||
|
responsible_name="hostmaster.example.test",
|
||||||
|
)
|
||||||
|
|
||||||
|
pages = {
|
||||||
|
"domains": [alias, "mailing.example.test"],
|
||||||
|
"dns": ["delegated.example.test"],
|
||||||
|
"forwarders": ["existing.example.test", "mailing.example.test"],
|
||||||
|
}
|
||||||
|
for page, available in pages.items():
|
||||||
|
path = reverse("panel:domain_workspace", args=[account.pk, page])
|
||||||
|
with self.subTest(page=page):
|
||||||
|
response = self.client.get(path)
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
for domain in available:
|
||||||
|
self.assertContains(response, f'<option value="{domain}"')
|
||||||
|
if page != "domains":
|
||||||
|
self.assertNotContains(
|
||||||
|
response, f'<option value="{alias}"'
|
||||||
|
)
|
||||||
|
self.assertEqual(
|
||||||
|
self.client.get(path, {"domain": alias}).status_code,
|
||||||
|
404,
|
||||||
|
)
|
||||||
|
|
||||||
|
mailbox_create = reverse("panel:mailbox_create", args=[account.pk])
|
||||||
|
self.assertEqual(
|
||||||
|
self.client.post(
|
||||||
|
f"{mailbox_create}?domain={alias}", {"local_part": "info"}
|
||||||
|
).status_code,
|
||||||
|
404,
|
||||||
|
)
|
||||||
|
self.assertFalse(
|
||||||
|
HostingMailDomain.objects.filter(domain=alias).exists()
|
||||||
|
)
|
||||||
|
|
||||||
|
@override_settings(
|
||||||
|
MAIL_IMAP_HOST="mail.service.test",
|
||||||
|
MAIL_SUBMISSION_HOST="submit.service.test",
|
||||||
|
LOCAL_MAILBOX_CREDENTIALS=False,
|
||||||
|
REMOTE_MAILBOX_CREDENTIALS=False,
|
||||||
|
)
|
||||||
|
def test_email_accounts_only_offers_available_credentials(self):
|
||||||
|
user = get_user_model().objects.create_user("customer")
|
||||||
|
account = HostingAccount.objects.create(
|
||||||
|
name="Example",
|
||||||
|
primary_domain="example.test",
|
||||||
|
customer=Customer.objects.create(user=user),
|
||||||
|
)
|
||||||
|
domain = HostingMailDomain.objects.create(
|
||||||
|
account=account, domain=account.primary_domain
|
||||||
|
)
|
||||||
|
mailbox = HostingMailbox.objects.create(
|
||||||
|
mail_domain=domain, local_part="info"
|
||||||
|
)
|
||||||
|
MailboxProvisioning.objects.create(
|
||||||
|
mailbox=mailbox, finished_at=timezone.now()
|
||||||
|
)
|
||||||
|
self.client.force_login(user)
|
||||||
|
path = reverse("panel:domain_workspace", args=[account.pk, "email"])
|
||||||
|
credentials = reverse("panel:mailbox_credentials", args=[mailbox.pk])
|
||||||
|
response = self.client.get(path, secure=True)
|
||||||
|
self.assertNotContains(response, credentials)
|
||||||
|
self.assertContains(response, "mail.service.test · port 993")
|
||||||
|
self.assertContains(response, "submit.service.test · port 587")
|
||||||
|
self.assertContains(response, "info@example.test")
|
||||||
|
with override_settings(REMOTE_MAILBOX_CREDENTIALS=True):
|
||||||
|
self.assertContains(
|
||||||
|
self.client.get(path, secure=True), credentials
|
||||||
|
)
|
||||||
|
|
||||||
def test_operator_creates_and_links_the_first_hosting_account(self):
|
def test_operator_creates_and_links_the_first_hosting_account(self):
|
||||||
users = get_user_model().objects
|
users = get_user_model().objects
|
||||||
operator = users.create_superuser("operator")
|
operator = users.create_superuser("operator")
|
||||||
|
|||||||
@@ -160,8 +160,7 @@ from .roundcube import mailbox_can_open_webmail, roundcube_available
|
|||||||
from .service_changes import request_service_change
|
from .service_changes import request_service_change
|
||||||
from .service_credentials import (
|
from .service_credentials import (
|
||||||
CredentialKind,
|
CredentialKind,
|
||||||
can_reveal_credentials,
|
show_credential_action,
|
||||||
enabled_credential_access,
|
|
||||||
)
|
)
|
||||||
from .sftp import (
|
from .sftp import (
|
||||||
SFTPKeyUploadForm,
|
SFTPKeyUploadForm,
|
||||||
@@ -865,12 +864,12 @@ class AccountDetail(TenantScopeMixin, PermissionRequiredMixin, DetailView):
|
|||||||
"-requested_at", "-pk"
|
"-requested_at", "-pk"
|
||||||
)[:10]
|
)[:10]
|
||||||
if getattr(self.request, "impersonation", None) is None:
|
if getattr(self.request, "impersonation", None) is None:
|
||||||
context["show_database_credentials"] = enabled_credential_access(
|
context["show_database_credentials"] = show_credential_action(
|
||||||
self.request, CredentialKind.DATABASE
|
self.request, CredentialKind.DATABASE
|
||||||
) and can_reveal_credentials(user, CredentialKind.DATABASE)
|
)
|
||||||
context["show_mailbox_credentials"] = enabled_credential_access(
|
context["show_mailbox_credentials"] = show_credential_action(
|
||||||
self.request, CredentialKind.MAILBOX
|
self.request, CredentialKind.MAILBOX
|
||||||
) and can_reveal_credentials(user, CredentialKind.MAILBOX)
|
)
|
||||||
context["show_phpmyadmin"] = context[
|
context["show_phpmyadmin"] = context[
|
||||||
"show_database_credentials"
|
"show_database_credentials"
|
||||||
] and phpmyadmin_available(self.request)
|
] and phpmyadmin_available(self.request)
|
||||||
@@ -2465,9 +2464,12 @@ class MailboxCreate(ResourceRequestCreate):
|
|||||||
self.request, "impersonation", None
|
self.request, "impersonation", None
|
||||||
):
|
):
|
||||||
raise Http404
|
raise Http404
|
||||||
|
from .domain_policies import managed_mail_domains
|
||||||
from .domain_services import allowed_domains
|
from .domain_services import allowed_domains
|
||||||
|
|
||||||
if domain not in allowed_domains(self.account):
|
if domain not in allowed_domains(
|
||||||
|
self.account
|
||||||
|
) or domain not in managed_mail_domains(self.account):
|
||||||
raise Http404
|
raise Http404
|
||||||
return domain
|
return domain
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
from datetime import timedelta
|
from datetime import UTC, datetime, timedelta
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.contrib.auth.mixins import PermissionRequiredMixin
|
from django.contrib.auth.mixins import PermissionRequiredMixin
|
||||||
@@ -27,6 +27,20 @@ def managed_sites(account):
|
|||||||
return sites
|
return sites
|
||||||
|
|
||||||
|
|
||||||
|
def access_log_entry(line):
|
||||||
|
try:
|
||||||
|
timestamp, size, status, method, path = line.split(" ", 4)
|
||||||
|
return {
|
||||||
|
"time": datetime.fromtimestamp(int(timestamp), tz=UTC),
|
||||||
|
"bytes": int(size),
|
||||||
|
"status": int(status),
|
||||||
|
"method": method,
|
||||||
|
"path": path,
|
||||||
|
}
|
||||||
|
except (ValueError, OverflowError, OSError):
|
||||||
|
return {"raw": line}
|
||||||
|
|
||||||
|
|
||||||
@method_decorator(never_cache, name="dispatch")
|
@method_decorator(never_cache, name="dispatch")
|
||||||
class WebsiteUsageView(TenantScopeMixin, PermissionRequiredMixin, DetailView):
|
class WebsiteUsageView(TenantScopeMixin, PermissionRequiredMixin, DetailView):
|
||||||
queryset = HostingAccount.objects.filter(retired_at__isnull=True)
|
queryset = HostingAccount.objects.filter(retired_at__isnull=True)
|
||||||
@@ -90,7 +104,17 @@ class WebsiteUsageView(TenantScopeMixin, PermissionRequiredMixin, DetailView):
|
|||||||
limits[str(self.object.pk)] = current_limit.applied_mib
|
limits[str(self.object.pk)] = current_limit.applied_mib
|
||||||
return super().get_context_data(
|
return super().get_context_data(
|
||||||
sites=[
|
sites=[
|
||||||
(site, reading, limits.get(site.node_key))
|
(
|
||||||
|
site,
|
||||||
|
reading,
|
||||||
|
limits.get(site.node_key),
|
||||||
|
[
|
||||||
|
access_log_entry(line)
|
||||||
|
for line in reading.report.get("access_lines", ())
|
||||||
|
]
|
||||||
|
if reading
|
||||||
|
else (),
|
||||||
|
)
|
||||||
for site, reading in rows
|
for site, reading in rows
|
||||||
],
|
],
|
||||||
month=month,
|
month=month,
|
||||||
|
|||||||
@@ -430,9 +430,7 @@ def dkim_key(record, *, expected=""):
|
|||||||
"attention",
|
"attention",
|
||||||
"RSA key published. Prefer at least 2048 bits.",
|
"RSA key published. Prefer at least 2048 bits.",
|
||||||
)
|
)
|
||||||
if expected and key.public_bytes(
|
if expected and not same_rsa_dkim_key(record, expected):
|
||||||
Encoding.DER, PublicFormat.PKCS1
|
|
||||||
) != decode_key(read_tags(expected).get("p", "")):
|
|
||||||
return (
|
return (
|
||||||
"attention",
|
"attention",
|
||||||
"The public key differs from the mail node's key.",
|
"The public key differs from the mail node's key.",
|
||||||
@@ -448,6 +446,46 @@ def decode_key(value):
|
|||||||
return base64.b64decode(data, validate=True)
|
return base64.b64decode(data, validate=True)
|
||||||
|
|
||||||
|
|
||||||
|
def rsa_dkim_key(record):
|
||||||
|
tags = read_tags(record)
|
||||||
|
if tags.get("k", "rsa") != "rsa" or (
|
||||||
|
"v" in tags and (next(iter(tags)) != "v" or tags["v"] != "DKIM1")
|
||||||
|
):
|
||||||
|
return None
|
||||||
|
try:
|
||||||
|
key = load_der_public_key(decode_key(tags.get("p", "")))
|
||||||
|
except (ValueError, UnsupportedAlgorithm):
|
||||||
|
return None
|
||||||
|
return key if isinstance(key, RSAPublicKey) else None
|
||||||
|
|
||||||
|
|
||||||
|
def same_rsa_dkim_key(first, second):
|
||||||
|
first_key = rsa_dkim_key(first)
|
||||||
|
second_key = rsa_dkim_key(second)
|
||||||
|
return (
|
||||||
|
first_key is not None
|
||||||
|
and second_key is not None
|
||||||
|
and first_key.public_numbers() == second_key.public_numbers()
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def normalize_rsa_dkim_record(record):
|
||||||
|
"""Encode the public key for DNS and preserve other tags."""
|
||||||
|
key = rsa_dkim_key(record)
|
||||||
|
if key is None:
|
||||||
|
return record
|
||||||
|
data = key.public_bytes(Encoding.DER, PublicFormat.SubjectPublicKeyInfo)
|
||||||
|
encoded = base64.b64encode(data).decode("ascii")
|
||||||
|
if decode_key(read_tags(record)["p"]) == data:
|
||||||
|
return record
|
||||||
|
return re.sub(
|
||||||
|
r"(^|;)(\s*p\s*=)[^;]*",
|
||||||
|
lambda match: match[1] + match[2] + encoded,
|
||||||
|
record,
|
||||||
|
count=1,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def sts_policy(record):
|
def sts_policy(record):
|
||||||
policy_id = read_tags(record).get("id", "")
|
policy_id = read_tags(record).get("id", "")
|
||||||
if not re.fullmatch(r"[A-Za-z0-9]{1,32}", policy_id):
|
if not re.fullmatch(r"[A-Za-z0-9]{1,32}", policy_id):
|
||||||
|
|||||||
@@ -65,6 +65,6 @@ def provision_dkim_key(domain):
|
|||||||
"The DKIM key must be RSA with at least 2048 bits."
|
"The DKIM key must be RSA with at least 2048 bits."
|
||||||
)
|
)
|
||||||
public = key.public_key().public_bytes(
|
public = key.public_key().public_bytes(
|
||||||
Encoding.DER, PublicFormat.PKCS1
|
Encoding.DER, PublicFormat.SubjectPublicKeyInfo
|
||||||
)
|
)
|
||||||
return "v=DKIM1; k=rsa; p=" + base64.b64encode(public).decode("ascii")
|
return "v=DKIM1; k=rsa; p=" + base64.b64encode(public).decode("ascii")
|
||||||
Reference in new issue
Block a user