Update AppImage

This commit is contained in:
MacRimi
2025-10-04 19:58:12 +02:00
parent 79525284b1
commit 98c5c5827c
2 changed files with 118 additions and 234 deletions

View File

@@ -8,8 +8,7 @@ import { Wifi, Globe, Shield, Activity, Network, Router, AlertCircle, Zap } from
import useSWR from "swr"
interface NetworkData {
physical_interfaces?: NetworkInterface[]
bridge_interfaces?: NetworkInterface[]
interfaces: NetworkInterface[]
vm_lxc_interfaces?: NetworkInterface[]
traffic: {
bytes_sent: number
@@ -18,11 +17,11 @@ interface NetworkData {
packets_recv?: number
packet_loss_in?: number
packet_loss_out?: number
dropin?: number
dropout?: number
}
physical_active_count?: number
physical_total_count?: number
bridge_active_count?: number
bridge_total_count?: number
active_count?: number
total_count?: number
vm_lxc_active_count?: number
vm_lxc_total_count?: number
}
@@ -69,6 +68,10 @@ const getInterfaceTypeBadge = (type: string) => {
return { color: "bg-purple-500/10 text-purple-500 border-purple-500/20", label: "Bond" }
case "vlan":
return { color: "bg-cyan-500/10 text-cyan-500 border-cyan-500/20", label: "VLAN" }
case "vm_lxc":
return { color: "bg-orange-500/10 text-orange-500 border-orange-500/20", label: "Virtual" }
case "virtual":
return { color: "bg-orange-500/10 text-orange-500 border-orange-500/20", label: "Virtual" }
default:
return { color: "bg-gray-500/10 text-gray-500 border-gray-500/20", label: "Unknown" }
}
@@ -98,10 +101,7 @@ const formatSpeed = (speed: number): string => {
}
const fetcher = async (url: string): Promise<NetworkData> => {
const baseUrl = typeof window !== "undefined" ? `${window.location.protocol}//${window.location.hostname}:8008` : ""
const fullUrl = `${baseUrl}${url}`
const response = await fetch(fullUrl, {
const response = await fetch(url, {
method: "GET",
headers: {
"Content-Type": "application/json",
@@ -122,7 +122,7 @@ export function NetworkMetrics() {
error,
isLoading,
} = useSWR<NetworkData>("/api/network", fetcher, {
refreshInterval: 30000,
refreshInterval: 30000, // Refresh every 30 seconds
revalidateOnFocus: false,
revalidateOnReconnect: true,
})
@@ -164,10 +164,6 @@ export function NetworkMetrics() {
const trafficOutGB = (networkData.traffic.bytes_sent / 1024 ** 3).toFixed(2)
const packetsRecvK = networkData.traffic.packets_recv ? (networkData.traffic.packets_recv / 1000).toFixed(0) : "0"
const physicalInterfaces = networkData.physical_interfaces || []
const bridgeInterfaces = networkData.bridge_interfaces || []
const vmLxcInterfaces = networkData.vm_lxc_interfaces || []
return (
<div className="space-y-6">
{/* Network Overview Cards */}
@@ -193,23 +189,13 @@ export function NetworkMetrics() {
<Network className="h-4 w-4 text-muted-foreground" />
</CardHeader>
<CardContent>
<div className="text-2xl font-bold text-foreground">
{(networkData.physical_active_count ?? 0) + (networkData.bridge_active_count ?? 0)}
</div>
<div className="flex flex-col gap-1 mt-2">
<div className="flex items-center justify-between text-xs">
<span className="text-muted-foreground">Physical:</span>
<Badge variant="outline" className="bg-blue-500/10 text-blue-500 border-blue-500/20">
{networkData.physical_active_count ?? 0}/{networkData.physical_total_count ?? 0}
</Badge>
</div>
<div className="flex items-center justify-between text-xs">
<span className="text-muted-foreground">Bridges:</span>
<Badge variant="outline" className="bg-green-500/10 text-green-500 border-green-500/20">
{networkData.bridge_active_count ?? 0}/{networkData.bridge_total_count ?? 0}
</Badge>
</div>
<div className="text-2xl font-bold text-foreground">{networkData.active_count ?? 0}</div>
<div className="flex items-center mt-2">
<Badge variant="outline" className="bg-green-500/10 text-green-500 border-green-500/20">
Online
</Badge>
</div>
<p className="text-xs text-muted-foreground mt-2">{networkData.total_count ?? 0} total interfaces</p>
</CardContent>
</Card>
@@ -251,250 +237,163 @@ export function NetworkMetrics() {
</Card>
</div>
{/* Physical Interfaces */}
{physicalInterfaces.length > 0 && (
<Card className="bg-card border-border">
<CardHeader>
<CardTitle className="text-foreground flex items-center">
<Router className="h-5 w-5 mr-2" />
Physical Interfaces
<Badge variant="outline" className="ml-3 bg-blue-500/10 text-blue-500 border-blue-500/20">
{networkData.physical_active_count ?? 0}/{networkData.physical_total_count ?? 0} Active
</Badge>
</CardTitle>
</CardHeader>
<CardContent>
<div className="space-y-4">
{physicalInterfaces.map((iface, index) => {
const typeBadge = getInterfaceTypeBadge(iface.type)
{/* Network Interfaces */}
<Card className="bg-card border-border">
<CardHeader>
<CardTitle className="text-foreground flex items-center">
<Router className="h-5 w-5 mr-2" />
Network Interfaces
</CardTitle>
</CardHeader>
<CardContent>
<div className="space-y-4">
{networkData.interfaces.map((interface_, index) => {
const typeBadge = getInterfaceTypeBadge(interface_.type)
return (
<div
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"
onClick={() => setSelectedInterface(iface)}
>
<div className="flex items-center gap-3 flex-wrap">
<Wifi className="h-5 w-5 text-muted-foreground flex-shrink-0" />
<div className="flex items-center gap-2 min-w-0">
<div className="font-medium text-foreground">{iface.name}</div>
<Badge variant="outline" className={typeBadge.color}>
{typeBadge.label}
</Badge>
</div>
<Badge
variant="outline"
className={
iface.status === "up"
? "bg-green-500/10 text-green-500 border-green-500/20 ml-auto"
: "bg-red-500/10 text-red-500 border-red-500/20 ml-auto"
}
>
{iface.status.toUpperCase()}
return (
<div
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"
onClick={() => setSelectedInterface(interface_)}
>
{/* First row: Icon, Name, Type Badge, Status */}
<div className="flex items-center gap-3 flex-wrap">
<Wifi className="h-5 w-5 text-muted-foreground flex-shrink-0" />
<div className="flex items-center gap-2 min-w-0">
<div className="font-medium text-foreground">{interface_.name}</div>
<Badge variant="outline" className={typeBadge.color}>
{typeBadge.label}
</Badge>
</div>
<div className="grid grid-cols-2 md:grid-cols-4 gap-4 text-sm">
<div>
<div className="text-muted-foreground text-xs">IP Address</div>
<div className="font-medium text-foreground font-mono text-sm truncate">
{iface.addresses.length > 0 ? iface.addresses[0].ip : "N/A"}
</div>
</div>
<div>
<div className="text-muted-foreground text-xs">Speed</div>
<div className="font-medium text-foreground flex items-center gap-1">
<Zap className="h-3 w-3" />
{formatSpeed(iface.speed)}
</div>
</div>
<div className="col-span-2 md:col-span-1">
<div className="text-muted-foreground text-xs">Traffic</div>
<div className="font-medium text-foreground text-xs">
<span className="text-green-500"> {formatBytes(iface.bytes_recv)}</span>
{" / "}
<span className="text-blue-500"> {formatBytes(iface.bytes_sent)}</span>
</div>
</div>
{iface.mac_address && (
<div className="col-span-2 md:col-span-1">
<div className="text-muted-foreground text-xs">MAC</div>
<div className="font-medium text-foreground font-mono text-xs truncate">
{iface.mac_address}
</div>
</div>
)}
</div>
<Badge
variant="outline"
className={
interface_.status === "up"
? "bg-green-500/10 text-green-500 border-green-500/20 ml-auto"
: "bg-red-500/10 text-red-500 border-red-500/20 ml-auto"
}
>
{interface_.status.toUpperCase()}
</Badge>
</div>
)
})}
</div>
</CardContent>
</Card>
)}
{/* Bridge Interfaces */}
{bridgeInterfaces.length > 0 && (
<Card className="bg-card border-border">
<CardHeader>
<CardTitle className="text-foreground flex items-center">
<Network className="h-5 w-5 mr-2" />
Bridge Interfaces
<Badge variant="outline" className="ml-3 bg-green-500/10 text-green-500 border-green-500/20">
{networkData.bridge_active_count ?? 0}/{networkData.bridge_total_count ?? 0} Active
</Badge>
</CardTitle>
</CardHeader>
<CardContent>
<div className="space-y-4">
{bridgeInterfaces.map((iface, index) => {
const typeBadge = getInterfaceTypeBadge(iface.type)
return (
<div
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"
onClick={() => setSelectedInterface(iface)}
>
<div className="flex items-center gap-3 flex-wrap">
<Wifi className="h-5 w-5 text-muted-foreground flex-shrink-0" />
<div className="flex items-center gap-2 min-w-0">
<div className="font-medium text-foreground">{iface.name}</div>
<Badge variant="outline" className={typeBadge.color}>
{typeBadge.label}
</Badge>
{/* Second row: Details - Responsive layout */}
<div className="grid grid-cols-2 md:grid-cols-4 gap-4 text-sm">
<div>
<div className="text-muted-foreground text-xs">IP Address</div>
<div className="font-medium text-foreground font-mono text-sm truncate">
{interface_.addresses.length > 0 ? interface_.addresses[0].ip : "N/A"}
</div>
<Badge
variant="outline"
className={
iface.status === "up"
? "bg-green-500/10 text-green-500 border-green-500/20 ml-auto"
: "bg-red-500/10 text-red-500 border-red-500/20 ml-auto"
}
>
{iface.status.toUpperCase()}
</Badge>
</div>
<div className="grid grid-cols-2 md:grid-cols-4 gap-4 text-sm">
<div>
<div className="text-muted-foreground text-xs">IP Address</div>
<div className="font-medium text-foreground font-mono text-sm truncate">
{iface.addresses.length > 0 ? iface.addresses[0].ip : "N/A"}
</div>
<div>
<div className="text-muted-foreground text-xs">Speed</div>
<div className="font-medium text-foreground flex items-center gap-1">
<Zap className="h-3 w-3" />
{formatSpeed(interface_.speed)}
</div>
</div>
<div>
<div className="text-muted-foreground text-xs">Speed</div>
<div className="font-medium text-foreground flex items-center gap-1">
<Zap className="h-3 w-3" />
{formatSpeed(iface.speed)}
</div>
<div className="col-span-2 md:col-span-1">
<div className="text-muted-foreground text-xs">Traffic</div>
<div className="font-medium text-foreground text-xs">
<span className="text-green-500"> {formatBytes(interface_.bytes_recv)}</span>
{" / "}
<span className="text-blue-500"> {formatBytes(interface_.bytes_sent)}</span>
</div>
</div>
{interface_.mac_address && (
<div className="col-span-2 md:col-span-1">
<div className="text-muted-foreground text-xs">Traffic</div>
<div className="font-medium text-foreground text-xs">
<span className="text-green-500"> {formatBytes(iface.bytes_recv)}</span>
{" / "}
<span className="text-blue-500"> {formatBytes(iface.bytes_sent)}</span>
<div className="text-muted-foreground text-xs">MAC</div>
<div className="font-medium text-foreground font-mono text-xs truncate">
{interface_.mac_address}
</div>
</div>
{iface.mac_address && (
<div className="col-span-2 md:col-span-1">
<div className="text-muted-foreground text-xs">MAC</div>
<div className="font-medium text-foreground font-mono text-xs truncate">
{iface.mac_address}
</div>
</div>
)}
</div>
)}
</div>
)
})}
</div>
</CardContent>
</Card>
)}
</div>
)
})}
</div>
</CardContent>
</Card>
{/* VM & LXC Network Interfaces */}
{vmLxcInterfaces.length > 0 && (
{networkData.vm_lxc_interfaces && networkData.vm_lxc_interfaces.length > 0 && (
<Card className="bg-card border-border">
<CardHeader>
<CardTitle className="text-foreground flex items-center">
<Network className="h-5 w-5 mr-2" />
VM & LXC Network Interfaces
<Badge variant="outline" className="ml-3 bg-orange-500/10 text-orange-500 border-orange-500/20">
{networkData.vm_lxc_active_count ?? 0}/{networkData.vm_lxc_total_count ?? 0} Active
{networkData.vm_lxc_active_count ?? 0} / {networkData.vm_lxc_total_count ?? 0} Active
</Badge>
</CardTitle>
</CardHeader>
<CardContent>
<div className="space-y-4">
{vmLxcInterfaces.map((iface, index) => {
const vmTypeBadge = getVMTypeBadge(iface.vm_type)
{networkData.vm_lxc_interfaces.map((interface_, index) => {
const vmTypeBadge = getVMTypeBadge(interface_.vm_type)
return (
<div
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"
onClick={() => setSelectedInterface(iface)}
onClick={() => setSelectedInterface(interface_)}
>
{/* First row: Icon, Name, VM/LXC Badge, VM Name, Status */}
<div className="flex items-center gap-3 flex-wrap">
<Wifi className="h-5 w-5 text-muted-foreground flex-shrink-0" />
<div className="flex items-center gap-2 min-w-0 flex-1">
<div className="font-medium text-foreground">{iface.name}</div>
<div className="font-medium text-foreground">{interface_.name}</div>
<Badge variant="outline" className={vmTypeBadge.color}>
{vmTypeBadge.label}
</Badge>
{iface.vm_name && (
<div className="text-sm text-muted-foreground truncate"> {iface.vm_name}</div>
{interface_.vm_name && (
<div className="text-sm text-muted-foreground truncate"> {interface_.vm_name}</div>
)}
</div>
<Badge
variant="outline"
className={
iface.status === "up"
interface_.status === "up"
? "bg-green-500/10 text-green-500 border-green-500/20"
: "bg-red-500/10 text-red-500 border-red-500/20"
}
>
{iface.status.toUpperCase()}
{interface_.status.toUpperCase()}
</Badge>
</div>
{/* Second row: Details - Responsive layout */}
<div className="grid grid-cols-2 md:grid-cols-4 gap-4 text-sm">
<div>
<div className="text-muted-foreground text-xs">VMID</div>
<div className="font-medium text-foreground">{iface.vmid ?? "N/A"}</div>
<div className="font-medium text-foreground">{interface_.vmid ?? "N/A"}</div>
</div>
<div>
<div className="text-muted-foreground text-xs">Speed</div>
<div className="font-medium text-foreground flex items-center gap-1">
<Zap className="h-3 w-3" />
{formatSpeed(iface.speed)}
{formatSpeed(interface_.speed)}
</div>
</div>
<div className="col-span-2 md:col-span-1">
<div className="text-muted-foreground text-xs">Traffic</div>
<div className="font-medium text-foreground text-xs">
<span className="text-green-500"> {formatBytes(iface.bytes_recv)}</span>
<span className="text-green-500"> {formatBytes(interface_.bytes_recv)}</span>
{" / "}
<span className="text-blue-500"> {formatBytes(iface.bytes_sent)}</span>
<span className="text-blue-500"> {formatBytes(interface_.bytes_sent)}</span>
</div>
</div>
{iface.mac_address && (
{interface_.mac_address && (
<div className="col-span-2 md:col-span-1">
<div className="text-muted-foreground text-xs">MAC</div>
<div className="font-medium text-foreground font-mono text-xs truncate">
{iface.mac_address}
{interface_.mac_address}
</div>
</div>
)}
@@ -507,7 +406,7 @@ export function NetworkMetrics() {
</Card>
)}
{/* Interface Details Dialog */}
{/* Interface Details Modal */}
<Dialog open={!!selectedInterface} onOpenChange={() => setSelectedInterface(null)}>
<DialogContent className="max-w-2xl max-h-[80vh] overflow-y-auto">
<DialogHeader>