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(unify): §5 — single SSL surface (basic + advanced)
Juan Denis15fce59543ca
diff --git a/backend/app/__init__.py b/backend/app/__init__.pyindex e31de055..7334f485 100644--- a/backend/app/__init__.py+++ b/backend/app/__init__.py@@ -336,8 +336,13 @@ def create_app(config_name=None):app.register_blueprint(workspaces_bp, url_prefix='/api/v1/workspaces')# Register blueprints - Advanced SSL+ # §5 unification: one SSL surface. The advanced cert operations (wildcard,+ # SAN, custom upload, profiles, health, expiry alerts) mount under the same+ # /api/v1/ssl prefix as the basic certbot routes (no path collisions). The+ # original /api/v1/ssl/advanced prefix is kept as a deprecated alias.from app.api.advanced_ssl import advanced_ssl_bpapp.register_blueprint(advanced_ssl_bp, url_prefix='/api/v1/ssl/advanced')+ app.register_blueprint(advanced_ssl_bp, url_prefix='/api/v1/ssl', name='advanced_ssl_unified')# Register blueprints - DNS Zonesfrom app.api.dns_zones import dns_zones_bpdiff --git a/backend/tests/test_ssl_unified_surface.py b/backend/tests/test_ssl_unified_surface.pynew file mode 100644index 00000000..e6161f5c--- /dev/null+++ b/backend/tests/test_ssl_unified_surface.py@@ -0,0 +1,36 @@+"""§5 unification — one /ssl surface.++The advanced certificate operations (wildcard, SAN, upload, profiles, health,+expiry alerts) are mounted under /api/v1/ssl alongside the basic certbot routes,+with /api/v1/ssl/advanced kept as a deprecated alias. Both resolve to the same+handlers.+"""+++def test_advanced_routes_mounted_under_ssl():+ from app import create_app+ application = create_app('testing')+ rules = {r.rule for r in application.url_map.iter_rules()}+ # Unified surface+ assert '/api/v1/ssl/profiles' in rules+ assert '/api/v1/ssl/wildcard' in rules+ assert '/api/v1/ssl/upload' in rules+ assert '/api/v1/ssl/expiry-alerts' in rules+ # Deprecated alias still present+ assert '/api/v1/ssl/advanced/profiles' in rules+++def test_basic_ssl_routes_still_present():+ from app import create_app+ application = create_app('testing')+ rules = {r.rule for r in application.url_map.iter_rules()}+ assert '/api/v1/ssl/certificates' in rules+ assert '/api/v1/ssl/status' in rules+++def test_profiles_resolves_on_both_prefixes(app, client, auth_headers):+ unified = client.get('/api/v1/ssl/profiles', headers=auth_headers)+ alias = client.get('/api/v1/ssl/advanced/profiles', headers=auth_headers)+ assert unified.status_code == 200+ assert alias.status_code == 200+ assert unified.get_json() == alias.get_json()diff --git a/frontend/src/pages/SSLCertificates.jsx b/frontend/src/pages/SSLCertificates.jsxindex 348288d0..2c0efe24 100644--- a/frontend/src/pages/SSLCertificates.jsx+++ b/frontend/src/pages/SSLCertificates.jsx@@ -2,7 +2,7 @@ import { useState, useEffect } from 'react';import {ShieldCheck, ShieldOff, RefreshCw, Plus, Trash2,Lock, Clock, Globe, CheckCircle, AlertTriangle,- Settings, Download+ Settings, Download, Upload} from 'lucide-react';import api from '../services/api';import Modal from '@/components/Modal';@@ -27,12 +27,24 @@ const SSLCertificates = () => {// Modal statesconst [showObtainModal, setShowObtainModal] = useState(false);+ const [showUploadModal, setShowUploadModal] = useState(false);- // Form states+ // Form states — Obtain (HTTP-01 or wildcard DNS-01)const [domains, setDomains] = useState('');const [email, setEmail] = useState('');const [useNginx, setUseNginx] = useState(true);const [webrootPath, setWebrootPath] = useState('');+ const [wildcard, setWildcard] = useState(false);+ const [dnsProvider, setDnsProvider] = useState('cloudflare');+ const [dnsToken, setDnsToken] = useState('');+ const [awsAccessKey, setAwsAccessKey] = useState('');+ const [awsSecretKey, setAwsSecretKey] = useState('');++ // Form states — Upload custom certificate+ const [uploadDomain, setUploadDomain] = useState('');+ const [uploadCert, setUploadCert] = useState('');+ const [uploadKey, setUploadKey] = useState('');+ const [uploadChain, setUploadChain] = useState('');useEffect(() => {loadData();@@ -53,20 +65,32 @@ const SSLCertificates = () => {async function handleObtainCertificate(e) {e.preventDefault();const domainList = domains.split(',').map(d => d.trim()).filter(Boolean);- if (domainList.length === 0 || !email) return;+ if (domainList.length === 0) return;try {setActionLoading(true);- const data = { domains: domainList, email, use_nginx: useNginx };- if (!useNginx && webrootPath) {- data.webroot_path = webrootPath;+ let result;+ if (wildcard) {+ // Wildcard certs need DNS-01 validation via a DNS provider.+ const credentials = dnsProvider === 'cloudflare'+ ? { dns_cloudflare_api_token: dnsToken }+ : { aws_access_key_id: awsAccessKey, aws_secret_access_key: awsSecretKey };+ result = await api.issueWildcardCert(domainList[0], dnsProvider, credentials);+ } else {+ if (!email) return;+ const data = { domains: domainList, email, use_nginx: useNginx };+ if (!useNginx && webrootPath) data.webroot_path = webrootPath;+ result = await api.obtainCertificate(data);}- const result = await api.obtainCertificate(data);if (result.success) {- toast.success('Certificate obtained successfully');+ toast.success(wildcard ? 'Wildcard certificate issued' : 'Certificate obtained successfully');setShowObtainModal(false);setDomains('');setEmail('');+ setDnsToken('');+ setAwsAccessKey('');+ setAwsSecretKey('');+ setWildcard(false);loadData();} else {toast.error(result.error || 'Failed to obtain certificate');@@ -78,6 +102,31 @@ const SSLCertificates = () => {}}+ async function handleUploadCertificate(e) {+ e.preventDefault();+ if (!uploadDomain || !uploadCert || !uploadKey) return;+ try {+ setActionLoading(true);+ const result = await api.uploadCustomCert(uploadDomain.trim(), uploadCert, uploadKey, uploadChain || null);+ // upload returns the saved cert paths (no `success` envelope).+ if (result && (result.cert_path || result.success)) {+ toast.success(`Certificate uploaded for ${uploadDomain}`);+ setShowUploadModal(false);+ setUploadDomain('');+ setUploadCert('');+ setUploadKey('');+ setUploadChain('');+ loadData();+ } else {+ toast.error(result?.error || 'Failed to upload certificate');+ }+ } catch (err) {+ toast.error(err.message || 'Failed to upload certificate');+ } finally {+ setActionLoading(false);+ }+ }+async function handleRenewCertificate(domain) {try {setRenewingDomain(domain);@@ -192,6 +241,10 @@ const SSLCertificates = () => {<RefreshCw size={15} />Refresh</Button>+ <Button variant="outline" size="sm" onClick={() => setShowUploadModal(true)}>+ <Upload size={15} />+ Upload+ </Button><Button size="sm" onClick={() => setShowObtainModal(true)} disabled={!certbotInstalled}><Plus size={15} />New Certificate@@ -381,48 +434,110 @@ const SSLCertificates = () => {</div></div><div className="form-group">- <Label>Domains</Label>+ <label className="checkbox-label">+ <Checkbox+ checked={wildcard}+ onCheckedChange={setWildcard}+ />+ Wildcard certificate (DNS-01 validation)+ </label>+ <p className="hint">Issues <code>domain</code> + <code>*.domain</code> via your DNS provider.</p>+ </div>+ <div className="form-group">+ <Label>{wildcard ? 'Base Domain' : 'Domains'}</Label><Inputtype="text"- placeholder="example.com, www.example.com"+ placeholder={wildcard ? 'example.com' : 'example.com, www.example.com'}value={domains}onChange={e => setDomains(e.target.value)}required/>- <p className="hint">Comma-separated list of domains</p>+ <p className="hint">{wildcard ? 'A single base domain for the wildcard cert' : 'Comma-separated list of domains'}</p></div>- <div className="form-group">- <Label>Email Address</Label>- <Input- type="email"- placeholder="[email protected]"- value={email}- onChange={e => setEmail(e.target.value)}- required- />- <p className="hint">For certificate expiration notifications</p>- </div>- <div className="form-group">- <label className="checkbox-label">- <Checkbox- checked={useNginx}- onCheckedChange={setUseNginx}- />- Use Nginx plugin (recommended)- </label>- </div>- {!useNginx && (- <div className="form-group">- <Label>Webroot Path</Label>- <Input- type="text"- placeholder="/var/www/html"- value={webrootPath}- onChange={e => setWebrootPath(e.target.value)}- required={!useNginx}- />- <p className="hint">Document root for HTTP validation</p>- </div>+ {!wildcard && (+ <>+ <div className="form-group">+ <Label>Email Address</Label>+ <Input+ type="email"+ placeholder="[email protected]"+ value={email}+ onChange={e => setEmail(e.target.value)}+ required={!wildcard}+ />+ <p className="hint">For certificate expiration notifications</p>+ </div>+ <div className="form-group">+ <label className="checkbox-label">+ <Checkbox+ checked={useNginx}+ onCheckedChange={setUseNginx}+ />+ Use Nginx plugin (recommended)+ </label>+ </div>+ {!useNginx && (+ <div className="form-group">+ <Label>Webroot Path</Label>+ <Input+ type="text"+ placeholder="/var/www/html"+ value={webrootPath}+ onChange={e => setWebrootPath(e.target.value)}+ required={!useNginx}+ />+ <p className="hint">Document root for HTTP validation</p>+ </div>+ )}+ </>+ )}+ {wildcard && (+ <>+ <div className="form-group">+ <Label>DNS Provider</Label>+ <select+ className="ui-select"+ value={dnsProvider}+ onChange={e => setDnsProvider(e.target.value)}+ >+ <option value="cloudflare">Cloudflare</option>+ <option value="route53">AWS Route 53</option>+ </select>+ </div>+ {dnsProvider === 'cloudflare' ? (+ <div className="form-group">+ <Label>Cloudflare API Token</Label>+ <Input+ type="password"+ placeholder="API token with DNS edit rights"+ value={dnsToken}+ onChange={e => setDnsToken(e.target.value)}+ required={wildcard}+ />+ </div>+ ) : (+ <>+ <div className="form-group">+ <Label>AWS Access Key ID</Label>+ <Input+ type="text"+ value={awsAccessKey}+ onChange={e => setAwsAccessKey(e.target.value)}+ required={wildcard}+ />+ </div>+ <div className="form-group">+ <Label>AWS Secret Access Key</Label>+ <Input+ type="password"+ value={awsSecretKey}+ onChange={e => setAwsSecretKey(e.target.value)}+ required={wildcard}+ />+ </div>+ </>+ )}+ </>)}<div className="modal-actions"><Button@@ -441,6 +556,69 @@ const SSLCertificates = () => {</div></form></Modal>++ {/* Upload Custom Certificate Modal */}+ <Modal open={showUploadModal} onClose={() => setShowUploadModal(false)} title="Upload Custom Certificate">+ <form onSubmit={handleUploadCertificate}>+ <div className="ssl-info-box">+ <Upload size={32} />+ <div>+ <h4>Bring your own certificate</h4>+ <p>Paste a PEM certificate, private key, and (optional) chain issued elsewhere.</p>+ </div>+ </div>+ <div className="form-group">+ <Label>Domain</Label>+ <Input+ type="text"+ placeholder="example.com"+ value={uploadDomain}+ onChange={e => setUploadDomain(e.target.value)}+ required+ />+ </div>+ <div className="form-group">+ <Label>Certificate (PEM)</Label>+ <textarea+ className="ui-textarea ssl-pem-input"+ rows={5}+ placeholder="-----BEGIN CERTIFICATE-----"+ value={uploadCert}+ onChange={e => setUploadCert(e.target.value)}+ required+ />+ </div>+ <div className="form-group">+ <Label>Private Key (PEM)</Label>+ <textarea+ className="ui-textarea ssl-pem-input"+ rows={5}+ placeholder="-----BEGIN PRIVATE KEY-----"+ value={uploadKey}+ onChange={e => setUploadKey(e.target.value)}+ required+ />+ </div>+ <div className="form-group">+ <Label>Chain (PEM, optional)</Label>+ <textarea+ className="ui-textarea ssl-pem-input"+ rows={4}+ placeholder="-----BEGIN CERTIFICATE----- (intermediate chain)"+ value={uploadChain}+ onChange={e => setUploadChain(e.target.value)}+ />+ </div>+ <div className="modal-actions">+ <Button type="button" variant="outline" onClick={() => setShowUploadModal(false)}>+ Cancel+ </Button>+ <Button type="submit" disabled={actionLoading}>+ {actionLoading ? 'Uploading...' : 'Upload Certificate'}+ </Button>+ </div>+ </form>+ </Modal></div>);};diff --git a/frontend/src/services/api/security.js b/frontend/src/services/api/security.jsindex dd348fee..ae5f3332 100644--- a/frontend/src/services/api/security.js+++ b/frontend/src/services/api/security.js@@ -125,35 +125,36 @@ export async function installCertbot() {return this.request('/ssl/install-certbot', { method: 'POST' });}-// Advanced SSL endpoints+// Advanced SSL endpoints — unified under the one /ssl surface (§5). The old+// /ssl/advanced/* paths still resolve (deprecated alias).export async function getSSLProfiles() {- return this.request('/ssl/advanced/profiles');+ return this.request('/ssl/profiles');}export async function issueWildcardCert(domain, dnsProvider, credentials) {- return this.request('/ssl/advanced/wildcard', {+ return this.request('/ssl/wildcard', {method: 'POST', body: { domain, dns_provider: dnsProvider, credentials }});}export async function issueSANCert(domains) {- return this.request('/ssl/advanced/san', {+ return this.request('/ssl/san', {method: 'POST', body: { domains }});}export async function uploadCustomCert(domain, certificate, privateKey, chain) {- return this.request('/ssl/advanced/upload', {+ return this.request('/ssl/upload', {method: 'POST', body: { domain, certificate, private_key: privateKey, chain }});}export async function getSSLHealth(domain) {- return this.request(`/ssl/advanced/health/${domain}`);+ return this.request(`/ssl/health/${domain}`);}export async function getSSLExpiryAlerts(days = 30) {- return this.request(`/ssl/advanced/expiry-alerts?days=${days}`);+ return this.request(`/ssl/expiry-alerts?days=${days}`);}// Security (ClamAV, File Integrity) endpoints