From 7bc25e54c3b1e6dd4846b0d1ca6c83662b39be78 Mon Sep 17 00:00:00 2001 From: Juan Denis Date: Sun, 22 Nov 2026 02:10:36 -0500 Subject: [PATCH] Offer unmanaged host sites on Services When this server's nginx serves sites no service accounts for, Services shows an Adopt button with the count; the dialog lists each site with what was detected and adopts it in one click. The button is absent on a host with nothing to adopt, so the top bar stays quiet. Host-managed rows drop the start/stop controls and the detail page names how they are run. Part of #269. --- .../src/components/apps/AdoptSitesDialog.jsx | 131 ++++++++++++++++++ frontend/src/i18n/locales/en.json | 25 ++++ frontend/src/pages/ServiceDetail.jsx | 10 +- frontend/src/pages/Services.jsx | 50 ++++++- frontend/src/services/api/index.js | 2 + frontend/src/services/api/siteAdoption.js | 15 ++ frontend/src/styles/pages/_services.scss | 63 +++++++++ 7 files changed, 292 insertions(+), 4 deletions(-) create mode 100644 frontend/src/components/apps/AdoptSitesDialog.jsx create mode 100644 frontend/src/services/api/siteAdoption.js diff --git a/frontend/src/components/apps/AdoptSitesDialog.jsx b/frontend/src/components/apps/AdoptSitesDialog.jsx new file mode 100644 index 00000000..717f7ed0 --- /dev/null +++ b/frontend/src/components/apps/AdoptSitesDialog.jsx @@ -0,0 +1,131 @@ +import { useState } from 'react'; +import { useTranslation } from 'react-i18next'; +import api from '@/services/api'; +import Modal from '@/components/Modal'; +import { Button } from '@/components/ui/button'; +import { Pill } from '@/components/ds'; +import { useToast } from '@/contexts/useToast.js'; +import { toastError } from '@/utils/errorMessage'; + +// Sites host nginx is serving that no service accounts for. Each row shows +// what discovery found; adopting records the site as it is. Nothing on the +// server is rewritten, which the dialog says in so many words because that is +// the question anyone with a live site asks first. +export default function AdoptSitesDialog({ open, onClose, sites, onAdopted }) { + const { t } = useTranslation(); + const toast = useToast(); + const [adopting, setAdopting] = useState(null); + + const kindLabel = (site) => ({ + wordpress: t('app.services.adopt.kindWordpress', 'WordPress'), + php: t('app.services.adopt.kindPhp', 'PHP'), + static: t('app.services.adopt.kindStatic', 'Static'), + }[site.app_type] || (site.kind === 'proxy' + ? t('app.services.adopt.kindProxy', 'Proxied app') + : t('app.services.adopt.kindRedirect', 'Redirect'))); + + async function handleAdopt(site) { + setAdopting(site.id); + try { + const result = await api.adoptHostSite(site.id, { apply: true }); + toast.success(t('app.services.adopt.adopted', { + name: result?.app?.name || site.primary_domain, + defaultValue: '{{name}} is now managed. Nothing on the server was changed.', + })); + await onAdopted?.(result?.app); + } catch (err) { + toastError(toast, t('app.services.adopt.failed', "Couldn't adopt this site."), err); + } finally { + setAdopting(null); + } + } + + return ( + + {t('common.actions.close', 'Close')} + + )} + > +

+ {t('app.services.adopt.intro', 'These sites are served by this server but are not managed here yet, so they have no monitoring, backups or SSL status. Adopting one records it as it is: the nginx config, PHP-FPM pool, database and certificate are left exactly as they are.')} +

