Initial commit
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<link rel="icon" type="image/svg+xml" href="/favicon.ico" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover" />
|
||||
<meta name="description" content="Monitor and manage your Unraid server" />
|
||||
<meta name="theme-color" content="#ff8c2f" />
|
||||
<link rel="apple-touch-icon" href="/apple-touch-icon.png" />
|
||||
<title>Unraid Monitor</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
<script type="module" src="/src/main.tsx"></script>
|
||||
</body>
|
||||
</html>
|
||||
Generated
+9058
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,37 @@
|
||||
{
|
||||
"name": "unraid-monitor-frontend",
|
||||
"version": "1.0.0",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "tsc && vite build",
|
||||
"preview": "vite preview",
|
||||
"lint": "eslint . --ext ts,tsx"
|
||||
},
|
||||
"dependencies": {
|
||||
"react": "^18.2.0",
|
||||
"react-dom": "^18.2.0",
|
||||
"react-router-dom": "^6.21.1",
|
||||
"@tanstack/react-query": "^5.17.9",
|
||||
"axios": "^1.6.5",
|
||||
"zustand": "^4.4.7",
|
||||
"recharts": "^2.10.3",
|
||||
"lucide-react": "^0.307.0",
|
||||
"clsx": "^2.1.0",
|
||||
"tailwind-merge": "^2.2.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/react": "^18.2.47",
|
||||
"@types/react-dom": "^18.2.18",
|
||||
"@vitejs/plugin-react": "^4.2.1",
|
||||
"vite": "^5.0.11",
|
||||
"vite-plugin-pwa": "^0.17.4",
|
||||
"typescript": "^5.3.3",
|
||||
"autoprefixer": "^10.4.16",
|
||||
"postcss": "^8.4.33",
|
||||
"tailwindcss": "^3.4.1",
|
||||
"eslint": "^8.56.0",
|
||||
"@typescript-eslint/eslint-plugin": "^6.18.1",
|
||||
"@typescript-eslint/parser": "^6.18.1"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
export default {
|
||||
plugins: {
|
||||
tailwindcss: {},
|
||||
autoprefixer: {},
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
||||
import { useAuthStore } from "./stores/authStore";
|
||||
import { BrowserRouter, Navigate, Route, Routes } from "react-router-dom";
|
||||
import Login from "./components/Login";
|
||||
import Layout from "./components/Layout";
|
||||
import Dashboard from "./components/Dashboard";
|
||||
import Containers from "./components/Containers";
|
||||
|
||||
const queryClient = new QueryClient({
|
||||
defaultOptions: {
|
||||
queries: {
|
||||
retry: 1,
|
||||
refetchOnWindowFocus: false,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
function ProtectedRoute({ children }: { children: React.ReactNode }) {
|
||||
const isAuthenticated = useAuthStore((state) => state.isAuthenticated);
|
||||
return isAuthenticated ? <>{children}</> : <Navigate to="/login" />;
|
||||
}
|
||||
|
||||
function App() {
|
||||
return (
|
||||
<QueryClientProvider client={queryClient}>
|
||||
<BrowserRouter>
|
||||
<Routes>
|
||||
<Route path="/login" element={<Login />} />
|
||||
<Route
|
||||
path="/"
|
||||
element={
|
||||
<ProtectedRoute>
|
||||
<Layout>
|
||||
<Dashboard />
|
||||
</Layout>
|
||||
</ProtectedRoute>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path="/containers"
|
||||
element={
|
||||
<ProtectedRoute>
|
||||
<Layout>
|
||||
<Containers />
|
||||
</Layout>
|
||||
</ProtectedRoute>
|
||||
}
|
||||
/>
|
||||
<Route path="*" element={<Navigate to="/" />} />
|
||||
</Routes>
|
||||
</BrowserRouter>
|
||||
</QueryClientProvider>
|
||||
);
|
||||
}
|
||||
|
||||
export default App;
|
||||
@@ -0,0 +1,219 @@
|
||||
import { formatDate } from "../lib/utils";
|
||||
import { dockerApi } from "../lib/api";
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import { AlertCircle, Box, CheckCircle, Play, RotateCw, Square } from "lucide-react";
|
||||
import { useState } from "react";
|
||||
|
||||
export default function Containers() {
|
||||
const queryClient = useQueryClient();
|
||||
const [actionLoading, setActionLoading] = useState<string | null>(null);
|
||||
const [selectedContainer, setSelectedContainer] = useState<string | null>(null);
|
||||
|
||||
const { data: containers, isLoading, error } = useQuery({
|
||||
queryKey: ['containers'],
|
||||
queryFn: async () => {
|
||||
const response = await dockerApi.getContainers();
|
||||
return response.data;
|
||||
},
|
||||
refetchInterval: 5000,
|
||||
});
|
||||
|
||||
const startMutation = useMutation({
|
||||
mutationFn: (id: string) => dockerApi.startContainer(id),
|
||||
onMutate: (id) => setActionLoading(id),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['containers'] });
|
||||
},
|
||||
onSettled: () => setActionLoading(null),
|
||||
});
|
||||
|
||||
const stopMutation = useMutation({
|
||||
mutationFn: (id: string) => dockerApi.stopContainer(id),
|
||||
onMutate: (id) => setActionLoading(id),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['containers'] });
|
||||
},
|
||||
onSettled: () => setActionLoading(null),
|
||||
});
|
||||
|
||||
const restartMutation = useMutation({
|
||||
mutationFn: (id: string) => dockerApi.restartContainer(id),
|
||||
onMutate: (id) => setActionLoading(id),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['containers'] });
|
||||
},
|
||||
onSettled: () => setActionLoading(null),
|
||||
});
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
<div className="flex items-center justify-center h-96">
|
||||
<div className="text-gray-400">Lade Container...</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (error) {
|
||||
return (
|
||||
<div className="flex items-center justify-center h-96">
|
||||
<div className="card max-w-md">
|
||||
<div className="flex items-center gap-3 text-red-400">
|
||||
<AlertCircle size={24} />
|
||||
<div>
|
||||
<h3 className="font-semibold">Fehler beim Laden</h3>
|
||||
<p className="text-sm text-gray-400">
|
||||
Container konnten nicht geladen erden
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const runningContainers = containers?.filter((c) => c.state === 'running') || [];
|
||||
const stoppedContainers = containers?.filter((c) => c.state !== 'running') || [];
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<div>
|
||||
<h2 className="text-2xl font-bold mb-2">Docker Containers</h2>
|
||||
<p className="text-gray-400">
|
||||
{runningContainers.length} laufend · {stoppedContainers.length} gestopped
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{/* Running Containers */}
|
||||
{runningContainers.length > 0 && (
|
||||
<div className="space-y-3">
|
||||
<h3 className="text-lg font-semibold flex items-center gap-2">
|
||||
<CheckCircle className="text-green-500" size={20} />
|
||||
Laufende Container
|
||||
</h3>
|
||||
<div className="grid gap-3">
|
||||
{runningContainers.map((container) => (
|
||||
<div
|
||||
key={container.id}
|
||||
className="card hover:border-gray-700 transition-colors cursor-pointer"
|
||||
onClick={() =>
|
||||
setSelectedContainer(selectedContainer === container.id ? null : container.id)
|
||||
}
|
||||
>
|
||||
<div className="flex items-center justify-between">
|
||||
<div className="flex items-center gap-4 flex-1">
|
||||
<Box className="text-unraid-orange" size={24} />
|
||||
<div className="flex-1 min-w-0">
|
||||
<h4 className="font-semibold truncate">{container.name}</h4>
|
||||
<p className="text-sm text-gray-400 truncate">{container.image}</p>
|
||||
</div>
|
||||
<div className="hidden sm:flex items-center gap-2">
|
||||
<div className="w-2 h-2 bg-green-500" rounded-full animate-pulse />
|
||||
<span className="text-sm text-green-500">Running</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center gap-2">
|
||||
<button
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
stopMutation.mutate(container.id);
|
||||
}}
|
||||
disabled={actionLoading === container.id}
|
||||
className="btn-danger p-2"
|
||||
title="Stop"
|
||||
>
|
||||
<Square size={16} />
|
||||
</button>
|
||||
<button
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
restartMutation.mutate(container.id);
|
||||
}}
|
||||
disabled={actionLoading === container.id}
|
||||
className="btn-secondary p-2"
|
||||
title="Restart"
|
||||
>
|
||||
<RotateCw size={16} />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{selectedContainer === container.id && (
|
||||
<div className="mt-4 pt-4 border-t border-gray-800 space-y-2 text-sm">
|
||||
<div className="flex justify-between">
|
||||
<span className="text-gray-400">ID:</span>
|
||||
<span className="font-mono">{container.id}</span>
|
||||
</div>
|
||||
<div className="flex justify-between">
|
||||
<span className="text-gray-400">Status:</span>
|
||||
<span>{container.status}</span>
|
||||
</div>
|
||||
<div className="flex justify-between">
|
||||
<span className="text-gray-400">Erstellt:</span>
|
||||
<span>{formatDate(container.created)}</span>
|
||||
</div>
|
||||
{container.ports.length > 0 && (
|
||||
<div>
|
||||
<span className="text-gray-400">Ports:</span>
|
||||
<div className="mt-1 space-y-1">
|
||||
{container.ports.map((port, idx) => (
|
||||
<div key={idx} className="font-mono text-xs">
|
||||
{port.publicPort
|
||||
? `${port.publicPort} → ${port.privatePort}/${port.type}`
|
||||
: `${port.privatePort}/${port.type}`}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Stopped Containers */}
|
||||
{stoppedContainers.length > 0 && (
|
||||
<div className="space-y-3">
|
||||
<h3 className="text-lg font-semibold flex items-center gap-2">
|
||||
<AlertCircle className="text-gray-500" size={20} />
|
||||
Gestoppte Container
|
||||
</h3>
|
||||
<div className="grid gap-3">
|
||||
{stoppedContainers.map((container) => (
|
||||
<div
|
||||
key={container.id}
|
||||
className="card hover:border-gray-700 transition-colors opacity-75"
|
||||
>
|
||||
<div className="flex items-center justify-between">
|
||||
<div className="flex items-center gap-4 flex-1">
|
||||
<Box className="text-gray-600" size={24} />
|
||||
<div className="flex-1 min-w-0">
|
||||
<h4 className="font-semibold truncate">{container.name}</h4>
|
||||
<p className="text-sm text-gray-400 truncate">{container.image}</p>
|
||||
</div>
|
||||
<div className="hidden sm:flex items-center gap-2">
|
||||
<div className="w-2 h-2 bg-gray-600 rounded-full" />
|
||||
<span className="text-sm text-gray-500">Stopped</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button
|
||||
onClick={() => startMutation.mutate(container.id)}
|
||||
disabled={actionLoading === container.id}
|
||||
className="btn-primary p-2"
|
||||
title="Start"
|
||||
>
|
||||
<Play size={16} />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,210 @@
|
||||
import { dockerApi, systemApi } from "../lib/api";
|
||||
import { formatBytes, formatUptime } from "../lib/utils";
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { Activity, AlertCircle, Cpu, HardDrive, Server } from "lucide-react";
|
||||
|
||||
export default function Dashboard() {
|
||||
const { data: stats, isLoading: statsLoading, error: statsError } = useQuery({
|
||||
queryKey: ['systemStats'],
|
||||
queryFn: async () => {
|
||||
const response = await systemApi.getStats();
|
||||
return response.data;
|
||||
},
|
||||
refetchInterval: 5000, //Update alle 5 Sekunden
|
||||
});
|
||||
|
||||
const { data: containers, isLoading: containersLoading } = useQuery({
|
||||
queryKey: ['containers'],
|
||||
queryFn: async () => {
|
||||
const response = await dockerApi.getContainers();
|
||||
return response.data;
|
||||
},
|
||||
refetchInterval: 10000, //Update all 10 Sekunden
|
||||
});
|
||||
|
||||
if (statsLoading) {
|
||||
return (
|
||||
<div className="flex items-center justify-center h-96">
|
||||
<div className="text-gray-400">Lade System-Statistiken...</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (statsError) {
|
||||
return (
|
||||
<div className="flex items-center justify-center h-96">
|
||||
<div className="card max-w-md">
|
||||
<div className="flex items-center gap-3 text-red-400">
|
||||
<AlertCircle size={24} />
|
||||
<div>
|
||||
<h3 className="font-semibold">Fehler beim Laden</h3>
|
||||
<p className="text-sm text-gray-400">
|
||||
System-Statistiken konnten nicht geladen werden
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const runningContainers = containers?.filter((c) => c.state === 'running').length || 0;
|
||||
const totalContainers = containers?.length || 0;
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<div>
|
||||
<h2 className="text-2xl font-bold mb-2">Dashboard</h2>
|
||||
<p className="text-gray-400">Übersicht über deinen Unraid-Server</p>
|
||||
</div>
|
||||
|
||||
{/* System Stats Grid */}
|
||||
<div className="grid grind-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4">
|
||||
{/* CPU */}
|
||||
<div className="card">
|
||||
<div className="flex items-center justify-between mb-3">
|
||||
<div className="flex items-center gap-2">
|
||||
<Cpu className="text-unraid-orange" size={20} />
|
||||
<h3 className="font-semibold">CPU</h3>
|
||||
</div>
|
||||
<span className="text-2xl font-bold">{stats?.cpu.usage.toFixed(1)}%</span>
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<div className="w-full bg-gray-800 rounded-full h-2">
|
||||
<div className="bg-unraid-orange h-2 rounded-full transition-all duration-300" style={{ width: `${stats?.cpu.usage}%` }}></div>
|
||||
</div>
|
||||
<div className="text-xs text-gray-400 flex justify-between">
|
||||
<span>{stats?.cpu.model}</span>
|
||||
{stats?.cpu.temp && <span>{stats.cpu.temp}°C</span>}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Memory */}
|
||||
<div className="card">
|
||||
<div className="flex items-center justify-between mb-3">
|
||||
<div className="flex items-center gap-2">
|
||||
<Activity className="text-blue-400" size={20} />
|
||||
<h3 className="font-semibold">RAM</h3>
|
||||
</div>
|
||||
<span className="text-2xl font-bold">{stats?.memory.percentage.toFixed(1)}%</span>
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<div className="w-full bg-gray-800 rounded-full h-2">
|
||||
<div
|
||||
className="bg-blue-400 h-2 rounded-full transition-all duration-300"
|
||||
style={{ width: `${stats?.memory.percentage}%` }}
|
||||
/>
|
||||
</div>
|
||||
<div className="text-xs text-gray-400">
|
||||
{formatBytes(stats?.memory.used || 0)} / {formatBytes(stats?.memory.total || 0)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Disk */}
|
||||
<div className="card">
|
||||
<div className="flex items-center justify-between mb-3">
|
||||
<div className="flex items-center gap-2">
|
||||
<HardDrive className="text-green-400" size={20} />
|
||||
<h3 className="font-semibold">Disk</h3>
|
||||
</div>
|
||||
<span className="text-2xl font-bold">
|
||||
{stats?.disk[0]?.percentage.toFixed(1)}%
|
||||
</span>
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<div className="w-full bg-gray-800 rounded-full h-2">
|
||||
<div
|
||||
className="bg-green-400 h-2 rounded-full transition-all duration-300"
|
||||
style={{ width: `${stats?.disk[0]?.percentage}%` }}
|
||||
/>
|
||||
</div>
|
||||
<div className="text-xs text-gray-400">
|
||||
{formatBytes(stats?.disk[0]?.used || 0)} / {formatBytes(stats?.disk[0]?.size || 0)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Uptime & Containers */}
|
||||
<div className="card">
|
||||
<div className="flex items-center gap-2 mb-3">
|
||||
<Server className="text-purple-400" size={20} />
|
||||
<h3 className="font-semibold">System</h3>
|
||||
</div>
|
||||
<div className="space-y-3">
|
||||
<div>
|
||||
<div className="text-xs text-gray-400 mb-1">Uptime</div>
|
||||
<div className="text-lg font-semibold">
|
||||
{formatUptime(stats?.uptime || 0)}
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<div className="text-xs text-gray-400 mb-1">Container</div>
|
||||
<div className="text-lg font-semibold">
|
||||
{runningContainers} / {totalContainers}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Disk Details */}
|
||||
{stats?.disk && stats.disk.length > 0 && (
|
||||
<div className="card">
|
||||
<h3 className="text-lg font-semibold mb-4">Festplatten</h3>
|
||||
<div className="space-y-4">
|
||||
{stats.disk.map((disk, index) => (
|
||||
<div key={index} className="space-y-2">
|
||||
<div className="flex items-center justify-between text-sm">
|
||||
<span className="text-gray-400">{disk.mountpoint}</span>
|
||||
<span className="font-semibold">{disk.percentage.toFixed(1)}%</span>
|
||||
</div>
|
||||
<div className="w-full bg-gray-800 rounded-full h-2">
|
||||
<div
|
||||
className={`h-2 rounded-full transition-all duration-300 ${
|
||||
disk.percentage > 90
|
||||
? 'bg-red-500'
|
||||
: disk.percentage > 75
|
||||
? 'bg-yellow-500'
|
||||
: 'bg-green-500'
|
||||
}`}
|
||||
style={{ width: `${disk.percentage}%` }}
|
||||
/>
|
||||
</div>
|
||||
<div className="flex justify-between text-xs text-gray-400">
|
||||
<span>{disk.device}</span>
|
||||
<span>
|
||||
{formatBytes(disk.used)} / {formatBytes(disk.size)}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Quick Container Overview */}
|
||||
{!containersLoading && containers && (
|
||||
<div className="card">
|
||||
<h3 className="text-lg font-semibold mb-4">Container-Übersicht</h3>
|
||||
<div className="grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 gap-3">
|
||||
{containers.slice(0, 8).map((container) => (
|
||||
<div
|
||||
key={container.id}
|
||||
className="bg-gray-800 rounded-lg p-3 flex items-center gap-2"
|
||||
>
|
||||
<div
|
||||
className={`w-2 h-2 rounded-full ${
|
||||
container.state === 'running' ? 'bg-green-500' : 'bg-gray-600'
|
||||
}`}
|
||||
/>
|
||||
<span className="text-sm truncate">{container.name}</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
import { useAuthStore } from "../stores/authStore";
|
||||
import { Box, Home, LogOut, Server } from "lucide-react";
|
||||
import { ReactNode } from "react";
|
||||
import { NavLink, useNavigate } from "react-router-dom";
|
||||
|
||||
interface LayoutProps {
|
||||
children: ReactNode;
|
||||
}
|
||||
|
||||
export default function Layout({ children }: LayoutProps) {
|
||||
const { user, logout } = useAuthStore();
|
||||
const navigate = useNavigate();
|
||||
|
||||
const handleLogout = () => {
|
||||
logout();
|
||||
navigate('/login');
|
||||
};
|
||||
|
||||
const navItems = [
|
||||
{ to: '/', icon: Home, label: 'Dashboard' },
|
||||
{ to: '/containers', icon: Box, label: 'Container' },
|
||||
];
|
||||
|
||||
return (
|
||||
<div className="min-h-screen bg-gray-950">
|
||||
{/* Header */}
|
||||
<header className="bg-gray-900 border-b border-gray-800 sticky top-0 z-50">
|
||||
<div className="max-2-7xl mx-auto px-4 py-4">
|
||||
<div className="flex items-center justify-between">
|
||||
<div className="flex items-center gap-3">
|
||||
<div className="bg-unraid-orange p-2 rounded-lg">
|
||||
<Server size={24} />
|
||||
</div>
|
||||
<h1 className="text-xl font-bold">Unraid Monitor</h1>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center gap-4">
|
||||
<span className="text-sm text-gray-400">{user?.username}</span>
|
||||
<button
|
||||
onClick={handleLogout}
|
||||
className="flex items-center gap-2 text-gray-400 hover:text-white transition-colors"
|
||||
>
|
||||
<LogOut size={20} />
|
||||
<span className="hidden sm:inline">Abmelden</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
{/* Mobile Navigation */}
|
||||
<nav className="md:hidden bg-gray-900 border-b border-gray-800 sticky top-[73px] z-40">
|
||||
<div className="flex">
|
||||
{navItems.map((item) => (
|
||||
<NavLink
|
||||
key={item.to}
|
||||
to={item.to}
|
||||
className={({isActive}) =>
|
||||
`flex-1 flex flex-col items-center gap-1 py-3 transition-colors ${
|
||||
isActive
|
||||
? 'text-unraid-orange border-b-2 border-unraid-orange'
|
||||
: 'text-gray-400 hover:text-white'
|
||||
}`
|
||||
}
|
||||
>
|
||||
<item.icon size={20} />
|
||||
<span className="text-xs">{item.label}</span>
|
||||
</NavLink>
|
||||
))}
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<div className="flex">
|
||||
{/* Desktop Sidebar */}
|
||||
<aside className="hidden md:block w-64 bg-gray-900 min-h-[calc(100vh-73px)] border-r border-gray-800 sticky top-[73px]">
|
||||
<nav className="p-4 space-y-2">
|
||||
{navItems.map((item) => (
|
||||
<NavLink
|
||||
key={item.to}
|
||||
to={item.to}
|
||||
className={({isActive}) =>
|
||||
`flex items-center gap-3 px-4 py-3 rounded-lg transition-colors ${
|
||||
isActive
|
||||
? 'bg-unraid-orange text-white'
|
||||
: 'text-gray-400 hover:bg-gray-800 hover:text-white'
|
||||
}`
|
||||
}
|
||||
>
|
||||
<item.icon size={20} />
|
||||
<span>{item.label}</span>
|
||||
</NavLink>
|
||||
))}
|
||||
</nav>
|
||||
</aside>
|
||||
|
||||
{/* Main Content */}
|
||||
<main className="flex-1 p-4 md:p-6 max-w-7xl mx-auto w-full">
|
||||
{children}
|
||||
</main>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
import { authApi } from "../lib/api";
|
||||
import { useAuthStore } from "../stores/authStore";
|
||||
import { Server } from "lucide-react";
|
||||
import { useState } from "react";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
|
||||
export default function Login() {
|
||||
const [username, setUsername] = useState('');
|
||||
const [password, setPassword] = useState('');
|
||||
const [error, setError] = useState('');
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
const login = useAuthStore((state) => state.login);
|
||||
const navigate = useNavigate();
|
||||
|
||||
const handleSubmit = async (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
setError('');
|
||||
setLoading(true);
|
||||
|
||||
try {
|
||||
const response = await authApi.login({ username, password });
|
||||
login(response.data.token, response.data.user);
|
||||
navigate('/');
|
||||
} catch (err: any) {
|
||||
setError(err.response?.data?.error || 'Login fehlgeschlagen');
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="min-h-screen flex items-center justify-center bg-gradient-to-br from-gray-950 via gray-900 to-unraid-dark">
|
||||
<div className="card max-w-md w-full mx-4">
|
||||
<div className="flex flex-col items-center mb-8">
|
||||
<div className="bg-unraid-orange p-4 rounded-full mb-4">
|
||||
<Server size={48} />
|
||||
</div>
|
||||
<h1 className="text-3xl font-bold">Unraid Monitor</h1>
|
||||
<p className="text-gray-400 mt-2">Melde dich an um fortzufahren</p>
|
||||
</div>
|
||||
|
||||
<form onSubmit={handleSubmit} className="space-y-4">
|
||||
{error && (
|
||||
<div className="bg-red-900/50 border border-red-700 text-red-200 px-4 py-3 rounded-lg">
|
||||
{error}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div>
|
||||
<label htmlFor="username" className="block text-sm font-medium mb-2">Benutzername</label>
|
||||
<input
|
||||
id="username"
|
||||
type="text"
|
||||
className="input w-full"
|
||||
value={username}
|
||||
onChange={(e) => setUsername(e.target.value)}
|
||||
required
|
||||
autoComplete="username"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label htmlFor="password" className="block text-sm font-medium mb-2">Passwort</label>
|
||||
<input
|
||||
id="password"
|
||||
type="password"
|
||||
className="input w-full"
|
||||
value={password}
|
||||
onChange={(e) => setPassword(e.target.value)}
|
||||
required
|
||||
autoComplete="current-password"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<button
|
||||
type="submit"
|
||||
className="btn-primary w-full"
|
||||
disabled={loading}
|
||||
>
|
||||
{loading ? 'Anmelden...' : 'Anmelden'}
|
||||
</button>
|
||||
</form>
|
||||
|
||||
<div className="mt-6 text-center text-sm text-gray-400">
|
||||
<p>Standard-Login: admin / admin</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
@tailwind base;
|
||||
@tailwind components;
|
||||
@tailwind utilities;
|
||||
|
||||
@layer base {
|
||||
body {
|
||||
@apply bg-gray-950 text-white;
|
||||
}
|
||||
}
|
||||
|
||||
@layer components {
|
||||
.card {
|
||||
@apply bg-gray-900 rounded-lg p-4 shadow-lg border border-gray-800;
|
||||
}
|
||||
|
||||
.btn-primary {
|
||||
@apply bg-unraid-orange hover:bg-unraid-orange-dark text-white font-semibold py-2 px-4 rounded-lg transition-colors;
|
||||
}
|
||||
|
||||
.btn-secondary {
|
||||
@apply bg-gray-800 hover:bg-gray-700 text-white font-semibold py-2 px-4 rounded-lg transition-colors;
|
||||
}
|
||||
|
||||
.btn-danger {
|
||||
@apply bg-red-600 hover:bg-red-700 text-white font-semibold py-2 px-4 rounded-lg transition-colors;
|
||||
}
|
||||
|
||||
.input {
|
||||
@apply bg-gray-800 border border-gray-700 text-white rounded-lg px-4 py-2 focus:outline-none focus:ring-2 focus:ring-unraid-orange;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
import { useAuthStore } from "../stores/authStore";
|
||||
import axios from "axios";
|
||||
|
||||
|
||||
const API_BASE_URL = import.meta.env.VITE_API_URL || '/api';
|
||||
|
||||
const api = axios.create({
|
||||
baseURL: API_BASE_URL,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
});
|
||||
|
||||
api.interceptors.request.use((config) => {
|
||||
const token = useAuthStore.getState().token;
|
||||
if (token) {
|
||||
config.headers.Authorization = `Bearer ${token}`;
|
||||
}
|
||||
return config;
|
||||
});
|
||||
|
||||
api.interceptors.response.use(
|
||||
(response) => response,
|
||||
(error) => {
|
||||
if (error.response?.status === 401) {
|
||||
useAuthStore.getState().logout();
|
||||
}
|
||||
return Promise.reject(error);
|
||||
}
|
||||
);
|
||||
|
||||
export interface SystemStats {
|
||||
cpu: {
|
||||
usage: number;
|
||||
temp: number | null;
|
||||
model: string;
|
||||
};
|
||||
memory: {
|
||||
total: number;
|
||||
used: number;
|
||||
free: number;
|
||||
percentage: number;
|
||||
};
|
||||
disk: Array<{
|
||||
device: string;
|
||||
mountpoint: string;
|
||||
size: number;
|
||||
used: number;
|
||||
available: number;
|
||||
percentage: number;
|
||||
}>;
|
||||
uptime: number;
|
||||
hostname: string;
|
||||
}
|
||||
|
||||
export interface DockerContainer {
|
||||
id: string;
|
||||
name: string;
|
||||
image: string;
|
||||
state: string;
|
||||
status: string;
|
||||
created: number;
|
||||
ports: Array<{
|
||||
privatePort: number;
|
||||
publicPort?: number;
|
||||
type: string;
|
||||
}>;
|
||||
}
|
||||
|
||||
export interface LoginCredentials {
|
||||
username: string;
|
||||
password: string;
|
||||
}
|
||||
|
||||
export interface LoginResponse {
|
||||
token: string;
|
||||
user: {
|
||||
id: string;
|
||||
username: string;
|
||||
};
|
||||
}
|
||||
|
||||
export const authApi = {
|
||||
login: (credentials: LoginCredentials) =>
|
||||
api.post<LoginResponse>('/auth/login', credentials),
|
||||
register: (credentials: LoginCredentials) =>
|
||||
api.post<LoginResponse>('/auth/register', credentials),
|
||||
me: () => api.get('/auth/me'),
|
||||
};
|
||||
|
||||
export const systemApi = {
|
||||
getStats: () => api.get<SystemStats>('/system/stats'),
|
||||
getUptime: () => api.get('/system/uptime'),
|
||||
};
|
||||
|
||||
export const dockerApi = {
|
||||
getContainers: () => api.get<DockerContainer[]>('/docker/containers'),
|
||||
getContainer: (id: string) => api.get<DockerContainer>(`/docker/containers/${id}`),
|
||||
startContainer: (id: string) => api.post(`/docker/containers/${id}/start`),
|
||||
stopContainer: (id: string) => api.post(`/docker/containers/${id}/stop`),
|
||||
restartContainer: (id: string) => api.post(`/docker/containers/${id}/restart`),
|
||||
getContainerLogs: (id: string, tail?: number) => api.get(`/docker/containers/${id}/logs`, { params: { tail } }),
|
||||
getContainerStats: (id: string) => api.get(`/docker/containers/${id}/stats`),
|
||||
};
|
||||
|
||||
export default api;
|
||||
@@ -0,0 +1,33 @@
|
||||
export function formatBytes(bytes: number, decimals = 2): string {
|
||||
if (bytes === 0) return '0 Bytes';
|
||||
|
||||
const k = 1204;
|
||||
const dm = decimals < 0 ? 0 : decimals;
|
||||
const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
|
||||
|
||||
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
||||
|
||||
return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
|
||||
}
|
||||
|
||||
export function formatUptime(seconds: number): string {
|
||||
const days = Math.floor(seconds / 86400);
|
||||
const hours = Math.floor((seconds % 86400) / 3600);
|
||||
const minutes = Math.floor((seconds % 3600) / 60);
|
||||
|
||||
if (days > 0) {
|
||||
return `${days}d ${hours}h`;
|
||||
} else if (hours > 0) {
|
||||
return `${hours}h ${minutes}m`;
|
||||
} else {
|
||||
return `${minutes}m`;
|
||||
}
|
||||
}
|
||||
|
||||
export function formatDate(timestamp: number): string {
|
||||
return new Date(timestamp * 1000).toLocaleString('de-DE');
|
||||
}
|
||||
|
||||
export function cn(...classes: (string | boolean | undefined)[]): string {
|
||||
return classes.filter(Boolean).join(' ');
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
|
||||
import React from 'react';
|
||||
import App from './App';
|
||||
import './index.css';
|
||||
import ReactDOM from 'react-dom/client';
|
||||
|
||||
ReactDOM.createRoot(document.getElementById('root')!).render(
|
||||
<React.StrictMode>
|
||||
<App />
|
||||
</React.StrictMode>
|
||||
);
|
||||
@@ -0,0 +1,32 @@
|
||||
import { create } from "zustand";
|
||||
import { persist } from "zustand/middleware";
|
||||
|
||||
interface User {
|
||||
id: string;
|
||||
username: string;
|
||||
}
|
||||
|
||||
interface AuthState {
|
||||
token: string | null;
|
||||
user: User | null;
|
||||
isAuthenticated: boolean;
|
||||
login: (token: string, user: User) => void;
|
||||
logout: () => void;
|
||||
}
|
||||
|
||||
export const useAuthStore = create<AuthState>()(
|
||||
persist(
|
||||
(set) => ({
|
||||
token: null,
|
||||
user: null,
|
||||
isAuthenticated: false,
|
||||
login: (token: string, user: User) =>
|
||||
set({ token, user, isAuthenticated: true }),
|
||||
logout: () =>
|
||||
set({ token: null, user: null, isAuthenticated: false }),
|
||||
}),
|
||||
{
|
||||
name: 'auth-storage',
|
||||
}
|
||||
)
|
||||
);
|
||||
Vendored
+10
@@ -0,0 +1,10 @@
|
||||
/// <reference types="vite/client" />
|
||||
/// <reference types="vite-plugin-pwa/client" />
|
||||
|
||||
interface ImportMetaEnv {
|
||||
readonly VITE_API_URL: string;
|
||||
}
|
||||
|
||||
interface ImportMeta {
|
||||
readonly env: ImportMetaEnv;
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
/** @type {import('tailwindcss').Config} */
|
||||
export default {
|
||||
content: [
|
||||
"./index.html",
|
||||
"./src/**/*.{js,ts,jsx,tsx}",
|
||||
],
|
||||
theme: {
|
||||
extend: {
|
||||
colors: {
|
||||
unraid: {
|
||||
orange: '#ff8c2f',
|
||||
'orange-dark': '#e67922',
|
||||
dark: '#1a1a1a',
|
||||
'dark-lighter': '#2d2d2d',
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
plugins: [],
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "es2020",
|
||||
"useDefineForClassFields": true,
|
||||
"lib": ["ES2020", "DOM", "DOM.Iterable"],
|
||||
"module": "esnext",
|
||||
"skipLibCheck": true,
|
||||
|
||||
/* Bundler mode */
|
||||
"moduleResolution": "bundler",
|
||||
"allowImportingTsExtensions": true,
|
||||
"resolveJsonModule": true,
|
||||
"isolatedModules": true,
|
||||
"noEmit": true,
|
||||
"jsx": "react-jsx",
|
||||
|
||||
/* Linting */
|
||||
"strict": true,
|
||||
"noUnusedLocals": true,
|
||||
"noUnusedParameters": true,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
|
||||
/* Paths */
|
||||
"baseUrl": ".",
|
||||
"paths": {
|
||||
"@/*": ["./src/*"]
|
||||
}
|
||||
},
|
||||
"include": ["src"],
|
||||
"references": [{ "path": "./tsconfig.node.json" }]
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"composite": true,
|
||||
"skipLibCheck": true,
|
||||
"module": "esnext",
|
||||
"moduleResolution": "bundler",
|
||||
"allowSyntheticDefaultImports": true
|
||||
},
|
||||
"include": [
|
||||
"vite.config.ts"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
import { defineConfig } from 'vite';
|
||||
import react from '@vitejs/plugin-react';
|
||||
import { VitePWA } from 'vite-plugin-pwa';
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [
|
||||
react(),
|
||||
VitePWA({
|
||||
registerType: 'autoUpdate',
|
||||
includeAssets: ['favicon.ico', 'robots.txt', 'apple-touch-icon.png'],
|
||||
manifest: {
|
||||
name: 'Unraid Monitor',
|
||||
short_name: 'Unraid Monitor',
|
||||
description: 'Monitor and manage your Unraid server',
|
||||
theme_color: '#ff8c2f',
|
||||
background_color: '#1a1a1a',
|
||||
display: 'standalone',
|
||||
orientation: 'portrait',
|
||||
icons: [
|
||||
{
|
||||
src: '/icon-192.png',
|
||||
sizes: '192x192',
|
||||
type: 'image/png'
|
||||
},
|
||||
{
|
||||
src: '/icon-512.png',
|
||||
sizes: '512x512',
|
||||
type: 'image/png'
|
||||
},
|
||||
{
|
||||
src: '/icon-512.png',
|
||||
sizes: '512x512',
|
||||
type: 'image/png',
|
||||
purpose: "any maskable"
|
||||
}
|
||||
]
|
||||
},
|
||||
workbox: {
|
||||
globPatterns: ['**/*.{js,css,html,ico,png,svg}'],
|
||||
runtimeCaching: [
|
||||
{
|
||||
urlPattern: /^https:\/\/api\..*/i,
|
||||
handler: 'NetworkFirst',
|
||||
options: {
|
||||
cacheName: 'api-cache',
|
||||
expiration: {
|
||||
maxEntries: 10,
|
||||
maxAgeSeconds: 60 * 5 // 5 Minuten
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
})
|
||||
],
|
||||
server: {
|
||||
port: 10000,
|
||||
proxy: {
|
||||
'/api': {
|
||||
target: 'http://localhost:4000',
|
||||
changeOrigin: true
|
||||
}
|
||||
}
|
||||
},
|
||||
build: {
|
||||
outDir: 'dist',
|
||||
sourcemap: false
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user