Update AppImage

This commit is contained in:
MacRimi
2025-10-05 14:16:21 +02:00
parent 49050c042d
commit 19f7ea70f0
2 changed files with 129 additions and 55 deletions

View File

@@ -4,7 +4,7 @@ import { useState } from "react"
import { Card, CardContent, CardHeader, CardTitle } from "./ui/card" import { Card, CardContent, CardHeader, CardTitle } from "./ui/card"
import { Badge } from "./ui/badge" import { Badge } from "./ui/badge"
import { Dialog, DialogContent, DialogHeader, DialogTitle } from "./ui/dialog" import { Dialog, DialogContent, DialogHeader, DialogTitle } from "./ui/dialog"
import { Wifi, Activity, Network, Router, AlertCircle, Zap } from "lucide-react" import { Wifi, Activity, Network, Router, AlertCircle, Zap, Shield } from "lucide-react"
import useSWR from "swr" import useSWR from "swr"
interface NetworkData { interface NetworkData {
@@ -214,6 +214,36 @@ export function NetworkMetrics() {
</CardContent> </CardContent>
</Card> </Card>
<Card className="bg-card border-border">
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
<CardTitle className="text-sm font-medium text-muted-foreground">Firewall Status</CardTitle>
<Shield className="h-4 w-4 text-muted-foreground" />
</CardHeader>
<CardContent>
<div className="text-2xl font-bold text-foreground">Active</div>
<Badge variant="outline" className="bg-green-500/10 text-green-500 border-green-500/20 mt-2">
Protected
</Badge>
<p className="text-xs text-muted-foreground mt-2">System protected</p>
</CardContent>
</Card>
<Card className="bg-card border-border">
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
<CardTitle className="text-sm font-medium text-muted-foreground">Packets</CardTitle>
<Activity className="h-4 w-4 text-muted-foreground" />
</CardHeader>
<CardContent>
<div className="text-2xl font-bold text-foreground">{packetsRecvK}K</div>
<Badge variant="outline" className="bg-green-500/10 text-green-500 border-green-500/20 mt-2">
Received
</Badge>
<p className="text-xs text-muted-foreground mt-2">No packet loss</p>
</CardContent>
</Card>
</div>
{networkData.physical_interfaces && networkData.physical_interfaces.length > 0 && (
<Card className="bg-card border-border"> <Card className="bg-card border-border">
<CardHeader> <CardHeader>
<CardTitle className="text-foreground flex items-center"> <CardTitle className="text-foreground flex items-center">
@@ -225,20 +255,19 @@ export function NetworkMetrics() {
</CardTitle> </CardTitle>
</CardHeader> </CardHeader>
<CardContent> <CardContent>
<div className="space-y-4"> <div className="grid grid-cols-1 lg:grid-cols-2 gap-4">
{networkData.physical_interfaces.map((interface_, index) => { {networkData.physical_interfaces.map((interface_, index) => {
const typeBadge = getInterfaceTypeBadge(interface_.type) const typeBadge = getInterfaceTypeBadge(interface_.type)
return ( return (
<div <div
key={index} key={index}
className="flex flex-col gap-3 p-4 rounded-lg border border-border bg-card/50 hover:bg-card/80 transition-colors cursor-pointer" className="p-4 rounded-lg border border-border bg-card/50 hover:bg-card/80 transition-colors cursor-pointer"
onClick={() => setSelectedInterface(interface_)} onClick={() => setSelectedInterface(interface_)}
> >
{/* First row: Icon, Name, Type Badge, Status */} <div className="flex items-center justify-between mb-3">
<div className="flex items-center gap-3 flex-wrap"> <div className="flex items-center gap-2">
<Wifi className="h-5 w-5 text-muted-foreground flex-shrink-0" /> <Wifi className="h-5 w-5 text-muted-foreground" />
<div className="flex items-center gap-2 min-w-0">
<div className="font-medium text-foreground">{interface_.name}</div> <div className="font-medium text-foreground">{interface_.name}</div>
<Badge variant="outline" className={typeBadge.color}> <Badge variant="outline" className={typeBadge.color}>
{typeBadge.label} {typeBadge.label}
@@ -248,32 +277,31 @@ export function NetworkMetrics() {
variant="outline" variant="outline"
className={ className={
interface_.status === "up" interface_.status === "up"
? "bg-green-500/10 text-green-500 border-green-500/20 ml-auto" ? "bg-green-500/10 text-green-500 border-green-500/20"
: "bg-red-500/10 text-red-500 border-red-500/20 ml-auto" : "bg-red-500/10 text-red-500 border-red-500/20"
} }
> >
{interface_.status.toUpperCase()} {interface_.status.toUpperCase()}
</Badge> </Badge>
</div> </div>
{/* Second row: Details - Responsive layout */} <div className="grid grid-cols-2 gap-3 text-sm">
<div className="grid grid-cols-2 md:grid-cols-4 gap-4 text-sm">
<div> <div>
<div className="text-muted-foreground text-xs">IP Address</div> <div className="text-muted-foreground text-xs">IP Address</div>
<div className="font-medium text-foreground font-mono text-sm truncate"> <div className="font-medium text-foreground font-mono text-xs truncate">
{interface_.addresses.length > 0 ? interface_.addresses[0].ip : "N/A"} {interface_.addresses.length > 0 ? interface_.addresses[0].ip : "N/A"}
</div> </div>
</div> </div>
<div> <div>
<div className="text-muted-foreground text-xs">Speed</div> <div className="text-muted-foreground text-xs">Speed</div>
<div className="font-medium text-foreground flex items-center gap-1"> <div className="font-medium text-foreground flex items-center gap-1 text-xs">
<Zap className="h-3 w-3" /> <Zap className="h-3 w-3" />
{formatSpeed(interface_.speed)} {formatSpeed(interface_.speed)}
</div> </div>
</div> </div>
<div className="col-span-2 md:col-span-1"> <div>
<div className="text-muted-foreground text-xs">Traffic</div> <div className="text-muted-foreground text-xs">Traffic</div>
<div className="font-medium text-foreground text-xs"> <div className="font-medium text-foreground text-xs">
<span className="text-green-500"> {formatBytes(interface_.bytes_recv)}</span> <span className="text-green-500"> {formatBytes(interface_.bytes_recv)}</span>
@@ -283,7 +311,7 @@ export function NetworkMetrics() {
</div> </div>
{interface_.mac_address && ( {interface_.mac_address && (
<div className="col-span-2 md:col-span-1"> <div>
<div className="text-muted-foreground text-xs">MAC</div> <div className="text-muted-foreground text-xs">MAC</div>
<div className="font-medium text-foreground font-mono text-xs truncate"> <div className="font-medium text-foreground font-mono text-xs truncate">
{interface_.mac_address} {interface_.mac_address}
@@ -297,7 +325,7 @@ export function NetworkMetrics() {
</div> </div>
</CardContent> </CardContent>
</Card> </Card>
</div> )}
{networkData.bridge_interfaces && networkData.bridge_interfaces.length > 0 && ( {networkData.bridge_interfaces && networkData.bridge_interfaces.length > 0 && (
<Card className="bg-card border-border"> <Card className="bg-card border-border">

View File

@@ -1,6 +1,6 @@
"use client" "use client"
import { useState } from "react" import { useState, useMemo } from "react"
import { Card, CardContent, CardHeader, CardTitle } from "./ui/card" import { Card, CardContent, CardHeader, CardTitle } from "./ui/card"
import { Badge } from "./ui/badge" import { Badge } from "./ui/badge"
import { Progress } from "./ui/progress" import { Progress } from "./ui/progress"
@@ -18,6 +18,7 @@ import {
Power, Power,
RotateCcw, RotateCcw,
StopCircle, StopCircle,
AlertTriangle,
} from "lucide-react" } from "lucide-react"
import useSWR from "swr" import useSWR from "swr"
@@ -227,6 +228,29 @@ export function VirtualMachines() {
// Safe data handling with default empty array // Safe data handling with default empty array
const safeVMData = vmData || [] const safeVMData = vmData || []
const totalAllocatedMemoryGB = useMemo(() => {
return (safeVMData.reduce((sum, vm) => sum + (vm.maxmem || 0), 0) / 1024 ** 3).toFixed(1)
}, [safeVMData])
const { data: overviewData } = useSWR("/api/overview", fetcher, {
refreshInterval: 30000,
revalidateOnFocus: false,
})
const physicalMemoryGB = useMemo(() => {
if (overviewData && overviewData.memory) {
return (overviewData.memory.total / 1024 ** 3).toFixed(1)
}
return null
}, [overviewData])
const isMemoryOvercommit = useMemo(() => {
if (physicalMemoryGB) {
return Number.parseFloat(totalAllocatedMemoryGB) > Number.parseFloat(physicalMemoryGB)
}
return false
}, [totalAllocatedMemoryGB, physicalMemoryGB])
if (isLoading) { if (isLoading) {
return ( return (
<div className="space-y-6"> <div className="space-y-6">
@@ -279,16 +303,26 @@ export function VirtualMachines() {
</CardContent> </CardContent>
</Card> </Card>
<Card className="bg-card border-border"> <Card className={`bg-card ${isMemoryOvercommit ? "border-yellow-500/50" : "border-border"}`}>
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2"> <CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
<CardTitle className="text-sm font-medium text-muted-foreground">Total Memory</CardTitle> <CardTitle className="text-sm font-medium text-muted-foreground">Total Memory</CardTitle>
<div className="flex items-center gap-2">
{isMemoryOvercommit && <AlertTriangle className="h-4 w-4 text-yellow-500" />}
<MemoryStick className="h-4 w-4 text-muted-foreground" /> <MemoryStick className="h-4 w-4 text-muted-foreground" />
</div>
</CardHeader> </CardHeader>
<CardContent> <CardContent>
<div className="text-2xl font-bold text-foreground"> <div className={`text-2xl font-bold ${isMemoryOvercommit ? "text-yellow-500" : "text-foreground"}`}>
{(safeVMData.reduce((sum, vm) => sum + (vm.maxmem || 0), 0) / 1024 ** 3).toFixed(1)} GB {totalAllocatedMemoryGB} GB
</div> </div>
{isMemoryOvercommit ? (
<p className="text-xs text-yellow-500 mt-2 flex items-center gap-1">
<AlertTriangle className="h-3 w-3" />
Overcommit: Excede memoria física ({physicalMemoryGB} GB)
</p>
) : (
<p className="text-xs text-muted-foreground mt-2">Allocated RAM</p> <p className="text-xs text-muted-foreground mt-2">Allocated RAM</p>
)}
</CardContent> </CardContent>
</Card> </Card>
@@ -339,13 +373,13 @@ export function VirtualMachines() {
className="p-6 rounded-lg border border-border bg-card/50 hover:bg-card/80 transition-colors cursor-pointer" className="p-6 rounded-lg border border-border bg-card/50 hover:bg-card/80 transition-colors cursor-pointer"
onClick={() => handleVMClick(vm)} onClick={() => handleVMClick(vm)}
> >
<div className="flex items-center justify-between mb-4"> <div className="flex flex-col sm:flex-row sm:items-center sm:justify-between gap-3 mb-4">
<div className="flex items-center space-x-4"> <div className="flex items-center space-x-4">
<Server className="h-6 w-6 text-muted-foreground" /> <Server className="h-6 w-6 text-muted-foreground flex-shrink-0" />
<div> <div className="min-w-0">
<div className="font-semibold text-foreground text-lg flex items-center"> <div className="font-semibold text-foreground text-lg flex items-center flex-wrap gap-2">
{vm.name} <span className="truncate">{vm.name}</span>
<Badge variant="outline" className={`ml-2 text-xs ${typeBadge.color}`}> <Badge variant="outline" className={`text-xs flex-shrink-0 ${typeBadge.color}`}>
{typeBadge.label} {typeBadge.label}
</Badge> </Badge>
</div> </div>
@@ -353,13 +387,14 @@ export function VirtualMachines() {
</div> </div>
</div> </div>
<div className="flex items-center space-x-3"> <Badge
<Badge variant="outline" className={getStatusColor(vm.status)}> variant="outline"
className={`${getStatusColor(vm.status)} flex-shrink-0 self-start sm:self-center`}
>
{getStatusIcon(vm.status)} {getStatusIcon(vm.status)}
{vm.status.toUpperCase()} {vm.status.toUpperCase()}
</Badge> </Badge>
</div> </div>
</div>
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6"> <div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6">
<div> <div>
@@ -376,7 +411,7 @@ export function VirtualMachines() {
<Progress value={Number.parseFloat(memPercent)} className="h-2 [&>div]:bg-blue-500" /> <Progress value={Number.parseFloat(memPercent)} className="h-2 [&>div]:bg-blue-500" />
</div> </div>
<div> <div className="hidden md:block">
<div className="text-sm text-muted-foreground mb-2">Disk I/O</div> <div className="text-sm text-muted-foreground mb-2">Disk I/O</div>
<div className="text-sm font-semibold text-foreground"> <div className="text-sm font-semibold text-foreground">
<div className="flex items-center gap-1"> <div className="flex items-center gap-1">
@@ -390,7 +425,7 @@ export function VirtualMachines() {
</div> </div>
</div> </div>
<div> <div className="hidden md:block">
<div className="text-sm text-muted-foreground mb-2">Network I/O</div> <div className="text-sm text-muted-foreground mb-2">Network I/O</div>
<div className="text-sm font-semibold text-foreground"> <div className="text-sm font-semibold text-foreground">
<div className="flex items-center gap-1"> <div className="flex items-center gap-1">
@@ -427,15 +462,17 @@ export function VirtualMachines() {
> >
<DialogContent className="max-w-4xl max-h-[95vh] overflow-y-auto"> <DialogContent className="max-w-4xl max-h-[95vh] overflow-y-auto">
<DialogHeader className="pb-4 border-b border-border"> <DialogHeader className="pb-4 border-b border-border">
<DialogTitle className="flex items-center gap-2 flex-wrap"> <DialogTitle className="flex flex-col sm:flex-row sm:items-center gap-3">
<Server className="h-5 w-5" />
<span className="text-lg">{selectedVM?.name}</span>
{selectedVM && (
<div className="flex items-center gap-2"> <div className="flex items-center gap-2">
<Badge variant="outline" className={getTypeBadge(selectedVM.type).color}> <Server className="h-5 w-5 flex-shrink-0" />
<span className="text-lg truncate">{selectedVM?.name}</span>
</div>
{selectedVM && (
<div className="flex items-center gap-2 flex-wrap">
<Badge variant="outline" className={`${getTypeBadge(selectedVM.type).color} flex-shrink-0`}>
{getTypeBadge(selectedVM.type).label} {getTypeBadge(selectedVM.type).label}
</Badge> </Badge>
<Badge variant="outline" className={getStatusColor(selectedVM.status)}> <Badge variant="outline" className={`${getStatusColor(selectedVM.status)} flex-shrink-0`}>
{selectedVM.status.toUpperCase()} {selectedVM.status.toUpperCase()}
</Badge> </Badge>
</div> </div>
@@ -446,7 +483,6 @@ export function VirtualMachines() {
<div className="space-y-6 py-4"> <div className="space-y-6 py-4">
{selectedVM && ( {selectedVM && (
<> <>
{/* Basic Information */}
<div> <div>
<h3 className="text-sm font-semibold text-muted-foreground mb-3 uppercase tracking-wide"> <h3 className="text-sm font-semibold text-muted-foreground mb-3 uppercase tracking-wide">
Basic Information Basic Information
@@ -456,22 +492,10 @@ export function VirtualMachines() {
<div className="text-xs text-muted-foreground mb-1">Name</div> <div className="text-xs text-muted-foreground mb-1">Name</div>
<div className="font-semibold text-foreground">{selectedVM.name}</div> <div className="font-semibold text-foreground">{selectedVM.name}</div>
</div> </div>
<div>
<div className="text-xs text-muted-foreground mb-1">Type</div>
<Badge variant="outline" className={getTypeBadge(selectedVM.type).color}>
{getTypeBadge(selectedVM.type).label}
</Badge>
</div>
<div> <div>
<div className="text-xs text-muted-foreground mb-1">VMID</div> <div className="text-xs text-muted-foreground mb-1">VMID</div>
<div className="font-semibold text-foreground">{selectedVM.vmid}</div> <div className="font-semibold text-foreground">{selectedVM.vmid}</div>
</div> </div>
<div>
<div className="text-xs text-muted-foreground mb-1">Status</div>
<Badge variant="outline" className={getStatusColor(selectedVM.status)}>
{selectedVM.status.toUpperCase()}
</Badge>
</div>
<div> <div>
<div className="text-xs text-muted-foreground mb-1">CPU Usage</div> <div className="text-xs text-muted-foreground mb-1">CPU Usage</div>
<div <div
@@ -510,6 +534,28 @@ export function VirtualMachines() {
<div className="text-xs text-muted-foreground mb-1">Uptime</div> <div className="text-xs text-muted-foreground mb-1">Uptime</div>
<div className="font-semibold text-foreground">{formatUptime(selectedVM.uptime)}</div> <div className="font-semibold text-foreground">{formatUptime(selectedVM.uptime)}</div>
</div> </div>
<div>
<div className="text-xs text-muted-foreground mb-1">Disk I/O</div>
<div className="text-sm font-semibold">
<div className="flex items-center gap-1">
<span className="text-green-500"> {formatBytes(selectedVM.diskread)}</span>
</div>
<div className="flex items-center gap-1">
<span className="text-blue-500"> {formatBytes(selectedVM.diskwrite)}</span>
</div>
</div>
</div>
<div>
<div className="text-xs text-muted-foreground mb-1">Network I/O</div>
<div className="text-sm font-semibold">
<div className="flex items-center gap-1">
<span className="text-green-500"> {formatBytes(selectedVM.netin)}</span>
</div>
<div className="flex items-center gap-1">
<span className="text-blue-500"> {formatBytes(selectedVM.netout)}</span>
</div>
</div>
</div>
</div> </div>
</div> </div>