feat: Add Cloudflare integration page and restructure sidebar
Add a dedicated Cloudflare page under Central for API token management with live verification against the Cloudflare API (token validity, zone access). Migrate the token secret path from ddns.cloudflare.apiToken to cloudflare.apiToken with backward-compatible fallback. Restructure sidebar into two groups: Central (networking platform services) and Wild Cloud (overview, instance management). The instance selector now sits inside the Wild Cloud section as a natural divider between meta and instance-scoped items. Move Central Domain & TLS config from Overview to the Cloudflare page. Move Node USB Installer route to /cloud/iso (not instance-scoped). Fix FirewallComponent Lucide icon title prop type error. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -163,12 +163,7 @@ func (api *API) reloadDDNSIfEnabled() {
|
||||
return
|
||||
}
|
||||
|
||||
// Read API token: env var takes precedence, then global secrets file
|
||||
apiToken := os.Getenv("WILD_DDNS_CLOUDFLARE_TOKEN")
|
||||
if apiToken == "" {
|
||||
secretsPath := api.dataDir + "/secrets.yaml"
|
||||
apiToken, _ = api.secrets.GetSecret(secretsPath, "ddns.cloudflare.apiToken")
|
||||
}
|
||||
apiToken := api.getCloudflareToken()
|
||||
|
||||
cfg := ddns.Config{
|
||||
Enabled: true,
|
||||
@@ -403,6 +398,9 @@ func (api *API) RegisterRoutes(r *mux.Router) {
|
||||
r.HandleFunc("/api/v1/cert/provision", api.CertProvision).Methods("POST")
|
||||
r.HandleFunc("/api/v1/cert/renew", api.CertRenew).Methods("POST")
|
||||
|
||||
// Cloudflare integration
|
||||
r.HandleFunc("/api/v1/cloudflare/verify", api.CloudflareVerify).Methods("GET")
|
||||
|
||||
// DDNS management
|
||||
r.HandleFunc("/api/v1/ddns/status", api.DDNSStatus).Methods("GET")
|
||||
r.HandleFunc("/api/v1/ddns/trigger", api.DDNSTrigger).Methods("POST")
|
||||
|
||||
@@ -44,11 +44,10 @@ func (api *API) CertProvision(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
// Get Cloudflare API token from global secrets
|
||||
secretsPath := api.dataDir + "/secrets.yaml"
|
||||
token, err := api.secrets.GetSecret(secretsPath, "ddns.cloudflare.apiToken")
|
||||
if err != nil || token == "" {
|
||||
respondError(w, http.StatusBadRequest, "Cloudflare API token not found in global secrets (ddns.cloudflare.apiToken)")
|
||||
// Get Cloudflare API token
|
||||
token := api.getCloudflareToken()
|
||||
if token == "" {
|
||||
respondError(w, http.StatusBadRequest, "Cloudflare API token not configured — set it on the Cloudflare page")
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
121
api/internal/api/v1/handlers_cloudflare.go
Normal file
121
api/internal/api/v1/handlers_cloudflare.go
Normal file
@@ -0,0 +1,121 @@
|
||||
package v1
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"os"
|
||||
)
|
||||
|
||||
// getCloudflareToken resolves the Cloudflare API token from env var or secrets.
|
||||
// Env var takes precedence, then cloudflare.apiToken, then legacy ddns.cloudflare.apiToken.
|
||||
func (api *API) getCloudflareToken() string {
|
||||
if t := os.Getenv("WILD_CLOUDFLARE_TOKEN"); t != "" {
|
||||
return t
|
||||
}
|
||||
secretsPath := api.dataDir + "/secrets.yaml"
|
||||
if t, err := api.secrets.GetSecret(secretsPath, "cloudflare.apiToken"); err == nil {
|
||||
return t
|
||||
}
|
||||
// Fallback for pre-migration secrets
|
||||
t, _ := api.secrets.GetSecret(secretsPath, "ddns.cloudflare.apiToken")
|
||||
return t
|
||||
}
|
||||
|
||||
type cloudflareZone struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
type cloudflareVerifyResponse struct {
|
||||
TokenConfigured bool `json:"tokenConfigured"`
|
||||
TokenValid bool `json:"tokenValid"`
|
||||
TokenStatus string `json:"tokenStatus"`
|
||||
Zones []cloudflareZone `json:"zones"`
|
||||
Error string `json:"error,omitempty"`
|
||||
}
|
||||
|
||||
// CloudflareVerify checks whether the stored Cloudflare API token is valid
|
||||
// and returns the zones it can access.
|
||||
// GET /api/v1/cloudflare/verify
|
||||
func (api *API) CloudflareVerify(w http.ResponseWriter, r *http.Request) {
|
||||
token := api.getCloudflareToken()
|
||||
if token == "" {
|
||||
respondJSON(w, http.StatusOK, cloudflareVerifyResponse{
|
||||
TokenConfigured: false,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
resp := cloudflareVerifyResponse{TokenConfigured: true}
|
||||
|
||||
// Verify token validity
|
||||
tokenStatus, err := verifyCloudflareToken(token)
|
||||
if err != nil {
|
||||
resp.Error = err.Error()
|
||||
respondJSON(w, http.StatusOK, resp)
|
||||
return
|
||||
}
|
||||
resp.TokenStatus = tokenStatus
|
||||
resp.TokenValid = tokenStatus == "active"
|
||||
|
||||
// List accessible zones
|
||||
zones, err := listCloudflareZones(token)
|
||||
if err != nil {
|
||||
resp.Error = "Token valid but failed to list zones: " + err.Error()
|
||||
respondJSON(w, http.StatusOK, resp)
|
||||
return
|
||||
}
|
||||
resp.Zones = zones
|
||||
|
||||
respondJSON(w, http.StatusOK, resp)
|
||||
}
|
||||
|
||||
// verifyCloudflareToken checks token validity via Cloudflare's verify endpoint.
|
||||
func verifyCloudflareToken(apiToken string) (string, error) {
|
||||
req, err := http.NewRequest(http.MethodGet,
|
||||
"https://api.cloudflare.com/client/v4/user/tokens/verify", nil)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
req.Header.Set("Authorization", "Bearer "+apiToken)
|
||||
|
||||
resp, err := http.DefaultClient.Do(req)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
var result struct {
|
||||
Result struct {
|
||||
Status string `json:"status"`
|
||||
} `json:"result"`
|
||||
}
|
||||
if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
|
||||
return "", err
|
||||
}
|
||||
return result.Result.Status, nil
|
||||
}
|
||||
|
||||
// listCloudflareZones returns zones accessible to the token.
|
||||
func listCloudflareZones(apiToken string) ([]cloudflareZone, error) {
|
||||
req, err := http.NewRequest(http.MethodGet,
|
||||
"https://api.cloudflare.com/client/v4/zones", nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
req.Header.Set("Authorization", "Bearer "+apiToken)
|
||||
|
||||
resp, err := http.DefaultClient.Do(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
var result struct {
|
||||
Result []cloudflareZone `json:"result"`
|
||||
}
|
||||
if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result.Result, nil
|
||||
}
|
||||
89
api/internal/api/v1/handlers_cloudflare_test.go
Normal file
89
api/internal/api/v1/handlers_cloudflare_test.go
Normal file
@@ -0,0 +1,89 @@
|
||||
package v1
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestCloudflareVerify_NoToken(t *testing.T) {
|
||||
api, _ := setupTestAPI(t)
|
||||
|
||||
req := httptest.NewRequest("GET", "/api/v1/cloudflare/verify", nil)
|
||||
w := httptest.NewRecorder()
|
||||
|
||||
api.CloudflareVerify(w, req)
|
||||
|
||||
if w.Code != 200 {
|
||||
t.Fatalf("Expected 200, got %d: %s", w.Code, w.Body.String())
|
||||
}
|
||||
|
||||
var resp cloudflareVerifyResponse
|
||||
if err := json.Unmarshal(w.Body.Bytes(), &resp); err != nil {
|
||||
t.Fatalf("Invalid JSON: %v", err)
|
||||
}
|
||||
if resp.TokenConfigured {
|
||||
t.Error("Expected tokenConfigured=false when no token is set")
|
||||
}
|
||||
if resp.TokenValid {
|
||||
t.Error("Expected tokenValid=false when no token is set")
|
||||
}
|
||||
}
|
||||
|
||||
func TestCloudflareVerify_TokenFromSecrets(t *testing.T) {
|
||||
api, tmpDir := setupTestAPI(t)
|
||||
|
||||
// Write a token to secrets — the verify endpoint will find it but
|
||||
// the actual Cloudflare API call will fail (expected in tests)
|
||||
secretsPath := tmpDir + "/secrets.yaml"
|
||||
content := "cloudflare:\n apiToken: test-token-invalid\n"
|
||||
if err := os.WriteFile(secretsPath, []byte(content), 0600); err != nil {
|
||||
t.Fatalf("Failed to write secrets: %v", err)
|
||||
}
|
||||
|
||||
req := httptest.NewRequest("GET", "/api/v1/cloudflare/verify", nil)
|
||||
w := httptest.NewRecorder()
|
||||
|
||||
api.CloudflareVerify(w, req)
|
||||
|
||||
if w.Code != 200 {
|
||||
t.Fatalf("Expected 200, got %d: %s", w.Code, w.Body.String())
|
||||
}
|
||||
|
||||
var resp cloudflareVerifyResponse
|
||||
if err := json.Unmarshal(w.Body.Bytes(), &resp); err != nil {
|
||||
t.Fatalf("Invalid JSON: %v", err)
|
||||
}
|
||||
if !resp.TokenConfigured {
|
||||
t.Error("Expected tokenConfigured=true when token is set")
|
||||
}
|
||||
}
|
||||
|
||||
func TestCloudflareVerify_LegacyFallback(t *testing.T) {
|
||||
api, tmpDir := setupTestAPI(t)
|
||||
|
||||
// Write token at the legacy path
|
||||
secretsPath := tmpDir + "/secrets.yaml"
|
||||
content := "ddns:\n cloudflare:\n apiToken: legacy-token\n"
|
||||
if err := os.WriteFile(secretsPath, []byte(content), 0600); err != nil {
|
||||
t.Fatalf("Failed to write secrets: %v", err)
|
||||
}
|
||||
|
||||
req := httptest.NewRequest("GET", "/api/v1/cloudflare/verify", nil)
|
||||
w := httptest.NewRecorder()
|
||||
|
||||
api.CloudflareVerify(w, req)
|
||||
|
||||
if w.Code != 200 {
|
||||
t.Fatalf("Expected 200, got %d: %s", w.Code, w.Body.String())
|
||||
}
|
||||
|
||||
var resp cloudflareVerifyResponse
|
||||
if err := json.Unmarshal(w.Body.Bytes(), &resp); err != nil {
|
||||
t.Fatalf("Invalid JSON: %v", err)
|
||||
}
|
||||
if !resp.TokenConfigured {
|
||||
t.Error("Expected tokenConfigured=true when legacy token is set")
|
||||
}
|
||||
}
|
||||
@@ -779,7 +779,7 @@ func TestGetGlobalSecrets_RedactsValues(t *testing.T) {
|
||||
api, tmpDir := setupTestAPI(t)
|
||||
|
||||
secretsPath := tmpDir + "/secrets.yaml"
|
||||
content := "ddns:\n cloudflare:\n apiToken: mytoken123\n"
|
||||
content := "cloudflare:\n apiToken: mytoken123\n"
|
||||
if err := os.WriteFile(secretsPath, []byte(content), 0600); err != nil {
|
||||
t.Fatalf("Failed to write secrets: %v", err)
|
||||
}
|
||||
@@ -798,8 +798,7 @@ func TestGetGlobalSecrets_RedactsValues(t *testing.T) {
|
||||
t.Fatalf("Failed to parse response: %v", err)
|
||||
}
|
||||
|
||||
ddns, _ := result["ddns"].(map[string]any)
|
||||
cf, _ := ddns["cloudflare"].(map[string]any)
|
||||
cf, _ := result["cloudflare"].(map[string]any)
|
||||
if cf["apiToken"] == "mytoken123" {
|
||||
t.Error("apiToken should be redacted")
|
||||
}
|
||||
@@ -812,7 +811,7 @@ func TestGetGlobalSecrets_RawMode(t *testing.T) {
|
||||
api, tmpDir := setupTestAPI(t)
|
||||
|
||||
secretsPath := tmpDir + "/secrets.yaml"
|
||||
content := "ddns:\n cloudflare:\n apiToken: mytoken123\n"
|
||||
content := "cloudflare:\n apiToken: mytoken123\n"
|
||||
if err := os.WriteFile(secretsPath, []byte(content), 0600); err != nil {
|
||||
t.Fatalf("Failed to write secrets: %v", err)
|
||||
}
|
||||
@@ -827,8 +826,7 @@ func TestGetGlobalSecrets_RawMode(t *testing.T) {
|
||||
t.Fatalf("Failed to parse response: %v", err)
|
||||
}
|
||||
|
||||
ddns, _ := result["ddns"].(map[string]any)
|
||||
cf, _ := ddns["cloudflare"].(map[string]any)
|
||||
cf, _ := result["cloudflare"].(map[string]any)
|
||||
if cf["apiToken"] != "mytoken123" {
|
||||
t.Errorf("Expected raw value 'mytoken123', got %v", cf["apiToken"])
|
||||
}
|
||||
@@ -839,9 +837,7 @@ func TestUpdateGlobalSecrets_CreatesAndMerges(t *testing.T) {
|
||||
|
||||
// PUT with new key — file doesn't exist yet
|
||||
body, _ := json.Marshal(map[string]any{
|
||||
"ddns": map[string]any{
|
||||
"cloudflare": map[string]any{"apiToken": "tok123"},
|
||||
},
|
||||
"cloudflare": map[string]any{"apiToken": "tok123"},
|
||||
})
|
||||
req := httptest.NewRequest("PUT", "/api/v1/secrets", bytes.NewReader(body))
|
||||
w := httptest.NewRecorder()
|
||||
@@ -860,8 +856,7 @@ func TestUpdateGlobalSecrets_CreatesAndMerges(t *testing.T) {
|
||||
if err := yaml.Unmarshal(data, &written); err != nil {
|
||||
t.Fatalf("Failed to parse written file: %v", err)
|
||||
}
|
||||
ddns, _ := written["ddns"].(map[string]any)
|
||||
cf, _ := ddns["cloudflare"].(map[string]any)
|
||||
cf, _ := written["cloudflare"].(map[string]any)
|
||||
if cf["apiToken"] != "tok123" {
|
||||
t.Errorf("Expected 'tok123', got %v", cf["apiToken"])
|
||||
}
|
||||
@@ -1102,7 +1097,7 @@ func TestUpdateGlobalSecrets_PreservesUnrelatedKeys(t *testing.T) {
|
||||
}
|
||||
|
||||
body, _ := json.Marshal(map[string]any{
|
||||
"ddns": map[string]any{"cloudflare": map[string]any{"apiToken": "tok456"}},
|
||||
"cloudflare": map[string]any{"apiToken": "tok456"},
|
||||
})
|
||||
req := httptest.NewRequest("PUT", "/api/v1/secrets", bytes.NewReader(body))
|
||||
w := httptest.NewRecorder()
|
||||
@@ -1121,8 +1116,7 @@ func TestUpdateGlobalSecrets_PreservesUnrelatedKeys(t *testing.T) {
|
||||
if other["key"] != "preserved" {
|
||||
t.Errorf("Expected unrelated key to be preserved, got %v", other["key"])
|
||||
}
|
||||
ddns, _ := written["ddns"].(map[string]any)
|
||||
cf, _ := ddns["cloudflare"].(map[string]any)
|
||||
cf, _ := written["cloudflare"].(map[string]any)
|
||||
if cf["apiToken"] != "tok456" {
|
||||
t.Errorf("Expected 'tok456', got %v", cf["apiToken"])
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ cloud:
|
||||
# wanInterface: eth0
|
||||
|
||||
# Dynamic DNS — updates DNS A records when your public IP changes.
|
||||
# API token goes in secrets.yaml under ddns.cloudflare.apiToken.
|
||||
# API token goes in secrets.yaml under cloudflare.apiToken.
|
||||
# ddns:
|
||||
# enabled: false
|
||||
# provider: cloudflare
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
import { useState } from 'react';
|
||||
import { NavLink, useParams, useMatch, useLocation } from 'react-router';
|
||||
import { Server, AppWindow, Settings, CloudLightning, Sun, Moon, Monitor, ChevronDown, Usb, Archive, TerminalSquare, Cog, Compass, Lock, Cpu, Layers, Loader2, Shield, Wifi, Network, ShieldAlert, Router } from 'lucide-react';
|
||||
import { Server, AppWindow, Settings, CloudLightning, Sun, Moon, Monitor, ChevronDown, Usb, Archive, TerminalSquare, Cog, Compass, Lock, Cpu, Layers, Loader2, Shield, Wifi, Network, ShieldAlert, Router, Cloud } from 'lucide-react';
|
||||
import {
|
||||
Sidebar,
|
||||
SidebarContent,
|
||||
SidebarFooter,
|
||||
SidebarGroup,
|
||||
SidebarGroupContent,
|
||||
SidebarGroupLabel,
|
||||
SidebarHeader,
|
||||
SidebarMenu,
|
||||
SidebarMenuButton,
|
||||
@@ -30,7 +33,6 @@ function useSidebarSection(key: string) {
|
||||
export function AppSidebar() {
|
||||
const { theme, setTheme } = useTheme();
|
||||
const { state } = useSidebar();
|
||||
const [centralOpen, setCentralOpen] = useSidebarSection('sidebar_central_open');
|
||||
const [cloudOpen, setCloudOpen] = useSidebarSection('sidebar_cloud_open');
|
||||
const [advancedOpen, setAdvancedOpen] = useSidebarSection('sidebar_advanced_open');
|
||||
const { instanceId: instanceIdParam } = useParams<{ instanceId: string }>();
|
||||
@@ -131,18 +133,60 @@ export function AppSidebar() {
|
||||
{/* When collapsed (icon mode), show all nav items at root level */}
|
||||
{state === 'collapsed' ? (
|
||||
<>
|
||||
{/* Central networking */}
|
||||
<SidebarMenuItem>
|
||||
<NavLink to="/central">
|
||||
<NavLink to="/central/cloudflare">
|
||||
{({ isActive }) => (
|
||||
<SidebarMenuButton isActive={isActive} tooltip="Wild Central">
|
||||
<Server className="h-4 w-4" />
|
||||
<span>Central</span>
|
||||
<SidebarMenuButton isActive={isActive} tooltip="Cloudflare">
|
||||
<Cloud className="h-4 w-4" />
|
||||
<span>Cloudflare</span>
|
||||
</SidebarMenuButton>
|
||||
)}
|
||||
</NavLink>
|
||||
</SidebarMenuItem>
|
||||
<SidebarMenuItem>
|
||||
<NavLink to={`/instances/${instanceId}/iso`}>
|
||||
<NavLink to="/central/dns">
|
||||
{({ isActive }) => (
|
||||
<SidebarMenuButton isActive={isActive} tooltip="DNS">
|
||||
<Router className="h-4 w-4" />
|
||||
<span>DNS</span>
|
||||
</SidebarMenuButton>
|
||||
)}
|
||||
</NavLink>
|
||||
</SidebarMenuItem>
|
||||
<SidebarMenuItem>
|
||||
<NavLink to="/central/firewall">
|
||||
{({ isActive }) => (
|
||||
<SidebarMenuButton isActive={isActive} tooltip="Firewall">
|
||||
<Shield className="h-4 w-4" />
|
||||
<span>Firewall</span>
|
||||
</SidebarMenuButton>
|
||||
)}
|
||||
</NavLink>
|
||||
</SidebarMenuItem>
|
||||
<SidebarMenuItem>
|
||||
<NavLink to="/central/vpn">
|
||||
{({ isActive }) => (
|
||||
<SidebarMenuButton isActive={isActive} tooltip="VPN">
|
||||
<Lock className="h-4 w-4" />
|
||||
<span>VPN</span>
|
||||
</SidebarMenuButton>
|
||||
)}
|
||||
</NavLink>
|
||||
</SidebarMenuItem>
|
||||
{/* Wild Cloud */}
|
||||
<SidebarMenuItem>
|
||||
<NavLink to="/cloud">
|
||||
{({ isActive }) => (
|
||||
<SidebarMenuButton isActive={isActive} tooltip="Overview">
|
||||
<Server className="h-4 w-4" />
|
||||
<span>Overview</span>
|
||||
</SidebarMenuButton>
|
||||
)}
|
||||
</NavLink>
|
||||
</SidebarMenuItem>
|
||||
<SidebarMenuItem>
|
||||
<NavLink to="/cloud/iso">
|
||||
{({ isActive }) => (
|
||||
<SidebarMenuButton isActive={isActive} tooltip="Node USB Installer">
|
||||
<Usb className="h-4 w-4" />
|
||||
@@ -214,268 +258,247 @@ export function AppSidebar() {
|
||||
)}
|
||||
</NavLink>
|
||||
</SidebarMenuItem>
|
||||
<SidebarMenuItem>
|
||||
<NavLink to={`/instances/${instanceId}/advanced/terminal`}>
|
||||
{({ isActive }) => (
|
||||
<SidebarMenuButton isActive={isActive} tooltip="Terminal">
|
||||
<TerminalSquare className="h-4 w-4" />
|
||||
<span>Terminal</span>
|
||||
</SidebarMenuButton>
|
||||
)}
|
||||
</NavLink>
|
||||
</SidebarMenuItem>
|
||||
<SidebarMenuItem>
|
||||
<NavLink to={`/instances/${instanceId}/advanced/headlamp`}>
|
||||
{({ isActive }) => (
|
||||
<SidebarMenuButton isActive={isActive} tooltip="Headlamp">
|
||||
<Compass className="h-4 w-4" />
|
||||
<span>Headlamp</span>
|
||||
</SidebarMenuButton>
|
||||
)}
|
||||
</NavLink>
|
||||
</SidebarMenuItem>
|
||||
</>
|
||||
) : (
|
||||
/* When expanded, show grouped/collapsible structure */
|
||||
/* When expanded, show grouped structure */
|
||||
<>
|
||||
<Collapsible open={centralOpen} onOpenChange={setCentralOpen} className="group/collapsible">
|
||||
<SidebarMenuItem>
|
||||
<CollapsibleTrigger asChild>
|
||||
<SidebarMenuButton>
|
||||
<Server className="h-4 w-4" />
|
||||
Central
|
||||
<ChevronDown className="ml-auto transition-transform group-data-[state=open]/collapsible:rotate-180" />
|
||||
</SidebarMenuButton>
|
||||
</CollapsibleTrigger>
|
||||
<CollapsibleContent>
|
||||
<SidebarMenuSub>
|
||||
<SidebarMenuSubItem>
|
||||
<SidebarMenuSubButton asChild isActive={location.pathname === "/central"}>
|
||||
<NavLink to="/central" end>
|
||||
<div className="p-1 rounded-md">
|
||||
<Server className="h-4 w-4" />
|
||||
</div>
|
||||
<span className="truncate">Overview</span>
|
||||
{/* Central — networking platform */}
|
||||
<SidebarGroup>
|
||||
<SidebarGroupLabel>Central</SidebarGroupLabel>
|
||||
<SidebarGroupContent>
|
||||
<SidebarMenu>
|
||||
<SidebarMenuItem>
|
||||
<NavLink to="/central/cloudflare">
|
||||
{({ isActive }) => (
|
||||
<SidebarMenuButton isActive={isActive}>
|
||||
<Cloud className="h-4 w-4" />
|
||||
<span className="truncate">Cloudflare</span>
|
||||
</SidebarMenuButton>
|
||||
)}
|
||||
</NavLink>
|
||||
</SidebarMenuSubButton>
|
||||
</SidebarMenuSubItem>
|
||||
|
||||
<SidebarMenuSubItem>
|
||||
<SidebarMenuSubButton asChild isActive={location.pathname.startsWith("/central/dns")}>
|
||||
</SidebarMenuItem>
|
||||
<SidebarMenuItem>
|
||||
<NavLink to="/central/dns">
|
||||
<div className="p-1 rounded-md">
|
||||
<Router className="h-4 w-4" />
|
||||
</div>
|
||||
<span className="truncate">DNS</span>
|
||||
{({ isActive }) => (
|
||||
<SidebarMenuButton isActive={isActive}>
|
||||
<Router className="h-4 w-4" />
|
||||
<span className="truncate">DNS</span>
|
||||
</SidebarMenuButton>
|
||||
)}
|
||||
</NavLink>
|
||||
</SidebarMenuSubButton>
|
||||
</SidebarMenuSubItem>
|
||||
|
||||
<SidebarMenuSubItem>
|
||||
<SidebarMenuSubButton asChild isActive={location.pathname.startsWith("/central/ingress")}>
|
||||
</SidebarMenuItem>
|
||||
<SidebarMenuItem>
|
||||
<NavLink to="/central/ingress">
|
||||
<div className="p-1 rounded-md">
|
||||
<Network className="h-4 w-4" />
|
||||
</div>
|
||||
<span className="truncate">Ingress Proxy</span>
|
||||
{({ isActive }) => (
|
||||
<SidebarMenuButton isActive={isActive}>
|
||||
<Network className="h-4 w-4" />
|
||||
<span className="truncate">Ingress Proxy</span>
|
||||
</SidebarMenuButton>
|
||||
)}
|
||||
</NavLink>
|
||||
</SidebarMenuSubButton>
|
||||
</SidebarMenuSubItem>
|
||||
|
||||
<SidebarMenuSubItem>
|
||||
<SidebarMenuSubButton asChild isActive={location.pathname.startsWith("/central/firewall")}>
|
||||
</SidebarMenuItem>
|
||||
<SidebarMenuItem>
|
||||
<NavLink to="/central/firewall">
|
||||
<div className="p-1 rounded-md">
|
||||
<Shield className="h-4 w-4" />
|
||||
</div>
|
||||
<span className="truncate">Firewall</span>
|
||||
{({ isActive }) => (
|
||||
<SidebarMenuButton isActive={isActive}>
|
||||
<Shield className="h-4 w-4" />
|
||||
<span className="truncate">Firewall</span>
|
||||
</SidebarMenuButton>
|
||||
)}
|
||||
</NavLink>
|
||||
</SidebarMenuSubButton>
|
||||
</SidebarMenuSubItem>
|
||||
|
||||
<SidebarMenuSubItem>
|
||||
<SidebarMenuSubButton asChild isActive={location.pathname.startsWith("/central/vpn")}>
|
||||
</SidebarMenuItem>
|
||||
<SidebarMenuItem>
|
||||
<NavLink to="/central/vpn">
|
||||
<div className="p-1 rounded-md">
|
||||
<Lock className="h-4 w-4" />
|
||||
</div>
|
||||
<span className="truncate">VPN</span>
|
||||
{({ isActive }) => (
|
||||
<SidebarMenuButton isActive={isActive}>
|
||||
<Lock className="h-4 w-4" />
|
||||
<span className="truncate">VPN</span>
|
||||
</SidebarMenuButton>
|
||||
)}
|
||||
</NavLink>
|
||||
</SidebarMenuSubButton>
|
||||
</SidebarMenuSubItem>
|
||||
|
||||
<SidebarMenuSubItem>
|
||||
<SidebarMenuSubButton asChild isActive={location.pathname.startsWith("/central/crowdsec")}>
|
||||
</SidebarMenuItem>
|
||||
<SidebarMenuItem>
|
||||
<NavLink to="/central/crowdsec">
|
||||
<div className="p-1 rounded-md">
|
||||
<ShieldAlert className="h-4 w-4" />
|
||||
</div>
|
||||
<span className="truncate">CrowdSec</span>
|
||||
{({ isActive }) => (
|
||||
<SidebarMenuButton isActive={isActive}>
|
||||
<ShieldAlert className="h-4 w-4" />
|
||||
<span className="truncate">CrowdSec</span>
|
||||
</SidebarMenuButton>
|
||||
)}
|
||||
</NavLink>
|
||||
</SidebarMenuSubButton>
|
||||
</SidebarMenuSubItem>
|
||||
|
||||
<SidebarMenuSubItem>
|
||||
<SidebarMenuSubButton asChild isActive={location.pathname.startsWith("/central/dhcp")}>
|
||||
</SidebarMenuItem>
|
||||
<SidebarMenuItem>
|
||||
<NavLink to="/central/dhcp">
|
||||
<div className="p-1 rounded-md">
|
||||
<Wifi className="h-4 w-4" />
|
||||
</div>
|
||||
<span className="truncate">DHCP</span>
|
||||
{({ isActive }) => (
|
||||
<SidebarMenuButton isActive={isActive}>
|
||||
<Wifi className="h-4 w-4" />
|
||||
<span className="truncate">DHCP</span>
|
||||
</SidebarMenuButton>
|
||||
)}
|
||||
</NavLink>
|
||||
</SidebarMenuSubButton>
|
||||
</SidebarMenuSubItem>
|
||||
</SidebarMenuItem>
|
||||
</SidebarMenu>
|
||||
</SidebarGroupContent>
|
||||
</SidebarGroup>
|
||||
|
||||
<SidebarMenuSubItem>
|
||||
<SidebarMenuSubButton asChild isActive={location.pathname === `/instances/${instanceId}/iso`}>
|
||||
<NavLink to={`/instances/${instanceId}/iso`}>
|
||||
<div className="p-1 rounded-md">
|
||||
<Usb className="h-4 w-4" />
|
||||
</div>
|
||||
<span className="truncate">Node USB Installer</span>
|
||||
{/* Wild Cloud — meta + instance management */}
|
||||
<SidebarGroup>
|
||||
<SidebarGroupLabel>Wild Cloud</SidebarGroupLabel>
|
||||
<SidebarGroupContent>
|
||||
<SidebarMenu>
|
||||
<SidebarMenuItem>
|
||||
<NavLink to="/cloud">
|
||||
{({ isActive }) => (
|
||||
<SidebarMenuButton isActive={isActive}>
|
||||
<Server className="h-4 w-4" />
|
||||
<span className="truncate">Overview</span>
|
||||
</SidebarMenuButton>
|
||||
)}
|
||||
</NavLink>
|
||||
</SidebarMenuSubButton>
|
||||
</SidebarMenuSubItem>
|
||||
</SidebarMenuSub>
|
||||
</CollapsibleContent>
|
||||
</SidebarMenuItem>
|
||||
</Collapsible>
|
||||
|
||||
{/* Instance Selector */}
|
||||
<SidebarMenuItem>
|
||||
<div className="px-2 py-2">
|
||||
<InstanceSwitcher />
|
||||
</div>
|
||||
</SidebarMenuItem>
|
||||
|
||||
<SidebarMenuItem>
|
||||
<NavLink to={`/instances/${instanceId}/dashboard`}>
|
||||
{({ isActive }) => (
|
||||
<SidebarMenuButton
|
||||
isActive={isActive}
|
||||
tooltip="Instance dashboard and overview"
|
||||
>
|
||||
<CloudLightning className="h-4 w-4" />
|
||||
<span className="truncate">Dashboard</span>
|
||||
</SidebarMenuButton>
|
||||
)}
|
||||
</NavLink>
|
||||
</SidebarMenuItem>
|
||||
|
||||
<Collapsible open={cloudOpen} onOpenChange={setCloudOpen} className="group/collapsible">
|
||||
<SidebarMenuItem>
|
||||
<CollapsibleTrigger asChild>
|
||||
<SidebarMenuButton>
|
||||
<CloudLightning className="h-4 w-4" />
|
||||
Cloud
|
||||
<ChevronDown className="ml-auto transition-transform group-data-[state=open]/collapsible:rotate-180" />
|
||||
</SidebarMenuButton>
|
||||
</CollapsibleTrigger>
|
||||
<CollapsibleContent>
|
||||
<SidebarMenuSub>
|
||||
<SidebarMenuSubItem>
|
||||
<SidebarMenuSubButton asChild isActive={location.pathname.startsWith(`/instances/${instanceId}/cluster`)}>
|
||||
<NavLink to={`/instances/${instanceId}/cluster`}>
|
||||
<div className="p-1 rounded-md">
|
||||
<Cpu className="h-4 w-4" />
|
||||
</div>
|
||||
<span className="truncate">Nodes</span>
|
||||
{renderPhaseIndicator('control-nodes')}
|
||||
</SidebarMenuItem>
|
||||
<SidebarMenuItem>
|
||||
<NavLink to="/cloud/iso">
|
||||
{({ isActive }) => (
|
||||
<SidebarMenuButton isActive={isActive}>
|
||||
<Usb className="h-4 w-4" />
|
||||
<span className="truncate">Node USB Installer</span>
|
||||
</SidebarMenuButton>
|
||||
)}
|
||||
</NavLink>
|
||||
</SidebarMenuSubButton>
|
||||
</SidebarMenuSubItem>
|
||||
</SidebarMenuItem>
|
||||
|
||||
<SidebarMenuSubItem>
|
||||
<SidebarMenuSubButton asChild isActive={servicesActive}>
|
||||
<NavLink to={`/instances/${instanceId}/apps/services`}>
|
||||
<div className="p-1 rounded-md">
|
||||
<Layers className="h-4 w-4" />
|
||||
</div>
|
||||
<span className="truncate">Services</span>
|
||||
{renderPhaseIndicator('cluster-services')}
|
||||
{/* Instance Selector — divides meta from instance-scoped items */}
|
||||
<SidebarMenuItem>
|
||||
<div className="px-2 py-2">
|
||||
<InstanceSwitcher />
|
||||
</div>
|
||||
</SidebarMenuItem>
|
||||
|
||||
<SidebarMenuItem>
|
||||
<NavLink to={`/instances/${instanceId}/dashboard`}>
|
||||
{({ isActive }) => (
|
||||
<SidebarMenuButton isActive={isActive} tooltip="Instance dashboard and overview">
|
||||
<CloudLightning className="h-4 w-4" />
|
||||
<span className="truncate">Dashboard</span>
|
||||
</SidebarMenuButton>
|
||||
)}
|
||||
</NavLink>
|
||||
</SidebarMenuSubButton>
|
||||
</SidebarMenuSubItem>
|
||||
</SidebarMenuSub>
|
||||
</CollapsibleContent>
|
||||
</SidebarMenuItem>
|
||||
</Collapsible>
|
||||
</SidebarMenuItem>
|
||||
|
||||
<SidebarMenuItem>
|
||||
<NavLink to={`/instances/${instanceId}/apps`}>
|
||||
{() => (
|
||||
<SidebarMenuButton isActive={appsActive} tooltip="Manage installed apps">
|
||||
<AppWindow className="h-4 w-4" />
|
||||
<span className="truncate">Apps</span>
|
||||
{renderPhaseIndicator('cluster-services')}
|
||||
</SidebarMenuButton>
|
||||
)}
|
||||
</NavLink>
|
||||
</SidebarMenuItem>
|
||||
<Collapsible open={cloudOpen} onOpenChange={setCloudOpen} className="group/collapsible">
|
||||
<SidebarMenuItem>
|
||||
<CollapsibleTrigger asChild>
|
||||
<SidebarMenuButton>
|
||||
<CloudLightning className="h-4 w-4" />
|
||||
Cloud
|
||||
<ChevronDown className="ml-auto transition-transform group-data-[state=open]/collapsible:rotate-180" />
|
||||
</SidebarMenuButton>
|
||||
</CollapsibleTrigger>
|
||||
<CollapsibleContent>
|
||||
<SidebarMenuSub>
|
||||
<SidebarMenuSubItem>
|
||||
<SidebarMenuSubButton asChild isActive={location.pathname.startsWith(`/instances/${instanceId}/cluster`)}>
|
||||
<NavLink to={`/instances/${instanceId}/cluster`}>
|
||||
<div className="p-1 rounded-md">
|
||||
<Cpu className="h-4 w-4" />
|
||||
</div>
|
||||
<span className="truncate">Nodes</span>
|
||||
{renderPhaseIndicator('control-nodes')}
|
||||
</NavLink>
|
||||
</SidebarMenuSubButton>
|
||||
</SidebarMenuSubItem>
|
||||
<SidebarMenuSubItem>
|
||||
<SidebarMenuSubButton asChild isActive={servicesActive}>
|
||||
<NavLink to={`/instances/${instanceId}/apps/services`}>
|
||||
<div className="p-1 rounded-md">
|
||||
<Layers className="h-4 w-4" />
|
||||
</div>
|
||||
<span className="truncate">Services</span>
|
||||
{renderPhaseIndicator('cluster-services')}
|
||||
</NavLink>
|
||||
</SidebarMenuSubButton>
|
||||
</SidebarMenuSubItem>
|
||||
</SidebarMenuSub>
|
||||
</CollapsibleContent>
|
||||
</SidebarMenuItem>
|
||||
</Collapsible>
|
||||
|
||||
<SidebarMenuItem>
|
||||
<NavLink to={`/instances/${instanceId}/backups`}>
|
||||
{({ isActive }) => (
|
||||
<SidebarMenuButton isActive={isActive} tooltip="Manage backups and recovery">
|
||||
<Archive className="h-4 w-4" />
|
||||
<span className="truncate">Backups</span>
|
||||
{hasRunningBackupOps ? (
|
||||
<Loader2 className="h-3 w-3 animate-spin ml-auto shrink-0 text-blue-500" />
|
||||
) : hasBackupWarning ? (
|
||||
<span className="h-2 w-2 rounded-full bg-red-500 ml-auto shrink-0" />
|
||||
) : null}
|
||||
</SidebarMenuButton>
|
||||
)}
|
||||
</NavLink>
|
||||
</SidebarMenuItem>
|
||||
|
||||
<Collapsible open={advancedOpen} onOpenChange={setAdvancedOpen} className="group/collapsible">
|
||||
<SidebarMenuItem>
|
||||
<CollapsibleTrigger asChild>
|
||||
<SidebarMenuButton>
|
||||
<Settings className="h-4 w-4" />
|
||||
Advanced
|
||||
<ChevronDown className="ml-auto transition-transform group-data-[state=open]/collapsible:rotate-180" />
|
||||
</SidebarMenuButton>
|
||||
</CollapsibleTrigger>
|
||||
<CollapsibleContent>
|
||||
<SidebarMenuSub>
|
||||
<SidebarMenuSubItem>
|
||||
<SidebarMenuSubButton asChild isActive={location.pathname.startsWith(`/instances/${instanceId}/advanced/config`)}>
|
||||
<NavLink to={`/instances/${instanceId}/advanced/config`}>
|
||||
<div className="p-1 rounded-md">
|
||||
<Cog className="h-4 w-4" />
|
||||
</div>
|
||||
<span className="truncate">Configuration</span>
|
||||
<SidebarMenuItem>
|
||||
<NavLink to={`/instances/${instanceId}/apps`}>
|
||||
{() => (
|
||||
<SidebarMenuButton isActive={appsActive} tooltip="Manage installed apps">
|
||||
<AppWindow className="h-4 w-4" />
|
||||
<span className="truncate">Apps</span>
|
||||
{renderPhaseIndicator('cluster-services')}
|
||||
</SidebarMenuButton>
|
||||
)}
|
||||
</NavLink>
|
||||
</SidebarMenuSubButton>
|
||||
</SidebarMenuSubItem>
|
||||
</SidebarMenuItem>
|
||||
|
||||
<SidebarMenuSubItem>
|
||||
<SidebarMenuSubButton asChild isActive={location.pathname.startsWith(`/instances/${instanceId}/advanced/terminal`)}>
|
||||
<NavLink to={`/instances/${instanceId}/advanced/terminal`}>
|
||||
<div className="p-1 rounded-md">
|
||||
<TerminalSquare className="h-4 w-4" />
|
||||
</div>
|
||||
<span className="truncate">Terminal</span>
|
||||
<SidebarMenuItem>
|
||||
<NavLink to={`/instances/${instanceId}/backups`}>
|
||||
{({ isActive }) => (
|
||||
<SidebarMenuButton isActive={isActive} tooltip="Manage backups and recovery">
|
||||
<Archive className="h-4 w-4" />
|
||||
<span className="truncate">Backups</span>
|
||||
{hasRunningBackupOps ? (
|
||||
<Loader2 className="h-3 w-3 animate-spin ml-auto shrink-0 text-blue-500" />
|
||||
) : hasBackupWarning ? (
|
||||
<span className="h-2 w-2 rounded-full bg-red-500 ml-auto shrink-0" />
|
||||
) : null}
|
||||
</SidebarMenuButton>
|
||||
)}
|
||||
</NavLink>
|
||||
</SidebarMenuSubButton>
|
||||
</SidebarMenuSubItem>
|
||||
</SidebarMenuItem>
|
||||
|
||||
<SidebarMenuSubItem>
|
||||
<SidebarMenuSubButton asChild isActive={location.pathname.startsWith(`/instances/${instanceId}/advanced/headlamp`)}>
|
||||
<NavLink to={`/instances/${instanceId}/advanced/headlamp`}>
|
||||
<div className="p-1 rounded-md">
|
||||
<Compass className="h-4 w-4" />
|
||||
</div>
|
||||
<span className="truncate">Headlamp</span>
|
||||
</NavLink>
|
||||
</SidebarMenuSubButton>
|
||||
</SidebarMenuSubItem>
|
||||
</SidebarMenuSub>
|
||||
</CollapsibleContent>
|
||||
</SidebarMenuItem>
|
||||
</Collapsible>
|
||||
<Collapsible open={advancedOpen} onOpenChange={setAdvancedOpen} className="group/collapsible">
|
||||
<SidebarMenuItem>
|
||||
<CollapsibleTrigger asChild>
|
||||
<SidebarMenuButton>
|
||||
<Settings className="h-4 w-4" />
|
||||
Advanced
|
||||
<ChevronDown className="ml-auto transition-transform group-data-[state=open]/collapsible:rotate-180" />
|
||||
</SidebarMenuButton>
|
||||
</CollapsibleTrigger>
|
||||
<CollapsibleContent>
|
||||
<SidebarMenuSub>
|
||||
<SidebarMenuSubItem>
|
||||
<SidebarMenuSubButton asChild isActive={location.pathname.startsWith(`/instances/${instanceId}/advanced/config`)}>
|
||||
<NavLink to={`/instances/${instanceId}/advanced/config`}>
|
||||
<div className="p-1 rounded-md">
|
||||
<Cog className="h-4 w-4" />
|
||||
</div>
|
||||
<span className="truncate">Configuration</span>
|
||||
</NavLink>
|
||||
</SidebarMenuSubButton>
|
||||
</SidebarMenuSubItem>
|
||||
<SidebarMenuSubItem>
|
||||
<SidebarMenuSubButton asChild isActive={location.pathname.startsWith(`/instances/${instanceId}/advanced/terminal`)}>
|
||||
<NavLink to={`/instances/${instanceId}/advanced/terminal`}>
|
||||
<div className="p-1 rounded-md">
|
||||
<TerminalSquare className="h-4 w-4" />
|
||||
</div>
|
||||
<span className="truncate">Terminal</span>
|
||||
</NavLink>
|
||||
</SidebarMenuSubButton>
|
||||
</SidebarMenuSubItem>
|
||||
<SidebarMenuSubItem>
|
||||
<SidebarMenuSubButton asChild isActive={location.pathname.startsWith(`/instances/${instanceId}/advanced/headlamp`)}>
|
||||
<NavLink to={`/instances/${instanceId}/advanced/headlamp`}>
|
||||
<div className="p-1 rounded-md">
|
||||
<Compass className="h-4 w-4" />
|
||||
</div>
|
||||
<span className="truncate">Headlamp</span>
|
||||
</NavLink>
|
||||
</SidebarMenuSubButton>
|
||||
</SidebarMenuSubItem>
|
||||
</SidebarMenuSub>
|
||||
</CollapsibleContent>
|
||||
</SidebarMenuItem>
|
||||
</Collapsible>
|
||||
</SidebarMenu>
|
||||
</SidebarGroupContent>
|
||||
</SidebarGroup>
|
||||
</>
|
||||
)}
|
||||
</SidebarMenu>
|
||||
|
||||
@@ -3,13 +3,12 @@ import { Card } from './ui/card';
|
||||
import { Button } from './ui/button';
|
||||
import { Input, Label } from './ui';
|
||||
import { Alert, AlertDescription } from './ui/alert';
|
||||
import { HardDrive, Settings, CheckCircle, BookOpen, ExternalLink, Loader2, AlertCircle, FolderTree, Mail, Edit2, Check, X, RotateCw, ArrowUpCircle, Terminal, Globe, Shield, KeyRound } from 'lucide-react';
|
||||
import { HardDrive, Settings, CheckCircle, BookOpen, ExternalLink, Loader2, AlertCircle, FolderTree, Mail, Edit2, Check, X, RotateCw, ArrowUpCircle, Terminal } from 'lucide-react';
|
||||
import { Badge } from './ui/badge';
|
||||
import { useCentralStatus } from '../hooks/useCentralStatus';
|
||||
import { useInstanceConfig, useInstanceContext, useConfig } from '../hooks';
|
||||
import { usePageHelp } from '../hooks/usePageHelp';
|
||||
import { useTalosClientInfo, useTalosClientUpgrade, useTalosVersions } from '../services/api';
|
||||
import { useCert } from '../hooks/useCert';
|
||||
|
||||
export function CentralComponent() {
|
||||
const { currentInstance } = useInstanceContext();
|
||||
@@ -19,10 +18,6 @@ export function CentralComponent() {
|
||||
|
||||
const [editingOperator, setEditingOperator] = useState(false);
|
||||
const [operatorEmail, setOperatorEmail] = useState('');
|
||||
|
||||
const { status: certStatus, isLoading: certLoading, provision: provisionCert, isProvisioning, provisionError } = useCert();
|
||||
const [editingDomain, setEditingDomain] = useState(false);
|
||||
const [domainInput, setDomainInput] = useState('');
|
||||
const [successMessage, setSuccessMessage] = useState<string | null>(null);
|
||||
const [errorMessage, setErrorMessage] = useState<string | null>(null);
|
||||
|
||||
@@ -324,133 +319,6 @@ export function CentralComponent() {
|
||||
</Card>
|
||||
)}
|
||||
|
||||
{/* Central Domain & TLS */}
|
||||
<Card className="p-4 border-l-4 border-l-green-500">
|
||||
<div className="flex items-center justify-between mb-3">
|
||||
<div className="flex items-center gap-2">
|
||||
<Globe className="h-5 w-5 text-green-500" />
|
||||
<div className="font-medium">Central Domain</div>
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
{certStatus?.cert?.exists && (
|
||||
<Badge variant="success" className="gap-1">
|
||||
<Shield className="h-3 w-3" />
|
||||
TLS
|
||||
</Badge>
|
||||
)}
|
||||
{!editingDomain && (
|
||||
<Button variant="ghost" size="sm" onClick={() => {
|
||||
setDomainInput(globalConfig?.cloud?.central?.domain || '');
|
||||
setEditingDomain(true);
|
||||
}} disabled={isUpdating}>
|
||||
<Edit2 className="h-4 w-4" />
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{editingDomain ? (
|
||||
<div className="space-y-3">
|
||||
<div>
|
||||
<Label htmlFor="central-domain">Domain</Label>
|
||||
<Input
|
||||
id="central-domain"
|
||||
value={domainInput}
|
||||
onChange={(e) => setDomainInput(e.target.value)}
|
||||
placeholder="central.example.com"
|
||||
className="mt-1 font-mono"
|
||||
/>
|
||||
<p className="text-xs text-muted-foreground mt-1">
|
||||
Must resolve to this server (via internal DNS or VPN).
|
||||
</p>
|
||||
</div>
|
||||
<div className="flex justify-end gap-2">
|
||||
<Button variant="outline" size="sm" onClick={() => setEditingDomain(false)} disabled={isUpdating}>
|
||||
<X className="h-4 w-4 mr-1" />Cancel
|
||||
</Button>
|
||||
<Button size="sm" onClick={async () => {
|
||||
if (!globalConfig) return;
|
||||
try {
|
||||
await updateGlobalConfig({
|
||||
...globalConfig,
|
||||
cloud: {
|
||||
...globalConfig.cloud,
|
||||
central: { domain: domainInput },
|
||||
},
|
||||
});
|
||||
setEditingDomain(false);
|
||||
showSuccess('Central domain saved');
|
||||
} catch (err) {
|
||||
showError(`Failed to save domain: ${err instanceof Error ? err.message : String(err)}`);
|
||||
}
|
||||
}} disabled={isUpdating}>
|
||||
{isUpdating ? <Loader2 className="h-4 w-4 mr-1 animate-spin" /> : <Check className="h-4 w-4 mr-1" />}
|
||||
Save
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<div className="space-y-3">
|
||||
<div className="font-mono text-sm ml-7">
|
||||
{globalConfig?.cloud?.central?.domain ? (
|
||||
<a
|
||||
href={`https://${globalConfig.cloud.central.domain}`}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className="text-primary hover:underline"
|
||||
>
|
||||
{globalConfig.cloud.central.domain}
|
||||
</a>
|
||||
) : (
|
||||
<span className="text-muted-foreground italic">Not configured</span>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{globalConfig?.cloud?.central?.domain && (
|
||||
<div className="ml-7 space-y-2">
|
||||
{certLoading ? (
|
||||
<Loader2 className="h-4 w-4 animate-spin text-muted-foreground" />
|
||||
) : certStatus?.cert?.exists ? (
|
||||
<div className="text-sm space-y-1">
|
||||
<div className="flex items-center gap-2 text-green-600 dark:text-green-400">
|
||||
<Shield className="h-4 w-4" />
|
||||
<span>Valid TLS certificate</span>
|
||||
</div>
|
||||
<div className="text-xs text-muted-foreground">
|
||||
Expires in {certStatus.cert.daysLeft} days
|
||||
{certStatus.cert.issuerCN && <> · {certStatus.cert.issuerCN}</>}
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<div className="space-y-2">
|
||||
<div className="flex items-center gap-2 text-amber-600 dark:text-amber-400 text-sm">
|
||||
<KeyRound className="h-4 w-4" />
|
||||
<span>No TLS certificate</span>
|
||||
</div>
|
||||
<Button
|
||||
size="sm"
|
||||
onClick={async () => {
|
||||
try { await provisionCert(); } catch { /* error shown below */ }
|
||||
}}
|
||||
disabled={isProvisioning}
|
||||
className="gap-1"
|
||||
>
|
||||
{isProvisioning ? <Loader2 className="h-3 w-3 animate-spin" /> : <Shield className="h-3 w-3" />}
|
||||
{isProvisioning ? 'Provisioning...' : 'Provision TLS Certificate'}
|
||||
</Button>
|
||||
{provisionError && (
|
||||
<Alert variant="error">
|
||||
<AlertCircle className="h-4 w-4" />
|
||||
<AlertDescription className="text-xs">{(provisionError as Error).message}</AlertDescription>
|
||||
</Alert>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</Card>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2,14 +2,15 @@ import { useState } from 'react';
|
||||
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
|
||||
import { Card, CardContent } from './ui/card';
|
||||
import { Button } from './ui/button';
|
||||
import { Input } from './ui';
|
||||
import { Input, Label } from './ui';
|
||||
import { Alert, AlertDescription } from './ui/alert';
|
||||
import {
|
||||
Cloud, CheckCircle, XCircle, AlertCircle, Loader2, Edit2,
|
||||
RefreshCw, ExternalLink, BookOpen, Globe, Key, Shield,
|
||||
RefreshCw, ExternalLink, BookOpen, Globe, Key, Shield, Check, X, KeyRound,
|
||||
} from 'lucide-react';
|
||||
import { Badge } from './ui/badge';
|
||||
import { useCloudflare } from '../hooks/useCloudflare';
|
||||
import { useConfig } from '../hooks';
|
||||
import { useDdns } from '../hooks/useDdns';
|
||||
import { useCert } from '../hooks/useCert';
|
||||
import { secretsApi } from '../services/api';
|
||||
@@ -17,8 +18,9 @@ import { usePageHelp } from '../hooks/usePageHelp';
|
||||
|
||||
export function CloudflareComponent() {
|
||||
const { verification, isLoading: isVerifying, refetch: reverify } = useCloudflare();
|
||||
const { config: globalConfig, updateConfig: updateGlobalConfig, isUpdating } = useConfig();
|
||||
const { status: ddnsStatus } = useDdns();
|
||||
const { status: certStatus } = useCert();
|
||||
const { status: certStatus, isLoading: certLoading, provision: provisionCert, isProvisioning, provisionError } = useCert();
|
||||
|
||||
const queryClient = useQueryClient();
|
||||
const { data: globalSecrets } = useQuery({
|
||||
@@ -44,6 +46,8 @@ export function CloudflareComponent() {
|
||||
|
||||
const [editingToken, setEditingToken] = useState(false);
|
||||
const [tokenValue, setTokenValue] = useState('');
|
||||
const [editingDomain, setEditingDomain] = useState(false);
|
||||
const [domainInput, setDomainInput] = useState('');
|
||||
const [successMessage, setSuccessMessage] = useState<string | null>(null);
|
||||
const [errorMessage, setErrorMessage] = useState<string | null>(null);
|
||||
|
||||
@@ -170,6 +174,134 @@ export function CloudflareComponent() {
|
||||
)}
|
||||
</Card>
|
||||
|
||||
{/* Central Domain & TLS Card */}
|
||||
<Card className="p-4 border-l-4 border-l-green-500">
|
||||
<div className="flex items-center justify-between mb-3">
|
||||
<div className="flex items-center gap-2">
|
||||
<Globe className="h-5 w-5 text-green-500" />
|
||||
<div className="font-medium">Central Domain</div>
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
{certStatus?.cert?.exists && (
|
||||
<Badge variant="success" className="gap-1">
|
||||
<Shield className="h-3 w-3" />
|
||||
TLS
|
||||
</Badge>
|
||||
)}
|
||||
{!editingDomain && (
|
||||
<Button variant="ghost" size="sm" onClick={() => {
|
||||
setDomainInput(globalConfig?.cloud?.central?.domain || '');
|
||||
setEditingDomain(true);
|
||||
}} disabled={isUpdating}>
|
||||
<Edit2 className="h-4 w-4" />
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{editingDomain ? (
|
||||
<div className="space-y-3 ml-7">
|
||||
<div>
|
||||
<Label htmlFor="central-domain">Domain</Label>
|
||||
<Input
|
||||
id="central-domain"
|
||||
value={domainInput}
|
||||
onChange={(e) => setDomainInput(e.target.value)}
|
||||
placeholder="central.example.com"
|
||||
className="mt-1 font-mono"
|
||||
/>
|
||||
<p className="text-xs text-muted-foreground mt-1">
|
||||
Must resolve to this server (via internal DNS or VPN).
|
||||
</p>
|
||||
</div>
|
||||
<div className="flex justify-end gap-2">
|
||||
<Button variant="outline" size="sm" onClick={() => setEditingDomain(false)} disabled={isUpdating}>
|
||||
<X className="h-4 w-4 mr-1" />Cancel
|
||||
</Button>
|
||||
<Button size="sm" onClick={async () => {
|
||||
if (!globalConfig) return;
|
||||
try {
|
||||
await updateGlobalConfig({
|
||||
...globalConfig,
|
||||
cloud: {
|
||||
...globalConfig.cloud,
|
||||
central: { domain: domainInput },
|
||||
},
|
||||
});
|
||||
setEditingDomain(false);
|
||||
showSuccess('Central domain saved');
|
||||
} catch (err) {
|
||||
showError(`Failed to save domain: ${err instanceof Error ? err.message : String(err)}`);
|
||||
}
|
||||
}} disabled={isUpdating}>
|
||||
{isUpdating ? <Loader2 className="h-4 w-4 mr-1 animate-spin" /> : <Check className="h-4 w-4 mr-1" />}
|
||||
Save
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<div className="space-y-3">
|
||||
<div className="font-mono text-sm ml-7">
|
||||
{globalConfig?.cloud?.central?.domain ? (
|
||||
<a
|
||||
href={`https://${globalConfig.cloud.central.domain}`}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className="text-primary hover:underline"
|
||||
>
|
||||
{globalConfig.cloud.central.domain}
|
||||
</a>
|
||||
) : (
|
||||
<span className="text-muted-foreground italic">Not configured</span>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{globalConfig?.cloud?.central?.domain && (
|
||||
<div className="ml-7 space-y-2">
|
||||
{certLoading ? (
|
||||
<Loader2 className="h-4 w-4 animate-spin text-muted-foreground" />
|
||||
) : certStatus?.cert?.exists ? (
|
||||
<div className="text-sm space-y-1">
|
||||
<div className="flex items-center gap-2 text-green-600 dark:text-green-400">
|
||||
<Shield className="h-4 w-4" />
|
||||
<span>Valid TLS certificate</span>
|
||||
</div>
|
||||
<div className="text-xs text-muted-foreground">
|
||||
Expires in {certStatus.cert.daysLeft} days
|
||||
{certStatus.cert.issuerCN && <> · {certStatus.cert.issuerCN}</>}
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<div className="space-y-2">
|
||||
<div className="flex items-center gap-2 text-amber-600 dark:text-amber-400 text-sm">
|
||||
<KeyRound className="h-4 w-4" />
|
||||
<span>No TLS certificate</span>
|
||||
</div>
|
||||
<Button
|
||||
size="sm"
|
||||
onClick={async () => {
|
||||
try { await provisionCert(); } catch { /* error shown below */ }
|
||||
}}
|
||||
disabled={isProvisioning}
|
||||
className="gap-1"
|
||||
>
|
||||
{isProvisioning ? <Loader2 className="h-3 w-3 animate-spin" /> : <Shield className="h-3 w-3" />}
|
||||
{isProvisioning ? 'Provisioning...' : 'Provision TLS Certificate'}
|
||||
</Button>
|
||||
{provisionError && (
|
||||
<Alert variant="error">
|
||||
<AlertCircle className="h-4 w-4" />
|
||||
<AlertDescription className="text-xs">{(provisionError as Error).message}</AlertDescription>
|
||||
</Alert>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</Card>
|
||||
|
||||
{/* Verification Checklist Card */}
|
||||
<Card className="p-4 border-l-4 border-l-blue-500">
|
||||
<div className="flex items-center justify-between mb-3">
|
||||
|
||||
@@ -207,7 +207,7 @@ export function FirewallComponent() {
|
||||
{entry.label}
|
||||
</span>
|
||||
{isAuto ? (
|
||||
<Lock className="h-3 w-3 text-muted-foreground shrink-0" title="Managed automatically" />
|
||||
<span title="Managed automatically"><Lock className="h-3 w-3 text-muted-foreground shrink-0" /></span>
|
||||
) : (
|
||||
<button
|
||||
onClick={() => removePort(entry.port, entry.protocol)}
|
||||
|
||||
@@ -12,6 +12,7 @@ export { ConfigEditor } from './ConfigEditor';
|
||||
export { ErrorBoundary, ErrorFallback } from './ErrorBoundary';
|
||||
export { CloudComponent } from './CloudComponent';
|
||||
export { CentralComponent } from './CentralComponent';
|
||||
export { CloudflareComponent } from './CloudflareComponent';
|
||||
export { DnsComponent } from './DnsComponent';
|
||||
export { DhcpComponent } from './DhcpComponent';
|
||||
export { AppsComponent } from './AppsComponent';
|
||||
|
||||
@@ -15,4 +15,5 @@ export { useAvailableApps, useAvailableApp, useDeployedApps, useAppBackups } fro
|
||||
export { useOperations, useOperation, useCancelOperation } from './useOperations';
|
||||
export { useSecrets, useUpdateSecrets } from './useSecrets';
|
||||
export { useKubeconfig, useTalosconfig, useRegenerateKubeconfig } from './useClusterAccess';
|
||||
export { useCentralStatus } from './useCentralStatus';
|
||||
export { useCentralStatus } from './useCentralStatus';
|
||||
export { useCloudflare } from './useCloudflare';
|
||||
18
web/src/hooks/useCloudflare.ts
Normal file
18
web/src/hooks/useCloudflare.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { cloudflareApi } from '../services/api/cloudflare';
|
||||
|
||||
export const useCloudflare = () => {
|
||||
const verifyQuery = useQuery({
|
||||
queryKey: ['cloudflare', 'verify'],
|
||||
queryFn: () => cloudflareApi.verify(),
|
||||
refetchInterval: false,
|
||||
staleTime: 60000,
|
||||
});
|
||||
|
||||
return {
|
||||
verification: verifyQuery.data,
|
||||
isLoading: verifyQuery.isLoading,
|
||||
error: verifyQuery.error,
|
||||
refetch: verifyQuery.refetch,
|
||||
};
|
||||
};
|
||||
10
web/src/router/pages/CloudflarePage.tsx
Normal file
10
web/src/router/pages/CloudflarePage.tsx
Normal file
@@ -0,0 +1,10 @@
|
||||
import { ErrorBoundary } from '../../components';
|
||||
import { CloudflareComponent } from '../../components/CloudflareComponent';
|
||||
|
||||
export function CloudflarePage() {
|
||||
return (
|
||||
<ErrorBoundary>
|
||||
<CloudflareComponent />
|
||||
</ErrorBoundary>
|
||||
);
|
||||
}
|
||||
@@ -34,6 +34,7 @@ import { HeadlampPage } from './pages/HeadlampPage';
|
||||
import { AssetsIsoPage } from './pages/AssetsIsoPage';
|
||||
import { AssetsPxePage } from './pages/AssetsPxePage';
|
||||
import { VpnPage } from './pages/VpnPage';
|
||||
import { CloudflarePage } from './pages/CloudflarePage';
|
||||
|
||||
export const routes: RouteObject[] = [
|
||||
{
|
||||
@@ -49,10 +50,18 @@ export const routes: RouteObject[] = [
|
||||
element: <AssetsPxePage />,
|
||||
},
|
||||
{
|
||||
path: '/central',
|
||||
path: '/cloud',
|
||||
element: <CentralLayout />,
|
||||
children: [
|
||||
{ index: true, element: <CentralPage /> },
|
||||
{ path: 'iso', element: <IsoPage /> },
|
||||
],
|
||||
},
|
||||
{
|
||||
path: '/central',
|
||||
element: <CentralLayout />,
|
||||
children: [
|
||||
{ path: 'cloudflare', element: <CloudflarePage /> },
|
||||
{ path: 'firewall', element: <FirewallPage /> },
|
||||
{ path: 'dhcp', element: <DhcpPage /> },
|
||||
{ path: 'crowdsec', element: <CrowdSecPage /> },
|
||||
|
||||
20
web/src/services/api/cloudflare.ts
Normal file
20
web/src/services/api/cloudflare.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { apiClient } from './client';
|
||||
|
||||
export interface CloudflareZone {
|
||||
id: string;
|
||||
name: string;
|
||||
}
|
||||
|
||||
export interface CloudflareVerifyResponse {
|
||||
tokenConfigured: boolean;
|
||||
tokenValid: boolean;
|
||||
tokenStatus: string;
|
||||
zones: CloudflareZone[] | null;
|
||||
error?: string;
|
||||
}
|
||||
|
||||
export const cloudflareApi = {
|
||||
async verify(): Promise<CloudflareVerifyResponse> {
|
||||
return apiClient.get('/api/v1/cloudflare/verify');
|
||||
},
|
||||
};
|
||||
@@ -14,6 +14,8 @@ export { vpnApi } from './vpn';
|
||||
export type { VpnStatus, VpnConfig, VpnPeer, VpnPeerConfig } from './vpn';
|
||||
export { certApi } from './cert';
|
||||
export type { CertStatusResponse, CertInfo } from './cert';
|
||||
export { cloudflareApi } from './cloudflare';
|
||||
export type { CloudflareVerifyResponse, CloudflareZone } from './cloudflare';
|
||||
export { pxeApi } from './pxe';
|
||||
export { assetsApi } from './assets';
|
||||
export { terminalApi } from './terminal';
|
||||
|
||||
Reference in New Issue
Block a user