import Refresh from '@mui/icons-material/Refresh' import { Alert, Box, Button } from '@mui/material' import { Board, BoardButtons, type BoardPanel } from './PanelBoard.tsx' import { useBoard } from './useBoard.ts' import { Grid, Pairs } from './ServerPanel.tsx' import { text } from './format.ts' import Toolbar from './Toolbar.tsx' import { DETAILS_SHAPE, request, type RouterDetails } from './api.ts' import { useRead } from './useRead.ts' /** The localStorage key of the tab's layout. */ const LAYOUT_KEY = 'linux-manager-ui.network-layout' /** Reads the server's /config. */ const readDetails = () => request('GET', '/config', DETAILS_SHAPE) /** * The server's network, from its /config: the interfaces but loopback, external when they hold an IPv4 default route * and internal otherwise; the internal gateway and the local CIDRs while the router is on; and the IPv4 routes. The * panels are on a board whose layout is kept in the browser. */ export default function NetworkPanel() { const { data: details, error, busy, refresh } = useRead(readDetails) const board = useBoard(LAYOUT_KEY) const network = details?.network const router = details?.configuration.router?.enabled === true // An interface holding an IPv4 default route is external, every other one internal. const external = new Set(network?.routes?.filter((route) => route.dst === 'default').map((route) => route.dev)) const panels: BoardPanel[] = network ? [ { id: 'interfaces', title: 'Interfaces', content: ( [ link.name, external.has(link.name) ? 'external' : 'internal', text(link.state), text(link.ipv4), text(link.ipv6), text(link.mac), ])} /> ), }, ...(router ? [{ id: 'router', title: 'Router', content: ( ), }] : []), { id: 'routes', title: 'Routes', content: ( [ route.dst, text(route.gateway), route.flags.length > 0 ? `${route.dev} (${route.flags.join(', ')})` : route.dev, text(route.prefsrc), text(route.protocol), text(route.metric), ])} /> ), }, ] : [] return ( {error && {error}} ) }