ServerKit is a lightweight, modern server control panel for managing web applications, databases, and services on your VPS or dedicated server. Built with Python/Flask backend and React frontend.
Python astracloudflarecontrol-panelcyberpaneldnsfablehosting-control-panelhosting-panelkimi-k3server-managementserverkitubuntu-web-panelwebserver
refactor(status): extract status-pages backend into serverkit-status extension
Juan Denis95681f8b8016
diff --git a/backend/app/__init__.py b/backend/app/__init__.pyindex 3ab34746..5ac08021 100644--- a/backend/app/__init__.py+++ b/backend/app/__init__.py@@ -420,9 +420,11 @@ def create_app(config_name=None):from app.api.nginx_advanced import nginx_advanced_bpapp.register_blueprint(nginx_advanced_bp, url_prefix='/api/v1/nginx/advanced')- # Register blueprints - Status Pages- from app.api.status_pages import status_pages_bp- app.register_blueprint(status_pages_bp, url_prefix='/api/v1/status')+ # Status Pages is an opt-in builtin extension (serverkit-status, plan 47) —+ # its blueprint (public + management routes) loads from builtin-extensions/+ # when installed, not from core. The StatusPage/StatusComponent models stay+ # core (G2); the WordPress health-check job reaches the extension's sync+ # helper via get_installed_extension_attr only when installed.# Cloud Provisioning is an opt-in builtin extension (serverkit-cloud-provision,# plan 47) — its blueprint loads from builtin-extensions/ when installed, not@@ -481,7 +483,9 @@ def create_app(config_name=None):app.register_blueprint(telemetry_bp, url_prefix='/api/v1/observability/events', name='obs_events')app.register_blueprint(uptime_bp, url_prefix='/api/v1/observability/uptime', name='obs_uptime')app.register_blueprint(fleet_monitor_bp, url_prefix='/api/v1/observability/fleet', name='obs_fleet')- app.register_blueprint(status_pages_bp, url_prefix='/api/v1/observability/status-pages', name='obs_status_pages')+ # status-pages observability alias dropped with the serverkit-status+ # extraction (plan 47) — it was unused by the frontend; status pages mount at+ # /api/v1/status from the extension when installed.# Register blueprints - Agent Pairing (RustDesk-style short-code flow)from app.api.pairing import pairing_bpdiff --git a/backend/app/jobs/builtin_handlers.py b/backend/app/jobs/builtin_handlers.pyindex 388e61f1..caa7119f 100644--- a/backend/app/jobs/builtin_handlers.py+++ b/backend/app/jobs/builtin_handlers.py@@ -90,10 +90,16 @@ def run_health_checks():from app.models.wordpress_site import WordPressSitefrom app.models.status_page import StatusComponentfrom app.services.environment_health_service import EnvironmentHealthService- from app.services.status_page_service import StatusPageService+ from app.services.plugin_service import get_installed_extension_attr_prune_old_health_checks()+ # Status-page component sync lives in the serverkit-status extension (plan 47);+ # reach it only when installed. StatusComponent rows can't exist without it,+ # so a lean panel simply runs the health checks without the sync.+ StatusPageService = get_installed_extension_attr(+ 'serverkit-status', 'status_page_service', 'StatusPageService')+sites = WordPressSite.query.filter_by(is_production=True).all()for site in sites:try:@@ -105,9 +111,10 @@ def run_health_checks():overall = result.get('overall_status')if not overall:continue- components = StatusComponent.query.filter_by(wordpress_site_id=site.id).all()- for comp in components:- StatusPageService.sync_component_from_health(comp, overall)+ if StatusPageService is not None:+ components = StatusComponent.query.filter_by(wordpress_site_id=site.id).all()+ for comp in components:+ StatusPageService.sync_component_from_health(comp, overall)except Exception as e:logger.error(f'Health check failed for site {site.id}: {e}')try:diff --git a/backend/tests/test_api_authz_hardening.py b/backend/tests/test_api_authz_hardening.pyindex cb865439..c1a66281 100644--- a/backend/tests/test_api_authz_hardening.py+++ b/backend/tests/test_api_authz_hardening.py@@ -248,29 +248,9 @@ def test_env_secret_masking_preserved(app, client, env_rbac):# Phase 4 — status pages (mutations admin-only, reads open) + raw docker-DB.# --------------------------------------------------------------------------- #-def test_status_page_mutations_admin_only(app, client):- """Reads stay open to any authed user; every mutation is admin-only via the- @admin_required decorator (plan 18 Decision 6). A non-admin is 403."""- from app import db- dev = _mk_user(db, 'sp_dev', role='developer')- admin = _mk_user(db, 'sp_admin', role='admin')-- # Reads are open to a plain developer.- assert client.get('/api/v1/status/', headers=_token(dev.id)).status_code == 200-- # Admin can create a page.- r = client.post('/api/v1/status/', json={'name': 'Ops', 'slug': 'ops'}, headers=_token(admin.id))- assert r.status_code == 201- page_id = r.get_json()['id']-- # A developer is denied every mutation.- assert client.post('/api/v1/status/', json={'name': 'X', 'slug': 'x'}, headers=_token(dev.id)).status_code == 403- assert client.put(f'/api/v1/status/{page_id}', json={'name': 'Y'}, headers=_token(dev.id)).status_code == 403- assert client.delete(f'/api/v1/status/{page_id}', headers=_token(dev.id)).status_code == 403- assert client.post(f'/api/v1/status/{page_id}/components', json={'name': 'c', 'check_type': 'http'},- headers=_token(dev.id)).status_code == 403- assert client.post(f'/api/v1/status/{page_id}/incidents', json={'title': 't'},- headers=_token(dev.id)).status_code == 403+# Status-page mutation authz moved to tests/test_status_extraction.py (plan 47) —+# the status blueprint now lives in the serverkit-status extension, so the test+# installs it before exercising the admin-only mutations.def test_raw_docker_db_routes_admin_only(app, client):@@ -375,11 +355,5 @@ def test_wordpress_standalone_host_ops_admin_only(app, client, scoping_rbac, perassert call(url, json={}, headers=scoping_rbac.admin).status_code != 403, f'admin denied {url}'[email protected]('persona', ['viewer', 'member', 'foreign'])-def test_status_component_check_admin_only(app, client, scoping_rbac, persona):- """#4 — `POST /status/components/<id>/check` triggers a live check + persists a- result (write-ish), so it joins its 9 admin-only mutation siblings. A non-admin- is 403; admin passes the gate (the check itself may 404 on a missing id)."""- url = '/api/v1/status/components/999999/check'- assert client.post(url, headers=getattr(scoping_rbac, persona)).status_code == 403, persona- assert client.post(url, headers=scoping_rbac.admin).status_code != 403+# test_status_component_check_admin_only moved to tests/test_status_extraction.py+# (plan 47) — the status blueprint is now in the serverkit-status extension.diff --git a/backend/tests/test_observability_namespace.py b/backend/tests/test_observability_namespace.pyindex 87012392..18ffe212 100644--- a/backend/tests/test_observability_namespace.py+++ b/backend/tests/test_observability_namespace.py@@ -15,7 +15,9 @@ def test_observability_aliases_registered():assert any(r.startswith('/api/v1/observability/events') for r in rules)assert any(r.startswith('/api/v1/observability/uptime') for r in rules)assert any(r.startswith('/api/v1/observability/fleet') for r in rules)- assert any(r.startswith('/api/v1/observability/status-pages') for r in rules)+ # The status-pages observability alias was dropped when status pages moved to+ # the serverkit-status extension (plan 47); the public status route now ships+ # with that extension rather than core.def test_original_prefixes_still_present():@@ -25,8 +27,6 @@ def test_original_prefixes_still_present():assert any(r.startswith('/api/v1/monitoring') for r in rules)assert any(r.startswith('/api/v1/telemetry') for r in rules)assert any(r.startswith('/api/v1/fleet-monitor') for r in rules)- # Public status page route untouched.- assert '/api/v1/status/public/<slug>' in rulesdef test_events_alias_matches_telemetry(app, client, auth_headers):diff --git a/backend/tests/test_status_extraction.py b/backend/tests/test_status_extraction.pynew file mode 100644index 00000000..4651bcf6--- /dev/null+++ b/backend/tests/test_status_extraction.py@@ -0,0 +1,133 @@+"""Prove the Status Pages extraction (plan 47 Phase 2).++The status-pages blueprint (public + management routes) and its service move into+serverkit-status; the StatusPage/StatusComponent models stay core (G2). Core's+WordPress health-check job syncs status components only when the extension is+installed (no crash on a lean panel). Re-homes the status-page mutation authz+test from test_api_authz_hardening.py.+"""+import importlib+import sys++import pytest+from werkzeug.security import generate_password_hash+from flask_jwt_extended import create_access_token++from app import db+from app.models.user import User+from app.models.plugin import InstalledPlugin+from app.services import plugin_service++SLUG = 'serverkit-status'+_PKG = f'app.plugins.{SLUG}'+++def test_core_has_no_status_page_routes(app):+ """The status-pages management/public routes are gone from core (the+ /api/v1/status/apps container-status aggregator is a different blueprint)."""+ rules = [r.rule for r in app.url_map.iter_rules()]+ assert '/api/v1/status/public/<slug>' not in rules+ assert '/api/v1/status/' not in rules+ assert not any('observability/status-pages' in r for r in rules)+++def test_core_import_of_status_service_gone():+ with pytest.raises(ModuleNotFoundError):+ importlib.import_module('app.services.status_page_service')+++def test_status_in_converted_builtin_slugs():+ from app.services.extension_migration import CONVERTED_BUILTIN_SLUGS+ assert SLUG in CONVERTED_BUILTIN_SLUGS+++def test_status_models_stay_core():+ from app.models.status_page import ( # noqa: F401+ StatusPage, StatusComponent)+++def test_health_check_job_no_ops_without_extension(app):+ """run_health_checks must not crash on a lean panel (no serverkit-status)."""+ from app.jobs.builtin_handlers import run_health_checks+ run_health_checks() # no production sites, no extension — clean no-op+++def install_dirs(tmp_path, monkeypatch):+ backend = tmp_path / 'plugins_backend'+ frontend = tmp_path / 'plugins_frontend'+ backend.mkdir()+ frontend.mkdir()+ monkeypatch.setattr(plugin_service, 'BACKEND_PLUGINS_DIR', str(backend))+ monkeypatch.setattr(plugin_service, 'FRONTEND_PLUGINS_DIR', str(frontend))++ added = str(backend)+ app_pkg_plugins = importlib.import_module('app.plugins')+ if added not in app_pkg_plugins.__path__:+ app_pkg_plugins.__path__.append(added)++ yield {'backend': backend, 'frontend': frontend}++ if added in app_pkg_plugins.__path__:+ app_pkg_plugins.__path__.remove(added)+ for name in list(sys.modules):+ if name == _PKG or name.startswith(_PKG + '.'):+ del sys.modules[name]+++def _mk_user(username, role):+ u = User(email=f'{username}@t.local', username=username, role=role,+ is_active=True, password_hash=generate_password_hash('x'))+ db.session.add(u)+ db.session.commit()+ return u+++def _token(uid):+ return {'Authorization': f'Bearer {create_access_token(identity=uid)}'}+++def test_install_registers_status_routes(app, client, auth_headers, install_dirs):+ plugin = plugin_service.install_builtin_extension(SLUG)+ assert plugin.status == InstalledPlugin.STATUS_ACTIVE+ assert plugin.has_backend is True+ assert plugin.url_prefix == '/api/v1/status'+ rules = [r.rule for r in app.url_map.iter_rules()]+ assert '/api/v1/status/public/<slug>' in rules+++def test_status_page_mutations_admin_only(app, client, install_dirs):+ """Reads open to any authed user; every mutation is admin-only (relocated+ from test_api_authz_hardening.py — now runs against the installed extension)."""+ plugin_service.install_builtin_extension(SLUG)+ dev = _mk_user('sp_dev', 'developer')+ admin = _mk_user('sp_admin', 'admin')++ assert client.get('/api/v1/status/', headers=_token(dev.id)).status_code == 200++ r = client.post('/api/v1/status/', json={'name': 'Ops', 'slug': 'ops'},+ headers=_token(admin.id))+ assert r.status_code == 201+ page_id = r.get_json()['id']++ assert client.post('/api/v1/status/', json={'name': 'X', 'slug': 'x'},+ headers=_token(dev.id)).status_code == 403+ assert client.put(f'/api/v1/status/{page_id}', json={'name': 'Y'},+ headers=_token(dev.id)).status_code == 403+ assert client.delete(f'/api/v1/status/{page_id}',+ headers=_token(dev.id)).status_code == 403+ assert client.post(f'/api/v1/status/{page_id}/components',+ json={'name': 'c', 'check_type': 'http'},+ headers=_token(dev.id)).status_code == 403+ assert client.post(f'/api/v1/status/{page_id}/incidents', json={'title': 't'},+ headers=_token(dev.id)).status_code == 403++[email protected]('persona', ['viewer', 'member', 'foreign'])+def test_status_component_check_admin_only(app, client, scoping_rbac, install_dirs, persona):+ """POST /status/components/<id>/check is a write-ish mutation → admin-only+ (relocated from test_api_authz_hardening.py, now against the extension)."""+ plugin_service.install_builtin_extension(SLUG)+ url = '/api/v1/status/components/999999/check'+ assert client.post(url, headers=getattr(scoping_rbac, persona)).status_code == 403, persona+ assert client.post(url, headers=scoping_rbac.admin).status_code != 403diff --git a/builtin-extensions/serverkit-status/backend/__init__.py b/builtin-extensions/serverkit-status/backend/__init__.pynew file mode 100644index 00000000..5087b60e--- /dev/null+++ b/builtin-extensions/serverkit-status/backend/__init__.py@@ -0,0 +1,16 @@+"""ServerKit Status Pages extension backend package.++Extracted from core (plan 47): the status-pages blueprint (public status/badge+routes + authenticated management API) and its service ship here so a fresh panel+that never publishes a status page loads none of it. Mounted under+``/api/v1/status`` via the manifest's ``url_prefix``; the public /status/<slug>+and /status/badge/<slug> pages work whenever the extension is installed. The+StatusPage / StatusComponent / StatusIncident / HealthCheck models stay in core+(G2). Core's WordPress health-check job reaches+``StatusPageService.sync_component_from_health`` through+``plugin_service.get_installed_extension_attr`` only when installed. Upgrades+re-acquire it automatically (``CONVERTED_BUILTIN_SLUGS``).+"""+from .status_pages import status_pages_bp++__all__ = ['status_pages_bp']diff --git a/backend/app/services/status_page_service.py b/builtin-extensions/serverkit-status/backend/status_page_service.pysimilarity index 100%rename from backend/app/services/status_page_service.pyrename to builtin-extensions/serverkit-status/backend/status_page_service.pydiff --git a/backend/app/api/status_pages.py b/builtin-extensions/serverkit-status/backend/status_pages.pysimilarity index 99%rename from backend/app/api/status_pages.pyrename to builtin-extensions/serverkit-status/backend/status_pages.pyindex 1c3042e8..491aecf1 100644--- a/backend/app/api/status_pages.py+++ b/builtin-extensions/serverkit-status/backend/status_pages.py@@ -1,6 +1,6 @@from flask import Blueprint, request, jsonifyfrom flask_jwt_extended import jwt_required-from app.services.status_page_service import StatusPageService+from .status_page_service import StatusPageServicestatus_pages_bp = Blueprint('status_pages', __name__)diff --git a/builtin-extensions/serverkit-status/plugin.json b/builtin-extensions/serverkit-status/plugin.jsonindex ed482450..425afdcf 100644--- a/builtin-extensions/serverkit-status/plugin.json+++ b/builtin-extensions/serverkit-status/plugin.json@@ -2,12 +2,14 @@"name": "serverkit-status","display_name": "Status Pages","version": "1.0.0",- "description": "Public status pages backed by uptime monitors, with the management UI as a tab in the Observability group. The public /status/<slug> page itself stays core.",+ "description": "Public status pages backed by uptime monitors, with the management UI as a tab in the Observability group. Installing the extension serves the public /status/<slug> and /status/badge/<slug> pages too.","author": "ServerKit","license": "MIT","category": "monitoring","homepage": "https://github.com/jhd3197/ServerKit","permissions": [],+ "entry_point": "status_pages:status_pages_bp",+ "url_prefix": "/api/v1/status","icon": "<circle cx=\"12\" cy=\"12\" r=\"10\"/><path d=\"M12 2a14.5 14.5 0 0 0 0 20 14.5 14.5 0 0 0 0-20\"/><path d=\"M2 12h20\"/>","contributions": {"tabs": [