2025-11-18 13:30:37 +01:00
|
|
|
|
"use client"
|
2025-11-04 18:07:13 +01:00
|
|
|
|
|
2025-11-18 13:30:37 +01:00
|
|
|
|
import { useState, useEffect } from "react"
|
|
|
|
|
|
import { Button } from "./ui/button"
|
|
|
|
|
|
import { Input } from "./ui/input"
|
|
|
|
|
|
import { Label } from "./ui/label"
|
|
|
|
|
|
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "./ui/card"
|
2026-02-07 18:36:14 +01:00
|
|
|
|
import { Shield, Lock, User, AlertCircle, CheckCircle, Info, LogOut, Wrench, Package, Key, Copy, Eye, EyeOff, Ruler, Trash2, RefreshCw, Clock, ShieldCheck, Globe, FileKey, AlertTriangle } from 'lucide-react'
|
2025-11-18 13:30:37 +01:00
|
|
|
|
import { APP_VERSION } from "./release-notes-modal"
|
|
|
|
|
|
import { getApiUrl, fetchApi } from "../lib/api-config"
|
|
|
|
|
|
import { TwoFactorSetup } from "./two-factor-setup"
|
2025-11-18 21:27:24 +01:00
|
|
|
|
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "./ui/select"
|
2025-11-18 22:05:54 +01:00
|
|
|
|
import { getNetworkUnit } from "../lib/format-network"
|
2025-11-04 18:07:13 +01:00
|
|
|
|
|
2025-11-09 20:52:39 +01:00
|
|
|
|
interface ProxMenuxTool {
|
2025-11-18 13:30:37 +01:00
|
|
|
|
key: string
|
|
|
|
|
|
name: string
|
|
|
|
|
|
enabled: boolean
|
2025-11-09 20:52:39 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-07 18:03:46 +01:00
|
|
|
|
interface ApiTokenEntry {
|
|
|
|
|
|
id: string
|
|
|
|
|
|
name: string
|
|
|
|
|
|
token_prefix: string
|
|
|
|
|
|
created_at: string
|
|
|
|
|
|
expires_at: string
|
|
|
|
|
|
revoked: boolean
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-04 18:07:13 +01:00
|
|
|
|
export function Settings() {
|
2025-11-18 13:30:37 +01:00
|
|
|
|
const [authEnabled, setAuthEnabled] = useState(false)
|
|
|
|
|
|
const [totpEnabled, setTotpEnabled] = useState(false)
|
|
|
|
|
|
const [loading, setLoading] = useState(false)
|
|
|
|
|
|
const [error, setError] = useState("")
|
|
|
|
|
|
const [success, setSuccess] = useState("")
|
2025-11-04 18:07:13 +01:00
|
|
|
|
|
|
|
|
|
|
// Setup form state
|
2025-11-18 13:30:37 +01:00
|
|
|
|
const [showSetupForm, setShowSetupForm] = useState(false)
|
|
|
|
|
|
const [username, setUsername] = useState("")
|
|
|
|
|
|
const [password, setPassword] = useState("")
|
|
|
|
|
|
const [confirmPassword, setConfirmPassword] = useState("")
|
2025-11-04 18:07:13 +01:00
|
|
|
|
|
|
|
|
|
|
// Change password form state
|
2025-11-18 13:30:37 +01:00
|
|
|
|
const [showChangePassword, setShowChangePassword] = useState(false)
|
|
|
|
|
|
const [currentPassword, setCurrentPassword] = useState("")
|
|
|
|
|
|
const [newPassword, setNewPassword] = useState("")
|
|
|
|
|
|
const [confirmNewPassword, setConfirmNewPassword] = useState("")
|
|
|
|
|
|
|
|
|
|
|
|
const [show2FASetup, setShow2FASetup] = useState(false)
|
|
|
|
|
|
const [show2FADisable, setShow2FADisable] = useState(false)
|
|
|
|
|
|
const [disable2FAPassword, setDisable2FAPassword] = useState("")
|
|
|
|
|
|
|
|
|
|
|
|
const [proxmenuxTools, setProxmenuxTools] = useState<ProxMenuxTool[]>([])
|
|
|
|
|
|
const [loadingTools, setLoadingTools] = useState(true)
|
|
|
|
|
|
const [expandedVersions, setExpandedVersions] = useState<Record<string, boolean>>({
|
2025-11-11 19:20:59 +01:00
|
|
|
|
[APP_VERSION]: true, // Current version expanded by default
|
2025-11-18 13:30:37 +01:00
|
|
|
|
})
|
2025-11-18 10:58:06 +01:00
|
|
|
|
|
2025-11-13 19:11:56 +01:00
|
|
|
|
// API Token state management
|
2025-11-18 13:30:37 +01:00
|
|
|
|
const [showApiTokenSection, setShowApiTokenSection] = useState(false)
|
|
|
|
|
|
const [apiToken, setApiToken] = useState("")
|
|
|
|
|
|
const [apiTokenVisible, setApiTokenVisible] = useState(false)
|
|
|
|
|
|
const [tokenPassword, setTokenPassword] = useState("")
|
|
|
|
|
|
const [tokenTotpCode, setTokenTotpCode] = useState("")
|
|
|
|
|
|
const [generatingToken, setGeneratingToken] = useState(false)
|
|
|
|
|
|
const [tokenCopied, setTokenCopied] = useState(false)
|
2025-11-13 19:11:56 +01:00
|
|
|
|
|
2026-02-07 18:03:46 +01:00
|
|
|
|
// Token list state
|
|
|
|
|
|
const [existingTokens, setExistingTokens] = useState<ApiTokenEntry[]>([])
|
|
|
|
|
|
const [loadingTokens, setLoadingTokens] = useState(false)
|
|
|
|
|
|
const [revokingTokenId, setRevokingTokenId] = useState<string | null>(null)
|
|
|
|
|
|
const [tokenName, setTokenName] = useState("API Token")
|
|
|
|
|
|
|
2026-02-07 18:36:14 +01:00
|
|
|
|
// SSL/HTTPS state
|
|
|
|
|
|
const [sslEnabled, setSslEnabled] = useState(false)
|
|
|
|
|
|
const [sslSource, setSslSource] = useState<"none" | "proxmox" | "custom">("none")
|
|
|
|
|
|
const [sslCertPath, setSslCertPath] = useState("")
|
|
|
|
|
|
const [sslKeyPath, setSslKeyPath] = useState("")
|
|
|
|
|
|
const [proxmoxCertAvailable, setProxmoxCertAvailable] = useState(false)
|
|
|
|
|
|
const [proxmoxCertInfo, setProxmoxCertInfo] = useState<{subject?: string; expires?: string; issuer?: string; is_self_signed?: boolean} | null>(null)
|
|
|
|
|
|
const [loadingSsl, setLoadingSsl] = useState(true)
|
|
|
|
|
|
const [configuringSsl, setConfiguringSsl] = useState(false)
|
|
|
|
|
|
const [showCustomCertForm, setShowCustomCertForm] = useState(false)
|
|
|
|
|
|
const [customCertPath, setCustomCertPath] = useState("")
|
|
|
|
|
|
const [customKeyPath, setCustomKeyPath] = useState("")
|
|
|
|
|
|
|
2025-11-18 22:05:54 +01:00
|
|
|
|
const [networkUnitSettings, setNetworkUnitSettings] = useState<"Bytes" | "Bits">("Bytes")
|
2025-11-18 21:27:24 +01:00
|
|
|
|
const [loadingUnitSettings, setLoadingUnitSettings] = useState(true)
|
2025-11-18 19:00:51 +01:00
|
|
|
|
|
2025-11-04 18:07:13 +01:00
|
|
|
|
useEffect(() => {
|
2025-11-18 13:30:37 +01:00
|
|
|
|
checkAuthStatus()
|
|
|
|
|
|
loadProxmenuxTools()
|
2026-02-07 18:03:46 +01:00
|
|
|
|
loadApiTokens()
|
2026-02-07 18:36:14 +01:00
|
|
|
|
loadSslStatus(setSslEnabled, setSslSource, setSslCertPath, setSslKeyPath, setProxmoxCertAvailable, setProxmoxCertInfo, setLoadingSsl)
|
2026-02-07 18:03:46 +01:00
|
|
|
|
getUnitsSettings()
|
2025-11-18 13:30:37 +01:00
|
|
|
|
}, [])
|
2025-11-18 10:58:06 +01:00
|
|
|
|
|
2025-11-04 18:07:13 +01:00
|
|
|
|
const checkAuthStatus = async () => {
|
|
|
|
|
|
try {
|
2025-11-18 13:30:37 +01:00
|
|
|
|
const response = await fetch(getApiUrl("/api/auth/status"))
|
|
|
|
|
|
const data = await response.json()
|
|
|
|
|
|
setAuthEnabled(data.auth_enabled || false)
|
|
|
|
|
|
setTotpEnabled(data.totp_enabled || false) // Get 2FA status
|
2025-11-04 18:07:13 +01:00
|
|
|
|
} catch (err) {
|
2025-11-18 13:30:37 +01:00
|
|
|
|
console.error("Failed to check auth status:", err)
|
2025-11-04 18:07:13 +01:00
|
|
|
|
}
|
2025-11-18 13:30:37 +01:00
|
|
|
|
}
|
2025-11-04 18:07:13 +01:00
|
|
|
|
|
2025-11-09 20:52:39 +01:00
|
|
|
|
const loadProxmenuxTools = async () => {
|
|
|
|
|
|
try {
|
2025-11-18 13:30:37 +01:00
|
|
|
|
const response = await fetch(getApiUrl("/api/proxmenux/installed-tools"))
|
|
|
|
|
|
const data = await response.json()
|
2025-11-09 20:52:39 +01:00
|
|
|
|
|
|
|
|
|
|
if (data.success) {
|
2025-11-18 13:30:37 +01:00
|
|
|
|
setProxmenuxTools(data.installed_tools || [])
|
2025-11-09 20:52:39 +01:00
|
|
|
|
}
|
|
|
|
|
|
} catch (err) {
|
2025-11-18 13:30:37 +01:00
|
|
|
|
console.error("Failed to load ProxMenux tools:", err)
|
2025-11-09 20:52:39 +01:00
|
|
|
|
} finally {
|
2025-11-18 13:30:37 +01:00
|
|
|
|
setLoadingTools(false)
|
2025-11-09 20:52:39 +01:00
|
|
|
|
}
|
2025-11-18 13:30:37 +01:00
|
|
|
|
}
|
2025-11-09 20:52:39 +01:00
|
|
|
|
|
2025-11-04 18:07:13 +01:00
|
|
|
|
const handleEnableAuth = async () => {
|
2025-11-18 13:30:37 +01:00
|
|
|
|
setError("")
|
|
|
|
|
|
setSuccess("")
|
2025-11-04 18:07:13 +01:00
|
|
|
|
|
|
|
|
|
|
if (!username || !password) {
|
2025-11-18 13:30:37 +01:00
|
|
|
|
setError("Please fill in all fields")
|
|
|
|
|
|
return
|
2025-11-04 18:07:13 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (password !== confirmPassword) {
|
2025-11-18 13:30:37 +01:00
|
|
|
|
setError("Passwords do not match")
|
|
|
|
|
|
return
|
2025-11-04 18:07:13 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (password.length < 6) {
|
2025-11-18 13:30:37 +01:00
|
|
|
|
setError("Password must be at least 6 characters")
|
|
|
|
|
|
return
|
2025-11-04 18:07:13 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-18 13:30:37 +01:00
|
|
|
|
setLoading(true)
|
2025-11-04 18:07:13 +01:00
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
const response = await fetch(getApiUrl("/api/auth/setup"), {
|
|
|
|
|
|
method: "POST",
|
|
|
|
|
|
headers: { "Content-Type": "application/json" },
|
|
|
|
|
|
body: JSON.stringify({
|
|
|
|
|
|
username,
|
|
|
|
|
|
password,
|
|
|
|
|
|
enable_auth: true,
|
|
|
|
|
|
}),
|
2025-11-18 13:30:37 +01:00
|
|
|
|
})
|
2025-11-04 18:07:13 +01:00
|
|
|
|
|
2025-11-18 13:30:37 +01:00
|
|
|
|
const data = await response.json()
|
2025-11-04 18:07:13 +01:00
|
|
|
|
|
|
|
|
|
|
if (!response.ok) {
|
2025-11-18 13:30:37 +01:00
|
|
|
|
throw new Error(data.error || "Failed to enable authentication")
|
2025-11-04 18:07:13 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Save token
|
2025-11-18 13:30:37 +01:00
|
|
|
|
localStorage.setItem("proxmenux-auth-token", data.token)
|
|
|
|
|
|
localStorage.setItem("proxmenux-auth-setup-complete", "true")
|
|
|
|
|
|
|
|
|
|
|
|
setSuccess("Authentication enabled successfully!")
|
|
|
|
|
|
setAuthEnabled(true)
|
|
|
|
|
|
setShowSetupForm(false)
|
|
|
|
|
|
setUsername("")
|
|
|
|
|
|
setPassword("")
|
|
|
|
|
|
setConfirmPassword("")
|
2025-11-04 18:07:13 +01:00
|
|
|
|
} catch (err) {
|
2025-11-18 13:30:37 +01:00
|
|
|
|
setError(err instanceof Error ? err.message : "Failed to enable authentication")
|
2025-11-04 18:07:13 +01:00
|
|
|
|
} finally {
|
2025-11-18 13:30:37 +01:00
|
|
|
|
setLoading(false)
|
2025-11-04 18:07:13 +01:00
|
|
|
|
}
|
2025-11-18 13:30:37 +01:00
|
|
|
|
}
|
2025-11-04 18:07:13 +01:00
|
|
|
|
|
|
|
|
|
|
const handleDisableAuth = async () => {
|
|
|
|
|
|
if (
|
|
|
|
|
|
!confirm(
|
2025-11-18 13:30:37 +01:00
|
|
|
|
"Are you sure you want to disable authentication? This will remove password protection from your dashboard.",
|
2025-11-04 18:07:13 +01:00
|
|
|
|
)
|
|
|
|
|
|
) {
|
2025-11-18 13:30:37 +01:00
|
|
|
|
return
|
2025-11-04 18:07:13 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-18 13:30:37 +01:00
|
|
|
|
setLoading(true)
|
|
|
|
|
|
setError("")
|
|
|
|
|
|
setSuccess("")
|
2025-11-04 18:07:13 +01:00
|
|
|
|
|
|
|
|
|
|
try {
|
2025-11-18 13:30:37 +01:00
|
|
|
|
const token = localStorage.getItem("proxmenux-auth-token")
|
2025-11-07 19:25:36 +01:00
|
|
|
|
const response = await fetch(getApiUrl("/api/auth/disable"), {
|
2025-11-04 18:07:13 +01:00
|
|
|
|
method: "POST",
|
2025-11-07 19:25:36 +01:00
|
|
|
|
headers: {
|
|
|
|
|
|
"Content-Type": "application/json",
|
2025-11-07 20:05:29 +01:00
|
|
|
|
Authorization: `Bearer ${token}`,
|
2025-11-07 19:25:36 +01:00
|
|
|
|
},
|
2025-11-18 13:30:37 +01:00
|
|
|
|
})
|
2025-11-04 18:07:13 +01:00
|
|
|
|
|
2025-11-18 13:30:37 +01:00
|
|
|
|
const data = await response.json()
|
2025-11-07 19:25:36 +01:00
|
|
|
|
|
|
|
|
|
|
if (!response.ok) {
|
2025-11-18 13:30:37 +01:00
|
|
|
|
throw new Error(data.message || "Failed to disable authentication")
|
2025-11-07 19:25:36 +01:00
|
|
|
|
}
|
2025-11-04 18:07:13 +01:00
|
|
|
|
|
2025-11-18 13:30:37 +01:00
|
|
|
|
localStorage.removeItem("proxmenux-auth-token")
|
|
|
|
|
|
localStorage.removeItem("proxmenux-auth-setup-complete")
|
2025-11-07 19:25:36 +01:00
|
|
|
|
|
2025-11-18 13:30:37 +01:00
|
|
|
|
setSuccess("Authentication disabled successfully! Reloading...")
|
2025-11-07 19:25:36 +01:00
|
|
|
|
|
|
|
|
|
|
setTimeout(() => {
|
2025-11-18 13:30:37 +01:00
|
|
|
|
window.location.reload()
|
|
|
|
|
|
}, 1000)
|
2025-11-04 18:07:13 +01:00
|
|
|
|
} catch (err) {
|
2025-11-18 13:30:37 +01:00
|
|
|
|
setError(err instanceof Error ? err.message : "Failed to disable authentication. Please try again.")
|
2025-11-04 18:07:13 +01:00
|
|
|
|
} finally {
|
2025-11-18 13:30:37 +01:00
|
|
|
|
setLoading(false)
|
2025-11-04 18:07:13 +01:00
|
|
|
|
}
|
2025-11-18 13:30:37 +01:00
|
|
|
|
}
|
2025-11-04 18:07:13 +01:00
|
|
|
|
|
|
|
|
|
|
const handleChangePassword = async () => {
|
2025-11-18 13:30:37 +01:00
|
|
|
|
setError("")
|
|
|
|
|
|
setSuccess("")
|
2025-11-04 18:07:13 +01:00
|
|
|
|
|
|
|
|
|
|
if (!currentPassword || !newPassword) {
|
2025-11-18 13:30:37 +01:00
|
|
|
|
setError("Please fill in all fields")
|
|
|
|
|
|
return
|
2025-11-04 18:07:13 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (newPassword !== confirmNewPassword) {
|
2025-11-18 13:30:37 +01:00
|
|
|
|
setError("New passwords do not match")
|
|
|
|
|
|
return
|
2025-11-04 18:07:13 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (newPassword.length < 6) {
|
2025-11-18 13:30:37 +01:00
|
|
|
|
setError("Password must be at least 6 characters")
|
|
|
|
|
|
return
|
2025-11-04 18:07:13 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-18 13:30:37 +01:00
|
|
|
|
setLoading(true)
|
2025-11-04 18:07:13 +01:00
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
const response = await fetch(getApiUrl("/api/auth/change-password"), {
|
|
|
|
|
|
method: "POST",
|
|
|
|
|
|
headers: {
|
|
|
|
|
|
"Content-Type": "application/json",
|
2025-11-18 13:30:37 +01:00
|
|
|
|
Authorization: `Bearer ${localStorage.getItem("proxmenux-auth-token")}`,
|
2025-11-04 18:07:13 +01:00
|
|
|
|
},
|
|
|
|
|
|
body: JSON.stringify({
|
|
|
|
|
|
current_password: currentPassword,
|
|
|
|
|
|
new_password: newPassword,
|
|
|
|
|
|
}),
|
2025-11-18 13:30:37 +01:00
|
|
|
|
})
|
2025-11-04 18:07:13 +01:00
|
|
|
|
|
2025-11-18 13:30:37 +01:00
|
|
|
|
const data = await response.json()
|
2025-11-04 18:07:13 +01:00
|
|
|
|
|
|
|
|
|
|
if (!response.ok) {
|
2025-11-18 13:30:37 +01:00
|
|
|
|
throw new Error(data.error || "Failed to change password")
|
2025-11-04 18:07:13 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Update token if provided
|
|
|
|
|
|
if (data.token) {
|
2025-11-18 13:30:37 +01:00
|
|
|
|
localStorage.setItem("proxmenux-auth-token", data.token)
|
2025-11-04 18:07:13 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-18 13:30:37 +01:00
|
|
|
|
setSuccess("Password changed successfully!")
|
|
|
|
|
|
setShowChangePassword(false)
|
|
|
|
|
|
setCurrentPassword("")
|
|
|
|
|
|
setNewPassword("")
|
|
|
|
|
|
setConfirmNewPassword("")
|
2025-11-04 18:07:13 +01:00
|
|
|
|
} catch (err) {
|
2025-11-18 13:30:37 +01:00
|
|
|
|
setError(err instanceof Error ? err.message : "Failed to change password")
|
2025-11-04 18:07:13 +01:00
|
|
|
|
} finally {
|
2025-11-18 13:30:37 +01:00
|
|
|
|
setLoading(false)
|
2025-11-04 18:07:13 +01:00
|
|
|
|
}
|
2025-11-18 13:30:37 +01:00
|
|
|
|
}
|
2025-11-04 18:07:13 +01:00
|
|
|
|
|
2025-11-07 20:36:46 +01:00
|
|
|
|
const handleDisable2FA = async () => {
|
2025-11-18 13:30:37 +01:00
|
|
|
|
setError("")
|
|
|
|
|
|
setSuccess("")
|
2025-11-07 20:36:46 +01:00
|
|
|
|
|
|
|
|
|
|
if (!disable2FAPassword) {
|
2025-11-18 13:30:37 +01:00
|
|
|
|
setError("Please enter your password")
|
|
|
|
|
|
return
|
2025-11-07 20:36:46 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-18 13:30:37 +01:00
|
|
|
|
setLoading(true)
|
2025-11-07 20:36:46 +01:00
|
|
|
|
|
|
|
|
|
|
try {
|
2025-11-18 13:30:37 +01:00
|
|
|
|
const token = localStorage.getItem("proxmenux-auth-token")
|
2025-11-07 20:36:46 +01:00
|
|
|
|
const response = await fetch(getApiUrl("/api/auth/totp/disable"), {
|
|
|
|
|
|
method: "POST",
|
|
|
|
|
|
headers: {
|
|
|
|
|
|
"Content-Type": "application/json",
|
|
|
|
|
|
Authorization: `Bearer ${token}`,
|
|
|
|
|
|
},
|
|
|
|
|
|
body: JSON.stringify({ password: disable2FAPassword }),
|
2025-11-18 13:30:37 +01:00
|
|
|
|
})
|
2025-11-07 20:36:46 +01:00
|
|
|
|
|
2025-11-18 13:30:37 +01:00
|
|
|
|
const data = await response.json()
|
2025-11-07 20:36:46 +01:00
|
|
|
|
|
|
|
|
|
|
if (!response.ok) {
|
2025-11-18 13:30:37 +01:00
|
|
|
|
throw new Error(data.message || "Failed to disable 2FA")
|
2025-11-07 20:36:46 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-18 13:30:37 +01:00
|
|
|
|
setSuccess("2FA disabled successfully!")
|
|
|
|
|
|
setTotpEnabled(false)
|
|
|
|
|
|
setShow2FADisable(false)
|
|
|
|
|
|
setDisable2FAPassword("")
|
|
|
|
|
|
checkAuthStatus()
|
2025-11-07 20:36:46 +01:00
|
|
|
|
} catch (err) {
|
2025-11-18 13:30:37 +01:00
|
|
|
|
setError(err instanceof Error ? err.message : "Failed to disable 2FA")
|
2025-11-07 20:36:46 +01:00
|
|
|
|
} finally {
|
2025-11-18 13:30:37 +01:00
|
|
|
|
setLoading(false)
|
2025-11-07 20:36:46 +01:00
|
|
|
|
}
|
2025-11-18 13:30:37 +01:00
|
|
|
|
}
|
2025-11-07 20:36:46 +01:00
|
|
|
|
|
2025-11-04 19:13:47 +01:00
|
|
|
|
const handleLogout = () => {
|
2025-11-18 13:30:37 +01:00
|
|
|
|
localStorage.removeItem("proxmenux-auth-token")
|
|
|
|
|
|
localStorage.removeItem("proxmenux-auth-setup-complete")
|
|
|
|
|
|
window.location.reload()
|
|
|
|
|
|
}
|
2025-11-04 19:13:47 +01:00
|
|
|
|
|
2026-02-07 18:03:46 +01:00
|
|
|
|
const loadApiTokens = async () => {
|
|
|
|
|
|
try {
|
|
|
|
|
|
setLoadingTokens(true)
|
|
|
|
|
|
const data = await fetchApi("/api/auth/api-tokens")
|
|
|
|
|
|
if (data.success) {
|
|
|
|
|
|
setExistingTokens(data.tokens || [])
|
|
|
|
|
|
}
|
|
|
|
|
|
} catch {
|
|
|
|
|
|
// Silently fail - tokens section is optional
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
setLoadingTokens(false)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const handleRevokeToken = async (tokenId: string) => {
|
|
|
|
|
|
if (!confirm("Are you sure you want to revoke this token? Any integration using it will stop working immediately.")) {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
setRevokingTokenId(tokenId)
|
|
|
|
|
|
setError("")
|
|
|
|
|
|
setSuccess("")
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
const data = await fetchApi(`/api/auth/api-tokens/${tokenId}`, {
|
|
|
|
|
|
method: "DELETE",
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
if (data.success) {
|
|
|
|
|
|
setSuccess("Token revoked successfully")
|
|
|
|
|
|
setExistingTokens((prev) => prev.filter((t) => t.id !== tokenId))
|
|
|
|
|
|
} else {
|
|
|
|
|
|
setError(data.message || "Failed to revoke token")
|
|
|
|
|
|
}
|
|
|
|
|
|
} catch (err) {
|
|
|
|
|
|
setError(err instanceof Error ? err.message : "Failed to revoke token")
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
setRevokingTokenId(null)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-13 19:11:56 +01:00
|
|
|
|
const handleGenerateApiToken = async () => {
|
2025-11-18 13:30:37 +01:00
|
|
|
|
setError("")
|
|
|
|
|
|
setSuccess("")
|
2025-11-13 19:11:56 +01:00
|
|
|
|
|
|
|
|
|
|
if (!tokenPassword) {
|
2025-11-18 13:30:37 +01:00
|
|
|
|
setError("Please enter your password")
|
|
|
|
|
|
return
|
2025-11-13 19:11:56 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (totpEnabled && !tokenTotpCode) {
|
2025-11-18 13:30:37 +01:00
|
|
|
|
setError("Please enter your 2FA code")
|
|
|
|
|
|
return
|
2025-11-13 19:11:56 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-18 13:30:37 +01:00
|
|
|
|
setGeneratingToken(true)
|
2025-11-13 19:11:56 +01:00
|
|
|
|
|
|
|
|
|
|
try {
|
2025-11-13 20:59:36 +01:00
|
|
|
|
const data = await fetchApi("/api/auth/generate-api-token", {
|
2025-11-13 19:11:56 +01:00
|
|
|
|
method: "POST",
|
|
|
|
|
|
headers: { "Content-Type": "application/json" },
|
|
|
|
|
|
body: JSON.stringify({
|
|
|
|
|
|
password: tokenPassword,
|
2025-11-13 20:10:00 +01:00
|
|
|
|
totp_token: totpEnabled ? tokenTotpCode : undefined,
|
2026-02-07 18:03:46 +01:00
|
|
|
|
token_name: tokenName || "API Token",
|
2025-11-13 19:11:56 +01:00
|
|
|
|
}),
|
2025-11-18 13:30:37 +01:00
|
|
|
|
})
|
2025-11-13 19:11:56 +01:00
|
|
|
|
|
2025-11-13 20:59:36 +01:00
|
|
|
|
if (!data.success) {
|
2025-11-18 13:30:37 +01:00
|
|
|
|
setError(data.message || data.error || "Failed to generate API token")
|
|
|
|
|
|
return
|
2025-11-13 19:11:56 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-13 20:36:35 +01:00
|
|
|
|
if (!data.token) {
|
2025-11-18 13:30:37 +01:00
|
|
|
|
setError("No token received from server")
|
|
|
|
|
|
return
|
2025-11-13 20:36:35 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-18 13:30:37 +01:00
|
|
|
|
setApiToken(data.token)
|
|
|
|
|
|
setSuccess("API token generated successfully! Make sure to copy it now as you won't be able to see it again.")
|
|
|
|
|
|
setTokenPassword("")
|
|
|
|
|
|
setTokenTotpCode("")
|
2026-02-07 18:03:46 +01:00
|
|
|
|
setTokenName("API Token")
|
|
|
|
|
|
loadApiTokens()
|
2025-11-13 19:11:56 +01:00
|
|
|
|
} catch (err) {
|
2025-11-18 13:30:37 +01:00
|
|
|
|
setError(err instanceof Error ? err.message : "Failed to generate API token. Please try again.")
|
2025-11-13 19:11:56 +01:00
|
|
|
|
} finally {
|
2025-11-18 13:30:37 +01:00
|
|
|
|
setGeneratingToken(false)
|
2025-11-13 19:11:56 +01:00
|
|
|
|
}
|
2025-11-18 13:30:37 +01:00
|
|
|
|
}
|
2025-11-13 19:11:56 +01:00
|
|
|
|
|
2026-02-07 18:03:46 +01:00
|
|
|
|
const copyToClipboard = async (text: string) => {
|
|
|
|
|
|
try {
|
|
|
|
|
|
if (navigator.clipboard && typeof navigator.clipboard.writeText === "function") {
|
|
|
|
|
|
await navigator.clipboard.writeText(text)
|
|
|
|
|
|
} else {
|
|
|
|
|
|
// Fallback for non-secure contexts (HTTP on local network)
|
|
|
|
|
|
const textarea = document.createElement("textarea")
|
|
|
|
|
|
textarea.value = text
|
|
|
|
|
|
textarea.style.position = "fixed"
|
|
|
|
|
|
textarea.style.left = "-9999px"
|
|
|
|
|
|
textarea.style.top = "-9999px"
|
|
|
|
|
|
textarea.style.opacity = "0"
|
|
|
|
|
|
document.body.appendChild(textarea)
|
|
|
|
|
|
textarea.focus()
|
|
|
|
|
|
textarea.select()
|
|
|
|
|
|
document.execCommand("copy")
|
|
|
|
|
|
document.body.removeChild(textarea)
|
|
|
|
|
|
}
|
|
|
|
|
|
return true
|
|
|
|
|
|
} catch {
|
|
|
|
|
|
return false
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const copyApiToken = async () => {
|
|
|
|
|
|
const ok = await copyToClipboard(apiToken)
|
|
|
|
|
|
if (ok) {
|
|
|
|
|
|
setTokenCopied(true)
|
|
|
|
|
|
setTimeout(() => setTokenCopied(false), 2000)
|
|
|
|
|
|
}
|
2025-11-18 13:30:37 +01:00
|
|
|
|
}
|
2025-11-13 19:11:56 +01:00
|
|
|
|
|
2025-11-11 19:20:59 +01:00
|
|
|
|
const toggleVersion = (version: string) => {
|
|
|
|
|
|
setExpandedVersions((prev) => ({
|
|
|
|
|
|
...prev,
|
|
|
|
|
|
[version]: !prev[version],
|
2025-11-18 13:30:37 +01:00
|
|
|
|
}))
|
|
|
|
|
|
}
|
2025-11-11 19:20:59 +01:00
|
|
|
|
|
2025-11-18 21:27:24 +01:00
|
|
|
|
const changeNetworkUnit = (unit: string) => {
|
2025-11-18 22:05:54 +01:00
|
|
|
|
const networkUnit = unit as "Bytes" | "Bits"
|
|
|
|
|
|
localStorage.setItem("proxmenux-network-unit", networkUnit)
|
|
|
|
|
|
setNetworkUnitSettings(networkUnit)
|
|
|
|
|
|
|
2025-11-18 21:27:24 +01:00
|
|
|
|
// Dispatch custom event to notify other components
|
2025-11-18 22:05:54 +01:00
|
|
|
|
window.dispatchEvent(new CustomEvent("networkUnitChanged", { detail: networkUnit }))
|
|
|
|
|
|
|
|
|
|
|
|
// Also dispatch storage event for backward compatibility
|
|
|
|
|
|
window.dispatchEvent(new StorageEvent("storage", {
|
|
|
|
|
|
key: "proxmenux-network-unit",
|
|
|
|
|
|
newValue: networkUnit,
|
|
|
|
|
|
url: window.location.href
|
|
|
|
|
|
}))
|
2025-11-18 21:27:24 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const getUnitsSettings = () => {
|
2025-11-18 22:05:54 +01:00
|
|
|
|
const networkUnit = getNetworkUnit()
|
2025-11-18 21:27:24 +01:00
|
|
|
|
setNetworkUnitSettings(networkUnit)
|
|
|
|
|
|
setLoadingUnitSettings(false)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-07 18:36:14 +01:00
|
|
|
|
const loadSslStatus = async () => {
|
|
|
|
|
|
try {
|
|
|
|
|
|
setLoadingSsl(true)
|
|
|
|
|
|
const data = await fetchApi("/api/ssl/status")
|
|
|
|
|
|
if (data.success) {
|
|
|
|
|
|
setSslEnabled(data.ssl_enabled || false)
|
|
|
|
|
|
setSslSource(data.source || "none")
|
|
|
|
|
|
setSslCertPath(data.cert_path || "")
|
|
|
|
|
|
setSslKeyPath(data.key_path || "")
|
|
|
|
|
|
setProxmoxCertAvailable(data.proxmox_available || false)
|
|
|
|
|
|
setProxmoxCertInfo(data.cert_info || null)
|
|
|
|
|
|
}
|
|
|
|
|
|
} catch {
|
|
|
|
|
|
// Silently fail
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
setLoadingSsl(false)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const handleEnableSsl = async (source: "proxmox" | "custom", certPath?: string, keyPath?: string) => {
|
|
|
|
|
|
setConfiguringSsl(true)
|
|
|
|
|
|
setError("")
|
|
|
|
|
|
setSuccess("")
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
const body: Record<string, string> = { source }
|
|
|
|
|
|
if (source === "custom" && certPath && keyPath) {
|
|
|
|
|
|
body.cert_path = certPath
|
|
|
|
|
|
body.key_path = keyPath
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const data = await fetchApi("/api/ssl/configure", {
|
|
|
|
|
|
method: "POST",
|
|
|
|
|
|
headers: { "Content-Type": "application/json" },
|
|
|
|
|
|
body: JSON.stringify(body),
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
if (data.success) {
|
|
|
|
|
|
setSuccess(data.message || "SSL configured successfully. Restart the monitor service to apply.")
|
|
|
|
|
|
setSslEnabled(true)
|
|
|
|
|
|
setSslSource(source)
|
|
|
|
|
|
setShowCustomCertForm(false)
|
|
|
|
|
|
setCustomCertPath("")
|
|
|
|
|
|
setCustomKeyPath("")
|
|
|
|
|
|
loadSslStatus()
|
|
|
|
|
|
} else {
|
|
|
|
|
|
setError(data.message || "Failed to configure SSL")
|
|
|
|
|
|
}
|
|
|
|
|
|
} catch (err) {
|
|
|
|
|
|
setError(err instanceof Error ? err.message : "Failed to configure SSL")
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
setConfiguringSsl(false)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const handleDisableSsl = async () => {
|
|
|
|
|
|
if (!confirm("Are you sure you want to disable HTTPS? The monitor will revert to HTTP after restart.")) {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
setConfiguringSsl(true)
|
|
|
|
|
|
setError("")
|
|
|
|
|
|
setSuccess("")
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
const data = await fetchApi("/api/ssl/disable", { method: "POST" })
|
|
|
|
|
|
|
|
|
|
|
|
if (data.success) {
|
|
|
|
|
|
setSuccess(data.message || "SSL disabled. Restart the monitor service to apply.")
|
|
|
|
|
|
setSslEnabled(false)
|
|
|
|
|
|
setSslSource("none")
|
|
|
|
|
|
setSslCertPath("")
|
|
|
|
|
|
setSslKeyPath("")
|
|
|
|
|
|
loadSslStatus()
|
|
|
|
|
|
} else {
|
|
|
|
|
|
setError(data.message || "Failed to disable SSL")
|
|
|
|
|
|
}
|
|
|
|
|
|
} catch (err) {
|
|
|
|
|
|
setError(err instanceof Error ? err.message : "Failed to disable SSL")
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
setConfiguringSsl(false)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-04 18:07:13 +01:00
|
|
|
|
return (
|
|
|
|
|
|
<div className="space-y-6">
|
|
|
|
|
|
<div>
|
|
|
|
|
|
<h1 className="text-3xl font-bold">Settings</h1>
|
2025-11-18 13:30:37 +01:00
|
|
|
|
<p className="text-muted-foreground mt-2">Manage your dashboard security and preferences</p>
|
2025-11-04 18:07:13 +01:00
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
{/* Authentication Settings */}
|
|
|
|
|
|
<Card>
|
|
|
|
|
|
<CardHeader>
|
|
|
|
|
|
<div className="flex items-center gap-2">
|
|
|
|
|
|
<Shield className="h-5 w-5 text-blue-500" />
|
|
|
|
|
|
<CardTitle>Authentication</CardTitle>
|
|
|
|
|
|
</div>
|
2025-11-18 13:30:37 +01:00
|
|
|
|
<CardDescription>Protect your dashboard with username and password authentication</CardDescription>
|
2025-11-04 18:07:13 +01:00
|
|
|
|
</CardHeader>
|
|
|
|
|
|
<CardContent className="space-y-4">
|
|
|
|
|
|
{error && (
|
|
|
|
|
|
<div className="bg-red-500/10 border border-red-500/20 rounded-lg p-3 flex items-start gap-2">
|
|
|
|
|
|
<AlertCircle className="h-5 w-5 text-red-500 flex-shrink-0 mt-0.5" />
|
|
|
|
|
|
<p className="text-sm text-red-500">{error}</p>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
|
|
{success && (
|
|
|
|
|
|
<div className="bg-green-500/10 border border-green-500/20 rounded-lg p-3 flex items-start gap-2">
|
|
|
|
|
|
<CheckCircle className="h-5 w-5 text-green-500 flex-shrink-0 mt-0.5" />
|
|
|
|
|
|
<p className="text-sm text-green-500">{success}</p>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
|
|
<div className="flex items-center justify-between p-4 bg-muted/50 rounded-lg">
|
|
|
|
|
|
<div className="flex items-center gap-3">
|
|
|
|
|
|
<div
|
2025-11-18 13:30:37 +01:00
|
|
|
|
className={`w-10 h-10 rounded-full flex items-center justify-center ${authEnabled ? "bg-green-500/10" : "bg-gray-500/10"}`}
|
2025-11-04 18:07:13 +01:00
|
|
|
|
>
|
2025-11-18 13:30:37 +01:00
|
|
|
|
<Lock className={`h-5 w-5 ${authEnabled ? "text-green-500" : "text-gray-500"}`} />
|
2025-11-04 18:07:13 +01:00
|
|
|
|
</div>
|
|
|
|
|
|
<div>
|
|
|
|
|
|
<p className="font-medium">Authentication Status</p>
|
|
|
|
|
|
<p className="text-sm text-muted-foreground">
|
2025-11-18 13:30:37 +01:00
|
|
|
|
{authEnabled ? "Password protection is enabled" : "No password protection"}
|
2025-11-04 18:07:13 +01:00
|
|
|
|
</p>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div
|
2025-11-18 13:30:37 +01:00
|
|
|
|
className={`px-3 py-1 rounded-full text-sm font-medium ${authEnabled ? "bg-green-500/10 text-green-500" : "bg-gray-500/10 text-gray-500"}`}
|
2025-11-04 18:07:13 +01:00
|
|
|
|
>
|
|
|
|
|
|
{authEnabled ? "Enabled" : "Disabled"}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
{!authEnabled && !showSetupForm && (
|
|
|
|
|
|
<div className="space-y-3">
|
|
|
|
|
|
<div className="bg-blue-500/10 border border-blue-500/20 rounded-lg p-3 flex items-start gap-2">
|
|
|
|
|
|
<Info className="h-5 w-5 text-blue-500 flex-shrink-0 mt-0.5" />
|
|
|
|
|
|
<p className="text-sm text-blue-500">
|
2025-11-18 13:30:37 +01:00
|
|
|
|
Enable authentication to protect your dashboard when accessing from non-private networks.
|
2025-11-04 18:07:13 +01:00
|
|
|
|
</p>
|
|
|
|
|
|
</div>
|
2025-11-18 13:30:37 +01:00
|
|
|
|
<Button onClick={() => setShowSetupForm(true)} className="w-full bg-blue-500 hover:bg-blue-600">
|
2025-11-04 18:07:13 +01:00
|
|
|
|
<Shield className="h-4 w-4 mr-2" />
|
|
|
|
|
|
Enable Authentication
|
|
|
|
|
|
</Button>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
|
|
{!authEnabled && showSetupForm && (
|
|
|
|
|
|
<div className="space-y-4 border border-border rounded-lg p-4">
|
|
|
|
|
|
<h3 className="font-semibold">Setup Authentication</h3>
|
|
|
|
|
|
|
|
|
|
|
|
<div className="space-y-2">
|
|
|
|
|
|
<Label htmlFor="setup-username">Username</Label>
|
|
|
|
|
|
<div className="relative">
|
|
|
|
|
|
<User className="absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground" />
|
|
|
|
|
|
<Input
|
|
|
|
|
|
id="setup-username"
|
|
|
|
|
|
type="text"
|
|
|
|
|
|
placeholder="Enter username"
|
|
|
|
|
|
value={username}
|
|
|
|
|
|
onChange={(e) => setUsername(e.target.value)}
|
|
|
|
|
|
className="pl-10"
|
|
|
|
|
|
disabled={loading}
|
|
|
|
|
|
/>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<div className="space-y-2">
|
|
|
|
|
|
<Label htmlFor="setup-password">Password</Label>
|
|
|
|
|
|
<div className="relative">
|
|
|
|
|
|
<Lock className="absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground" />
|
|
|
|
|
|
<Input
|
|
|
|
|
|
id="setup-password"
|
|
|
|
|
|
type="password"
|
|
|
|
|
|
placeholder="Enter password (min 6 characters)"
|
|
|
|
|
|
value={password}
|
|
|
|
|
|
onChange={(e) => setPassword(e.target.value)}
|
|
|
|
|
|
className="pl-10"
|
|
|
|
|
|
disabled={loading}
|
|
|
|
|
|
/>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<div className="space-y-2">
|
|
|
|
|
|
<Label htmlFor="setup-confirm-password">Confirm Password</Label>
|
|
|
|
|
|
<div className="relative">
|
|
|
|
|
|
<Lock className="absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground" />
|
|
|
|
|
|
<Input
|
|
|
|
|
|
id="setup-confirm-password"
|
|
|
|
|
|
type="password"
|
|
|
|
|
|
placeholder="Confirm password"
|
|
|
|
|
|
value={confirmPassword}
|
|
|
|
|
|
onChange={(e) => setConfirmPassword(e.target.value)}
|
|
|
|
|
|
className="pl-10"
|
|
|
|
|
|
disabled={loading}
|
|
|
|
|
|
/>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<div className="flex gap-2">
|
2025-11-18 13:30:37 +01:00
|
|
|
|
<Button onClick={handleEnableAuth} className="flex-1 bg-blue-500 hover:bg-blue-600" disabled={loading}>
|
2025-11-04 18:07:13 +01:00
|
|
|
|
{loading ? "Enabling..." : "Enable"}
|
|
|
|
|
|
</Button>
|
2025-11-18 13:30:37 +01:00
|
|
|
|
<Button onClick={() => setShowSetupForm(false)} variant="outline" className="flex-1" disabled={loading}>
|
2025-11-04 18:07:13 +01:00
|
|
|
|
Cancel
|
|
|
|
|
|
</Button>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
|
|
{authEnabled && (
|
|
|
|
|
|
<div className="space-y-3">
|
2025-11-18 13:30:37 +01:00
|
|
|
|
<Button onClick={handleLogout} variant="outline" className="w-full bg-transparent">
|
2025-11-07 20:05:29 +01:00
|
|
|
|
<LogOut className="h-4 w-4 mr-2" />
|
2025-11-04 19:13:47 +01:00
|
|
|
|
Logout
|
|
|
|
|
|
</Button>
|
|
|
|
|
|
|
2025-11-04 18:07:13 +01:00
|
|
|
|
{!showChangePassword && (
|
2025-11-18 13:30:37 +01:00
|
|
|
|
<Button onClick={() => setShowChangePassword(true)} variant="outline" className="w-full">
|
2025-11-04 18:07:13 +01:00
|
|
|
|
<Lock className="h-4 w-4 mr-2" />
|
|
|
|
|
|
Change Password
|
|
|
|
|
|
</Button>
|
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
|
|
{showChangePassword && (
|
|
|
|
|
|
<div className="space-y-4 border border-border rounded-lg p-4">
|
|
|
|
|
|
<h3 className="font-semibold">Change Password</h3>
|
|
|
|
|
|
|
|
|
|
|
|
<div className="space-y-2">
|
|
|
|
|
|
<Label htmlFor="current-password">Current Password</Label>
|
|
|
|
|
|
<div className="relative">
|
|
|
|
|
|
<Lock className="absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground" />
|
|
|
|
|
|
<Input
|
|
|
|
|
|
id="current-password"
|
|
|
|
|
|
type="password"
|
|
|
|
|
|
placeholder="Enter current password"
|
|
|
|
|
|
value={currentPassword}
|
|
|
|
|
|
onChange={(e) => setCurrentPassword(e.target.value)}
|
|
|
|
|
|
className="pl-10"
|
|
|
|
|
|
disabled={loading}
|
|
|
|
|
|
/>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<div className="space-y-2">
|
|
|
|
|
|
<Label htmlFor="new-password">New Password</Label>
|
|
|
|
|
|
<div className="relative">
|
|
|
|
|
|
<Lock className="absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground" />
|
|
|
|
|
|
<Input
|
|
|
|
|
|
id="new-password"
|
|
|
|
|
|
type="password"
|
|
|
|
|
|
placeholder="Enter new password (min 6 characters)"
|
|
|
|
|
|
value={newPassword}
|
|
|
|
|
|
onChange={(e) => setNewPassword(e.target.value)}
|
|
|
|
|
|
className="pl-10"
|
|
|
|
|
|
disabled={loading}
|
|
|
|
|
|
/>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<div className="space-y-2">
|
2025-11-18 13:30:37 +01:00
|
|
|
|
<Label htmlFor="confirm-new-password">Confirm New Password</Label>
|
2025-11-04 18:07:13 +01:00
|
|
|
|
<div className="relative">
|
|
|
|
|
|
<Lock className="absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground" />
|
|
|
|
|
|
<Input
|
|
|
|
|
|
id="confirm-new-password"
|
|
|
|
|
|
type="password"
|
|
|
|
|
|
placeholder="Confirm new password"
|
|
|
|
|
|
value={confirmNewPassword}
|
|
|
|
|
|
onChange={(e) => setConfirmNewPassword(e.target.value)}
|
|
|
|
|
|
className="pl-10"
|
|
|
|
|
|
disabled={loading}
|
|
|
|
|
|
/>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<div className="flex gap-2">
|
|
|
|
|
|
<Button
|
|
|
|
|
|
onClick={handleChangePassword}
|
|
|
|
|
|
className="flex-1 bg-blue-500 hover:bg-blue-600"
|
|
|
|
|
|
disabled={loading}
|
|
|
|
|
|
>
|
|
|
|
|
|
{loading ? "Changing..." : "Change Password"}
|
|
|
|
|
|
</Button>
|
|
|
|
|
|
<Button
|
|
|
|
|
|
onClick={() => setShowChangePassword(false)}
|
|
|
|
|
|
variant="outline"
|
|
|
|
|
|
className="flex-1"
|
|
|
|
|
|
disabled={loading}
|
|
|
|
|
|
>
|
|
|
|
|
|
Cancel
|
|
|
|
|
|
</Button>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
|
|
|
|
|
|
2025-11-13 20:01:08 +01:00
|
|
|
|
{!totpEnabled && (
|
|
|
|
|
|
<div className="space-y-3">
|
|
|
|
|
|
<div className="bg-blue-500/10 border border-blue-500/20 rounded-lg p-3 flex items-start gap-2">
|
|
|
|
|
|
<Info className="h-5 w-5 text-blue-500 flex-shrink-0 mt-0.5" />
|
|
|
|
|
|
<div className="text-sm text-blue-400">
|
2025-11-18 13:30:37 +01:00
|
|
|
|
<p className="font-medium mb-1">Two-Factor Authentication (2FA)</p>
|
2025-11-13 20:01:08 +01:00
|
|
|
|
<p className="text-blue-300">
|
2025-11-18 13:30:37 +01:00
|
|
|
|
Add an extra layer of security by requiring a code from your authenticator app in addition to
|
|
|
|
|
|
your password.
|
2025-11-13 20:01:08 +01:00
|
|
|
|
</p>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
2025-11-18 13:30:37 +01:00
|
|
|
|
<Button onClick={() => setShow2FASetup(true)} variant="outline" className="w-full">
|
2025-11-13 20:01:08 +01:00
|
|
|
|
<Shield className="h-4 w-4 mr-2" />
|
|
|
|
|
|
Enable Two-Factor Authentication
|
|
|
|
|
|
</Button>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
|
|
|
|
|
|
2025-11-07 20:36:46 +01:00
|
|
|
|
{totpEnabled && (
|
|
|
|
|
|
<div className="space-y-3">
|
|
|
|
|
|
<div className="bg-green-500/10 border border-green-500/20 rounded-lg p-3 flex items-center gap-2">
|
|
|
|
|
|
<CheckCircle className="h-5 w-5 text-green-500" />
|
2025-11-18 13:30:37 +01:00
|
|
|
|
<p className="text-sm text-green-500 font-medium">2FA is enabled</p>
|
2025-11-07 20:36:46 +01:00
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
{!show2FADisable && (
|
2025-11-18 13:30:37 +01:00
|
|
|
|
<Button onClick={() => setShow2FADisable(true)} variant="outline" className="w-full">
|
2025-11-07 20:36:46 +01:00
|
|
|
|
<Shield className="h-4 w-4 mr-2" />
|
2025-11-07 21:14:56 +01:00
|
|
|
|
Disable 2FA
|
2025-11-07 20:36:46 +01:00
|
|
|
|
</Button>
|
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
|
|
{show2FADisable && (
|
|
|
|
|
|
<div className="space-y-4 border border-border rounded-lg p-4">
|
2025-11-18 13:30:37 +01:00
|
|
|
|
<h3 className="font-semibold">Disable Two-Factor Authentication</h3>
|
|
|
|
|
|
<p className="text-sm text-muted-foreground">Enter your password to confirm</p>
|
2025-11-07 20:36:46 +01:00
|
|
|
|
|
|
|
|
|
|
<div className="space-y-2">
|
2025-11-07 21:14:56 +01:00
|
|
|
|
<Label htmlFor="disable-2fa-password">Password</Label>
|
2025-11-07 20:36:46 +01:00
|
|
|
|
<div className="relative">
|
|
|
|
|
|
<Lock className="absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground" />
|
|
|
|
|
|
<Input
|
|
|
|
|
|
id="disable-2fa-password"
|
|
|
|
|
|
type="password"
|
2025-11-07 21:14:56 +01:00
|
|
|
|
placeholder="Enter your password"
|
2025-11-07 20:36:46 +01:00
|
|
|
|
value={disable2FAPassword}
|
2025-11-18 13:30:37 +01:00
|
|
|
|
onChange={(e) => setDisable2FAPassword(e.target.value)}
|
2025-11-07 20:36:46 +01:00
|
|
|
|
className="pl-10"
|
|
|
|
|
|
disabled={loading}
|
|
|
|
|
|
/>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<div className="flex gap-2">
|
2025-11-18 13:30:37 +01:00
|
|
|
|
<Button onClick={handleDisable2FA} variant="destructive" className="flex-1" disabled={loading}>
|
2025-11-07 21:14:56 +01:00
|
|
|
|
{loading ? "Disabling..." : "Disable 2FA"}
|
2025-11-07 20:36:46 +01:00
|
|
|
|
</Button>
|
|
|
|
|
|
<Button
|
|
|
|
|
|
onClick={() => {
|
2025-11-18 13:30:37 +01:00
|
|
|
|
setShow2FADisable(false)
|
|
|
|
|
|
setDisable2FAPassword("")
|
|
|
|
|
|
setError("")
|
2025-11-07 20:36:46 +01:00
|
|
|
|
}}
|
|
|
|
|
|
variant="outline"
|
|
|
|
|
|
className="flex-1"
|
|
|
|
|
|
disabled={loading}
|
|
|
|
|
|
>
|
2025-11-07 21:14:56 +01:00
|
|
|
|
Cancel
|
2025-11-07 20:36:46 +01:00
|
|
|
|
</Button>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
|
|
|
|
|
|
2025-11-18 13:30:37 +01:00
|
|
|
|
<Button onClick={handleDisableAuth} variant="destructive" className="w-full" disabled={loading}>
|
2025-11-04 18:07:13 +01:00
|
|
|
|
Disable Authentication
|
|
|
|
|
|
</Button>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
|
|
|
|
|
</CardContent>
|
|
|
|
|
|
</Card>
|
|
|
|
|
|
|
2025-11-18 21:27:24 +01:00
|
|
|
|
{/* Network Units Settings */}
|
|
|
|
|
|
<Card>
|
|
|
|
|
|
<CardHeader>
|
|
|
|
|
|
<div className="flex items-center gap-2">
|
|
|
|
|
|
<Ruler className="h-5 w-5 text-green-500" />
|
|
|
|
|
|
<CardTitle>Network Units</CardTitle>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<CardDescription>Change how network traffic is displayed</CardDescription>
|
|
|
|
|
|
</CardHeader>
|
|
|
|
|
|
<CardContent>
|
|
|
|
|
|
{loadingUnitSettings ? (
|
|
|
|
|
|
<div className="flex items-center justify-center py-8">
|
|
|
|
|
|
<div className="animate-spin h-8 w-8 border-4 border-green-500 border-t-transparent rounded-full" />
|
|
|
|
|
|
</div>
|
|
|
|
|
|
) : (
|
|
|
|
|
|
<div className="text-foreground flex items-center justify-between">
|
|
|
|
|
|
<div className="flex items-center">Network Unit Display</div>
|
|
|
|
|
|
<Select value={networkUnitSettings} onValueChange={changeNetworkUnit}>
|
|
|
|
|
|
<SelectTrigger className="w-28 h-8 text-xs">
|
|
|
|
|
|
<SelectValue />
|
|
|
|
|
|
</SelectTrigger>
|
|
|
|
|
|
<SelectContent>
|
|
|
|
|
|
<SelectItem value="Bytes">Bytes</SelectItem>
|
|
|
|
|
|
<SelectItem value="Bits">Bits</SelectItem>
|
|
|
|
|
|
</SelectContent>
|
|
|
|
|
|
</Select>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
|
|
|
|
|
</CardContent>
|
|
|
|
|
|
</Card>
|
|
|
|
|
|
|
2025-11-13 19:11:56 +01:00
|
|
|
|
{/* API Access Tokens */}
|
|
|
|
|
|
{authEnabled && (
|
|
|
|
|
|
<Card>
|
|
|
|
|
|
<CardHeader>
|
|
|
|
|
|
<div className="flex items-center gap-2">
|
|
|
|
|
|
<Key className="h-5 w-5 text-purple-500" />
|
|
|
|
|
|
<CardTitle>API Access Tokens</CardTitle>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<CardDescription>
|
2025-11-18 13:30:37 +01:00
|
|
|
|
Generate long-lived API tokens for external integrations like Homepage and Home Assistant
|
2025-11-13 19:11:56 +01:00
|
|
|
|
</CardDescription>
|
|
|
|
|
|
</CardHeader>
|
|
|
|
|
|
<CardContent className="space-y-4">
|
|
|
|
|
|
{error && (
|
|
|
|
|
|
<div className="bg-red-500/10 border border-red-500/20 rounded-lg p-3 flex items-start gap-2">
|
|
|
|
|
|
<AlertCircle className="h-5 w-5 text-red-500 flex-shrink-0 mt-0.5" />
|
|
|
|
|
|
<p className="text-sm text-red-500">{error}</p>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
|
|
{success && (
|
|
|
|
|
|
<div className="bg-green-500/10 border border-green-500/20 rounded-lg p-3 flex items-start gap-2">
|
|
|
|
|
|
<CheckCircle className="h-5 w-5 text-green-500 flex-shrink-0 mt-0.5" />
|
|
|
|
|
|
<p className="text-sm text-green-500">{success}</p>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
|
|
<div className="bg-blue-500/10 border border-blue-500/20 rounded-lg p-4">
|
|
|
|
|
|
<div className="flex items-start gap-3">
|
|
|
|
|
|
<Info className="h-5 w-5 text-blue-500 flex-shrink-0 mt-0.5" />
|
|
|
|
|
|
<div className="space-y-2 text-sm text-blue-400">
|
|
|
|
|
|
<p className="font-medium">About API Tokens</p>
|
|
|
|
|
|
<ul className="list-disc list-inside space-y-1 text-blue-300">
|
|
|
|
|
|
<li>Tokens are valid for 1 year</li>
|
|
|
|
|
|
<li>Use them to access APIs from external services</li>
|
|
|
|
|
|
<li>Include in Authorization header: Bearer YOUR_TOKEN</li>
|
|
|
|
|
|
<li>See README.md for complete integration examples</li>
|
|
|
|
|
|
</ul>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
{!showApiTokenSection && !apiToken && (
|
2025-11-18 13:30:37 +01:00
|
|
|
|
<Button onClick={() => setShowApiTokenSection(true)} className="w-full bg-purple-500 hover:bg-purple-600">
|
2025-11-13 19:11:56 +01:00
|
|
|
|
<Key className="h-4 w-4 mr-2" />
|
|
|
|
|
|
Generate New API Token
|
|
|
|
|
|
</Button>
|
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
|
|
{showApiTokenSection && !apiToken && (
|
|
|
|
|
|
<div className="space-y-4 border border-border rounded-lg p-4">
|
|
|
|
|
|
<h3 className="font-semibold">Generate API Token</h3>
|
|
|
|
|
|
<p className="text-sm text-muted-foreground">
|
|
|
|
|
|
Enter your credentials to generate a new long-lived API token
|
|
|
|
|
|
</p>
|
|
|
|
|
|
|
2026-02-07 18:03:46 +01:00
|
|
|
|
<div className="space-y-2">
|
|
|
|
|
|
<Label htmlFor="token-name">Token Name</Label>
|
|
|
|
|
|
<div className="relative">
|
|
|
|
|
|
<Key className="absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground" />
|
|
|
|
|
|
<Input
|
|
|
|
|
|
id="token-name"
|
|
|
|
|
|
type="text"
|
|
|
|
|
|
placeholder="e.g. Homepage, Home Assistant"
|
|
|
|
|
|
value={tokenName}
|
|
|
|
|
|
onChange={(e) => setTokenName(e.target.value)}
|
|
|
|
|
|
className="pl-10"
|
|
|
|
|
|
disabled={generatingToken}
|
|
|
|
|
|
/>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
2025-11-13 19:11:56 +01:00
|
|
|
|
<div className="space-y-2">
|
|
|
|
|
|
<Label htmlFor="token-password">Password</Label>
|
|
|
|
|
|
<div className="relative">
|
|
|
|
|
|
<Lock className="absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground" />
|
|
|
|
|
|
<Input
|
|
|
|
|
|
id="token-password"
|
|
|
|
|
|
type="password"
|
|
|
|
|
|
placeholder="Enter your password"
|
|
|
|
|
|
value={tokenPassword}
|
|
|
|
|
|
onChange={(e) => setTokenPassword(e.target.value)}
|
|
|
|
|
|
className="pl-10"
|
|
|
|
|
|
disabled={generatingToken}
|
|
|
|
|
|
/>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
{totpEnabled && (
|
|
|
|
|
|
<div className="space-y-2">
|
|
|
|
|
|
<Label htmlFor="token-totp">2FA Code</Label>
|
|
|
|
|
|
<div className="relative">
|
|
|
|
|
|
<Shield className="absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground" />
|
|
|
|
|
|
<Input
|
|
|
|
|
|
id="token-totp"
|
|
|
|
|
|
type="text"
|
|
|
|
|
|
placeholder="Enter 6-digit code"
|
|
|
|
|
|
value={tokenTotpCode}
|
|
|
|
|
|
onChange={(e) => setTokenTotpCode(e.target.value)}
|
|
|
|
|
|
className="pl-10"
|
|
|
|
|
|
maxLength={6}
|
|
|
|
|
|
disabled={generatingToken}
|
|
|
|
|
|
/>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
|
|
<div className="flex gap-2">
|
|
|
|
|
|
<Button
|
|
|
|
|
|
onClick={handleGenerateApiToken}
|
|
|
|
|
|
className="flex-1 bg-purple-500 hover:bg-purple-600"
|
|
|
|
|
|
disabled={generatingToken}
|
|
|
|
|
|
>
|
|
|
|
|
|
{generatingToken ? "Generating..." : "Generate Token"}
|
|
|
|
|
|
</Button>
|
|
|
|
|
|
<Button
|
|
|
|
|
|
onClick={() => {
|
2025-11-18 13:30:37 +01:00
|
|
|
|
setShowApiTokenSection(false)
|
|
|
|
|
|
setTokenPassword("")
|
|
|
|
|
|
setTokenTotpCode("")
|
2026-02-07 18:03:46 +01:00
|
|
|
|
setTokenName("API Token")
|
2025-11-18 13:30:37 +01:00
|
|
|
|
setError("")
|
2025-11-13 19:11:56 +01:00
|
|
|
|
}}
|
|
|
|
|
|
variant="outline"
|
|
|
|
|
|
className="flex-1"
|
|
|
|
|
|
disabled={generatingToken}
|
|
|
|
|
|
>
|
|
|
|
|
|
Cancel
|
|
|
|
|
|
</Button>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
|
|
{apiToken && (
|
|
|
|
|
|
<div className="space-y-4 border border-green-500/20 bg-green-500/5 rounded-lg p-4">
|
|
|
|
|
|
<div className="flex items-center gap-2 text-green-500">
|
|
|
|
|
|
<CheckCircle className="h-5 w-5" />
|
|
|
|
|
|
<h3 className="font-semibold">Your API Token</h3>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
2025-11-13 21:12:32 +01:00
|
|
|
|
<div className="bg-amber-500/10 border border-amber-500/30 rounded-lg p-3 flex items-start gap-2">
|
|
|
|
|
|
<AlertCircle className="h-5 w-5 text-amber-500 flex-shrink-0 mt-0.5" />
|
|
|
|
|
|
<div className="space-y-1">
|
|
|
|
|
|
<p className="text-sm text-amber-600 dark:text-amber-400 font-semibold">
|
|
|
|
|
|
⚠️ Important: Save this token now!
|
|
|
|
|
|
</p>
|
|
|
|
|
|
<p className="text-xs text-amber-600/80 dark:text-amber-400/80">
|
|
|
|
|
|
You won't be able to see it again. Store it securely.
|
|
|
|
|
|
</p>
|
|
|
|
|
|
</div>
|
2025-11-13 19:11:56 +01:00
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<div className="space-y-2">
|
|
|
|
|
|
<Label>Token</Label>
|
|
|
|
|
|
<div className="relative">
|
|
|
|
|
|
<Input
|
|
|
|
|
|
value={apiToken}
|
|
|
|
|
|
readOnly
|
|
|
|
|
|
type={apiTokenVisible ? "text" : "password"}
|
|
|
|
|
|
className="pr-20 font-mono text-sm"
|
|
|
|
|
|
/>
|
|
|
|
|
|
<div className="absolute right-2 top-1/2 -translate-y-1/2 flex gap-1">
|
|
|
|
|
|
<Button
|
|
|
|
|
|
size="sm"
|
|
|
|
|
|
variant="ghost"
|
|
|
|
|
|
onClick={() => setApiTokenVisible(!apiTokenVisible)}
|
|
|
|
|
|
className="h-7 w-7 p-0"
|
|
|
|
|
|
>
|
2025-11-18 13:30:37 +01:00
|
|
|
|
{apiTokenVisible ? <EyeOff className="h-4 w-4" /> : <Eye className="h-4 w-4" />}
|
2025-11-13 19:11:56 +01:00
|
|
|
|
</Button>
|
2025-11-18 13:30:37 +01:00
|
|
|
|
<Button size="sm" variant="ghost" onClick={copyApiToken} className="h-7 w-7 p-0">
|
|
|
|
|
|
<Copy className={`h-4 w-4 ${tokenCopied ? "text-green-500" : ""}`} />
|
2025-11-13 19:11:56 +01:00
|
|
|
|
</Button>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
{tokenCopied && (
|
|
|
|
|
|
<p className="text-xs text-green-500 flex items-center gap-1">
|
|
|
|
|
|
<CheckCircle className="h-3 w-3" />
|
|
|
|
|
|
Copied to clipboard!
|
|
|
|
|
|
</p>
|
|
|
|
|
|
)}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<div className="space-y-2">
|
|
|
|
|
|
<p className="text-sm font-medium">How to use this token:</p>
|
|
|
|
|
|
<div className="bg-muted/50 rounded p-3 text-xs font-mono">
|
2025-11-18 13:30:37 +01:00
|
|
|
|
<p className="text-muted-foreground mb-2"># Add to request headers:</p>
|
2025-11-13 19:11:56 +01:00
|
|
|
|
<p>Authorization: Bearer YOUR_TOKEN_HERE</p>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<p className="text-xs text-muted-foreground">
|
2025-11-18 13:30:37 +01:00
|
|
|
|
See the README documentation for complete integration examples with Homepage and Home Assistant.
|
2025-11-13 19:11:56 +01:00
|
|
|
|
</p>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<Button
|
|
|
|
|
|
onClick={() => {
|
2025-11-18 13:30:37 +01:00
|
|
|
|
setApiToken("")
|
|
|
|
|
|
setShowApiTokenSection(false)
|
2025-11-13 19:11:56 +01:00
|
|
|
|
}}
|
|
|
|
|
|
variant="outline"
|
|
|
|
|
|
className="w-full"
|
|
|
|
|
|
>
|
|
|
|
|
|
Done
|
|
|
|
|
|
</Button>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
2026-02-07 18:03:46 +01:00
|
|
|
|
|
|
|
|
|
|
{/* Existing Tokens List */}
|
|
|
|
|
|
{!loadingTokens && existingTokens.length > 0 && (
|
|
|
|
|
|
<div className="space-y-3">
|
|
|
|
|
|
<div className="flex items-center justify-between">
|
|
|
|
|
|
<h3 className="text-sm font-semibold text-muted-foreground">Active Tokens</h3>
|
|
|
|
|
|
<Button
|
|
|
|
|
|
variant="ghost"
|
|
|
|
|
|
size="sm"
|
|
|
|
|
|
onClick={loadApiTokens}
|
|
|
|
|
|
className="h-7 px-2 text-xs text-muted-foreground hover:text-foreground"
|
|
|
|
|
|
>
|
|
|
|
|
|
<RefreshCw className="h-3 w-3 mr-1" />
|
|
|
|
|
|
Refresh
|
|
|
|
|
|
</Button>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<div className="space-y-2">
|
|
|
|
|
|
{existingTokens.map((token) => (
|
|
|
|
|
|
<div
|
|
|
|
|
|
key={token.id}
|
|
|
|
|
|
className="flex items-center justify-between p-3 bg-muted/50 rounded-lg border border-border"
|
|
|
|
|
|
>
|
|
|
|
|
|
<div className="flex items-center gap-3 min-w-0">
|
|
|
|
|
|
<div className="w-8 h-8 rounded-full bg-blue-500/10 flex items-center justify-center flex-shrink-0">
|
|
|
|
|
|
<Key className="h-4 w-4 text-blue-500" />
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div className="min-w-0">
|
|
|
|
|
|
<p className="text-sm font-medium truncate">{token.name}</p>
|
|
|
|
|
|
<div className="flex items-center gap-2 text-xs text-muted-foreground">
|
|
|
|
|
|
<code className="font-mono">{token.token_prefix}</code>
|
|
|
|
|
|
<span className="flex items-center gap-1">
|
|
|
|
|
|
<Clock className="h-3 w-3" />
|
|
|
|
|
|
{token.created_at
|
|
|
|
|
|
? new Date(token.created_at).toLocaleDateString()
|
|
|
|
|
|
: "Unknown"}
|
|
|
|
|
|
</span>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<Button
|
|
|
|
|
|
variant="ghost"
|
|
|
|
|
|
size="sm"
|
|
|
|
|
|
onClick={() => handleRevokeToken(token.id)}
|
|
|
|
|
|
disabled={revokingTokenId === token.id}
|
|
|
|
|
|
className="h-8 px-2 text-red-500 hover:text-red-400 hover:bg-red-500/10 flex-shrink-0"
|
|
|
|
|
|
>
|
|
|
|
|
|
{revokingTokenId === token.id ? (
|
|
|
|
|
|
<div className="animate-spin h-4 w-4 border-2 border-red-500 border-t-transparent rounded-full" />
|
|
|
|
|
|
) : (
|
|
|
|
|
|
<Trash2 className="h-4 w-4" />
|
|
|
|
|
|
)}
|
|
|
|
|
|
<span className="ml-1 text-xs hidden sm:inline">Revoke</span>
|
|
|
|
|
|
</Button>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
))}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
|
|
{loadingTokens && (
|
|
|
|
|
|
<div className="flex items-center justify-center py-4">
|
|
|
|
|
|
<div className="animate-spin h-5 w-5 border-2 border-blue-500 border-t-transparent rounded-full" />
|
|
|
|
|
|
<span className="ml-2 text-sm text-muted-foreground">Loading tokens...</span>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
|
|
{!loadingTokens && existingTokens.length === 0 && !showApiTokenSection && !apiToken && (
|
|
|
|
|
|
<div className="text-center py-4 text-sm text-muted-foreground">
|
|
|
|
|
|
No API tokens created yet
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
2025-11-13 19:11:56 +01:00
|
|
|
|
</CardContent>
|
|
|
|
|
|
</Card>
|
|
|
|
|
|
)}
|
2025-11-18 19:00:51 +01:00
|
|
|
|
|
2026-02-07 18:36:14 +01:00
|
|
|
|
{/* SSL/HTTPS Configuration */}
|
|
|
|
|
|
<Card>
|
|
|
|
|
|
<CardHeader>
|
|
|
|
|
|
<div className="flex items-center gap-2">
|
|
|
|
|
|
<ShieldCheck className="h-5 w-5 text-green-500" />
|
|
|
|
|
|
<CardTitle>SSL / HTTPS</CardTitle>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<CardDescription>
|
|
|
|
|
|
Serve ProxMenux Monitor over HTTPS using your Proxmox host certificate or a custom certificate
|
|
|
|
|
|
</CardDescription>
|
|
|
|
|
|
</CardHeader>
|
|
|
|
|
|
<CardContent className="space-y-4">
|
|
|
|
|
|
{loadingSsl ? (
|
|
|
|
|
|
<div className="flex items-center justify-center py-8">
|
|
|
|
|
|
<div className="animate-spin h-8 w-8 border-4 border-green-500 border-t-transparent rounded-full" />
|
|
|
|
|
|
</div>
|
|
|
|
|
|
) : (
|
|
|
|
|
|
<>
|
|
|
|
|
|
{/* Current Status */}
|
|
|
|
|
|
<div className="flex items-center justify-between p-4 bg-muted/50 rounded-lg">
|
|
|
|
|
|
<div className="flex items-center gap-3">
|
|
|
|
|
|
<div className={`w-10 h-10 rounded-full flex items-center justify-center ${sslEnabled ? "bg-green-500/10" : "bg-gray-500/10"}`}>
|
|
|
|
|
|
<Globe className={`h-5 w-5 ${sslEnabled ? "text-green-500" : "text-gray-500"}`} />
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div>
|
|
|
|
|
|
<p className="font-medium">
|
|
|
|
|
|
{sslEnabled ? "HTTPS Enabled" : "HTTP (No SSL)"}
|
|
|
|
|
|
</p>
|
|
|
|
|
|
<p className="text-sm text-muted-foreground">
|
|
|
|
|
|
{sslEnabled
|
|
|
|
|
|
? `Using ${sslSource === "proxmox" ? "Proxmox host" : "custom"} certificate`
|
|
|
|
|
|
: "Monitor is served over unencrypted HTTP"}
|
|
|
|
|
|
</p>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div className={`px-3 py-1 rounded-full text-sm font-medium ${sslEnabled ? "bg-green-500/10 text-green-500" : "bg-gray-500/10 text-gray-500"}`}>
|
|
|
|
|
|
{sslEnabled ? "HTTPS" : "HTTP"}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
{/* Active certificate info */}
|
|
|
|
|
|
{sslEnabled && (
|
|
|
|
|
|
<div className="space-y-2 p-3 bg-green-500/5 border border-green-500/20 rounded-lg">
|
|
|
|
|
|
<div className="flex items-center gap-2 text-sm font-medium text-green-500">
|
|
|
|
|
|
<FileKey className="h-4 w-4" />
|
|
|
|
|
|
Active Certificate
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div className="grid gap-1 text-sm text-muted-foreground">
|
|
|
|
|
|
<p><span className="font-medium text-foreground">Cert:</span> <code className="text-xs">{sslCertPath}</code></p>
|
|
|
|
|
|
<p><span className="font-medium text-foreground">Key:</span> <code className="text-xs">{sslKeyPath}</code></p>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<Button
|
|
|
|
|
|
onClick={handleDisableSsl}
|
|
|
|
|
|
variant="outline"
|
|
|
|
|
|
size="sm"
|
|
|
|
|
|
disabled={configuringSsl}
|
|
|
|
|
|
className="mt-2 text-red-500 border-red-500/30 hover:bg-red-500/10 bg-transparent"
|
|
|
|
|
|
>
|
|
|
|
|
|
{configuringSsl ? "Disabling..." : "Disable HTTPS"}
|
|
|
|
|
|
</Button>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
|
|
{/* Proxmox certificate detection */}
|
|
|
|
|
|
{!sslEnabled && proxmoxCertAvailable && (
|
|
|
|
|
|
<div className="space-y-3 p-4 border border-border rounded-lg">
|
|
|
|
|
|
<div className="flex items-center gap-2">
|
|
|
|
|
|
<ShieldCheck className="h-4 w-4 text-green-500" />
|
|
|
|
|
|
<h3 className="font-semibold text-sm">Proxmox Host Certificate Detected</h3>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
{proxmoxCertInfo && (
|
|
|
|
|
|
<div className="grid gap-1 text-sm text-muted-foreground bg-muted/50 p-3 rounded">
|
|
|
|
|
|
{proxmoxCertInfo.subject && (
|
|
|
|
|
|
<p><span className="font-medium text-foreground">Subject:</span> {proxmoxCertInfo.subject}</p>
|
|
|
|
|
|
)}
|
|
|
|
|
|
{proxmoxCertInfo.issuer && (
|
|
|
|
|
|
<p><span className="font-medium text-foreground">Issuer:</span> {proxmoxCertInfo.issuer}</p>
|
|
|
|
|
|
)}
|
|
|
|
|
|
{proxmoxCertInfo.expires && (
|
|
|
|
|
|
<p><span className="font-medium text-foreground">Expires:</span> {proxmoxCertInfo.expires}</p>
|
|
|
|
|
|
)}
|
|
|
|
|
|
{proxmoxCertInfo.is_self_signed && (
|
|
|
|
|
|
<div className="flex items-center gap-1.5 mt-1 text-yellow-500">
|
|
|
|
|
|
<AlertTriangle className="h-3.5 w-3.5" />
|
|
|
|
|
|
<span className="text-xs">Self-signed certificate (browsers will show a security warning)</span>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
|
|
<Button
|
|
|
|
|
|
onClick={() => handleEnableSsl("proxmox")}
|
|
|
|
|
|
className="w-full bg-green-600 hover:bg-green-700 text-white"
|
|
|
|
|
|
disabled={configuringSsl}
|
|
|
|
|
|
>
|
|
|
|
|
|
{configuringSsl ? (
|
|
|
|
|
|
<div className="flex items-center gap-2">
|
|
|
|
|
|
<div className="animate-spin h-4 w-4 border-2 border-white border-t-transparent rounded-full" />
|
|
|
|
|
|
Configuring...
|
|
|
|
|
|
</div>
|
|
|
|
|
|
) : (
|
|
|
|
|
|
<>
|
|
|
|
|
|
<ShieldCheck className="h-4 w-4 mr-2" />
|
|
|
|
|
|
Use Proxmox Certificate
|
|
|
|
|
|
</>
|
|
|
|
|
|
)}
|
|
|
|
|
|
</Button>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
|
|
{!sslEnabled && !proxmoxCertAvailable && (
|
|
|
|
|
|
<div className="bg-yellow-500/10 border border-yellow-500/20 rounded-lg p-3 flex items-start gap-2">
|
|
|
|
|
|
<AlertTriangle className="h-5 w-5 text-yellow-500 flex-shrink-0 mt-0.5" />
|
|
|
|
|
|
<p className="text-sm text-yellow-500">
|
|
|
|
|
|
No Proxmox host certificate detected. You can configure a custom certificate below.
|
|
|
|
|
|
</p>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
|
|
{/* Custom certificate option */}
|
|
|
|
|
|
{!sslEnabled && (
|
|
|
|
|
|
<div className="space-y-3">
|
|
|
|
|
|
{!showCustomCertForm ? (
|
|
|
|
|
|
<Button
|
|
|
|
|
|
onClick={() => setShowCustomCertForm(true)}
|
|
|
|
|
|
variant="outline"
|
|
|
|
|
|
className="w-full"
|
|
|
|
|
|
>
|
|
|
|
|
|
<FileKey className="h-4 w-4 mr-2" />
|
|
|
|
|
|
Use Custom Certificate
|
|
|
|
|
|
</Button>
|
|
|
|
|
|
) : (
|
|
|
|
|
|
<div className="space-y-4 border border-border rounded-lg p-4">
|
|
|
|
|
|
<h3 className="font-semibold text-sm">Custom Certificate Paths</h3>
|
|
|
|
|
|
<p className="text-xs text-muted-foreground">
|
|
|
|
|
|
Enter the absolute paths to your SSL certificate and private key files on the Proxmox server.
|
|
|
|
|
|
</p>
|
|
|
|
|
|
|
|
|
|
|
|
<div className="space-y-2">
|
|
|
|
|
|
<Label htmlFor="ssl-cert-path">Certificate Path (.pem / .crt)</Label>
|
|
|
|
|
|
<Input
|
|
|
|
|
|
id="ssl-cert-path"
|
|
|
|
|
|
type="text"
|
|
|
|
|
|
placeholder="/etc/ssl/certs/mydomain.pem"
|
|
|
|
|
|
value={customCertPath}
|
|
|
|
|
|
onChange={(e) => setCustomCertPath(e.target.value)}
|
|
|
|
|
|
disabled={configuringSsl}
|
|
|
|
|
|
/>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<div className="space-y-2">
|
|
|
|
|
|
<Label htmlFor="ssl-key-path">Private Key Path (.key / .pem)</Label>
|
|
|
|
|
|
<Input
|
|
|
|
|
|
id="ssl-key-path"
|
|
|
|
|
|
type="text"
|
|
|
|
|
|
placeholder="/etc/ssl/private/mydomain.key"
|
|
|
|
|
|
value={customKeyPath}
|
|
|
|
|
|
onChange={(e) => setCustomKeyPath(e.target.value)}
|
|
|
|
|
|
disabled={configuringSsl}
|
|
|
|
|
|
/>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<div className="flex gap-2">
|
|
|
|
|
|
<Button
|
|
|
|
|
|
onClick={() => handleEnableSsl("custom", customCertPath, customKeyPath)}
|
|
|
|
|
|
className="flex-1 bg-green-600 hover:bg-green-700 text-white"
|
|
|
|
|
|
disabled={configuringSsl || !customCertPath || !customKeyPath}
|
|
|
|
|
|
>
|
|
|
|
|
|
{configuringSsl ? "Configuring..." : "Enable HTTPS"}
|
|
|
|
|
|
</Button>
|
|
|
|
|
|
<Button
|
|
|
|
|
|
onClick={() => {
|
|
|
|
|
|
setShowCustomCertForm(false)
|
|
|
|
|
|
setCustomCertPath("")
|
|
|
|
|
|
setCustomKeyPath("")
|
|
|
|
|
|
}}
|
|
|
|
|
|
variant="outline"
|
|
|
|
|
|
className="flex-1"
|
|
|
|
|
|
disabled={configuringSsl}
|
|
|
|
|
|
>
|
|
|
|
|
|
Cancel
|
|
|
|
|
|
</Button>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
|
|
{/* Info note about restart */}
|
|
|
|
|
|
<div className="bg-blue-500/10 border border-blue-500/20 rounded-lg p-3 flex items-start gap-2">
|
|
|
|
|
|
<Info className="h-5 w-5 text-blue-500 flex-shrink-0 mt-0.5" />
|
|
|
|
|
|
<p className="text-sm text-blue-500">
|
|
|
|
|
|
Changes to SSL configuration require a monitor service restart to take effect.
|
|
|
|
|
|
The service will automatically use HTTPS on port 8008 when enabled.
|
|
|
|
|
|
</p>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</>
|
|
|
|
|
|
)}
|
|
|
|
|
|
</CardContent>
|
|
|
|
|
|
</Card>
|
|
|
|
|
|
|
2025-11-09 20:52:39 +01:00
|
|
|
|
{/* ProxMenux Optimizations */}
|
2025-11-04 18:07:13 +01:00
|
|
|
|
<Card>
|
|
|
|
|
|
<CardHeader>
|
2025-11-09 20:52:39 +01:00
|
|
|
|
<div className="flex items-center gap-2">
|
|
|
|
|
|
<Wrench className="h-5 w-5 text-orange-500" />
|
|
|
|
|
|
<CardTitle>ProxMenux Optimizations</CardTitle>
|
2025-11-04 18:07:13 +01:00
|
|
|
|
</div>
|
2025-11-18 13:30:37 +01:00
|
|
|
|
<CardDescription>System optimizations and utilities installed via ProxMenux</CardDescription>
|
2025-11-09 20:52:39 +01:00
|
|
|
|
</CardHeader>
|
|
|
|
|
|
<CardContent>
|
|
|
|
|
|
{loadingTools ? (
|
|
|
|
|
|
<div className="flex items-center justify-center py-8">
|
|
|
|
|
|
<div className="animate-spin h-8 w-8 border-4 border-orange-500 border-t-transparent rounded-full" />
|
|
|
|
|
|
</div>
|
|
|
|
|
|
) : proxmenuxTools.length === 0 ? (
|
|
|
|
|
|
<div className="text-center py-8">
|
|
|
|
|
|
<Package className="h-12 w-12 text-muted-foreground mx-auto mb-3 opacity-50" />
|
2025-11-18 13:30:37 +01:00
|
|
|
|
<p className="text-muted-foreground">No ProxMenux optimizations installed yet</p>
|
|
|
|
|
|
<p className="text-sm text-muted-foreground mt-1">Run ProxMenux to configure system optimizations</p>
|
2025-11-09 20:52:39 +01:00
|
|
|
|
</div>
|
|
|
|
|
|
) : (
|
|
|
|
|
|
<div className="space-y-2">
|
|
|
|
|
|
<div className="flex items-center justify-between mb-4 pb-2 border-b border-border">
|
2025-11-18 13:30:37 +01:00
|
|
|
|
<span className="text-sm font-medium text-muted-foreground">Installed Tools</span>
|
|
|
|
|
|
<span className="text-sm font-semibold text-orange-500">{proxmenuxTools.length} active</span>
|
2025-11-09 20:52:39 +01:00
|
|
|
|
</div>
|
|
|
|
|
|
<div className="grid grid-cols-1 md:grid-cols-2 gap-2">
|
|
|
|
|
|
{proxmenuxTools.map((tool) => (
|
|
|
|
|
|
<div
|
|
|
|
|
|
key={tool.key}
|
|
|
|
|
|
className="flex items-center gap-2 p-3 bg-muted/50 rounded-lg border border-border hover:bg-muted transition-colors"
|
|
|
|
|
|
>
|
|
|
|
|
|
<div className="w-2 h-2 rounded-full bg-green-500 flex-shrink-0" />
|
|
|
|
|
|
<span className="text-sm font-medium">{tool.name}</span>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
))}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
2025-11-04 18:07:13 +01:00
|
|
|
|
</CardContent>
|
|
|
|
|
|
</Card>
|
2025-11-07 20:36:46 +01:00
|
|
|
|
|
|
|
|
|
|
<TwoFactorSetup
|
|
|
|
|
|
open={show2FASetup}
|
|
|
|
|
|
onClose={() => setShow2FASetup(false)}
|
|
|
|
|
|
onSuccess={() => {
|
2025-11-18 13:30:37 +01:00
|
|
|
|
setSuccess("2FA enabled successfully!")
|
|
|
|
|
|
checkAuthStatus()
|
2025-11-07 20:36:46 +01:00
|
|
|
|
}}
|
|
|
|
|
|
/>
|
2025-11-04 18:07:13 +01:00
|
|
|
|
</div>
|
2025-11-18 13:30:37 +01:00
|
|
|
|
)
|
2025-11-18 19:00:51 +01:00
|
|
|
|
}
|