From 7b486c491b0775e8aa97f6d848f6b4f1095d8b88 Mon Sep 17 00:00:00 2001 From: Peter van Arkel Date: Fri, 4 Dec 2026 13:09:13 +0100 Subject: [PATCH 1/2] Separate current web configurations from provisioning history --- docs/development.md | 9 +- docs/panel-design.md | 5 + .../templates/hosting/account_detail.html | 23 ++-- .../templates/hosting/account_history.html | 45 ++++++++ .../templates/hosting/plan_detail.html | 34 ++++-- .../hosting/templates/hosting/plan_list.html | 49 ++++++-- .../hosting/templates/hosting/plan_table.html | 5 +- src/coulobre/hosting/test_customers.py | 6 +- src/coulobre/hosting/test_panel.py | 64 ++++++++++- src/coulobre/hosting/test_resellers.py | 2 +- src/coulobre/hosting/views.py | 107 ++++++++++++++---- src/coulobre/hosting/web_history.py | 44 +++++++ 12 files changed, 331 insertions(+), 62 deletions(-) create mode 100644 src/coulobre/hosting/templates/hosting/account_history.html create mode 100644 src/coulobre/hosting/web_history.py diff --git a/docs/development.md b/docs/development.md index f230a67..c95806d 100644 --- a/docs/development.md +++ b/docs/development.md @@ -873,10 +873,13 @@ celery -A coulobre worker --pool=solo celery -A coulobre beat ``` -Open an account in **Hosting accounts** and select **Request Apache preview**. +Open an account in **Hosting accounts**, select **History**, and choose +**Request Apache preview**. The preview page shows the request status and the configuration once the worker -finishes. Use **Refresh status** for pending requests or **Web provisioning** to -find earlier previews. Each request captures the primary domain at queue time. +finishes. Use **Refresh status** for pending requests or **Web provisioning → +History** to find earlier previews. **Current configurations** lists the last +successfully applied Apache configuration for each primary website. Each +preview request captures the primary domain at queue time. The preview references the future document root and PHP-FPM socket for the account. Preview generation makes no changes to the hosting services. diff --git a/docs/panel-design.md b/docs/panel-design.md index 7c26ade..f6d8aaa 100644 --- a/docs/panel-design.md +++ b/docs/panel-design.md @@ -27,6 +27,11 @@ only use shared components available in its supported Core versions. each service. Keep metadata compact and link to the relevant workflow for the active role. Distinguish configuration from public reachability or delivery. Use measured usage only when the panel has it. +- Keep current configuration separate from history. Show one current + record per resource in the working view. Use a **History** tab for + time-stamped events and snapshots. Label historical details explicitly + and keep live actions on the current resource or in a dedicated workflow. + Keep history scoped to the viewer’s role, especially internal config. - Use `.surface` for sections, `.section-heading` for ordinary section headers, and `.table-scroll` around tables. Keep horizontal overflow in the table wrapper and give empty or pending states an explicit label. diff --git a/src/coulobre/hosting/templates/hosting/account_detail.html b/src/coulobre/hosting/templates/hosting/account_detail.html index 171bd5b..ae83f2b 100644 --- a/src/coulobre/hosting/templates/hosting/account_detail.html +++ b/src/coulobre/hosting/templates/hosting/account_detail.html @@ -20,6 +20,7 @@ {% if is_tenant or perms.hosting.view_hostingdatabase %}Databases{% endif %} {% if show_account_backups or export_backup_manifest %}Backups{% endif %} {% if can_change_hosting_services or service_change or can_retire_account or is_operator and perms.hosting.change_hostingaccount %}Account management{% endif %} + History {% endblock %} {% block page_content %} @@ -55,6 +56,7 @@
Added
{{ account.created_at|date:"j M Y, H:i" }} UTC
{% include "hosting/account_overview.html" %} + {% include "hosting/account_history.html" %} {% if can_change_hosting_services or service_change or can_retire_account or is_operator and perms.hosting.change_hostingaccount %}
{% if can_retire_account or is_operator and perms.hosting.change_hostingaccount %} @@ -107,18 +109,21 @@ {% if website_aliases or can_add_website_alias %} {% include "hosting/website_aliases.html" %} {% endif %} - {% if show_web_previews %} -
+ {% if website_readiness %} +
-

Recent Apache previews

- {% if is_operator and perms.hosting.change_hostingaccount %} -
- {% csrf_token %} - -
+
+

Primary website

+

{{ account.primary_domain }}

+
+ {% if can_view_apache_plans and current_apache_plan %} + View Apache configuration {% endif %}
- {% include "hosting/plan_table.html" %} +
+
Website setup
{{ website_readiness }}
+
HTTPS
{{ https_status.label }}
+
{% endif %} diff --git a/src/coulobre/hosting/templates/hosting/account_history.html b/src/coulobre/hosting/templates/hosting/account_history.html new file mode 100644 index 0000000..a7f0f51 --- /dev/null +++ b/src/coulobre/hosting/templates/hosting/account_history.html @@ -0,0 +1,45 @@ + diff --git a/src/coulobre/hosting/templates/hosting/plan_detail.html b/src/coulobre/hosting/templates/hosting/plan_detail.html index 0cf765e..910197b 100644 --- a/src/coulobre/hosting/templates/hosting/plan_detail.html +++ b/src/coulobre/hosting/templates/hosting/plan_detail.html @@ -1,34 +1,52 @@ {% extends "hosting/workspace_page.html" %} -{% block title %}Apache preview · Coulobre Panel{% endblock %} +{% block title %}{% if plan_mode == "current" %}Apache configuration{% else %}Apache preview{% endif %} · Coulobre Panel{% endblock %} {% block page_header %}
-

Apache preview

+

{% if plan_mode == "current" %}Apache configuration{% elif plan_mode == "history" %}Apache preview history{% else %}Apache preview{% endif %}

{{ plan.primary_domain }}

- {% if not plan.completed_at or manage_activation and plan.activation and not plan.activation.finished_at or manage_https and plan.https and not plan.https.finished_at %} + {% if continue_apache_setup %} + Continue website setup + {% elif plan_mode == "preview" %} + {% if not plan.completed_at or manage_activation and plan.activation and not plan.activation.finished_at or manage_https and plan.https and not plan.https.finished_at %} Refresh status + {% endif %} {% endif %}
{% endblock %} {% block page_context %} - ← Web provisioning + ← Web provisioning {% endblock %} {% block page_content %}
-
Status
{% include "hosting/plan_status.html" %}
+ {% if plan_mode == "current" %} +
Applied
{{ plan.activation.finished_at|date:"j M Y, H:i" }} UTC
+
HTTPS
{{ https_status.label }}
+ {% else %} +
Preview result
{% include "hosting/plan_status.html" %}
+ {% endif %}
Hosting account
{% if is_reseller or perms.hosting.view_hostingaccount %}{{ plan.account.name }}{% else %}{{ plan.account.name }}{% endif %}
-
Requested
{{ plan.requested_at|date:"j M Y, H:i" }} UTC
+ {% if plan_mode != "current" %}
Requested
{{ plan.requested_at|date:"j M Y, H:i" }} UTC
{% endif %}
+ {% if plan_mode == "history" %} +

This entry records a preview request and does not show the website’s current state. + {% if current_apache_plan %}View current Apache configuration{% endif %} +

+ {% endif %} {% if plan.primary_domain != plan.account.primary_domain %}

This preview captures the original domain. The hosting account now uses {{ plan.account.primary_domain }}.

{% endif %} {% if plan.completed_at %}
-

Virtual host configuration

- {% if not is_reseller and plan.can_export %} +
+

{% if plan_mode == "current" %}Primary HTTP virtual host{% else %}Virtual host configuration{% endif %}

+ {% if plan_mode == "current" %}

Coulobre’s recorded configuration. HTTPS and alias configuration are managed separately.

{% endif %} +
+ {% if plan_mode != "history" and not is_reseller and plan.can_export %}
+ {% if may_manage_https %}Manage HTTPS{% endif %} Download deployment manifest Download test bundle
diff --git a/src/coulobre/hosting/templates/hosting/plan_list.html b/src/coulobre/hosting/templates/hosting/plan_list.html index 0c0d5b5..803aeb3 100644 --- a/src/coulobre/hosting/templates/hosting/plan_list.html +++ b/src/coulobre/hosting/templates/hosting/plan_list.html @@ -1,16 +1,45 @@ {% extends "hosting/workspace_page.html" %} {% block title %}Web provisioning · Coulobre Panel{% endblock %} -{% block page_header %} -
-
-

Web provisioning

-

{{ paginator.count }} Apache preview{{ paginator.count|pluralize }}

-
-
+{% block page_title %}Web provisioning{% endblock %} +{% block page_tabs %} + {% endblock %} {% block page_content %} -
- {% include "hosting/plan_table.html" %} - {% include "hosting/pagination.html" %} +
+
+
+ {% if show_history %} +

Web provisioning history

+

Apache preview requests, including earlier configurations.

+ {% else %} +

Current Apache configurations

+

The latest configuration applied by Coulobre for each primary website.

+ {% endif %} +
+
+ {% if show_history %} + {% include "hosting/plan_table.html" %} + {% elif plans %} +
+ + + + {% for plan in plans %} + + + + + + {% endfor %} + +
Primary domainHosting accountApplied
{{ plan.primary_domain }}{{ plan.account.name }}{{ plan.activation.finished_at|date:"j M Y, H:i" }} UTC
+
+ {% else %} +

No Apache configurations have been applied to current primary websites.

+ {% endif %}
+ {% include "hosting/pagination.html" %} {% endblock %} diff --git a/src/coulobre/hosting/templates/hosting/plan_table.html b/src/coulobre/hosting/templates/hosting/plan_table.html index 381386c..2836e66 100644 --- a/src/coulobre/hosting/templates/hosting/plan_table.html +++ b/src/coulobre/hosting/templates/hosting/plan_table.html @@ -1,11 +1,12 @@ {% if plans %}
- + {% for plan in plans %} - + + diff --git a/src/coulobre/hosting/test_customers.py b/src/coulobre/hosting/test_customers.py index c07cd6a..66868e2 100644 --- a/src/coulobre/hosting/test_customers.py +++ b/src/coulobre/hosting/test_customers.py @@ -123,10 +123,14 @@ class CustomerAccessTests(TestCase): detail = self.client.get(self.account.get_absolute_url()) for label in ( "Edit account", - "Recent Apache previews", + "Apache preview requested", + "Request Apache preview", + "View Apache configuration", "Download manifest", ): self.assertNotContains(detail, label) + self.assertContains(detail, 'href="#history"') + self.assertContains(detail, "Hosting account created") for route, args in ( ("panel:plans", ()), diff --git a/src/coulobre/hosting/test_panel.py b/src/coulobre/hosting/test_panel.py index 7a7501e..1554dfe 100644 --- a/src/coulobre/hosting/test_panel.py +++ b/src/coulobre/hosting/test_panel.py @@ -1,9 +1,10 @@ from django.contrib.auth import get_user_model from django.contrib.auth.models import Permission -from django.test import Client, TestCase +from django.test import Client, TestCase, override_settings from django.urls import reverse +from django.utils import timezone -from .models import HostingAccount, WebProvisioningPlan +from .models import HostingAccount, WebActivation, WebProvisioningPlan from .tasks import render_web_plan @@ -90,7 +91,64 @@ class PanelTests(TestCase): self.assertContains( self.client.get(preview_url), "ServerName example.org" ) - self.assertContains(self.client.get(reverse("panel:plans")), "Ready") + self.assertContains( + self.client.get(reverse("panel:plans"), {"tab": "history"}), + "Ready", + ) + + @override_settings(LOCAL_WEB_ACTIVATION=True, LOCAL_WEB_HTTPS=True) + def test_current_configuration_excludes_older_and_unapplied_previews(self): + self.client.force_login(self.operator) + older, current, draft = [ + WebProvisioningPlan.objects.create( + account=self.account, + primary_domain=self.account.primary_domain, + completed_at=timezone.now(), + apache_config=f"# {label}", + ) + for label in ("older", "current", "draft") + ] + for plan in (older, current): + WebActivation.objects.create(plan=plan, finished_at=timezone.now()) + WebActivation.objects.create( + plan=draft, finished_at=timezone.now(), problem="Failed activation" + ) + listing = reverse("panel:plans") + older_url, current_url, draft_url = [ + reverse("panel:plan", args=[plan.pk]) + for plan in (older, current, draft) + ] + response = self.client.get(listing) + self.assertContains(response, f'{current_url}?view=current"') + self.assertNotContains(response, older_url) + self.assertNotContains(response, draft_url) + response = self.client.get(listing, {"tab": "history"}) + for url in (older_url, current_url, draft_url): + self.assertContains(response, f'{url}?view=history"') + + response = self.client.get(self.account.get_absolute_url()) + self.assertContains(response, 'href="#history"') + self.assertContains(response, f'{current_url}?view=current"') + self.assertNotContains(response, "Recent Apache previews") + self.assertContains( + self.client.get(current_url, {"view": "current"}), "# current" + ) + response = self.client.get(older_url) + self.assertContains(response, "Apache preview history") + self.assertNotContains(response, "Enable HTTPS") + self.assertNotContains(response, "Activate site") + self.assertNotContains(response, "Continue website setup") + for action in ("plan_activate", "plan_https"): + self.assertEqual( + self.client.post( + reverse(f"panel:{action}", args=[older.pk]) + ).status_code, + 409, + ) + response = self.client.get(draft_url, {"view": "history"}) + self.assertContains(response, "Continue website setup") + self.assertNotContains(response, "Retry activation") + self.assertContains(self.client.get(draft_url), "Retry activation") def test_viewer_cannot_mutate_accounts_or_read_previews(self): plan = WebProvisioningPlan.for_account(self.account) diff --git a/src/coulobre/hosting/test_resellers.py b/src/coulobre/hosting/test_resellers.py index 6a0bd23..64a967c 100644 --- a/src/coulobre/hosting/test_resellers.py +++ b/src/coulobre/hosting/test_resellers.py @@ -74,7 +74,7 @@ class ResellerAccessTests(TestCase): self.client.get(account.get_absolute_url()).status_code, 404 ) - previews = self.client.get(reverse("panel:plans")) + previews = self.client.get(reverse("panel:plans"), {"tab": "history"}) self.assertContains(previews, "alice.example") self.assertNotContains(previews, "bob.example") preview = self.client.get( diff --git a/src/coulobre/hosting/views.py b/src/coulobre/hosting/views.py index 238661a..e7c467e 100644 --- a/src/coulobre/hosting/views.py +++ b/src/coulobre/hosting/views.py @@ -182,6 +182,7 @@ from .sftp import ( site_is_active, ) from .smtp_applications import smtp_applications_available +from .web_history import current_web_plan, current_web_plans, is_superseded from .web_node import ( SiteStorageLimitForm, build_web_smoke_bundle, @@ -886,13 +887,17 @@ class AccountDetail(TenantScopeMixin, PermissionRequiredMixin, DetailView): and owns_customer_operations(user, self.object) and (site_active or hasattr(self.object, "sftp")) ) - if reseller is not None or ( + context["can_view_apache_plans"] = reseller is not None or ( customer is None and user.has_perm(VIEW_PLANS) - ): - context["show_web_previews"] = True - context["plans"] = self.object.webprovisioningplan_set.order_by( - "-requested_at", "-pk" - )[:10] + ) + context["can_request_apache_plan"] = not tenant and user.has_perms( + (CHANGE_ACCOUNTS, VIEW_PLANS) + ) + if context["can_view_apache_plans"]: + history = self.object.webprovisioningplan_set.defer( + "apache_config" + ).order_by("-requested_at", "-pk") + context["apache_history"] = list(history[:10]) if getattr(self.request, "impersonation", None) is None: context["show_database_credentials"] = show_credential_action( self.request, CredentialKind.DATABASE @@ -1085,14 +1090,16 @@ class AccountDetail(TenantScopeMixin, PermissionRequiredMixin, DetailView): or getattr(context.get("website_storage"), "measured_at", None) or getattr(context.get("website_limit"), "applied_at", None) ) - context["show_website"] = any( + applied = current_web_plan(self.object) + context["current_apache_plan"] = applied + context["show_website"] = applied is not None or any( context.get(name) for name in ( "show_website_storage", "website_php_settings", "website_aliases", "can_add_website_alias", - "show_web_previews", + "can_view_apache_plans", "show_website_usage", "primary_file_access", "manage_website_jobs", @@ -1106,20 +1113,9 @@ class AccountDetail(TenantScopeMixin, PermissionRequiredMixin, DetailView): plans = self.object.webprovisioningplan_set.filter( primary_domain=self.object.primary_domain ).select_related("activation") - plan = ( - plans.filter( - activation__finished_at__isnull=False, - activation__problem="", - ) - .order_by("-pk") - .first() + plan = applied or ( + plans.filter(activation__isnull=False).order_by("-pk").first() ) - if plan is None: - plan = ( - plans.filter(activation__isnull=False) - .order_by("-pk") - .first() - ) context["website_readiness"] = provisioning_readiness( getattr(plan, "activation", None), "Not set up", "Configured" ) @@ -2992,8 +2988,8 @@ class RequestWebPlan( class PlanList(TenantScopeMixin, PermissionRequiredMixin, ListView): - queryset = WebProvisioningPlan.objects.select_related("account").order_by( - "-requested_at", "-pk" + queryset = WebProvisioningPlan.objects.select_related("account").defer( + "apache_config" ) permission_required = VIEW_PLANS reseller_relation = "account__reseller" @@ -3001,6 +2997,22 @@ class PlanList(TenantScopeMixin, PermissionRequiredMixin, ListView): context_object_name = "plans" paginate_by = 20 + def get_queryset(self): + plans = super().get_queryset() + if self.request.GET.get("tab") == "history": + return plans.order_by("-requested_at", "-pk") + return ( + current_web_plans(plans) + .select_related("activation") + .order_by("primary_domain", "pk") + ) + + def get_context_data(self, **kwargs): + return super().get_context_data( + show_history=self.request.GET.get("tab") == "history", + **kwargs, + ) + class PlanDetail(TenantScopeMixin, PermissionRequiredMixin, DetailView): queryset = WebProvisioningPlan.objects.select_related( @@ -3013,13 +3025,46 @@ class PlanDetail(TenantScopeMixin, PermissionRequiredMixin, DetailView): def get_context_data(self, **kwargs): user = self.request.user + plan = self.object + current = ( + None if plan.account.retired_at else current_web_plan(plan.account) + ) + mode = self.request.GET.get("view") + if mode == "current" and current and current.pk == plan.pk: + mode = "current" + elif ( + mode in {"current", "history"} + or plan.account.retired_at + or is_superseded(plan, current) + ): + mode = "history" + else: + mode = "preview" return super().get_context_data( - manage_activation=not is_tenant(user) + plan_mode=mode, + current_apache_plan=current, + continue_apache_setup=mode == "history" + and not plan.account.retired_at + and plan.primary_domain == plan.account.primary_domain + and (current is None or plan.pk > current.pk) + and not is_tenant(user) + and user.has_perms(ACTIVATE_WEB) + and panel_feature_allowed("LOCAL_WEB_ACTIVATION"), + https_status=( + primary_https_status(plan.account) + if mode == "current" + else None + ), + may_manage_https=mode == "current" + and may_manage_https(self.request, plan.account), + manage_activation=mode == "preview" + and not is_tenant(user) and user.has_perms(ACTIVATE_WEB), local_activation_enabled=panel_feature_allowed( "LOCAL_WEB_ACTIVATION" ), - manage_https=not is_tenant(user) + manage_https=mode == "preview" + and not is_tenant(user) and user.has_perms(ENABLE_WEB_HTTPS), local_https_enabled=panel_feature_allowed("LOCAL_WEB_HTTPS"), **kwargs, @@ -3036,6 +3081,12 @@ class RequestWebActivation( if not panel_feature_allowed("LOCAL_WEB_ACTIVATION"): raise Http404 plan = self.get_object() + if plan.account.retired_at or is_superseded( + plan, current_web_plan(plan.account) + ): + return provisioning_conflict( + ValidationError("This Apache preview is historical.") + ) if not plan.can_export: return HttpResponse( "Request a completed Apache preview for the current " @@ -3065,6 +3116,12 @@ class RequestWebHTTPS( if not panel_feature_allowed("LOCAL_WEB_HTTPS"): raise Http404 plan = self.get_object() + if plan.account.retired_at or is_superseded( + plan, current_web_plan(plan.account) + ): + return provisioning_conflict( + ValidationError("This Apache preview is historical.") + ) if not plan.can_enable_https: return HttpResponse( "Activate the site for the current domain first.", diff --git a/src/coulobre/hosting/web_history.py b/src/coulobre/hosting/web_history.py new file mode 100644 index 0000000..aa50fb6 --- /dev/null +++ b/src/coulobre/hosting/web_history.py @@ -0,0 +1,44 @@ +from django.db.models import F, OuterRef, Subquery + +from .models import WebProvisioningPlan + + +def configured_web_plans(): + return WebProvisioningPlan.objects.filter( + primary_domain=F("account__primary_domain"), + completed_at__isnull=False, + activation__finished_at__isnull=False, + activation__problem="", + ).exclude(apache_config="") + + +def current_web_plan(account): + return ( + configured_web_plans() + .filter(account=account) + .select_related("activation") + .order_by("-activation__finished_at", "-pk") + .first() + ) + + +def current_web_plans(plans): + latest = ( + configured_web_plans() + .filter(account_id=OuterRef("account_id")) + .order_by("-activation__finished_at", "-pk") + .values("pk")[:1] + ) + return plans.filter(account__retired_at__isnull=True, pk=Subquery(latest)) + + +def is_superseded(plan, current): + return ( + current is not None + and current.pk != plan.pk + and ( + current.pk > plan.pk + or getattr(getattr(plan, "activation", None), "state", None) + == "configured" + ) + ) From b58d683f219e4951a97401ed1c261cbbdcbe249f Mon Sep 17 00:00:00 2001 From: Peter van Arkel Date: Fri, 4 Dec 2026 13:17:28 +0100 Subject: [PATCH 2/2] Move technical manifest exports out of panel workflows --- docs/deployment.md | 8 +- docs/development.md | 75 ++++++++----- docs/panel-design.md | 3 + .../management/commands/export_manifest.py | 83 ++++++++++++++ .../templates/hosting/account_detail.html | 23 +--- .../hosting/independent_websites.html | 3 - .../templates/hosting/plan_detail.html | 8 +- src/coulobre/hosting/test_account_backup.py | 4 +- .../hosting/test_database_provisioning.py | 2 +- src/coulobre/hosting/test_dns_zones.py | 2 +- src/coulobre/hosting/test_export_manifest.py | 102 ++++++++++++++++++ src/coulobre/hosting/test_mailbox_imports.py | 15 ++- src/coulobre/hosting/test_web_node.py | 4 +- src/coulobre/hosting/views.py | 6 -- 14 files changed, 265 insertions(+), 73 deletions(-) create mode 100644 src/coulobre/hosting/management/commands/export_manifest.py create mode 100644 src/coulobre/hosting/test_export_manifest.py diff --git a/docs/deployment.md b/docs/deployment.md index 0dfc901..84fafec 100644 --- a/docs/deployment.md +++ b/docs/deployment.md @@ -1421,7 +1421,7 @@ confirm its domain using **Retire website**. The web node archives its data and disables its Apache and PHP configuration. Retiring a failed provisioning request also frees its place in the plan. Its domain remains reserved until released with the account's names. -Operators can download the website's version 2 manifest. Use the existing +Export the website's version 2 manifest with `export_manifest website`. Use the existing [website SFTP setup](development.md#install-sftp-keys-on-a-web-node) on the web node with that manifest to authorize a key for the site's own user. The web node suspends new SFTP logins for a suspended independent website when @@ -1936,9 +1936,9 @@ managed database and restore it to an empty database with the same identity. ## Back up an account's website and databases -Download an account backup manifest from the panel. Use it to create one ZIP +Export an account backup manifest from the CLI. Use it to create one ZIP on a single server or bundle native archives from separate nodes. The CLI can -also include mailbox archives when the downloaded manifest lists mailboxes. +also include mailbox archives when the manifest lists mailboxes. [Account backup and recovery](development.md#back-up-a-hosting-account) ### Start local account backups from the panel @@ -2787,7 +2787,7 @@ reported failure. Operators need permission to view hosting accounts and mailbox requests and the **Can add mailbox provisioning** permission. The initial password is kept in the root-only credentials file on the mail node. -To locate that file, download the manifest and use the node's `apply` command. +To locate that file, export the mailbox manifest and use the node's `apply` command. Reapplying the manifest preserves the password and prints the file path. [Show mailbox connection details in the panel](#show-local-database-and-mailbox-connection-details) diff --git a/docs/development.md b/docs/development.md index c95806d..032285c 100644 --- a/docs/development.md +++ b/docs/development.md @@ -146,14 +146,35 @@ ID, operation, resource, and time. SSH key changes record fingerprints of the keys added or removed. Queued changes still report their execution status in the hosting account. +## Export manifests from the command line + +Routine provisioning and backups in the panel do not require a separate +manifest. For manual node operations or local testing, export the matching +resource using the panel's Django management environment. + +```sh +panel_manage export_manifest database 1 > coulobre-database-1.json +panel_manage export_manifest dns-zone 1 > coulobre-zone.json +panel_manage export_manifest mailbox 1 > coulobre-mailbox-1.json +panel_manage export_manifest website 1 > coulobre-website-1.json +panel_manage export_manifest apache-preview 1 > coulobre-web-plan-1.json +panel_manage export_manifest account-backup 1 --include-mail > account.json +``` + +Replace `1` with the ID of the matching database, DNS zone, mailbox, +independent website, Apache preview, or hosting account. Use the +[`panel_manage` helper](deployment.md#prepare-the-panel) on an installed +server, or `python manage.py` in a development checkout. The command only +exports metadata and does not apply changes or create a backup. + ## Request a MariaDB database Open a hosting account and select **Request database**. Choose a short suffix such as `wordpress`. The panel derives the full database name from the account ID and suffix, so two accounts can each request a database named `wordpress`. -The account page shows the requested databases. Operators can download a -versioned deployment manifest containing the account ID and suffix. Managers +The account page shows the requested databases. The CLI manifest contains the +account ID and suffix. Managers can view the requested database names on their own assigned accounts. The manifest describes the database to provision on a MariaDB node. @@ -168,7 +189,7 @@ coulobre-database-node inspect coulobre-database-1.json Use a local MariaDB server with Unix socket authentication for `root@localhost`. Install Coulobre with the `mariadb` extra in a root-owned -virtual environment and apply the downloaded manifest on that server. +virtual environment and apply the exported manifest on that server. ```sh sudo /opt/coulobre/bin/coulobre-database-node apply coulobre-database-1.json @@ -286,11 +307,11 @@ Use `@` for the zone domain in either field. Use fully qualified names for other records. The panel increments the SOA serial when the zone data changes. Changing the account's primary domain preserves its existing DNS zones. -Select **Download manifest** in the DNS table and copy the file to the -hosting server or a separate DNS node. Managers can see the configured -domains and serials for their assigned accounts. Operators with the -appropriate permissions can add and edit zones and download manifests. -The panel exports version 2 for zones containing MX or TXT records and +Export the zone using the CLI and copy the file to the hosting server or a +separate DNS node. Managers can see the configured domains and serials for +their assigned accounts. Operators with the appropriate permissions can add +and edit zones in the panel. +Coulobre exports version 2 for zones containing MX or TXT records and version 1 for other zones. A manifest can also be written directly for local testing. Save the @@ -391,7 +412,7 @@ sudo /opt/coulobre/bin/coulobre-dns-node apply coulobre-zone.json Coulobre validates the zone with `named-checkzone` and installs it under `/etc/bind/coulobre/`. BIND9 persists the primary zone registration through -`rndc addzone`. To publish an edit, download the updated manifest and apply +`rndc addzone`. To publish an edit manually, export the updated manifest and apply it again. Coulobre checks the SOA serial, reloads the individual zone, and waits for BIND9 to report the requested serial. Reapply the same manifest to resume after an interrupted reload. See the [BIND9 command reference](https://bind9.readthedocs.io/en/v9.18.39/manpages.html#rndc) and [RFC 1982](https://www.rfc-editor.org/rfc/rfc1982.html). @@ -425,8 +446,8 @@ the `@`, such as `support`. The panel uses the account's primary domain, lowercases the local part, and converts the domain to its ASCII DNS form. Existing mailbox requests keep their addresses when the primary domain changes. -The **Mailbox requests** table shows the email addresses. Operators can -download a versioned manifest that contains the domain and local part. +The **Mailbox requests** table shows the email addresses. The CLI export +contains the domain and local part. Managers can see mailbox requests on their assigned accounts. Version 2 adds `quota_mib` for mailboxes with a storage limit. Version 1 manifests continue to apply with no Coulobre storage limit. @@ -571,7 +592,7 @@ mailbox already provisioned through the panel, saving queues an update on the local mail node. Use **Retry provisioning** to retry a failed update before setting another limit. -For a mailbox provisioned manually, download its updated manifest and run +For a mailbox provisioned manually, export its updated manifest and run the following command on the mail node. ```sh @@ -609,7 +630,7 @@ running the check without root privileges. ### Back up and restore a mailbox -Download the mailbox manifest from the panel and run the backup on the node +Export the mailbox manifest and run the backup on the node that hosts the mailbox. Use a new archive name in a root-controlled directory. ```sh @@ -734,8 +755,8 @@ python manage.py import_directadmin user.admin.customer.tar.zst The import checks domain ownership again and creates the new hosting account, supported database requests and selected domain's mailbox requests in one transaction. The JSON report includes the new account ID and the MariaDB -names derived from the database requests. Use the account page to download -deployment manifests for the nodes. The `manual_review` list records the +names derived from the database requests. Use the CLI to export deployment +manifests for the nodes. The `manual_review` list records the website, DNS, mail and SQL data to review before completing the separate restore steps below. @@ -890,8 +911,8 @@ are eligible for delivery again. ## Render configuration on a web node -Open a completed preview for the account's current domain and select **Download -deployment manifest**. The versioned JSON file contains the account ID and +Export a completed preview for the account's current domain with +`export_manifest apache-preview`. The versioned JSON file contains the account ID and primary domain. The web node command validates those values and derives the system user, document root, and PHP-FPM socket from the account ID. @@ -1188,11 +1209,10 @@ backup. The website can be recovered while its web services are stopped. ## Back up a hosting account -Open the account as an operator and select **Download backup manifest**. The -manifest lists the primary website and all database requests for the account. -Select **Download backup manifest with mail** to also include mailbox requests -from every mail domain assigned to the account. This option requires permission -to view mailbox requests. Provision all listed resources before running the +Export the backup manifest with `export_manifest account-backup`. It lists the +website and database resources for the account. Pass `--include-mail` to also +include mailbox requests from every mail domain assigned to the account. +Provision all listed resources before running the backup. The ZIP contains the native website archive, a compressed SQL dump for each listed database, and the requested mailbox archives. Back up DNS and panel settings separately. @@ -1272,13 +1292,18 @@ continue to unpack with the same filenames. ## Run an isolated PHP test site -Open a completed preview for the account's current domain and select **Download -test bundle**. The archive contains the exact Apache preview, a matching PHP-FPM +Export a completed preview for the account's current domain to a new tar file. + +```sh +python manage.py export_manifest apache-preview 1 --smoke-bundle coulobre-web-plan-1.tar +``` + +The archive contains the exact Apache preview, a matching PHP-FPM pool, site metadata, and a small PHP test page. It is intended for the isolated Ubuntu check below. Run the test with Docker from the repository root. Set the bundle path to the -downloaded tar archive. +exported tar archive. ```sh docker build -t coulobre-web-smoke tests/web-node diff --git a/docs/panel-design.md b/docs/panel-design.md index f6d8aaa..dbf3ab0 100644 --- a/docs/panel-design.md +++ b/docs/panel-design.md @@ -32,6 +32,9 @@ only use shared components available in its supported Core versions. time-stamped events and snapshots. Label historical details explicitly and keep live actions on the current resource or in a dedicated workflow. Keep history scoped to the viewer’s role, especially internal config. +- Keep low-level provisioning manifests and developer test bundles out of + routine panel actions. Document their CLI export instead. Keep meaningful + user downloads, such as backup archives, in the relevant workflow. - Use `.surface` for sections, `.section-heading` for ordinary section headers, and `.table-scroll` around tables. Keep horizontal overflow in the table wrapper and give empty or pending states an explicit label. diff --git a/src/coulobre/hosting/management/commands/export_manifest.py b/src/coulobre/hosting/management/commands/export_manifest.py new file mode 100644 index 0000000..2ac393d --- /dev/null +++ b/src/coulobre/hosting/management/commands/export_manifest.py @@ -0,0 +1,83 @@ +import json +from pathlib import Path + +from django.core.management.base import BaseCommand, CommandError + +from ...account_backups import account_backup_manifest +from ...models import ( + HostingAccount, + HostingDatabase, + HostingDnsZone, + HostingMailbox, + IndependentWebsite, + WebProvisioningPlan, +) +from ...web_node import build_web_smoke_bundle, serialize_deployment_manifest + +RESOURCE_MODELS = { + "account-backup": HostingAccount, + "database": HostingDatabase, + "dns-zone": HostingDnsZone, + "mailbox": HostingMailbox, + "website": IndependentWebsite, + "apache-preview": WebProvisioningPlan, +} + + +class Command(BaseCommand): + help = "Export a Coulobre provisioning or backup manifest as JSON." + + def add_arguments(self, parser): + parser.add_argument("resource", choices=RESOURCE_MODELS) + parser.add_argument("id", type=int) + parser.add_argument("--include-mail", action="store_true") + parser.add_argument("--smoke-bundle", type=Path, metavar="TAR") + + def handle(self, *args, **options): + resource = options["resource"] + record_id = options["id"] + include_mail = options["include_mail"] + bundle = options["smoke_bundle"] + if include_mail and resource != "account-backup": + raise CommandError("--include-mail requires account-backup.") + if bundle and resource != "apache-preview": + raise CommandError("--smoke-bundle requires apache-preview.") + if not 0 < record_id < 2**63: + raise CommandError("Enter a positive 64-bit resource ID.") + + model = RESOURCE_MODELS[resource] + try: + record = model.objects.get(pk=record_id) + except model.DoesNotExist as error: + raise CommandError( + f"No {resource} with ID {record_id}." + ) from error + + if resource == "apache-preview": + if not record.can_export: + raise CommandError( + "Select a completed preview for the current domain." + ) + if bundle: + self.write_bundle(record, bundle) + return + return serialize_deployment_manifest(record) + if resource == "account-backup": + if record.retired_at: + raise CommandError("Select an active hosting account.") + manifest = account_backup_manifest( + record, include_mailboxes=include_mail + ) + else: + manifest = record.spec.manifest() + return json.dumps(manifest, indent=2) + + def write_bundle(self, plan, path): + data = build_web_smoke_bundle(plan) + try: + with path.open("xb") as output: + output.write(data) + except OSError as error: + raise CommandError( + f"Could not write the bundle: {error}" + ) from error diff --git a/src/coulobre/hosting/templates/hosting/account_detail.html b/src/coulobre/hosting/templates/hosting/account_detail.html index ae83f2b..49f7430 100644 --- a/src/coulobre/hosting/templates/hosting/account_detail.html +++ b/src/coulobre/hosting/templates/hosting/account_detail.html @@ -18,7 +18,7 @@ {% if is_tenant or perms.hosting.view_hostingdnszone %}Domains and DNS{% endif %} {% if is_tenant or perms.hosting.view_hostingmailbox %}Email{% endif %} {% if is_tenant or perms.hosting.view_hostingdatabase %}Databases{% endif %} - {% if show_account_backups or export_backup_manifest %}Backups{% endif %} + {% if show_account_backups %}Backups{% endif %} {% if can_change_hosting_services or service_change or can_retire_account or is_operator and perms.hosting.change_hostingaccount %}Account management{% endif %} History @@ -174,9 +174,6 @@ {% endif %} - {% if is_operator %} - Download manifest - {% endif %} {% if is_operator and manage_database_provisioning and database.provisioning.problem %}

