From 3ea5bd4201c74ea2147e48a127076578f691c606 Mon Sep 17 00:00:00 2001 From: Maaxxs <61059039+MaaxxsDev@users.noreply.github.com> Date: Wed, 9 Sep 2026 02:16:41 +0200 Subject: [PATCH] Add one-click git-based auto-update (manual trigger only) Phase 6 of the dashboard roadmap - the largest and riskiest item, since it overwrites live production code. Pulls the current main branch from the public Gitea repo over plain HTTPS (archive zip download + REST API for commit info) and applies it to the live hifi/ tree - no SSH, git binary, exec(), or shell_exec() anywhere, so it works on plain shared PHP hosting with no CI/deploy pipeline (exactly the hosting this site actually runs on, per DEPLOY.md's manual-FTP fallback). Six independent endpoints (status/check/download/extract/backup/apply) instead of one big request, mirroring the existing multi-step SetupController pattern - this app has no job-queue infrastructure, and a single ~127MB download+extract+backup+copy is the most likely way to hit an unknown host's max_execution_time or reverse-proxy timeout. GitUpdateService.php does the actual work; UpdateController.php is a thin adapter that marks each step in-progress/failed in a new gitignored update-state.php (same convention as db.php) so a crashed step shows as failed rather than stuck, and a retry starts clean. Security-critical bits: - The backup zip necessarily contains db.php (must be fully restorable), so it lives under hifi/_update/ behind a "Require all denied" .htaccess written the instant the directory is created, and hifi/_update/ was added to .gitignore in this same commit, before any code that could write into it - both needed since a physically-existing file bypasses this app's SPA-fallback/API rewrite rules entirely. - Only hifi/'s own subtree is extracted from the archive (hifi-src/ and everything else ignored) via a wrapper-folder-prefix detected at runtime, not hardcoded. - Copy-then-prune (not copy-only) across the whole hifi/ tree, since Vite renames JS/CSS chunks on every build and a copy-only updater would let stale chunks accumulate forever - guarded by a denylist (db.php, setup.php, ga-service-account.json, update-state.php, api/uploads/, plus local Claude-tooling dirs) that must never be touched in either direction. - index.html is swapped in last via copy+rename (near-atomic), after the new hashed assets it references are already fully in place. - Reuses SchemaController's existing migration logic as the last apply step (extracted into a new runMigration() so it's callable without Http::send()/exit ending the response early) and app_settings' existing maintenance-mode column to show visitors a maintenance page during the brief apply window, restoring whatever maintenance state existed before the update ran (not just forcing it off). Gated behind a new, narrower system.update permission (not the broader settings.manage), with its own settings tab hidden from anyone lacking it - unlike this app's usual "everyone with settings.manage sees every tab" pattern, since this one can overwrite the whole site. Verified in isolation (synthetic zip + fixture directories in a scratch folder, not the real hifi/ tree): wrapper-folder detection and selective hifi/-subtree extraction, and copy+prune with denylist enforcement. Not yet verified: behavior on an actual shared-hosting target (max_execution_time, ZipArchive availability, outbound HTTPS egress, disk quota vs disk_free_space()) - per the plan, validate against the Plesk test server from DEPLOY.md before ever running this against a real client site. Also enabled the php_zip extension in the local XAMPP php.ini, since it was disabled and this feature needs it. Co-Authored-By: Claude Sonnet 5 --- .gitignore | 9 + hifi-src/src/App.jsx | 5 + .../pages/admin/settings/SettingsLayout.jsx | 10 +- .../pages/admin/settings/UpdateSettings.jsx | 197 ++++++ hifi/api/public/index.php | 10 + hifi/api/src/Controllers/SchemaController.php | 16 +- hifi/api/src/Controllers/UpdateController.php | 95 +++ hifi/api/src/Services/GitUpdateService.php | 587 ++++++++++++++++++ hifi/api/src/Support/Permissions.php | 1 + .../{index-C8YANYNU.js => index-DMjv3wnD.js} | 104 ++-- hifi/index.html | 2 +- 11 files changed, 981 insertions(+), 55 deletions(-) create mode 100644 hifi-src/src/pages/admin/settings/UpdateSettings.jsx create mode 100644 hifi/api/src/Controllers/UpdateController.php create mode 100644 hifi/api/src/Services/GitUpdateService.php rename hifi/assets/{index-C8YANYNU.js => index-DMjv3wnD.js} (77%) diff --git a/.gitignore b/.gitignore index 66a8eb5..3e7f985 100644 --- a/.gitignore +++ b/.gitignore @@ -31,6 +31,15 @@ # (wird vom Admin-Panel automatisch neu geschrieben, enthält einen privaten Schlüssel) /hifi/api/config/ga-service-account.json +# Merkt sich den aktuell installierten Git-Commit fürs Auto-Update-Feature +# (GitUpdateService) - pro Umgebung unterschiedlich, wird automatisch geschrieben. +/hifi/api/config/update-state.php + +# Arbeits-/Backup-Verzeichnis des Auto-Update-Features. Die Backup-ZIPs darin enthalten +# zwangsläufig db.php (siehe oben) - darf NIE ins Repo gelangen, sonst landen +# Datenbank-Zugangsdaten im (öffentlichen!) Git-Repo. +/hifi/_update/ + # Claude-Code-Tooling (Skills/lokale Einstellungen) - gehört nicht zum Website-Projekt /hifi/.claude/ /hifi/.agents/ diff --git a/hifi-src/src/App.jsx b/hifi-src/src/App.jsx index f580a70..4b1c5a7 100644 --- a/hifi-src/src/App.jsx +++ b/hifi-src/src/App.jsx @@ -40,6 +40,7 @@ import PermissionGroups from './pages/admin/PermissionGroups.jsx'; import SettingsLayout from './pages/admin/settings/SettingsLayout.jsx'; import WebsiteSettings from './pages/admin/settings/WebsiteSettings.jsx'; import LegalSettings from './pages/admin/settings/LegalSettings.jsx'; +import UpdateSettings from './pages/admin/settings/UpdateSettings.jsx'; import EmailSettings from './pages/admin/settings/EmailSettings.jsx'; import DatabaseSettings from './pages/admin/settings/DatabaseSettings.jsx'; import ExportImportSettings from './pages/admin/settings/ExportImportSettings.jsx'; @@ -100,6 +101,10 @@ export default function App() { } /> } /> } /> + } + /> } /> diff --git a/hifi-src/src/pages/admin/settings/SettingsLayout.jsx b/hifi-src/src/pages/admin/settings/SettingsLayout.jsx index 590be8d..14f7830 100644 --- a/hifi-src/src/pages/admin/settings/SettingsLayout.jsx +++ b/hifi-src/src/pages/admin/settings/SettingsLayout.jsx @@ -1,4 +1,5 @@ import { NavLink, Outlet } from 'react-router-dom'; +import { useAuth } from '../../../context/AuthContext.jsx'; const tabs = [ { to: '/admin/settings/website', label: 'Website' }, @@ -7,10 +8,17 @@ const tabs = [ { to: '/admin/settings/database', label: 'Datenbank' }, { to: '/admin/settings/export-import', label: 'Export & Import' }, { to: '/admin/settings/maintenance', label: 'Wartungsmodus' }, + // Eigene, engere Berechtigung (ueberschreibt Live-Code) statt nur der allgemeinen + // settings.manage-Sperre um den ganzen Bereich - anders als die restlichen Tabs hier + // gefiltert, nicht jeder mit Zugriff auf "Einstellungen" soll das automatisch sehen. + { to: '/admin/settings/update', label: 'Updates', permission: 'system.update' }, { to: '/admin/settings/reset', label: 'Zurücksetzen' }, ]; export default function SettingsLayout() { + const { hasPermission } = useAuth(); + const visibleTabs = tabs.filter((tab) => !tab.permission || hasPermission(tab.permission)); + const tabClass = ({ isActive }) => `rounded-md px-4 py-2 text-sm font-medium transition ${ isActive @@ -25,7 +33,7 @@ export default function SettingsLayout() { Werkzeuge rund um Datenbank, Server-Umzug und Zurücksetzen dieser Seite.