One integration per project (read-only API token, read every 5 minutes). Alerts for a server that was running and is off, stuck statuses, traffic at 80%/100% of the monthly quota, rescue mode left on, and late backups. The Hetzner page lists servers, volumes, snapshots and a cost estimate; a server the app knows by its agent gets a Hetzner card on its own page. /metrics and docs updated. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
258 lines
12 KiB
TypeScript
258 lines
12 KiB
TypeScript
import { useEffect, useState, type ReactNode } from "react";
|
|
import { Routes, Route, Navigate, useLocation, useParams } from "react-router-dom";
|
|
import { api, type CurrentUser, type UserRole, UnauthorizedError } from "./api/client";
|
|
import Login from "./pages/Login";
|
|
import Dashboard from "./pages/Dashboard";
|
|
import Users from "./pages/Users";
|
|
import Secrets from "./pages/Secrets";
|
|
import Ipam from "./pages/Ipam";
|
|
import NetworkDevices from "./pages/NetworkDevices";
|
|
import ProxyHosts from "./pages/ProxyHosts";
|
|
import AlertRules from "./pages/AlertRules";
|
|
import HomeAssistant from "./pages/HomeAssistant";
|
|
import Ups from "./pages/Ups";
|
|
import Jellyfin from "./pages/Jellyfin";
|
|
import Authentik from "./pages/Authentik";
|
|
import Prometheus from "./pages/Prometheus";
|
|
import Immich from "./pages/Immich";
|
|
import Paperless from "./pages/Paperless";
|
|
import N8n from "./pages/N8n";
|
|
import NetBox from "./pages/NetBox";
|
|
import Nextcloud from "./pages/Nextcloud";
|
|
import Hetzner from "./pages/Hetzner";
|
|
import ServiceLevels from "./pages/ServiceLevels";
|
|
import Duplicati from "./pages/Duplicati";
|
|
import MyWorkPage from "./pages/MyWork";
|
|
import ApiTokens from "./pages/ApiTokens";
|
|
import Todo from "./pages/Todo";
|
|
import InventoryRacks from "./pages/InventoryRacks";
|
|
import Ports from "./pages/Ports";
|
|
import Dns from "./pages/Dns";
|
|
import Servers from "./pages/Servers";
|
|
import ServerDetail from "./pages/ServerDetail";
|
|
import ServerCompare from "./pages/ServerCompare";
|
|
import Integrations from "./pages/Integrations";
|
|
import Docker from "./pages/Docker";
|
|
import Tailscale from "./pages/Tailscale";
|
|
import Semaphore from "./pages/Semaphore";
|
|
import Gitea from "./pages/Gitea";
|
|
import Proxmox from "./pages/Proxmox";
|
|
import Synology from "./pages/Synology";
|
|
import UptimeKuma from "./pages/UptimeKuma";
|
|
import PbsBackup from "./pages/PbsBackup";
|
|
import OsTicket from "./pages/OsTicket";
|
|
import AdminLinks from "./pages/AdminLinks";
|
|
import Alerts from "./pages/Alerts";
|
|
import Generator from "./pages/Generator";
|
|
import Maintenance from "./pages/Maintenance";
|
|
import Updates from "./pages/Updates";
|
|
import IncidentDetail from "./pages/IncidentDetail";
|
|
import Inventory from "./pages/Inventory";
|
|
import InventoryLabels from "./pages/InventoryLabels";
|
|
import InventoryLifecycle from "./pages/InventoryLifecycle";
|
|
import Endpoints from "./pages/Endpoints";
|
|
import Heartbeats from "./pages/Heartbeats";
|
|
import ComingUp from "./pages/ComingUp";
|
|
import MonthlyReport from "./pages/MonthlyReport";
|
|
import ChangeLog from "./pages/ChangeLog";
|
|
import Backups from "./pages/Backups";
|
|
import Consistency from "./pages/Consistency";
|
|
import Privacy from "./pages/Privacy";
|
|
import Settings from "./pages/Settings";
|
|
import { DataGroup, DisplayGroup, NotificationsGroup } from "./pages/settings/SettingsGroups";
|
|
import TagSettings from "./pages/settings/TagSettings";
|
|
import NameSettings from "./pages/settings/NameSettings";
|
|
import ShareSettings from "./pages/settings/ShareSettings";
|
|
import SignInSettings from "./pages/settings/SignInSettings";
|
|
import ApiSettings from "./pages/settings/ApiSettings";
|
|
import AppShell from "./layout/AppShell";
|
|
import DialogHost from "./components/DialogHost";
|
|
import Wall from "./pages/Wall";
|
|
import SharedWall from "./pages/SharedWall";
|
|
import SharedStatus from "./pages/SharedStatus";
|
|
import MapPage from "./pages/Map";
|
|
import { setDateTimeSettings } from "./utils/date";
|
|
import { setPageSize } from "./utils/pageSize";
|
|
import ToastHost from "./components/ToastHost";
|
|
|
|
const roleRank: Record<UserRole, number> = { viewer: 0, operator: 1, admin: 2 };
|
|
|
|
function RequireRole({
|
|
user,
|
|
minRole,
|
|
children,
|
|
}: {
|
|
user: CurrentUser;
|
|
minRole: UserRole;
|
|
children: ReactNode;
|
|
}) {
|
|
if (roleRank[user.role] < roleRank[minRole]) {
|
|
return (
|
|
<div className="alert alert-danger">You don't have permission to view this page.</div>
|
|
);
|
|
}
|
|
return <>{children}</>;
|
|
}
|
|
|
|
/** An old /incidents/<id> link, sent to the same incident under Alerts. */
|
|
function OldIncidentLink() {
|
|
const { id } = useParams();
|
|
return <Navigate to={/^\d+$/.test(id ?? "") ? `/alerts/incidents/${id}` : "/alerts?view=history"} replace />;
|
|
}
|
|
|
|
export default function App() {
|
|
const [user, setUser] = useState<CurrentUser | null | undefined>(undefined);
|
|
// A share link's page is for someone who isn't signed in: it asks nothing of the app's own session.
|
|
const shared = useLocation().pathname.startsWith("/share/wall/") || useLocation().pathname.startsWith("/share/status/");
|
|
|
|
useEffect(() => {
|
|
if (shared) return;
|
|
api.me().then(
|
|
(res) => setUser(res.user),
|
|
(err) => {
|
|
if (!(err instanceof UnauthorizedError)) {
|
|
console.error(err);
|
|
}
|
|
setUser(null);
|
|
},
|
|
);
|
|
api.settings.display().then((res) => {
|
|
setDateTimeSettings(res.display);
|
|
setPageSize(res.display.pageSize);
|
|
}).catch(() => {});
|
|
}, []);
|
|
|
|
if (shared) {
|
|
return (
|
|
<Routes>
|
|
<Route path="/share/wall/:token" element={<SharedWall />} />
|
|
<Route path="/share/status/:token" element={<SharedStatus />} />
|
|
</Routes>
|
|
);
|
|
}
|
|
|
|
if (user === undefined) {
|
|
return <div className="loading-screen">Loading…</div>;
|
|
}
|
|
|
|
if (user === null) {
|
|
return <Login />;
|
|
}
|
|
|
|
// The wall display is a screen of its own, with none of the app's menu around it; everything else sits inside the shell.
|
|
return (
|
|
<Routes>
|
|
<Route path="/wall" element={<Wall />} />
|
|
<Route path="*" element={<Shelled user={user} />} />
|
|
</Routes>
|
|
);
|
|
}
|
|
|
|
function Shelled({ user }: { user: CurrentUser }) {
|
|
return (
|
|
<AppShell user={user}>
|
|
<Routes>
|
|
<Route path="/" element={<Dashboard user={user} />} />
|
|
<Route path="/my-work" element={<MyWorkPage user={user} />} />
|
|
<Route path="/api-tokens" element={<ApiTokens />} />
|
|
<Route path="/todo" element={<Todo user={user} />} />
|
|
<Route path="/map" element={<MapPage user={user} />} />
|
|
<Route path="/servers" element={<Servers user={user} />} />
|
|
<Route path="/servers/compare" element={<ServerCompare />} />
|
|
<Route path="/servers/:id" element={<ServerDetail user={user} />} />
|
|
<Route path="/dns" element={<Dns user={user} />} />
|
|
<Route path="/ipam" element={<Ipam user={user} />} />
|
|
<Route path="/network/devices" element={<NetworkDevices user={user} />} />
|
|
<Route path="/proxy-hosts" element={<ProxyHosts user={user} />} />
|
|
<Route path="/alert-rules" element={<AlertRules user={user} />} />
|
|
<Route path="/home-assistant" element={<HomeAssistant user={user} />} />
|
|
<Route path="/ups" element={<Ups user={user} />} />
|
|
<Route path="/jellyfin" element={<Jellyfin />} />
|
|
<Route path="/authentik" element={<Authentik />} />
|
|
<Route path="/prometheus" element={<Prometheus />} />
|
|
<Route path="/immich" element={<Immich />} />
|
|
<Route path="/paperless" element={<Paperless />} />
|
|
<Route path="/n8n" element={<N8n />} />
|
|
<Route path="/netbox" element={<NetBox />} />
|
|
<Route path="/nextcloud" element={<Nextcloud />} />
|
|
<Route path="/hetzner" element={<Hetzner />} />
|
|
<Route path="/service-levels" element={<ServiceLevels user={user} />} />
|
|
<Route path="/duplicati" element={<Duplicati user={user} />} />
|
|
<Route path="/ports" element={<Ports user={user} />} />
|
|
<Route path="/secrets" element={<Secrets user={user} />} />
|
|
<Route path="/integrations" element={<Integrations user={user} />} />
|
|
<Route path="/generator" element={<Generator user={user} />} />
|
|
<Route path="/privacy" element={<Privacy />} />
|
|
<Route path="/consistency" element={<Consistency user={user} />} />
|
|
<Route path="/domains" element={<Navigate to="/dns?view=domains" replace />} />
|
|
<Route path="/maintenance" element={<Maintenance user={user} />} />
|
|
<Route path="/updates" element={<Updates user={user} />} />
|
|
<Route path="/inventory" element={<Inventory user={user} />} />
|
|
<Route path="/inventory/racks" element={<InventoryRacks />} />
|
|
<Route path="/inventory/labels" element={<InventoryLabels />} />
|
|
<Route path="/inventory/lifecycle" element={<InventoryLifecycle />} />
|
|
{/* These were pages of their own; they are sections of other pages now, and old links, bookmarks and notifications still arrive. */}
|
|
<Route path="/dependencies" element={<Navigate to="/map?view=dependencies" replace />} />
|
|
<Route path="/sessions" element={<Navigate to="/users?view=sessions" replace />} />
|
|
<Route path="/audit-log" element={<Navigate to="/changes?view=audit" replace />} />
|
|
<Route path="/diag-log" element={<Navigate to="/integrations?view=calls" replace />} />
|
|
<Route path="/endpoints" element={<Endpoints user={user} />} />
|
|
<Route path="/heartbeats" element={<Heartbeats user={user} />} />
|
|
<Route path="/coming-up" element={<ComingUp user={user} />} />
|
|
<Route path="/reports" element={<MonthlyReport user={user} />} />
|
|
<Route path="/changes" element={user.role === "viewer" ? <Navigate to="/" replace /> : <ChangeLog />} />
|
|
<Route path="/backups" element={<Backups user={user} />} />
|
|
<Route path="/docker" element={<Docker user={user} />} />
|
|
<Route path="/tailscale" element={<Tailscale user={user} />} />
|
|
<Route path="/semaphore" element={<Semaphore user={user} />} />
|
|
<Route path="/gitea" element={<Gitea user={user} />} />
|
|
<Route path="/proxmox" element={<Proxmox user={user} />} />
|
|
<Route path="/synology" element={<Synology user={user} />} />
|
|
<Route path="/uptime-kuma" element={<UptimeKuma user={user} />} />
|
|
<Route path="/pbs" element={<PbsBackup user={user} />} />
|
|
<Route path="/osticket" element={<OsTicket user={user} />} />
|
|
<Route path="/admin-links" element={<AdminLinks user={user} />} />
|
|
<Route path="/alerts" element={<Alerts user={user} />} />
|
|
<Route path="/alerts/incidents/:id" element={<IncidentDetail user={user} />} />
|
|
{/* Incidents used to be a page of their own: old links, bookmarks and notifications still arrive. */}
|
|
<Route path="/incidents" element={<Navigate to="/alerts?view=history" replace />} />
|
|
<Route path="/incidents/:id" element={<OldIncidentLink />} />
|
|
<Route
|
|
path="/users"
|
|
element={
|
|
<RequireRole user={user} minRole="admin">
|
|
<Users />
|
|
</RequireRole>
|
|
}
|
|
/>
|
|
<Route
|
|
path="/settings"
|
|
element={
|
|
<RequireRole user={user} minRole="admin">
|
|
<Settings />
|
|
</RequireRole>
|
|
}
|
|
>
|
|
<Route index element={<Navigate to="notifications" replace />} />
|
|
<Route path="notifications" element={<NotificationsGroup />} />
|
|
<Route path="sign-in" element={<SignInSettings />} />
|
|
<Route path="display" element={<DisplayGroup />} />
|
|
<Route path="names" element={<NameSettings />} />
|
|
<Route path="tags" element={<TagSettings />} />
|
|
<Route path="share" element={<ShareSettings />} />
|
|
<Route path="api" element={<ApiSettings />} />
|
|
<Route path="data" element={<DataGroup />} />
|
|
{/* Tabs that were gathered into others: old links and bookmarks still arrive. */}
|
|
<Route path="badges" element={<Navigate to="/settings/display?view=badges" replace />} />
|
|
<Route path="alert-tickets" element={<Navigate to="/settings/notifications?view=tickets" replace />} />
|
|
<Route path="backup" element={<Navigate to="/settings/data" replace />} />
|
|
<Route path="logs" element={<Navigate to="/settings/data?view=logs" replace />} />
|
|
<Route path="cache" element={<Navigate to="/settings/data?view=cache" replace />} />
|
|
</Route>
|
|
</Routes>
|
|
<DialogHost />
|
|
<ToastHost />
|
|
</AppShell>
|
|
);
|
|
}
|