import { useState } from 'react'; import { useGetOne, Title, useNotify } from 'react-admin'; import { Card, CardContent, Typography, Box, Chip, Stack, Divider, Button } from '@mui/material'; import VpnKeyIcon from '@mui/icons-material/VpnKey'; import { apiFetch } from './dataProvider'; const Mono = ({ children }) => ( {children} ); const DkimButton = ({ domain, onDone }) => { const [busy, setBusy] = useState(false); const notify = useNotify(); const gen = () => { setBusy(true); apiFetch('/mailserver/dkim', { method: 'POST', body: JSON.stringify({ domain }) }) .then(() => { notify(`DKIM für ${domain} erzeugt`, { type: 'success' }); onDone?.(); }) .catch((e) => notify(e?.body?.error || 'DKIM-Erzeugung fehlgeschlagen', { type: 'warning' })) .finally(() => setBusy(false)); }; return ( ); }; export const StatusPage = () => { const { data, isLoading, error, refetch } = useGetOne('status', { id: 'status' }); if (isLoading) return Lädt …; if (error) return Fehler beim Laden des Status.; return ( <CardContent> <Typography variant="h6" gutterBottom>Mailserver</Typography> <Stack direction="row" spacing={1} sx={{ mb: 2, flexWrap: 'wrap', gap: 1 }}> <Chip label={`Host: ${data.fqdn}`} /> <Chip color="primary" label={`${data.accounts} Postfächer`} /> <Chip color="secondary" label={`${data.aliases} Aliase`} /> {(data.domains || []).map((d) => <Chip key={d} variant="outlined" label={d} />)} </Stack> <Typography variant="h6" gutterBottom>DNS — Mailhost (einmalig)</Typography> <Mono>{[data.host?.a, data.host?.ptr].filter(Boolean).join('\n')}</Mono> {(data.records || []).map((r) => ( <Box key={r.domain} sx={{ mt: 3 }}> <Divider sx={{ mb: 1 }} /> <Typography variant="h6" gutterBottom>{r.domain}</Typography> <Mono>{[r.mx, r.spf, r.dmarc].join('\n')}</Mono> <Typography variant="subtitle2" sx={{ mt: 1 }}>DKIM (TXT)</Typography> {r.dkim ? <Mono>{r.dkim}</Mono> : <Typography color="text.secondary" variant="body2">Noch kein DKIM-Schlüssel.</Typography>} <DkimButton domain={r.domain} onDone={refetch} /> </Box> ))} </CardContent> </Card> ); };