+ + +
+ ); +} diff --git a/frontend/src/i18n/locales/en.json b/frontend/src/i18n/locales/en.json index d085560d..7d5e3e2b 100644 --- a/frontend/src/i18n/locales/en.json +++ b/frontend/src/i18n/locales/en.json @@ -6005,6 +6005,7 @@ "failedToLoadVersions": "Couldn't load versions.", "failedToRollback": "Couldn't roll back.", "failedToUploadNewVersion": "Couldn't upload the new version.", + "hostManaged": "Host nginx", "loadingService": "Loading service", "loadingVersions": "Loading versions…", "localService": "Local service", @@ -6051,6 +6052,30 @@ "wordpress": "WordPress" }, "services": { + "adopt": { + "action": "Adopt", + "adopted": "{{name}} is now managed. Nothing on the server was changed.", + "adopting": "Adopting…", + "alsoServes": "Also serves", + "button": "Adopt ({{count}})", + "buttonTitle": "Sites running on this server that are not managed here yet", + "certificate": "Certificate", + "database": "Database", + "failed": "Couldn't adopt this site.", + "intro": "These sites are served by this server but are not managed here yet, so they have no monitoring, backups or SSL status. Adopting one records it as it is: the nginx config, PHP-FPM pool, database and certificate are left exactly as they are.", + "kindPhp": "PHP", + "kindProxy": "Proxied app", + "kindRedirect": "Redirect", + "kindStatic": "Static", + "kindWordpress": "WordPress", + "noCertificate": "None", + "php": "PHP-FPM", + "root": "Document root", + "title": "Adopt existing sites", + "unknownVersion": "Unknown version", + "upstream": "Proxies to", + "vhost": "nginx config" + }, "assignSelected_one": "Assign 1 selected service to a project and environment, or leave it unassigned.", "assignSelected_other": "Assign {{count}} selected services to a project and environment, or leave them unassigned.", "bulkRestartSent_one": "Restart sent to 1 service", diff --git a/frontend/src/pages/ServiceDetail.jsx b/frontend/src/pages/ServiceDetail.jsx index 2d5954d8..21b6cd90 100644 --- a/frontend/src/pages/ServiceDetail.jsx +++ b/frontend/src/pages/ServiceDetail.jsx @@ -476,7 +476,7 @@ const ServiceDetail = () => { {service.managed_by && ( <> → - {service.managed_by === 'docker_compose' ? t('app.serviceDetail.dockerCompose', 'Docker Compose') : 'systemd'} + {managedByLabel(service.managed_by, t)} )} @@ -585,6 +585,14 @@ const ServiceDetail = () => { ); }; +// How a locally registered service is run. `host` is a site that was already +// being served by this server's nginx when it was adopted. +function managedByLabel(managedBy, t) { + if (managedBy === 'docker_compose') return t('app.serviceDetail.dockerCompose', 'Docker Compose'); + if (managedBy === 'host') return t('app.serviceDetail.hostManaged', 'Host nginx'); + return 'systemd'; +} + function extractRepoDisplay(url) { if (!url) return ''; try { diff --git a/frontend/src/pages/Services.jsx b/frontend/src/pages/Services.jsx index 03a185c4..ce4c7e29 100644 --- a/frontend/src/pages/Services.jsx +++ b/frontend/src/pages/Services.jsx @@ -1,6 +1,6 @@ import { useCallback, useState, useEffect, useMemo } from 'react'; import { useNavigate, Link } from 'react-router-dom'; -import { Layers, Plus, Square, Play, RotateCw, GitBranch, FolderOpen, FileArchive, FolderKanban, ArrowDownToLine } from 'lucide-react'; +import { Layers, Plus, Square, Play, RotateCw, GitBranch, FolderOpen, FileArchive, FolderKanban, ArrowDownToLine, ScanSearch } from 'lucide-react'; import { SiGithub as Github } from 'react-icons/si'; import api from '../services/api'; import { useToast } from '../contexts/useToast.js'; @@ -23,6 +23,8 @@ import { } from '@/components/ui/select'; import Modal from '@/components/Modal'; import RequiresDocker from '../components/RequiresDocker'; +import AdoptSitesDialog from '@/components/apps/AdoptSitesDialog'; +import { useAuth } from '@/contexts/useAuth.js'; import { useTranslation } from 'react-i18next'; import { toastError } from '@/utils/errorMessage'; import { translateLabel } from '@/i18n/labels'; @@ -120,6 +122,22 @@ const Services = () => { const [bulkLoading, setBulkLoading] = useState(false); const [showMoveDialog, setShowMoveDialog] = useState(false); const [bandwidth, setBandwidth] = useState({}); + const { isAdmin } = useAuth(); + // Sites this server's nginx is serving that no service accounts for. + const [unmanagedSites, setUnmanagedSites] = useState([]); + const [showAdoptDialog, setShowAdoptDialog] = useState(false); + + // Best-effort and admin-only (the endpoint reads host config): a failure + // just means the Adopt button does not appear. + const loadUnmanagedSites = useCallback(async () => { + if (!isAdmin) return; + try { + const data = await api.getHostSites(); + setUnmanagedSites((data?.sites || []).filter((site) => !site.linked_app && site.kind !== 'redirect')); + } catch { + setUnmanagedSites([]); + } + }, [isAdmin]); const loadApps = useCallback(async () => { try { @@ -141,6 +159,10 @@ const Services = () => { .catch(() => {}); }, [loadApps]); + useEffect(() => { + loadUnmanagedSites(); + }, [loadUnmanagedSites]); + async function handleAction(e, appId, action) { e.stopPropagation(); @@ -203,6 +225,17 @@ const Services = () => { useTopbarActions(() => <> + {unmanagedSites.length > 0 && ( + + )}