"use client"; import { useFormState } from "react-dom"; import { Alert, Box, Button, Card, CardContent, Checkbox, FormControlLabel, Stack, TextField, Typography } from "@mui/material"; import type { GeneralSettings, AuthentikSettings, LoggingSettings, MetricsSettings } from "@/src/lib/settings"; import { updateCloudflareSettingsAction, updateGeneralSettingsAction, updateAuthentikSettingsAction, updateLoggingSettingsAction, updateMetricsSettingsAction } from "./actions"; type Props = { general: GeneralSettings | null; cloudflare: { hasToken: boolean; zoneId?: string; accountId?: string; }; authentik: AuthentikSettings | null; logging: { enabled: boolean; lokiUrl?: string; lokiUsername?: string; hasPassword: boolean; labels?: Record; } | null; metrics: MetricsSettings | null; }; export default function SettingsClient({ general, cloudflare, authentik, logging, metrics }: Props) { const [generalState, generalFormAction] = useFormState(updateGeneralSettingsAction, null); const [cloudflareState, cloudflareFormAction] = useFormState(updateCloudflareSettingsAction, null); const [authentikState, authentikFormAction] = useFormState(updateAuthentikSettingsAction, null); const [loggingState, loggingFormAction] = useFormState(updateLoggingSettingsAction, null); const [metricsState, metricsFormAction] = useFormState(updateMetricsSettingsAction, null); return ( Settings Configure organization-wide defaults and DNS automation. General {generalState?.message && ( {generalState.message} )} Cloudflare DNS Configure a Cloudflare API token with Zone.DNS Edit permissions to enable DNS-01 challenges for wildcard certificates. {cloudflare.hasToken && ( A Cloudflare API token is already configured. Leave the token field blank to keep it, or select “Remove existing token” to delete it. )} {cloudflareState?.message && ( {cloudflareState.message} )} } label="Remove existing token" disabled={!cloudflare.hasToken} /> Authentik Defaults Set default Authentik forward authentication values. These will be pre-filled when creating new proxy hosts but can be customized per host. {authentikState?.message && ( {authentikState.message} )} Logging Enable comprehensive request logging to Loki for debugging and monitoring. You must deploy your own Loki instance and provide its URL. {logging?.hasPassword && ( A Loki password is already configured. Leave the password field blank to keep it, or enter a new password to update it. )} {loggingState?.message && ( {loggingState.message} )} } label="Enable request logging" /> } label="Remove existing password" disabled={!logging?.hasPassword} /> After enabling logging, all Caddy requests will be sent to your Loki instance. You can query and visualize logs in Grafana using the Loki datasource. Metrics & Monitoring Enable Caddy metrics exposure for monitoring with Prometheus, Grafana, or other observability tools. Metrics will be available at http://caddy:{metrics?.port ?? 9090}/metrics on a separate port (NOT the admin API port for security). {metricsState?.message && ( {metricsState.message} )} } label="Enable metrics endpoint" /> After enabling metrics, configure your monitoring tool to scrape http://caddy-proxy-manager-caddy:{metrics?.port ?? 9090}/metrics from within the Docker network. To expose metrics externally, add a port mapping like "{metrics?.port ?? 9090}:{metrics?.port ?? 9090}" in docker-compose.yml. ); }