{{ database.provisioning.problem }}

@@ -224,7 +221,6 @@ {% if is_operator %}
{% endfor %} diff --git a/src/coulobre/hosting/templates/hosting/plan_detail.html b/src/coulobre/hosting/templates/hosting/plan_detail.html index 910197b..4432e49 100644 --- a/src/coulobre/hosting/templates/hosting/plan_detail.html +++ b/src/coulobre/hosting/templates/hosting/plan_detail.html @@ -44,12 +44,8 @@

{% if plan_mode == "current" %}Primary HTTP virtual host{% else %}Virtual host configuration{% endif %}

{% if plan_mode == "current" %}

Coulobre’s recorded configuration. HTTPS and alias configuration are managed separately.

{% endif %} - {% if plan_mode != "history" and not is_reseller and plan.can_export %} -
- {% if may_manage_https %}Manage HTTPS{% endif %} - Download deployment manifest - Download test bundle -
+ {% if may_manage_https %} + Manage HTTPS {% endif %}
{{ plan.apache_config }}
diff --git a/src/coulobre/hosting/test_account_backup.py b/src/coulobre/hosting/test_account_backup.py index 594cac7..ee0aa61 100644 --- a/src/coulobre/hosting/test_account_backup.py +++ b/src/coulobre/hosting/test_account_backup.py @@ -83,7 +83,7 @@ class AccountBackupManifestTests(TestCase): (self.cms.spec, self.shop.spec), ), ) - self.assertContains( + self.assertNotContains( self.client.get(self.account.get_absolute_url()), self.url ) @@ -141,7 +141,7 @@ class AccountBackupManifestTests(TestCase): AccountBackup.from_manifest(response.json()).mailboxes, (old_mailbox.spec, current_mailbox.spec), ) - self.assertContains( + self.assertNotContains( self.client.get(self.account.get_absolute_url()), "Download backup manifest with mail", ) diff --git a/src/coulobre/hosting/test_database_provisioning.py b/src/coulobre/hosting/test_database_provisioning.py index 8a13ceb..bd1589c 100644 --- a/src/coulobre/hosting/test_database_provisioning.py +++ b/src/coulobre/hosting/test_database_provisioning.py @@ -121,7 +121,7 @@ class DatabaseProvisioningTests(TestCase): def test_disabled_provisioning_preserves_existing_manifest_download(self): detail = self.client.get(self.detail) self.assertNotContains(detail, "Provision database") - self.assertContains(detail, "Download manifest") + self.assertNotContains(detail, "Download manifest") self.assertEqual(self.client.post(self.url).status_code, 404) def test_operator_can_retry_a_failed_request(self): diff --git a/src/coulobre/hosting/test_dns_zones.py b/src/coulobre/hosting/test_dns_zones.py index e2dffc9..62db7d8 100644 --- a/src/coulobre/hosting/test_dns_zones.py +++ b/src/coulobre/hosting/test_dns_zones.py @@ -391,7 +391,7 @@ class DnsZonePanelTests(TestCase): zone = self.create_zone() self.client.force_login(self.reader) account = self.client.get(self.account.get_absolute_url()) - self.assertContains(account, "Download DNS manifest") + self.assertNotContains(account, "Download DNS manifest") self.assertNotContains(account, "Edit DNS zone") self.assertContains( self.client.get( diff --git a/src/coulobre/hosting/test_export_manifest.py b/src/coulobre/hosting/test_export_manifest.py new file mode 100644 index 0000000..9d83369 --- /dev/null +++ b/src/coulobre/hosting/test_export_manifest.py @@ -0,0 +1,102 @@ +import json +import tarfile +from io import StringIO +from pathlib import Path +from tempfile import TemporaryDirectory + +from django.core.management import CommandError, call_command +from django.test import TestCase + +from .models import ( + HostingAccount, + HostingDatabase, + HostingDnsZone, + HostingMailbox, + HostingMailDomain, + IndependentWebsite, + WebProvisioningPlan, + WebsiteDomain, +) +from .tasks import render_web_plan + + +class ExportManifestTests(TestCase): + @classmethod + def setUpTestData(cls): + cls.account = HostingAccount.objects.create( + name="Example", primary_domain="example.net" + ) + cls.database = HostingDatabase.objects.create( + account=cls.account, suffix="cms" + ) + domain = HostingMailDomain.objects.create( + account=cls.account, domain=cls.account.primary_domain + ) + cls.mailbox = HostingMailbox.objects.create( + mail_domain=domain, local_part="contact" + ) + cls.zone = HostingDnsZone.objects.create( + account=cls.account, + domain=cls.account.primary_domain, + responsible_name="hostmaster.example.net", + nameservers=["ns1.provider.example", "ns2.provider.example"], + ) + cls.website = IndependentWebsite.objects.create( + reservation=WebsiteDomain.objects.create( + account=cls.account, domain="blog.example.net" + ) + ) + cls.preview = WebProvisioningPlan.for_account(cls.account) + cls.preview.save() + + def export(self, resource, pk, *args): + result = StringIO() + call_command( + "export_manifest", resource, str(pk), *args, stdout=result + ) + return json.loads(result.getvalue()) + + def test_provisioning_exports_match_their_manifest_format(self): + for resource, model in ( + ("database", self.database), + ("dns-zone", self.zone), + ("mailbox", self.mailbox), + ("website", self.website), + ): + with self.subTest(resource=resource): + self.assertEqual( + self.export(resource, model.pk), model.spec.manifest() + ) + + def test_backup_manifest_can_include_requested_mailboxes(self): + self.assertNotIn( + "mailboxes", self.export("account-backup", self.account.pk) + ) + self.assertEqual( + self.export("account-backup", self.account.pk, "--include-mail")[ + "mailboxes" + ], + [self.mailbox.spec.manifest()], + ) + + def test_preview_must_be_ready_and_bundle_cannot_replace_a_file(self): + with self.assertRaisesMessage(CommandError, "completed preview"): + self.export("apache-preview", self.preview.pk) + render_web_plan.run(self.preview.pk) + self.assertEqual( + self.export("apache-preview", self.preview.pk)["domain"], + "example.net", + ) + with TemporaryDirectory() as directory: + path = Path(directory, "test.tar") + args = ( + "apache-preview", + str(self.preview.pk), + "--smoke-bundle", + str(path), + ) + call_command("export_manifest", *args) + with tarfile.open(path) as archive: + self.assertIn("apache.conf", archive.getnames()) + with self.assertRaisesMessage(CommandError, "Could not write"): + call_command("export_manifest", *args) diff --git a/src/coulobre/hosting/test_mailbox_imports.py b/src/coulobre/hosting/test_mailbox_imports.py index bd0f213..5c33a4b 100644 --- a/src/coulobre/hosting/test_mailbox_imports.py +++ b/src/coulobre/hosting/test_mailbox_imports.py @@ -82,6 +82,7 @@ class MailboxImportTests(TestCase): email = reverse("panel:domain_workspace", args=[account.pk, "email"]) for path in (email, account.get_absolute_url()): response = self.client.get(path, secure=True) + self.assertNotContains(response, "View import result") for name, label, variant in ( ("mailbox_import", "Import mail", "secondary"), ( @@ -126,11 +127,19 @@ class MailboxImportTests(TestCase): job.finished_at = timezone.now() job.problem = "Check your source password." job.save(update_fields=["finished_at", "problem"]) - self.assertContains(self.client.get(email), "Import needs attention") + for path in (email, account.get_absolute_url()): + response = self.client.get(path) + self.assertContains(response, "Import needs attention") + self.assertContains(response, ">Review import") + self.assertNotContains(response, "View import result") job.problem = "" job.save(update_fields=["problem"]) - self.assertContains(self.client.get(email), "Import complete") - self.assertNotContains(self.client.get(email), "Import in progress") + for path in (email, account.get_absolute_url()): + response = self.client.get(path) + self.assertContains(response, "Import complete") + self.assertContains(response, ">View import result", count=1) + self.assertContains(response, ">Import mail", count=1) + self.assertNotContains(response, "Import in progress") def test_only_the_owner_and_authorized_operator_can_start_import(self): self.sign_in(self.stranger) diff --git a/src/coulobre/hosting/test_web_node.py b/src/coulobre/hosting/test_web_node.py index ed64efb..2b214b0 100644 --- a/src/coulobre/hosting/test_web_node.py +++ b/src/coulobre/hosting/test_web_node.py @@ -39,7 +39,7 @@ class WebSmokeBundleTests(TestCase): render_web_plan.run(self.plan.pk) detail = self.client.get(reverse("panel:plan", args=[self.plan.pk])) - self.assertContains(detail, "Download test bundle") + self.assertNotContains(detail, "Download test bundle") response = self.client.get(self.download) self.assertEqual(response.status_code, 200) self.assertEqual(response["Content-Type"], "application/x-tar") @@ -96,7 +96,7 @@ class WebSmokeBundleTests(TestCase): render_web_plan.run(self.plan.pk) detail = self.client.get(reverse("panel:plan", args=[self.plan.pk])) - self.assertContains(detail, "Download deployment manifest") + self.assertNotContains(detail, "Download deployment manifest") response = self.client.get(self.manifest) self.assertEqual(response.status_code, 200) self.assertIn(".json", response["Content-Disposition"]) diff --git a/src/coulobre/hosting/views.py b/src/coulobre/hosting/views.py index e7c467e..5e7207e 100644 --- a/src/coulobre/hosting/views.py +++ b/src/coulobre/hosting/views.py @@ -824,12 +824,6 @@ class AccountDetail(TenantScopeMixin, PermissionRequiredMixin, DetailView): context["can_enable_alias_https"] = panel_feature_allowed( "LOCAL_WEB_HTTPS" ) and user.has_perms(ENABLE_WEB_HTTPS) - context["export_backup_manifest"] = not tenant and user.has_perms( - EXPORT_BACKUP_MANIFEST - ) - context["export_mail_backup_manifest"] = context[ - "export_backup_manifest" - ] and user.has_perm(VIEW_MAILBOXES) if ( settings.LOCAL_ACCOUNT_BACKUPS and not tenant
Primary domainRequestedStatus
EventPrimary domainRequestedResult
{{ plan.primary_domain }}Apache preview requested{{ plan.primary_domain }} {{ plan.requested_at|date:"j M Y, H:i" }} UTC {% include "hosting/plan_status.html" %}
- Download manifest {% if show_dns_replication %} Check replication {% endif %} @@ -366,9 +362,6 @@ {% if show_mailbox_credentials %} Connection details {% endif %} - {% if is_operator %} - Download manifest - {% endif %} {% endif %} {% include "hosting/mailbox_management_links.html" %}
@@ -402,19 +395,9 @@ {% endif %} {% endif %} - {% if show_account_backups or export_backup_manifest %} + {% if show_account_backups %} {% endif %} {% endblock %} diff --git a/src/coulobre/hosting/templates/hosting/independent_websites.html b/src/coulobre/hosting/templates/hosting/independent_websites.html index ba3a5e1..3c7362e 100644 --- a/src/coulobre/hosting/templates/hosting/independent_websites.html +++ b/src/coulobre/hosting/templates/hosting/independent_websites.html @@ -33,9 +33,6 @@ {% if action.value == 'settings' %}{{ action.label }} {% else %}{{ action.label }}{% endif %} {% endfor %} - {% if is_operator and perms.hosting.view_hostingaccount %} - Download manifest - {% endif %}