feature: the package installs the Router Manager, which is no longer a package of its own.
Release / release (push) Failing after 4s
Release / release (push) Failing after 4s
This commit is contained in:
1 parent
6d90441bee
commit
8efe21bfa6
129 files changed
+17381
-104
No files matched your search
+320
@@ -0,0 +1,320 @@
|
||||
import AccountCircle from '@mui/icons-material/AccountCircle'
|
||||
import EditNote from '@mui/icons-material/EditNote'
|
||||
import HelpOutline from '@mui/icons-material/HelpOutlineOutlined'
|
||||
import Logout from '@mui/icons-material/Logout'
|
||||
import Terminal from '@mui/icons-material/Terminal'
|
||||
import { Box, Button, CircularProgress, Container, IconButton, Link, Stack, Tab, Tabs, Tooltip, Typography } from '@mui/material'
|
||||
import { useCallback, useEffect, useState } from 'react'
|
||||
import AccountPanel from './AccountPanel.tsx'
|
||||
import BackupPanel from './BackupPanel.tsx'
|
||||
import CertificatesPanel from './CertificatesPanel.tsx'
|
||||
import GroupsPanel from './GroupsPanel.tsx'
|
||||
import HelpPanel, { HELP_HOME, HELP_WIDTH } from './HelpPanel.tsx'
|
||||
import LogsPanel from './LogsPanel.tsx'
|
||||
import MetricsPanel from './MetricsPanel.tsx'
|
||||
import DockerPanel from './DockerPanel.tsx'
|
||||
import DnsPanel from './DnsPanel.tsx'
|
||||
import PageMenu, { CA_PATH, DOCKER_PATH, REMOTE_ACCESS_PATH, SHELL_PATH, SITES_PATH, SITE_TO_SITE_PATH, USERS_PATH, USER_PATH } from './PageMenu.tsx'
|
||||
import NetworkPanel from './NetworkPanel.tsx'
|
||||
import RemoteAccessPanel from './RemoteAccessPanel.tsx'
|
||||
import RouterPanel from './RouterPanel.tsx'
|
||||
import ServiceAccountsPanel from './ServiceAccountsPanel.tsx'
|
||||
import SettingsButton from './SettingsButton.tsx'
|
||||
import ShellPanel from './ShellPanel.tsx'
|
||||
import SignIn from './SignIn.tsx'
|
||||
import SystemPanel from './SystemPanel.tsx'
|
||||
import SiteFiles from './SiteFiles.tsx'
|
||||
import SitesPanel from './SitesPanel.tsx'
|
||||
import SiteToSitePanel from './SiteToSitePanel.tsx'
|
||||
import SiteToSiteStatusPanel from './SiteToSiteStatusPanel.tsx'
|
||||
import ThemeMenu from './ThemeMenu.tsx'
|
||||
import UsersPanel from './UsersPanel.tsx'
|
||||
import {
|
||||
ACCOUNT_SHAPE, SESSION_EXPIRED, SESSION_SHAPE, request, type Account, type Info, type RemoteAccessSystem, type Session,
|
||||
} from './api.ts'
|
||||
|
||||
/** The tabs of the Router page, router being the Overview tab, of the Identities page, of the Connectivity page and of the Web Sites page. */
|
||||
type View = 'router' | 'metrics' | 'logs' | 'backup' | 'system'
|
||||
type UsersView = 'users' | 'groups' | 'service-accounts'
|
||||
type SiteToSiteView = 'status' | 'network' | 'connections'
|
||||
type SitesView = 'sites' | 'files' | 'dns'
|
||||
|
||||
/** The help topic of each tab of the Web Sites page. */
|
||||
const SITES_TOPICS: Record<SitesView, string> = { sites: 'sites.md', files: 'site-files.md', dns: 'dns.md' }
|
||||
|
||||
/** The prefix of the sessionStorage keys of the pages the account and the shell page were opened from, by their paths. */
|
||||
const RETURN_KEY = 'vpn-router-manager.return:'
|
||||
|
||||
/** The pages of an administrator besides Router, which every other path shows. */
|
||||
const PAGE_PATHS = [USER_PATH, USERS_PATH, SITE_TO_SITE_PATH, REMOTE_ACCESS_PATH, CA_PATH, SITES_PATH, DOCKER_PATH, SHELL_PATH]
|
||||
|
||||
/** The help topic of each page, a document of /docs; the Router, the Identities and the Web Sites page have one per tab. */
|
||||
const HELP_TOPICS: Record<string, string> = {
|
||||
[USER_PATH]: 'account.md',
|
||||
[SITE_TO_SITE_PATH]: 'site-to-site.md',
|
||||
[REMOTE_ACCESS_PATH]: 'remote-access.md',
|
||||
[CA_PATH]: 'certificates.md',
|
||||
[DOCKER_PATH]: 'docker.md',
|
||||
[SHELL_PATH]: 'shell.md',
|
||||
}
|
||||
|
||||
/** The localStorage key of whether the help is open. */
|
||||
const HELP_KEY = 'vpn-router-manager.help'
|
||||
|
||||
/**
|
||||
* The page asks for a sign-in until a session exists. At USER_PATH, and for a user who is not a member of admins at
|
||||
* every path, it then shows the user's own account; at USERS_PATH the router's users, groups or service accounts; at
|
||||
* SITE_TO_SITE_PATH its site-to-site connections, their state and its network with its routes; at REMOTE_ACCESS_PATH its IKEv2, OpenVPN and
|
||||
* WireGuard access; at CA_PATH its certificates; at SITES_PATH its web
|
||||
* sites, the files of a site, opened from the sites too, and its name server; at DOCKER_PATH the state of Docker; at SHELL_PATH a shell on the router; otherwise the state of the router, with the update information of its packages in
|
||||
* the Status panel, its metrics, its logs, its backups or the updates of its system's packages. A page shows one tab at a time, each read only while shown. An
|
||||
* administrator switches pages with the page menu at the right end of the header; the button with the user's name,
|
||||
* left of Sign out, opens the user's own account, and an administrator's shell button, left of it, the shell; pressed
|
||||
* on their page, each returns to the page it was opened from. While files are open in the shell's editor, the editor
|
||||
* button left of the shell button switches the Shell page between the terminal and the editor. The help button, between the theme switcher and the page menu, opens or closes the help on
|
||||
* the right (HelpPanel) at the topic of the page and tab shown (HELP_TOPICS), the page moving left; the browser keeps
|
||||
* whether it is open. A call answered 401 ends the session and asks for a sign-in again.
|
||||
*/
|
||||
export default function App(props: { info: Info }) {
|
||||
const [view, setView] = useState<View>('router')
|
||||
const [usersView, setUsersView] = useState<UsersView>('users')
|
||||
const [siteToSiteView, setSiteToSiteView] = useState<SiteToSiteView>('status')
|
||||
const [remoteAccessView, setRemoteAccessView] = useState<RemoteAccessSystem>('p2s')
|
||||
const [sitesView, setSitesView] = useState<SitesView>('sites')
|
||||
const [filesSite, setFilesSite] = useState<string | null>(null)
|
||||
const [session, setSession] = useState<Session | null | undefined>(undefined)
|
||||
const [role, setRole] = useState<{ name: string; admin: boolean } | null>(null)
|
||||
const page = PAGE_PATHS.find((path) => path === window.location.pathname) ?? '/'
|
||||
const userPage = page === USER_PATH
|
||||
const admin = session && role?.name === session.name ? role.admin : undefined
|
||||
// The account page is the page of every user who is not an administrator, and of an administrator at USER_PATH.
|
||||
const accountShown = Boolean(session) && admin !== undefined && (userPage || !admin)
|
||||
const [helpOpen, setHelpOpen] = useState(() => window.localStorage.getItem(HELP_KEY) === 'open')
|
||||
// The files open in the Shell page's editor, and whether the editor is shown in place of the terminal.
|
||||
const [editorFiles, setEditorFiles] = useState(0)
|
||||
const [editorShown, setEditorShown] = useState(false)
|
||||
const showFiles = useCallback((count: number) => {
|
||||
setEditorFiles(count)
|
||||
if (count === 0) {
|
||||
setEditorShown(false)
|
||||
}
|
||||
}, [])
|
||||
const showEditor = useCallback(() => setEditorShown(true), [])
|
||||
const helpShown = Boolean(session) && helpOpen
|
||||
const topic = !admin ? 'account.md'
|
||||
: page === '/' ? `${view === 'router' ? 'router' : view}.md`
|
||||
: page === USERS_PATH ? `${usersView}.md`
|
||||
: page === SITES_PATH ? SITES_TOPICS[sitesView]
|
||||
: HELP_TOPICS[page] ?? HELP_HOME
|
||||
|
||||
/** Opens or closes the help, kept in localStorage. */
|
||||
function toggleHelp() {
|
||||
window.localStorage.setItem(HELP_KEY, helpOpen ? 'closed' : 'open')
|
||||
setHelpOpen(!helpOpen)
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
request<Session>('GET', '/session', SESSION_SHAPE).then(setSession).catch(() => setSession(null))
|
||||
const expired = () => setSession(null)
|
||||
window.addEventListener(SESSION_EXPIRED, expired)
|
||||
return () => window.removeEventListener(SESSION_EXPIRED, expired)
|
||||
}, [])
|
||||
|
||||
useEffect(() => {
|
||||
if (!session) {
|
||||
return
|
||||
}
|
||||
request<Account>('GET', '/account', ACCOUNT_SHAPE)
|
||||
.then((account) => setRole({ name: session.name, admin: account.admin }))
|
||||
.catch(() => setRole({ name: session.name, admin: false }))
|
||||
}, [session])
|
||||
|
||||
/** Opens the page of the path, keeping the page it was opened from in sessionStorage, or returns to that page from it. */
|
||||
function toggle(path: string) {
|
||||
if (page === path) {
|
||||
window.location.assign(window.sessionStorage.getItem(RETURN_KEY + path) ?? '/')
|
||||
return
|
||||
}
|
||||
window.sessionStorage.setItem(RETURN_KEY + path, window.location.pathname)
|
||||
window.location.assign(path)
|
||||
}
|
||||
|
||||
async function signOut() {
|
||||
await request('DELETE', '/session', () => true).catch(() => undefined)
|
||||
setSession(null)
|
||||
}
|
||||
|
||||
return (
|
||||
<Box
|
||||
sx={(theme) => ({
|
||||
mr: { sm: helpShown ? `${HELP_WIDTH}px` : 0 },
|
||||
transition: theme.transitions.create('margin', { duration: theme.transitions.duration.enteringScreen }),
|
||||
})}
|
||||
>
|
||||
{session && <HelpPanel open={helpShown} topic={topic} onClose={toggleHelp} />}
|
||||
<Container maxWidth="xl" sx={{ py: 3 }}>
|
||||
<Stack direction="row" sx={{ mb: 2, alignItems: 'center', justifyContent: 'space-between', gap: 2 }}>
|
||||
<Stack direction="row" sx={{ alignItems: 'center', gap: 2 }}>
|
||||
<Box component="img" src="/favicon.svg" alt="" sx={{ width: 56, height: 56 }} />
|
||||
<Box>
|
||||
<Stack direction="row" sx={{ alignItems: 'baseline', gap: 1 }}>
|
||||
<Typography variant="h5" component="h1">
|
||||
VPN Router Manager
|
||||
</Typography>
|
||||
<Typography variant="caption" color="text.secondary" sx={{ fontFamily: 'monospace' }}>
|
||||
{props.info.version ?? 'development'}
|
||||
</Typography>
|
||||
</Stack>
|
||||
<Typography variant="body2" color="text.secondary" sx={{ mt: 1 }}>
|
||||
Router status page:{' '}
|
||||
{props.info.status_url
|
||||
? <Link href={props.info.status_url} target="_blank" rel="noreferrer">{props.info.status_url}</Link>
|
||||
: <b>not configured</b>}
|
||||
</Typography>
|
||||
</Box>
|
||||
</Stack>
|
||||
<Stack direction="row" sx={{ alignItems: 'center', gap: 2 }}>
|
||||
{session && admin && page === SHELL_PATH && editorFiles > 0 && (
|
||||
<Tooltip title={editorShown ? 'Back to the terminal' : 'Editor'}>
|
||||
<IconButton
|
||||
aria-label="editor"
|
||||
color={editorShown ? 'primary' : 'default'}
|
||||
onClick={() => setEditorShown(!editorShown)}
|
||||
sx={editorShown ? { bgcolor: 'action.selected' } : undefined}
|
||||
>
|
||||
<EditNote />
|
||||
</IconButton>
|
||||
</Tooltip>
|
||||
)}
|
||||
{session && admin && (
|
||||
<Tooltip title={page === SHELL_PATH ? 'Back from the shell' : 'Shell'}>
|
||||
<IconButton
|
||||
aria-label="shell"
|
||||
color={page === SHELL_PATH ? 'primary' : 'default'}
|
||||
onClick={() => toggle(SHELL_PATH)}
|
||||
sx={page === SHELL_PATH ? { bgcolor: 'action.selected' } : undefined}
|
||||
>
|
||||
<Terminal />
|
||||
</IconButton>
|
||||
</Tooltip>
|
||||
)}
|
||||
{session && (
|
||||
<>
|
||||
<Button variant={userPage ? 'contained' : 'outlined'} startIcon={<AccountCircle />} onClick={() => toggle(USER_PATH)} sx={{ textTransform: 'none' }}>
|
||||
{session.name}
|
||||
</Button>
|
||||
<Button variant="outlined" startIcon={<Logout />} onClick={() => void signOut()}>Sign out</Button>
|
||||
</>
|
||||
)}
|
||||
{session && admin !== undefined && !accountShown && <SettingsButton />}
|
||||
<ThemeMenu />
|
||||
{session && (
|
||||
<Tooltip title={helpShown ? 'Close the help' : 'Help'}>
|
||||
<IconButton
|
||||
aria-label="help"
|
||||
color={helpShown ? 'primary' : 'default'}
|
||||
onClick={toggleHelp}
|
||||
sx={helpShown ? { bgcolor: 'action.selected' } : undefined}
|
||||
>
|
||||
<HelpOutline />
|
||||
</IconButton>
|
||||
</Tooltip>
|
||||
)}
|
||||
{session && admin && <PageMenu path={page} />}
|
||||
</Stack>
|
||||
</Stack>
|
||||
{session === undefined && <CircularProgress />}
|
||||
{session === null && <SignIn onSignedIn={setSession} />}
|
||||
{session && admin === undefined && <CircularProgress />}
|
||||
{accountShown && <AccountPanel onPasswordChanged={() => void signOut()} />}
|
||||
{session && admin && page === CA_PATH && (
|
||||
<>
|
||||
<Typography variant="h6" component="h2" sx={{ mb: 2 }}>Certificates</Typography>
|
||||
<CertificatesPanel />
|
||||
</>
|
||||
)}
|
||||
{session && admin && page === SITES_PATH && (
|
||||
<>
|
||||
<Tabs value={sitesView} onChange={(_event, next: SitesView) => setSitesView(next)} sx={{ mb: 3, borderBottom: 1, borderColor: 'divider' }}>
|
||||
<Tab value="sites" label="Sites" />
|
||||
<Tab value="files" label="Files" />
|
||||
<Tab value="dns" label="DNS" />
|
||||
</Tabs>
|
||||
{sitesView === 'sites' && (
|
||||
<SitesPanel
|
||||
onOpenFiles={(name) => {
|
||||
setFilesSite(name)
|
||||
setSitesView('files')
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
{sitesView === 'files' && <SiteFiles key={filesSite ?? ''} site={filesSite} onSite={setFilesSite} />}
|
||||
{sitesView === 'dns' && <DnsPanel />}
|
||||
</>
|
||||
)}
|
||||
{session && admin && page === DOCKER_PATH && (
|
||||
<>
|
||||
<Typography variant="h6" component="h2" sx={{ mb: 2 }}>Docker</Typography>
|
||||
<DockerPanel />
|
||||
</>
|
||||
)}
|
||||
{session && admin && page === SHELL_PATH && (
|
||||
<>
|
||||
<Typography variant="h6" component="h2" sx={{ mb: 2 }}>Shell</Typography>
|
||||
<ShellPanel editorShown={editorShown} onFiles={showFiles} onOpened={showEditor} />
|
||||
</>
|
||||
)}
|
||||
{session && admin && page === REMOTE_ACCESS_PATH && (
|
||||
<>
|
||||
<Tabs value={remoteAccessView} onChange={(_event, next: RemoteAccessSystem) => setRemoteAccessView(next)} sx={{ mb: 3, borderBottom: 1, borderColor: 'divider' }}>
|
||||
<Tab value="p2s" label="IKEv2" />
|
||||
<Tab value="openvpn" label="OpenVPN" />
|
||||
<Tab value="wireguard" label="WireGuard" />
|
||||
</Tabs>
|
||||
<RemoteAccessPanel key={remoteAccessView} system={remoteAccessView} />
|
||||
</>
|
||||
)}
|
||||
{session && admin && page === SITE_TO_SITE_PATH && (
|
||||
<>
|
||||
<Tabs value={siteToSiteView} onChange={(_event, next: SiteToSiteView) => setSiteToSiteView(next)} sx={{ mb: 3, borderBottom: 1, borderColor: 'divider' }}>
|
||||
<Tab value="status" label="Status" />
|
||||
<Tab value="network" label="Network" />
|
||||
<Tab value="connections" label="Connections" />
|
||||
</Tabs>
|
||||
{siteToSiteView === 'connections' && <SiteToSitePanel />}
|
||||
{siteToSiteView === 'status' && <SiteToSiteStatusPanel />}
|
||||
{siteToSiteView === 'network' && <NetworkPanel />}
|
||||
</>
|
||||
)}
|
||||
{session && admin && page === USERS_PATH && (
|
||||
<>
|
||||
<Tabs value={usersView} onChange={(_event, next: UsersView) => setUsersView(next)} sx={{ mb: 3, borderBottom: 1, borderColor: 'divider' }}>
|
||||
<Tab value="users" label="Users" />
|
||||
<Tab value="groups" label="Groups" />
|
||||
<Tab value="service-accounts" label="Service Accounts" />
|
||||
</Tabs>
|
||||
{usersView === 'users' && <UsersPanel />}
|
||||
{usersView === 'groups' && <GroupsPanel />}
|
||||
{usersView === 'service-accounts' && <ServiceAccountsPanel />}
|
||||
</>
|
||||
)}
|
||||
{session && admin && page === '/' && (
|
||||
<>
|
||||
<Tabs value={view} onChange={(_event, next: View) => setView(next)} sx={{ mb: 3, borderBottom: 1, borderColor: 'divider' }}>
|
||||
<Tab value="router" label="Overview" />
|
||||
<Tab value="metrics" label="Metrics" />
|
||||
<Tab value="logs" label="Logs" />
|
||||
<Tab value="backup" label="Backup" />
|
||||
<Tab value="system" label="System" />
|
||||
</Tabs>
|
||||
{view === 'router' && <RouterPanel />}
|
||||
{view === 'metrics' && <MetricsPanel />}
|
||||
{view === 'logs' && <LogsPanel />}
|
||||
{view === 'backup' && <BackupPanel />}
|
||||
{view === 'system' && <SystemPanel />}
|
||||
</>
|
||||
)}
|
||||
</Container>
|
||||
</Box>
|
||||
)
|
||||
}
|
||||
Reference in new issue
Block a user