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
Backend fixes, API renames, and style utilities
Juan Denis9138a8b178d0
diff --git a/backend/app/__init__.py b/backend/app/__init__.pyindex f9616a5d..1abe149e 100644--- a/backend/app/__init__.py+++ b/backend/app/__init__.py@@ -12,6 +12,12 @@ from config import configdb = SQLAlchemy()jwt = JWTManager()migrate = Migrate()++# PyJWT 2.10+ enforces that 'sub' must be a string.+# Stringify the identity so integer user IDs work transparently.[email protected]_identity_loader+def _user_identity(user_id):+ return str(user_id)limiter = Limiter(key_func=get_remote_address, default_limits=["100 per minute"])# Note: key_func is updated to get_rate_limit_key after app initsocketio = Nonediff --git a/backend/app/middleware/security.py b/backend/app/middleware/security.pyindex 20a2ce5b..d592153b 100644--- a/backend/app/middleware/security.py+++ b/backend/app/middleware/security.py@@ -21,15 +21,27 @@ def register_security_headers(app: Flask):response.headers['Referrer-Policy'] = 'strict-origin-when-cross-origin'# Content Security Policy- csp_directives = [- "default-src 'self'",- "script-src 'self'",- "style-src 'self'",- "img-src 'self' data: https:",- "font-src 'self'",- "connect-src 'self' ws: wss:",- "frame-ancestors 'none'",- ]+ # In debug mode, allow inline styles/scripts for Vite dev tooling+ if app.debug:+ csp_directives = [+ "default-src 'self'",+ "script-src 'self' 'unsafe-inline'",+ "style-src 'self' 'unsafe-inline'",+ "img-src 'self' data: https:",+ "font-src 'self'",+ "connect-src 'self' ws: wss: http://localhost:* http://127.0.0.1:*",+ "frame-ancestors 'none'",+ ]+ else:+ csp_directives = [+ "default-src 'self'",+ "script-src 'self'",+ "style-src 'self'",+ "img-src 'self' data: https:",+ "font-src 'self'",+ "connect-src 'self' ws: wss:",+ "frame-ancestors 'none'",+ ]response.headers['Content-Security-Policy'] = '; '.join(csp_directives)# Permissions Policy (formerly Feature-Policy)diff --git a/backend/app/models/cloud_server.py b/backend/app/models/cloud_server.pyindex fc692fd4..a033d7ac 100644--- a/backend/app/models/cloud_server.py+++ b/backend/app/models/cloud_server.py@@ -73,11 +73,11 @@ class CloudServer(db.Model):snapshots = db.relationship('CloudSnapshot', backref='server', lazy='dynamic', cascade='all, delete-orphan')@property- def metadata(self):+ def server_metadata(self):return json.loads(self.metadata_json) if self.metadata_json else {}- @metadata.setter- def metadata(self, v):+ @server_metadata.setter+ def server_metadata(self, v):self.metadata_json = json.dumps(v)def to_dict(self):diff --git a/backend/app/services/cloud_provisioning_service.py b/backend/app/services/cloud_provisioning_service.pyindex af90cd8b..8b99593a 100644--- a/backend/app/services/cloud_provisioning_service.py+++ b/backend/app/services/cloud_provisioning_service.py@@ -119,7 +119,7 @@ class CloudProvisioningService:db.session.commit()except Exception as e:server.status = CloudServer.STATUS_ERROR- server.metadata = {'error': str(e)}+ server.server_metadata = {'error': str(e)}db.session.commit()raisediff --git a/backend/app/services/migration_service.py b/backend/app/services/migration_service.pyindex a8f438ac..8e4612a6 100644--- a/backend/app/services/migration_service.py+++ b/backend/app/services/migration_service.py@@ -31,24 +31,62 @@ class MigrationService:cfg.set_main_option('sqlalchemy.url', app.config['SQLALCHEMY_DATABASE_URI'])return cfg+ # Map SQLAlchemy type names to SQLite-compatible type strings+ _TYPE_MAP = {+ 'INTEGER': 'INTEGER', 'BIGINTEGER': 'INTEGER', 'SMALLINTEGER': 'INTEGER',+ 'FLOAT': 'REAL', 'NUMERIC': 'REAL',+ 'BOOLEAN': 'BOOLEAN',+ 'DATETIME': 'DATETIME', 'DATE': 'DATE', 'TIME': 'TIME',+ 'TEXT': 'TEXT', 'STRING': 'TEXT', 'VARCHAR': 'TEXT',+ 'JSON': 'TEXT',+ }++ @classmethod+ def _sqlite_type(cls, sa_type):+ """Convert a SQLAlchemy column type to a SQLite type string."""+ type_name = type(sa_type).__name__.upper()+ return cls._TYPE_MAP.get(type_name, 'TEXT')+@classmethoddef _fix_missing_columns(cls, db):- """Add columns that may be missing from existing tables.+ """Sync database schema with ORM models.+ Compares every model column against the actual database and adds any+ that are missing. Also creates tables that don't exist yet.Runs raw SQL before any ORM queries to prevent crashes when modelsreference columns that don't exist in the database yet."""inspector = sa_inspect(db.engine)- existing_tables = inspector.get_table_names()-- if 'users' in existing_tables:- cols = {c['name'] for c in inspector.get_columns('users')}- if 'auth_provider' not in cols:- logger.info('Adding missing column: users.auth_provider')- with db.engine.begin() as conn:- conn.execute(text(- "ALTER TABLE users ADD COLUMN auth_provider VARCHAR(50) DEFAULT 'local'"- ))+ existing_tables = set(inspector.get_table_names())+ added = 0++ for table_name, table_obj in db.metadata.tables.items():+ if table_name not in existing_tables:+ # Entire table is missing — create_all will handle it later+ continue++ existing_cols = {c['name'] for c in inspector.get_columns(table_name)}++ for col in table_obj.columns:+ if col.name in existing_cols:+ continue++ sqlite_type = cls._sqlite_type(col.type)+ sql = f'ALTER TABLE {table_name} ADD COLUMN {col.name} {sqlite_type}'++ try:+ with db.engine.begin() as conn:+ conn.execute(text(sql))+ logger.info(f'Auto-added missing column: {table_name}.{col.name} ({sqlite_type})')+ added += 1+ except Exception as e:+ logger.warning(f'Failed to add {table_name}.{col.name}: {e}')++ # Create any entirely new tables+ db.create_all()++ if added:+ logger.info(f'Schema sync complete: {added} column(s) added')@classmethoddef check_and_prepare(cls, app):diff --git a/backend/app/utils/system.py b/backend/app/utils/system.pyindex 88047f3a..0c2cce60 100644--- a/backend/app/utils/system.py+++ b/backend/app/utils/system.py@@ -66,6 +66,23 @@ def run_privileged(cmd: Union[List[str], str], *, user: Optional[str] = None, **return subprocess.run(cmd, **kwargs)+def run_command(cmd: Union[List[str], str], *, timeout: int = 60,+ capture_stderr: bool = False, **kwargs) -> dict:+ """Run a shell command and return a dict with stdout/stderr/returncode.++ This is a convenience wrapper used by services that need simple dict results+ rather than a raw ``CompletedProcess`` object.+ """+ kwargs.setdefault('capture_output', True)+ kwargs.setdefault('text', True)+ result = subprocess.run(cmd, timeout=timeout, **kwargs)+ return {+ 'stdout': result.stdout or '',+ 'stderr': result.stderr or '',+ 'returncode': result.returncode,+ }++def is_command_available(cmd: str) -> bool:"""Check whether *cmd* is available on the system.diff --git a/frontend/src/pages/ApplicationDetail.jsx b/frontend/src/pages/ApplicationDetail.jsxindex 06660aa9..05a34f03 100644--- a/frontend/src/pages/ApplicationDetail.jsx+++ b/frontend/src/pages/ApplicationDetail.jsx@@ -1425,7 +1425,7 @@ const DeployTab = ({ appId, appPath }) => {postDeployScript: configRes.config.post_deploy_script || ''});try {- const statusRes = await api.getGitStatus(appId);+ const statusRes = await api.getAppGitStatus(appId);setGitStatus(statusRes);} catch (e) {}} else {@@ -1474,7 +1474,7 @@ const DeployTab = ({ appId, appPath }) => {setDeploying(true);setError(null);try {- const result = await api.triggerDeploy(appId, force);+ const result = await api.triggerAppDeploy(appId, force);if (result.success) {toast.success('Deployment completed successfully!');} else {diff --git a/frontend/src/pages/Git.jsx b/frontend/src/pages/Git.jsxindex c65d492c..cd9b3784 100644--- a/frontend/src/pages/Git.jsx+++ b/frontend/src/pages/Git.jsx@@ -94,7 +94,7 @@ function Git() {const loadStatus = async () => {try {- const data = await api.getGitStatus();+ const data = await api.getGitServerStatus();setStatus(data);} catch (error) {console.error('Failed to load status:', error);@@ -367,7 +367,7 @@ function Git() {const handleTriggerDeploy = async (appId) => {setDeployingAppId(appId);try {- const result = await api.triggerDeploy(appId);+ const result = await api.triggerGitDeploy(appId);if (result.success) {toast.success(`Deployment started: v${result.version}`);await loadAllDeployments();diff --git a/frontend/src/pages/WorkflowBuilder.jsx b/frontend/src/pages/WorkflowBuilder.jsxindex ad31b02c..61b7624e 100644--- a/frontend/src/pages/WorkflowBuilder.jsx+++ b/frontend/src/pages/WorkflowBuilder.jsx@@ -11,7 +11,7 @@ import {MiniMap} from '@xyflow/react';import '@xyflow/react/dist/style.css';-import { Server, Database, Globe, Box, Save, FolderOpen, Plus, RefreshCw, Play, Layout, Eye, Bell, Terminal } from 'lucide-react';+import { Server, Database, Globe, Box, Save, FolderOpen, Plus, RefreshCw, Play, Layout, Eye, Bell, Terminal, Activity } from 'lucide-react';import api from '../services/api';import WorkflowListModal from '../components/workflow/WorkflowListModal';import DeploymentProgressModal from '../components/workflow/DeploymentProgressModal';diff --git a/frontend/src/services/api.js b/frontend/src/services/api.jsindex dbd3d7e7..5e76f404 100644--- a/frontend/src/services/api.js+++ b/frontend/src/services/api.js@@ -383,7 +383,7 @@ class ApiService {return this.request('/system/check-update');}- async getProcesses() {+ async getSystemProcesses() {return this.request('/system/processes');}@@ -1328,7 +1328,7 @@ class ApiService {return this.request(`/deploy/apps/${appId}/config`, { method: 'DELETE' });}- async triggerDeploy(appId, force = false) {+ async triggerAppDeploy(appId, force = false) {return this.request(`/deploy/apps/${appId}/deploy`, {method: 'POST',body: { force }@@ -1342,7 +1342,7 @@ class ApiService {});}- async getGitStatus(appId) {+ async getAppGitStatus(appId) {return this.request(`/deploy/apps/${appId}/git-status`);}@@ -1840,7 +1840,7 @@ class ApiService {// ========================================// Git Server endpoints// ========================================- async getGitStatus() {+ async getGitServerStatus() {return this.request('/git/status');}@@ -1942,7 +1942,7 @@ class ApiService {return this.request(`/git/webhooks/${webhookId}/toggle`, { method: 'POST' });}- async getWebhookLogs(webhookId, limit = 50) {+ async getGitWebhookLogs(webhookId, limit = 50) {return this.request(`/git/webhooks/${webhookId}/logs?limit=${limit}`);}@@ -2010,7 +2010,7 @@ class ApiService {return this.request(`/git/deployments/${deploymentId}?logs=${includeLogs}`);}- async triggerDeploy(appId, branch = null) {+ async triggerGitDeploy(appId, branch = null) {return this.request(`/git/deployments/app/${appId}/deploy`, {method: 'POST',body: branch ? { branch } : {}@@ -3673,11 +3673,11 @@ class ApiService {return this.request('/nginx/advanced/proxy', { method: 'POST', body: data });}- async testNginxConfig() {+ async testAdvancedNginxConfig() {return this.request('/nginx/advanced/test', { method: 'POST' });}- async reloadNginx() {+ async reloadAdvancedNginx() {return this.request('/nginx/advanced/reload', { method: 'POST' });}diff --git a/frontend/src/styles/_variables.less b/frontend/src/styles/_variables.lessindex 3d00cc82..503def86 100644--- a/frontend/src/styles/_variables.less+++ b/frontend/src/styles/_variables.less@@ -204,3 +204,20 @@@color-primary: @accent-primary;@bg-code: @bg-tertiary;@bg-input: @bg-card;++// Spacing aliases (used by newer page stylesheets)+@spacing-xs: @space-1;+@spacing-sm: @space-2;+@spacing-md: @space-4;+@spacing-lg: @space-6;+@spacing-xl: @space-8;++// Legacy aliases (used by newer page stylesheets)+@border-color: @border-default;+@card-bg: @bg-card;+@hover-bg: @bg-hover;+@primary-color: @accent-primary;+@text-muted: @text-tertiary;+@success-color: @success;+@warning-color: @warning;+@danger-color: @danger;diff --git a/frontend/src/styles/base/_utilities.less b/frontend/src/styles/base/_utilities.lessnew file mode 100644index 00000000..396b28f8--- /dev/null+++ b/frontend/src/styles/base/_utilities.less@@ -0,0 +1,164 @@+// ============================================+// TAILWIND-LIKE UTILITY CLASSES+// ============================================+// These classes provide layout and spacing utilities+// used in some newer pages that expect Tailwind.++// --------------------------------------------+// DISPLAY & FLEX+// --------------------------------------------+.flex { display: flex; }+.flex-wrap { flex-wrap: wrap; }+.flex-col { flex-direction: column; }+.items-center { align-items: center; }+.justify-between { justify-content: space-between; }+.justify-end { justify-content: flex-end; }+.justify-center { justify-content: center; }++// --------------------------------------------+// GRID+// --------------------------------------------+.grid { display: grid; }+.grid-cols-1 { grid-template-columns: repeat(1, minmax(0, 1fr)); }+.grid-cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }+.grid-cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }+.grid-cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }++@media (min-width: 768px) {+ .md\:grid-cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }+ .md\:grid-cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }+ .md\:grid-cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }+}++@media (min-width: 1024px) {+ .lg\:grid-cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }+ .lg\:grid-cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }+ .lg\:grid-cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }+}++// --------------------------------------------+// SPACING (Gaps)+// --------------------------------------------+.gap-1 { gap: 0.25rem; }+.gap-2 { gap: 0.5rem; }+.gap-3 { gap: 0.75rem; }+.gap-4 { gap: 1rem; }+.gap-6 { gap: 1.5rem; }+.gap-8 { gap: 2rem; }++// --------------------------------------------+// STACK SPACING (space-y)+// --------------------------------------------+.space-y-2 > * + * { margin-top: 0.5rem; }+.space-y-4 > * + * { margin-top: 1rem; }+.space-y-6 > * + * { margin-top: 1.5rem; }+.space-y-8 > * + * { margin-top: 2rem; }++.space-x-2 > * + * { margin-left: 0.5rem; }+.space-x-4 > * + * { margin-left: 1rem; }++// --------------------------------------------+// MARGINS+// --------------------------------------------+.mt-1 { margin-top: 0.25rem; }+.mt-2 { margin-top: 0.5rem; }+.mt-4 { margin-top: 1rem; }+.mt-6 { margin-top: 1.5rem; }+.mt-8 { margin-top: 2rem; }++.mb-1 { margin-bottom: 0.25rem; }+.mb-2 { margin-bottom: 0.5rem; }+.mb-3 { margin-bottom: 0.75rem; }+.mb-4 { margin-bottom: 1rem; }+.mb-6 { margin-bottom: 1.5rem; }+.mb-8 { margin-bottom: 2rem; }++.ml-1 { margin-left: 0.25rem; }+.ml-2 { margin-left: 0.5rem; }+.ml-3 { margin-left: 0.75rem; }+.ml-4 { margin-left: 1rem; }++.mr-1 { margin-right: 0.25rem; }+.mr-2 { margin-right: 0.5rem; }++.mx-1 { margin-left: 0.25rem; margin-right: 0.25rem; }+.mx-2 { margin-left: 0.5rem; margin-right: 0.5rem; }+.mx-auto { margin-left: auto; margin-right: auto; }++// --------------------------------------------+// PADDING+// --------------------------------------------+.p-2 { padding: 0.5rem; }+.p-4 { padding: 1rem; }+.p-6 { padding: 1.5rem; }+.px-2 { padding-left: 0.5rem; padding-right: 0.5rem; }+.px-4 { padding-left: 1rem; padding-right: 1rem; }+.py-2 { padding-top: 0.5rem; padding-bottom: 0.5rem; }+.py-4 { padding-top: 1rem; padding-bottom: 1rem; }+.py-12 { padding-top: 3rem; padding-bottom: 3rem; }++// --------------------------------------------+// SIZING+// --------------------------------------------+.w-full { width: 100%; }+.w-\[1px\] { width: 1px; }+.h-6 { height: 1.5rem; }+.h-full { height: 100%; }++// --------------------------------------------+// TEXT+// --------------------------------------------+.text-xs { font-size: 0.75rem; }+.text-sm { font-size: 0.875rem; }+.text-lg { font-size: 1.125rem; }+.text-xl { font-size: 1.25rem; }+.text-gray-300 { color: #d1d5db; }+.text-gray-400 { color: #9ca3af; }+.text-gray-500 { color: #6b7280; }+.text-gray-600 { color: #4b5563; }+.text-blue-600 { color: #2563eb; }+.text-green-600 { color: #16a34a; }+.text-red-600 { color: #dc2626; }+.text-green-400 { color: #4ade80; }+.font-medium { font-weight: 500; }+.font-semibold { font-weight: 600; }+.font-bold { font-weight: 700; }+.text-center { text-align: center; }++// --------------------------------------------+// BACKGROUNDS+// --------------------------------------------+.bg-gray-700 { background-color: #374151; }+.bg-gray-100 { background-color: #f3f4f6; }+.bg-blue-100 { background-color: #dbeafe; }+.bg-green-100 { background-color: #dcfce7; }+.bg-red-100 { background-color: #fee2e2; }+.bg-body { background-color: @bg-body; }++// --------------------------------------------+// BORDERS+// --------------------------------------------+.border { border: 1px solid @border-default; }+.border-b { border-bottom: 1px solid @border-subtle; }+.rounded { border-radius: @radius-md; }+.rounded-lg { border-radius: @radius-lg; }++// --------------------------------------------+// MISC+// --------------------------------------------+.block { display: block; }+.hidden { display: none; }+.overflow-y-auto { overflow-y: auto; }+.max-h-24 { max-height: 6rem; }+.animate-spin { animation: spin 1s linear infinite; }+.animate-pulse { animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite; }++@keyframes spin {+ from { transform: rotate(0deg); }+ to { transform: rotate(360deg); }+}++@keyframes pulse {+ 0%, 100% { opacity: 1; }+ 50% { opacity: .5; }+}diff --git a/frontend/src/styles/components/_badges.less b/frontend/src/styles/components/_badges.lessindex 69b8d78d..12f9d033 100644--- a/frontend/src/styles/components/_badges.less+++ b/frontend/src/styles/components/_badges.less@@ -153,3 +153,41 @@opacity: 0.7;}}++// Global Badge Base+.badge {+ display: inline-flex;+ align-items: center;+ justify-content: center;+ padding: 0.25rem 0.5rem;+ font-size: 0.75rem;+ font-weight: 600;+ line-height: 1;+ border-radius: 9999px;+ white-space: nowrap;+}++.badge-info {+ background-color: fade(@info, 15%);+ color: @info;+}++.badge-success {+ background-color: fade(@success, 15%);+ color: @success;+}++.badge-error {+ background-color: fade(@danger, 15%);+ color: @danger;+}++.badge-warning {+ background-color: fade(@warning, 15%);+ color: @warning;+}++.badge-default {+ background-color: fade(@text-tertiary-raw, 15%);+ color: @text-tertiary;+}diff --git a/frontend/src/styles/layout/_main-content.less b/frontend/src/styles/layout/_main-content.lessindex 7267c92e..91c0498d 100644--- a/frontend/src/styles/layout/_main-content.less+++ b/frontend/src/styles/layout/_main-content.less@@ -52,6 +52,14 @@gap: @space-3;}+// Shared Page Wrapper+.page-container {+ width: 100%;+ max-width: 1400px;+ margin: 0 auto;+ padding-bottom: @space-10;+}+// Page Header (shared base).page-header {display: flex;@@ -61,21 +69,25 @@flex-wrap: wrap;gap: @space-4;- .page-header-content {+ .page-header-content,+ .header-info {h1 {font-size: @font-size-2xl;font-weight: @font-weight-semibold;margin: 0 0 @space-1 0;+ color: @text-primary;}- .page-description {+ .page-description,+ p {color: @text-secondary;font-size: @font-size-sm;margin: 0;}}- .page-header-actions {+ .page-header-actions,+ .header-actions {display: flex;gap: @space-2;align-items: center;@@ -86,7 +98,8 @@flex-direction: column;align-items: stretch;- .page-header-actions {+ .page-header-actions,+ .header-actions {justify-content: flex-end;}}diff --git a/frontend/src/styles/layout/_sidebar.less b/frontend/src/styles/layout/_sidebar.lessindex 7d71bca2..991d6e8d 100644--- a/frontend/src/styles/layout/_sidebar.less+++ b/frontend/src/styles/layout/_sidebar.less@@ -456,7 +456,7 @@.nav-item {display: flex;align-items: center;- gap: 12px;+ gap: 16px;padding: 0.5rem 0.75rem;border-radius: @radius-lg;color: @text-tertiary;@@ -510,7 +510,7 @@stroke-linecap: round;stroke-linejoin: round;fill: none;- opacity: 0.8;+ opacity: 1;flex-shrink: 0;}diff --git a/frontend/src/styles/main.less b/frontend/src/styles/main.lessindex 66475b51..a2332239 100644--- a/frontend/src/styles/main.less+++ b/frontend/src/styles/main.less@@ -17,6 +17,7 @@// --------------------------------------------@import 'base/_reset';@import 'base/_typography';+@import 'base/_utilities';// --------------------------------------------// 3. LAYOUT