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
feat(14): Add version update check via GitHub releases API
Juan Denis4f5da492cca6
diff --git a/backend/app/api/system.py b/backend/app/api/system.pyindex ea019f98..728a8946 100644--- a/backend/app/api/system.py+++ b/backend/app/api/system.py@@ -1,9 +1,19 @@import os+import time+import urllib.request+import jsonfrom flask import Blueprint, jsonify, current_appfrom flask_jwt_extended import jwt_required, get_jwt_identityfrom app.models import Userfrom app.services.system_service import SystemService+# Cache for update check (to avoid hitting GitHub API too often)+_update_cache = {+ 'last_check': 0,+ 'result': None,+ 'ttl': 3600 # 1 hour cache+}+system_bp = Blueprint('system', __name__)@@ -34,6 +44,79 @@ def get_version():}), 200+@system_bp.route('/check-update', methods=['GET'])+def check_update():+ """Check for updates from GitHub releases - no auth required."""+ global _update_cache++ # Return cached result if still valid+ if _update_cache['result'] and (time.time() - _update_cache['last_check']) < _update_cache['ttl']:+ return jsonify(_update_cache['result']), 200++ # Get current version+ current_version = '1.0.0'+ version_paths = [+ '/opt/serverkit/VERSION',+ os.path.join(current_app.root_path, '..', 'VERSION'),+ os.path.join(current_app.root_path, '..', '..', 'VERSION'),+ ]+ for path in version_paths:+ try:+ if os.path.exists(path):+ with open(path, 'r') as f:+ current_version = f.read().strip()+ break+ except Exception:+ pass++ result = {+ 'current_version': current_version,+ 'latest_version': None,+ 'update_available': False,+ 'release_url': None,+ 'release_notes': None,+ 'error': None+ }++ try:+ # Fetch latest release from GitHub API+ req = urllib.request.Request(+ 'https://api.github.com/repos/jhd3197/ServerKit/releases/latest',+ headers={'User-Agent': 'ServerKit-UpdateChecker'}+ )+ with urllib.request.urlopen(req, timeout=10) as response:+ data = json.loads(response.read().decode('utf-8'))++ latest_version = data.get('tag_name', '').lstrip('v')+ result['latest_version'] = latest_version+ result['release_url'] = data.get('html_url')+ result['release_notes'] = data.get('body', '')[:500] # Truncate release notes++ # Simple version comparison (works for semver-like versions)+ def parse_version(v):+ try:+ return tuple(int(x) for x in v.split('.'))+ except:+ return (0, 0, 0)++ if parse_version(latest_version) > parse_version(current_version):+ result['update_available'] = True++ except urllib.error.HTTPError as e:+ if e.code == 404:+ result['error'] = 'No releases found'+ else:+ result['error'] = f'GitHub API error: {e.code}'+ except Exception as e:+ result['error'] = f'Failed to check for updates: {str(e)}'++ # Cache the result+ _update_cache['last_check'] = time.time()+ _update_cache['result'] = result++ return jsonify(result), 200++@system_bp.route('/metrics', methods=['GET'])@jwt_required()def get_metrics():diff --git a/frontend/src/pages/Settings.jsx b/frontend/src/pages/Settings.jsxindex b03ce0a6..468a59c5 100644--- a/frontend/src/pages/Settings.jsx+++ b/frontend/src/pages/Settings.jsx@@ -3,7 +3,7 @@ import { useAuth } from '../contexts/AuthContext';import api from '../services/api';import UsersTab from '../components/settings/UsersTab';import AuditLogTab from '../components/settings/AuditLogTab';-import { Github, FileText, HelpCircle, MessageSquare, Bug, Check, Layers } from 'lucide-react';+import { Github, FileText, HelpCircle, MessageSquare, Bug, Check, Layers, Download, CheckCircle, RefreshCw, ExternalLink } from 'lucide-react';const Settings = () => {const [activeTab, setActiveTab] = useState('profile');@@ -1649,6 +1649,8 @@ const SystemInfo = () => {const AboutSection = () => {const [version, setVersion] = useState('...');+ const [updateInfo, setUpdateInfo] = useState(null);+ const [checkingUpdate, setCheckingUpdate] = useState(false);useEffect(() => {const fetchVersion = async () => {@@ -1662,6 +1664,17 @@ const AboutSection = () => {fetchVersion();}, []);+ const checkForUpdate = async () => {+ setCheckingUpdate(true);+ try {+ const data = await api.checkUpdate();+ setUpdateInfo(data);+ } catch (error) {+ setUpdateInfo({ error: 'Failed to check for updates' });+ }+ setCheckingUpdate(false);+ };+return (<div className="settings-section"><div className="section-header">@@ -1679,6 +1692,45 @@ const AboutSection = () => {A modern, lightweight server management panel for managing web applications,databases, domains, and more. Built with Flask and React.</p>++ <div className="update-check">+ {!updateInfo ? (+ <button+ className="btn btn-secondary btn-sm"+ onClick={checkForUpdate}+ disabled={checkingUpdate}+ >+ {checkingUpdate ? (+ <><RefreshCw size={14} className="spinning" /> Checking...</>+ ) : (+ <><Download size={14} /> Check for Updates</>+ )}+ </button>+ ) : updateInfo.error ? (+ <div className="update-status error">+ <span>{updateInfo.error}</span>+ <button className="btn-link" onClick={checkForUpdate}>Retry</button>+ </div>+ ) : updateInfo.update_available ? (+ <div className="update-status available">+ <Download size={16} />+ <span>Update available: <strong>v{updateInfo.latest_version}</strong></span>+ <a+ href={updateInfo.release_url}+ target="_blank"+ rel="noopener noreferrer"+ className="btn btn-accent btn-sm"+ >+ View Release <ExternalLink size={12} />+ </a>+ </div>+ ) : (+ <div className="update-status current">+ <CheckCircle size={16} />+ <span>You're up to date!</span>+ </div>+ )}+ </div></div><div className="settings-card">diff --git a/frontend/src/services/api.js b/frontend/src/services/api.jsindex ed3de254..169ba66b 100644--- a/frontend/src/services/api.js+++ b/frontend/src/services/api.js@@ -314,6 +314,10 @@ class ApiService {return this.request('/system/version');}+ async checkUpdate() {+ return this.request('/system/check-update');+ }+async getProcesses() {return this.request('/system/processes');}diff --git a/frontend/src/styles/pages/_settings.less b/frontend/src/styles/pages/_settings.lessindex c41f3900..34ee04e7 100644--- a/frontend/src/styles/pages/_settings.less+++ b/frontend/src/styles/pages/_settings.less@@ -592,6 +592,72 @@max-width: 500px;margin: 0 auto;}++ .update-check {+ margin-top: @space-4;+ padding-top: @space-4;+ border-top: 1px solid @border-subtle;++ .btn-sm {+ font-size: @font-size-xs;+ padding: @space-2 @space-3;+ display: inline-flex;+ align-items: center;+ gap: @space-1;++ .spinning {+ animation: spin 1s linear infinite;+ }+ }++ .update-status {+ display: flex;+ align-items: center;+ justify-content: center;+ gap: @space-2;+ font-size: @font-size-sm;++ &.current {+ color: @success;+ }++ &.available {+ color: @warning;+ flex-wrap: wrap;++ .btn {+ margin-left: @space-2;+ display: inline-flex;+ align-items: center;+ gap: @space-1;+ }+ }++ &.error {+ color: @danger;++ .btn-link {+ background: none;+ border: none;+ color: @accent-primary;+ cursor: pointer;+ text-decoration: underline;+ font-size: @font-size-sm;+ padding: 0;+ margin-left: @space-2;++ &:hover {+ color: @accent-hover;+ }+ }+ }+ }+ }+}++@keyframes spin {+ from { transform: rotate(0deg); }+ to { transform: rotate(360deg); }}// Feature List