84 lines
3.7 KiB
TypeScript
84 lines
3.7 KiB
TypeScript
import ArrowDropDown from '@mui/icons-material/ArrowDropDown'
|
|
import Dns from '@mui/icons-material/Dns'
|
|
import Hub from '@mui/icons-material/Hub'
|
|
import MenuIcon from '@mui/icons-material/Menu'
|
|
import People from '@mui/icons-material/People'
|
|
import Public from '@mui/icons-material/Public'
|
|
import ViewInAr from '@mui/icons-material/ViewInAr'
|
|
import Router from '@mui/icons-material/Router'
|
|
import VerifiedUser from '@mui/icons-material/VerifiedUser'
|
|
import VpnKey from '@mui/icons-material/VpnKey'
|
|
import { Button, ListItemIcon, ListItemText, Menu, MenuItem } from '@mui/material'
|
|
import { useState, type ReactNode } from 'react'
|
|
|
|
/** The path of the signed-in user's own account page. */
|
|
export const USER_PATH = '/user'
|
|
|
|
/** The path of the Remote Access page: IKEv2, OpenVPN and WireGuard. */
|
|
export const REMOTE_ACCESS_PATH = '/remote-access-manager'
|
|
|
|
/** The path of the Certificates page. */
|
|
export const CA_PATH = '/ca-manager'
|
|
|
|
/** The path of the Identities page: the users, the groups and the service accounts. */
|
|
export const USERS_PATH = '/user-manager'
|
|
|
|
/** The path of the Connectivity page: the site-to-site connections and their state. */
|
|
export const SITE_TO_SITE_PATH = '/site-to-site-manager'
|
|
|
|
/** The path of the Docker page: the state of Docker and of its rules. */
|
|
export const DOCKER_PATH = '/docker-manager'
|
|
|
|
/** The path of the Web Sites page: the sites Caddy serves and their files. */
|
|
export const SITES_PATH = '/sites-manager'
|
|
|
|
/** The path of the DNS page: the name server's settings, domains and records. */
|
|
export const DNS_PATH = '/dns-manager'
|
|
|
|
/** The path of the shell page: a login shell on the server, opened with the shell button of the header, not the menu. */
|
|
export const SHELL_PATH = '/shell'
|
|
|
|
/** The pages of an administrator in the menu: path, label and icon. */
|
|
const PAGES: { path: string; label: string; icon: ReactNode }[] = [
|
|
{ path: '/', label: 'Server', icon: <Router fontSize="small" /> },
|
|
{ path: USERS_PATH, label: 'Identities', icon: <People fontSize="small" /> },
|
|
{ path: SITE_TO_SITE_PATH, label: 'Connectivity', icon: <Hub fontSize="small" /> },
|
|
{ path: REMOTE_ACCESS_PATH, label: 'Remote Access', icon: <VpnKey fontSize="small" /> },
|
|
{ path: CA_PATH, label: 'Certificates', icon: <VerifiedUser fontSize="small" /> },
|
|
{ path: SITES_PATH, label: 'Web Sites', icon: <Public fontSize="small" /> },
|
|
{ path: DNS_PATH, label: 'DNS', icon: <Dns fontSize="small" /> },
|
|
{ path: DOCKER_PATH, label: 'Docker', icon: <ViewInAr fontSize="small" /> },
|
|
]
|
|
|
|
/**
|
|
* A button naming the page shown, or Pages on the account and the shell page, whose menu opens the pages of an
|
|
* administrator but those of hidden, the pages of a component switched off or of software the server does not have.
|
|
*/
|
|
export default function PageMenu(props: { path: string; hidden: string[] }) {
|
|
const [anchor, setAnchor] = useState<HTMLElement | null>(null)
|
|
const current = PAGES.find((page) => page.path === props.path) ?? { path: props.path, label: 'Pages', icon: <MenuIcon fontSize="small" /> }
|
|
return (
|
|
<>
|
|
<Button
|
|
variant="text"
|
|
color="inherit"
|
|
startIcon={current.icon}
|
|
endIcon={<ArrowDropDown />}
|
|
aria-haspopup="menu"
|
|
aria-expanded={anchor !== null}
|
|
onClick={(event) => setAnchor(event.currentTarget)}
|
|
>
|
|
{current.label}
|
|
</Button>
|
|
<Menu anchorEl={anchor} open={anchor !== null} onClose={() => setAnchor(null)}>
|
|
{PAGES.filter((page) => !props.hidden.includes(page.path)).map((page) => (
|
|
<MenuItem key={page.path} component="a" href={page.path} selected={page.path === current.path}>
|
|
<ListItemIcon>{page.icon}</ListItemIcon>
|
|
<ListItemText>{page.label}</ListItemText>
|
|
</MenuItem>
|
|
))}
|
|
</Menu>
|
|
</>
|
|
)
|
|
}
|