diff --git a/docs/deployment.md b/docs/deployment.md index bb70586..5ca0bbf 100644 --- a/docs/deployment.md +++ b/docs/deployment.md @@ -2888,8 +2888,9 @@ sudo systemctl enable --now coulobre-operator-apply.socket \ ``` To enable APT actions, set `COULOBRE_SERVER_PACKAGE_UPDATES=1` in -`/etc/coulobre/panel.env`. Open **System → Updates → Server package updates** -and request a preview. The receiver refreshes package indexes and records the +`/etc/coulobre/panel.env` and restart `coulobre-panel`. Open +**System → Updates → Server packages** and check for updates. The receiver +refreshes package indexes and records the proposed versions. Applying a preview requires confirmation and a fresh matching package plan. Use the job history and the host's package logs to review the result. diff --git a/src/coulobre/hosting/operator_tools.py b/src/coulobre/hosting/operator_tools.py index c68510b..b34952f 100644 --- a/src/coulobre/hosting/operator_tools.py +++ b/src/coulobre/hosting/operator_tools.py @@ -2,11 +2,14 @@ from datetime import timedelta from pathlib import Path from django import forms +from django.conf import settings from django.contrib import messages +from django.contrib.auth import get_user_model from django.db import DatabaseError, connection, transaction from django.shortcuts import redirect from django.utils import timezone from django.utils.decorators import method_decorator +from django.utils.functional import cached_property from django.views.decorators.cache import never_cache from django.views.generic import FormView, TemplateView @@ -20,15 +23,24 @@ from coulobre.operator_node import ( from .account_administration import OperatorAuthorization from .models import OperatorOperation -from .tasks import run_operator_operation +from .tasks import OPERATOR_OPERATION_LEASE, run_operator_operation from .update_views import inspect_linked_nodes ACTION_LABELS = { - "package-preview": "Review available updates", + "package-preview": "Check for package updates", "package-upgrade": "Apply reviewed updates", } +def package_operation_pending(job): + return ( + job is not None + and job.finished_at is None + and (job.started_at or job.requested_at) + > timezone.now() - OPERATOR_OPERATION_LEASE + ) + + def queue_operator_request(user, spec, *, source=None): job = OperatorOperation.objects.create( actor=user, @@ -78,64 +90,73 @@ class ServerUpdateForm(forms.Form): return data +@method_decorator(never_cache, name="dispatch") class ServerUpdatesView(OperatorAuthorization, FormView): form_class = ServerUpdateForm template_name = "hosting/server_updates.html" - def preview(self): - return ( - OperatorOperation.objects.filter( - action="package-preview", - actor=self.request.user, - problem="", - finished_at__gte=timezone.now() - timedelta(minutes=15), - ) - .order_by("-pk") - .first() - ) + def package_jobs(self): + return OperatorOperation.objects.filter( + action__in=ACTION_LABELS + ).order_by("-pk") + + @cached_property + def latest(self): + return self.package_jobs().filter(actor=self.request.user).first() + + def preview(self, job): + if ( + job is not None + and job.action == "package-preview" + and not job.problem + and job.finished_at is not None + and job.finished_at >= timezone.now() - timedelta(minutes=15) + ): + return job + return None def get_form_kwargs(self): - return super().get_form_kwargs() | {"preview": self.preview()} + kwargs = super().get_form_kwargs() + return kwargs | {"preview": self.preview(self.latest)} def get_context_data(self, **kwargs): + latest = self.latest return super().get_context_data( available=Path(SOCKET).is_socket(), - jobs=OperatorOperation.objects.filter( - action__in=ACTION_LABELS - ).order_by("-pk")[:20], + enabled=settings.SERVER_PACKAGE_UPDATES, + latest=latest, + pending=package_operation_pending(latest), + jobs=self.package_jobs().select_related("actor")[:20], **kwargs, ) @transaction.atomic def form_valid(self, form): - if not Path(SOCKET).is_socket(): + if not settings.SERVER_PACKAGE_UPDATES or not Path(SOCKET).is_socket(): + return self.form_invalid(form) + # Serialize an operator's submissions before checking the plan. + user = self.request.user + get_user_model().objects.select_for_update().get(pk=user.pk) + latest = self.package_jobs().filter(actor=user).first() + if package_operation_pending(latest): + return redirect(self.request.path) + spec = form.spec + preview = form.preview if spec.action == "package-upgrade" else None + if preview is not None and ( + self.preview(latest) != preview + or not preview.result.get("count") + or OperatorOperation.objects.filter(source=preview).exists() + ): form.add_error( None, - "Enable the local operator service before requesting " - "an operation.", + "Check for updates and review the current package list.", ) return self.form_invalid(form) - spec = form.spec - if form.preview is not None and spec.action == "package-upgrade": - OperatorOperation.objects.select_for_update().get( - pk=form.preview.pk - ) - recent = OperatorOperation.objects.filter( - source=form.preview - ).exists() - if recent: - form.add_error( - None, - "Collect a new preview before starting another " - "package update.", - ) - return self.form_invalid(form) queue_operator_request( - self.request.user, + user, spec, - source=form.preview if spec.action == "package-upgrade" else None, + source=preview, ) - messages.success(self.request, "Host operation queued.") return redirect(self.request.path) diff --git a/src/coulobre/hosting/static/hosting/panel-icons.svg b/src/coulobre/hosting/static/hosting/panel-icons.svg new file mode 100644 index 0000000..ff4b454 --- /dev/null +++ b/src/coulobre/hosting/static/hosting/panel-icons.svg @@ -0,0 +1,75 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/coulobre/hosting/static/hosting/panel-live-status.js b/src/coulobre/hosting/static/hosting/panel-live-status.js index 78aa7d5..fab3f1a 100644 --- a/src/coulobre/hosting/static/hosting/panel-live-status.js +++ b/src/coulobre/hosting/static/hosting/panel-live-status.js @@ -3,15 +3,18 @@ const liveRegions = [...document.querySelectorAll("[data-live-status]")]; let statusRefreshTimer; let statusRefreshStopped = false; +let statusRefreshRunning = false; function scheduleStatusRefresh() { clearTimeout(statusRefreshTimer); - if (!document.hidden && !statusRefreshStopped) { - statusRefreshTimer = setTimeout(refreshStatus, 15_000); + if (!document.hidden && !statusRefreshStopped && !statusRefreshRunning) { + const pending = document.querySelector("[data-live-pending]"); + statusRefreshTimer = setTimeout(refreshStatus, pending ? 2_000 : 15_000); } } async function refreshStatus() { + statusRefreshRunning = true; try { const response = await fetch(location.href, { headers: {"X-Coulobre-Status": "1"}, @@ -32,8 +35,15 @@ async function refreshStatus() { for (const region of liveRegions) { const next = refreshed.get(region.dataset.liveStatus); if (!next || region.contains(document.activeElement) || - region.querySelector("details[open], form input:checked") || - region.innerHTML === next.innerHTML) { + region.querySelector("details[open]:not([data-live-detail]), form input:checked")) { + continue; + } + const openDetails = new Set([...region.querySelectorAll("details[open][data-live-detail]")] + .map(detail => detail.dataset.liveDetail)); + for (const detail of next.querySelectorAll("details[data-live-detail]")) { + detail.open = openDetails.has(detail.dataset.liveDetail); + } + if (region.innerHTML === next.innerHTML) { continue; } const scrollPositions = [...region.querySelectorAll(".table-scroll")] @@ -46,6 +56,7 @@ async function refreshStatus() { } catch { // The current readings remain visible if a refresh fails. } finally { + statusRefreshRunning = false; scheduleStatusRefresh(); } } diff --git a/src/coulobre/hosting/static/hosting/panel-navigation.js b/src/coulobre/hosting/static/hosting/panel-navigation.js index 9b54114..18b05fd 100644 --- a/src/coulobre/hosting/static/hosting/panel-navigation.js +++ b/src/coulobre/hosting/static/hosting/panel-navigation.js @@ -31,6 +31,23 @@ navigation.addEventListener("keydown", (event) => { compactLayout.addEventListener("change", updateMenuLayout); updateMenuLayout(); +const roleSwitch = document.querySelector("[data-role-switch]"); +if (roleSwitch) { + const picker = roleSwitch.querySelector("select"); + const currentRole = picker.value; + roleSwitch.classList.add("role-switch-on-change"); + roleSwitch.querySelector("button").hidden = true; + picker.setAttribute("aria-label", "Panel role (switches when selected)"); + picker.addEventListener("change", () => { + if (picker.value !== currentRole) { + roleSwitch.requestSubmit(); + } + }); + window.addEventListener("pageshow", () => { + picker.value = currentRole; + }); +} + const accountTabs = document.querySelector("[data-account-tabs]"); if (accountTabs) { const panels = [...document.querySelectorAll("[data-account-section]")]; diff --git a/src/coulobre/hosting/static/hosting/panel.css b/src/coulobre/hosting/static/hosting/panel.css index 52c484a..d3152e1 100644 --- a/src/coulobre/hosting/static/hosting/panel.css +++ b/src/coulobre/hosting/static/hosting/panel.css @@ -142,7 +142,6 @@ button, input, select, textarea { display: flex; height: 100dvh; flex-direction: column; - overflow-y: auto; padding: 1.65rem 1.1rem 1.1rem; background: linear-gradient(160deg, var(--sidebar-gradient), var(--sidebar) 55%); color: var(--sidebar-text); @@ -196,6 +195,17 @@ button, input, select, textarea { margin-top: 1.4rem; } +@media (min-width: 781px) { + .navigation { + min-height: 0; + align-content: start; + overflow-y: auto; + overscroll-behavior: contain; + padding: 0.15rem; + scrollbar-width: thin; + } +} + .navigation a { display: flex; align-items: center; @@ -245,175 +255,35 @@ button, input, select, textarea { display: none; } -.nav-icon { - display: inline-block; +.nav-icon, +.sidebar-icon-action svg { + display: block; width: 1rem; - height: 0.85rem; - flex: 0 0 auto; - border: 1px solid currentColor; - border-radius: 2px; + height: 1rem; + flex: 0 0 1rem; + fill: none; + stroke: currentColor; + stroke-width: 1.6px; + stroke-linecap: round; + stroke-linejoin: round; +} + +.nav-icon { color: var(--sidebar-icon); } -.nav-icon-accounts { - background: linear-gradient(currentColor, currentColor) center / 100% 1px no-repeat; -} - -.nav-icon-plans { - width: 0.8rem; - height: 1rem; - margin-inline: 0.1rem; - background: - linear-gradient(currentColor, currentColor) center 35% / 55% 1px no-repeat, - linear-gradient(currentColor, currentColor) center 65% / 55% 1px no-repeat; -} - -.nav-icon-packages { - background: linear-gradient(currentColor, currentColor) center 35% / 40% 1px no-repeat; -} - -.nav-icon-resellers { - background: - linear-gradient(currentColor, currentColor) center 35% / 55% 1px no-repeat, - linear-gradient(currentColor, currentColor) center 65% / 75% 1px no-repeat; -} - -.nav-icon-health { - background: - linear-gradient(currentColor, currentColor) 25% bottom / 1px 40% no-repeat, - linear-gradient(currentColor, currentColor) center bottom / 1px 70% no-repeat, - linear-gradient(currentColor, currentColor) 75% bottom / 1px 55% no-repeat; -} - -.nav-icon-information { - display: grid; - place-content: center; - border-radius: 50%; - font-size: 0.7rem; - font-weight: 700; -} - -.nav-icon-customers { - position: relative; - height: 0.46rem; - margin-top: 0.47rem; - border-radius: 0.4rem 0.4rem 2px 2px; -} - -.nav-icon-customers::before { - position: absolute; - left: 50%; - bottom: calc(100% + 2px); - width: 0.39rem; - height: 0.39rem; - transform: translateX(-50%); - border: 1px solid currentColor; - border-radius: 50%; - content: ""; -} - -.nav-icon-mail { - background: - linear-gradient(35deg, transparent 47%, currentColor 50%, transparent 54%) left top / 50% 68% no-repeat, - linear-gradient(-35deg, transparent 47%, currentColor 50%, transparent 54%) right top / 50% 68% no-repeat; -} - -.nav-icon-network { - height: 1rem; - border-radius: 50%; - background: - linear-gradient(currentColor, currentColor) center / 100% 1px no-repeat, - linear-gradient(currentColor, currentColor) center / 1px 100% no-repeat; -} - -.nav-icon-lock { - position: relative; - height: 0.66rem; - margin-top: 0.35rem; -} - -.nav-icon-lock::before { - position: absolute; - inset: auto 19% 100%; - height: 0.36rem; - border: 1px solid currentColor; - border-radius: 0.6rem 0.6rem 0 0; - content: ""; -} - -.nav-icon-database { - height: 1rem; - border-radius: 50% / 22%; - background: - linear-gradient(currentColor, currentColor) center 35% / 100% 1px no-repeat, - linear-gradient(currentColor, currentColor) center 70% / 100% 1px no-repeat; -} - -.nav-icon-folder { - position: relative; - height: 0.68rem; - margin-top: 0.2rem; -} - -.nav-icon-folder::before { - position: absolute; - inset: auto auto 100% -1px; - width: 0.45rem; - height: 0.24rem; - border: 1px solid currentColor; - border-radius: 2px 2px 0 0; - content: ""; -} - -.nav-icon-settings { - border: 1px dashed currentColor; - border-radius: 50%; - background: radial-gradient(circle, transparent 21%, currentColor 23% 34%, transparent 36%); -} - -.nav-icon-appearance { - border-radius: 50%; - background: linear-gradient(90deg, currentColor 50%, transparent 50%); -} - -.nav-icon-archive { - background: - linear-gradient(currentColor, currentColor) center 28% / 100% 1px no-repeat, - linear-gradient(currentColor, currentColor) center 63% / 38% 1px no-repeat; -} - -.nav-icon-clock { - height: 1rem; - border-radius: 50%; - background: - linear-gradient(currentColor, currentColor) center 27% / 1px 30% no-repeat, - linear-gradient(currentColor, currentColor) 71% center / 30% 1px no-repeat; -} - -.nav-icon-transfer { - border-width: 0 0 1px; - border-radius: 0; - background: linear-gradient(currentColor, currentColor) left 35% / 88% 1px no-repeat; - position: relative; -} - -.nav-icon-transfer::before { - position: absolute; - right: 0.1rem; - top: 0.04rem; - width: 0.4rem; - height: 0.4rem; - transform: rotate(45deg); - border-top: 1px solid currentColor; - border-right: 1px solid currentColor; - content: ""; +.navigation a:hover .nav-icon, +.navigation a[aria-current] .nav-icon { + color: currentColor; } .sidebar-account { display: grid; + grid-template-columns: minmax(0, 1fr); gap: 0.55rem; + flex: 0 0 auto; margin-top: auto; - padding-top: 0.85rem; + padding-top: 0.7rem; border-top: 1px solid var(--sidebar-divider); font-size: 0.88rem; } @@ -465,6 +335,10 @@ a.sidebar-identity:hover { font-size: 0.82rem; } +.panel-role-switch.role-switch-on-change { + display: block; +} + .panel-role-switch select { width: 100%; min-width: 0; @@ -494,6 +368,13 @@ a.sidebar-identity:hover { color: var(--sidebar-text); } +.sidebar-icon-action { + display: grid; + width: 2.2rem; + padding: 0; + place-items: center; +} + .appearance-control { min-width: 2.2rem; font-size: 1rem; @@ -616,6 +497,11 @@ h2 { overflow-wrap: anywhere; } +.package-controls { + display: grid; + gap: 0.75rem; +} + .update-release { padding: 0.75rem 0.9rem; border: 1px solid var(--line); diff --git a/src/coulobre/hosting/tasks.py b/src/coulobre/hosting/tasks.py index f4a5cd7..3998d13 100644 --- a/src/coulobre/hosting/tasks.py +++ b/src/coulobre/hosting/tasks.py @@ -123,6 +123,7 @@ from .website_jobs import ( REDISPATCH_AFTER = timedelta(minutes=5) ACCOUNT_BACKUP_LEASE = timedelta(seconds=BACKUP_TIMEOUT_SECONDS + 60) ACCOUNT_RESTORE_LEASE = timedelta(seconds=RESTORE_TIMEOUT_SECONDS + 60) +OPERATOR_OPERATION_LEASE = timedelta(minutes=35) ACCOUNT_BACKUP_QUEUE = "coulobre-account-backups" UNCONFIRMED_RESTORE = ( "Could not confirm the restore on the local backup node. " @@ -1338,7 +1339,7 @@ def run_operator_operation(job_id): apply, "The operator service did not report a result. " "Check the service journal.", - lease=timedelta(minutes=35), + lease=OPERATOR_OPERATION_LEASE, ) diff --git a/src/coulobre/hosting/templates/hosting/account_list.html b/src/coulobre/hosting/templates/hosting/account_list.html index 4ba9c21..d76e801 100644 --- a/src/coulobre/hosting/templates/hosting/account_list.html +++ b/src/coulobre/hosting/templates/hosting/account_list.html @@ -27,12 +27,7 @@ {% endblock %} {% block page_content %} - {% if health_summary %} -
-

{% if not health_summary.configured %}Service checks need setup.{% elif health_summary.needs_attention %}{{ health_summary.needs_attention }} of {{ health_summary.configured }} service checks need attention.{% else %}All {{ health_summary.configured }} service checks are healthy.{% endif %}

- Service health -
- {% elif is_reseller %} + {% if is_reseller %}

Manage the logins for your assigned customers.

My customers diff --git a/src/coulobre/hosting/templates/hosting/base.html b/src/coulobre/hosting/templates/hosting/base.html index 5d23ec2..eb73888 100644 --- a/src/coulobre/hosting/templates/hosting/base.html +++ b/src/coulobre/hosting/templates/hosting/base.html @@ -1,15 +1,15 @@ -{% load static %} +{% load static panel_assets %} {% block title %}Coulobre Panel{% endblock %} - + {% if custom_panel_theme %}{% endif %} {% if has_user_theme %}{% endif %} {% block extra_styles %}{% endblock %} - + {% if request.user.is_authenticated and not auth_screen %} @@ -27,6 +27,7 @@ {% include "hosting/workspace_navigation.html" %} @@ -83,7 +86,7 @@ {% block content %}{% endblock %} - + {% block extra_scripts %}{% endblock %} {% else %} {% block public_content %}{% endblock %} diff --git a/src/coulobre/hosting/templates/hosting/operator_operation_history.html b/src/coulobre/hosting/templates/hosting/operator_operation_history.html index 118c97f..c840cbe 100644 --- a/src/coulobre/hosting/templates/hosting/operator_operation_history.html +++ b/src/coulobre/hosting/templates/hosting/operator_operation_history.html @@ -1,8 +1,8 @@

Operation history

{% for job in jobs %} -
- {{ job.requested_at|date:"j M Y H:i" }} UTC · {{ job.action|capfirst }}{% if job.target %} {{ job.target }}{% endif %} · {{ job.state|capfirst }} +
+ {{ job.requested_at|date:"j M Y H:i" }} UTC · {% if job.action == 'package-preview' %}Package check{% elif job.action == 'package-upgrade' %}Package update{% else %}{{ job.action|capfirst }}{% endif %}{% if job.target %} {{ job.target }}{% endif %} · {% if job.state == 'configured' %}Completed{% else %}{{ job.state|capfirst }}{% endif %} {% if job.actor %}

Requested by {{ job.actor }}

{% endif %} {% if job.problem %}

{{ job.problem }}

{% endif %} {% if job.action == 'package-preview' and job.result.fingerprint %} diff --git a/src/coulobre/hosting/templates/hosting/server_updates.html b/src/coulobre/hosting/templates/hosting/server_updates.html index 720e483..f0b474c 100644 --- a/src/coulobre/hosting/templates/hosting/server_updates.html +++ b/src/coulobre/hosting/templates/hosting/server_updates.html @@ -1,33 +1,63 @@ {% extends "hosting/update_workspace.html" %} {% block title %}Server package updates · Coulobre Panel{% endblock %} {% block page_content %} -
- {% if available %} -
- {% csrf_token %} - -
- {{ form.non_field_errors }} - {{ form.action.errors }} - {% if form.preview.result.count %} -
- {% csrf_token %} - {{ form.preview_id }} - {{ form.preview_id.errors }} -
    - {% for package in form.preview.result.packages %}
  • {{ package }}
  • {% endfor %} -
-
- - {{ form.confirm.errors }} -
- -
+
+

Package updates

+
+ {% if not enabled %} +

Server package updates are disabled. To enable them, set + COULOBRE_SERVER_PACKAGE_UPDATES=1 in + /etc/coulobre/panel.env and restart + coulobre-panel.

+ {% elif not available %} +

The local operator service is unavailable.

+ {% elif pending %} +

+ {% if latest.action == 'package-preview' %} + {% if latest.started_at %}Checking for package updates…{% else %}Package check queued.{% endif %} + {% else %} + {% if latest.started_at %}Applying package updates…{% else %}Package update queued.{% endif %} + {% endif %} +

+ {% elif latest and not latest.finished_at %} +

The operator service did not report a result. Check its journal before retrying.

+ {% elif latest.problem %} +

{% if latest.action == 'package-preview' %}Package check failed.{% else %}Package update failed.{% endif %} + {{ latest.problem }}

+ {% elif latest.action == 'package-upgrade' %} +

Package update complete. {{ latest.result.upgrades_remaining }} update{{ latest.result.upgrades_remaining|pluralize }} remaining.

+ {% elif latest.action == 'package-preview' and not latest.result.count %} +

No package updates are available.

+ {% elif form.preview %} +

{{ form.preview.result.count }} package update{{ form.preview.result.count|pluralize }} ready to review.

+ {% elif latest %} +

The package review expired. Check again for the current list.

{% else %} - {% if form.preview %}

No packages are ready to update.

{% endif %} - {{ form.preview_id.errors }} +

Check for available operating system and service package updates.

{% endif %} - {% else %}

Enable the operator service on the host to review server updates.

{% endif %} +
+ {% if form.errors %}{% endif %} + {% if available and enabled %} +
+
+ {% csrf_token %} + +
+ {% if form.preview.result.count %} +
+ {% csrf_token %} + {{ form.preview_id }} +
    + {% for package in form.preview.result.packages %}
  • {{ package }}
  • {% endfor %} +
+
+ +
+ +
+ {% endif %} +
+ {% endif %}
{% include "hosting/operator_operation_history.html" %} {% endblock %} diff --git a/src/coulobre/hosting/templates/hosting/service_health.html b/src/coulobre/hosting/templates/hosting/service_health.html index 0f2b2f5..5390f8a 100644 --- a/src/coulobre/hosting/templates/hosting/service_health.html +++ b/src/coulobre/hosting/templates/hosting/service_health.html @@ -11,7 +11,7 @@

{{ node.node }}

- {% if node.transport == 'local' %}Local{% else %}Remote{% endif %} + {% if node.transport == 'local' %}Local{% else %}Remote · monitoring only{% endif %}
@@ -40,7 +40,7 @@ - {% else %}—{% endif %} + {% else %}Manage on host{% endif %} {% endif %} diff --git a/src/coulobre/hosting/templates/hosting/workspace_navigation.html b/src/coulobre/hosting/templates/hosting/workspace_navigation.html index 7c81a6a..7aac246 100644 --- a/src/coulobre/hosting/templates/hosting/workspace_navigation.html +++ b/src/coulobre/hosting/templates/hosting/workspace_navigation.html @@ -1,9 +1,11 @@ +{% load panel_assets %} +{% panel_asset 'hosting/panel-icons.svg' as panel_icons %} {% for title, entries in navigation_groups %}