diff --git a/frontend/src/app/(hub)/servers/[id]/page.tsx b/frontend/src/app/(hub)/servers/[id]/page.tsx
index e180147..ced837f 100644
--- a/frontend/src/app/(hub)/servers/[id]/page.tsx
+++ b/frontend/src/app/(hub)/servers/[id]/page.tsx
@@ -1,13 +1,13 @@
"use client";
-import React, { useCallback, useEffect, useState } from "react";
+import React, { useCallback, useEffect, useMemo, useState } from "react";
import Link from "next/link";
import { useParams, useRouter } from "next/navigation";
-import { Plus, Trash2 } from "lucide-react";
+import { Plus, Trash2, Upload } from "lucide-react";
import { api, errorText } from "@/lib/api";
import { ago, bytes, fmtDate } from "@/lib/format";
import { useServerPaged } from "@/lib/paging";
-import { Loading, Message, PageTitle, Pager } from "@/components/ui";
+import { Field, Fields, FormError, Loading, Message, Modal, ModalButtons, PageMessage, PageTitle, Pager, ReadCard, useSubmit } from "@/components/ui";
import { PercentChart, ServersNav, StatusPill, pct, type Deployment, type Job, type ServerSummary } from "@/components/servers";
import { FrpConfig, type FrpState } from "@/components/FrpConfig";
@@ -32,36 +32,56 @@ const SUGGESTED: { key: string; hint: string }[] = [
{ key: "DB_ADMIN_URL", hint: "postgresql://admin:…@host/postgres: may create databases and roles. Blank: the local PostgreSQL via sudo -u postgres" },
];
-function ConfigEditor({ id, config, onSaved }: { id: string; config: Record; onSaved: (m: Msg) => void }) {
- const [rows, setRows] = useState<[string, string][]>(() => {
- const keys = [...new Set([...SUGGESTED.map(s => s.key), ...Object.keys(config)])];
- return keys.map(k => [k, config[k] ?? (k === "TRUST_PROXY" ? "loopback" : "")]);
- });
+/** The keys a church server's configuration shows: the suggested ones, then any others it has. */
+const configKeys = (config: Record) => [...new Set([...SUGGESTED.map(x => x.key), ...Object.keys(config)])];
+
+/** Hub 2.17.0: the server's configuration, edited in a popup. */
+function ConfigModal({ id, config, onClose, onSaved }: { id: string; config: Record; onClose: () => void; onSaved: (text: string) => void }) {
+ const initial = useMemo<[string, string][]>(() => configKeys(config).map(k => [k, config[k] ?? (k === "TRUST_PROXY" ? "loopback" : "")]), [config]);
+ const [rows, setRows] = useState(initial);
+ const { busy, error, run } = useSubmit();
const set = (i: number, j: 0 | 1, v: string) => setRows(rows.map((r, n) => (n === i ? (j === 0 ? [v.toUpperCase(), r[1]] : [r[0], v]) : r)));
- const save = async () => {
- try {
+ const save = (e: React.FormEvent) => {
+ e.preventDefault();
+ run(async () => {
await api(`/api/admin/servers/${id}/config`, { method: "PUT", body: { values: Object.fromEntries(rows.filter(r => r[0].trim())) } });
- onSaved({ type: "ok", text: "Configuration saved. Jobs from now on carry it, sealed to this server's key." });
- } catch (e) { onSaved({ type: "err", text: errorText(e) }); }
+ onSaved("Configuration saved. Jobs from now on carry it, sealed to this server's key.");
+ });
};
return (
-
-
Configuration
-
The server layer of every install's .env here. Stored encrypted; sent only inside jobs, sealed to this server. Values ending in _URL, KEY, SECRET or PASSWORD show as dots: leave them to keep them.
Asks the agent what's on the server. A site added there without the Hub (crosscode add, or by hand) is added to Installs and tied to its registration. It also runs by itself once a day when a registered site has no install record here.
Every port frps opens on the central server must be unique across servers. Mark ports used by anything else (today's tunnels written by hand) as taken.
-
{!ports ? : (
Port
Use
Server
Note
diff --git a/frontend/src/components/FrpConfig.tsx b/frontend/src/components/FrpConfig.tsx
index 6bc29f1..cb9f4c0 100644
--- a/frontend/src/components/FrpConfig.tsx
+++ b/frontend/src/components/FrpConfig.tsx
@@ -2,10 +2,11 @@
import React, { useEffect, useState } from "react";
import Link from "next/link";
-import { RefreshCw, Save } from "lucide-react";
+import { Pencil, RefreshCw } from "lucide-react";
import { api, errorText } from "@/lib/api";
import { fmtDate } from "@/lib/format";
import { StatusPill } from "@/components/servers";
+import { FormError, Modal, ModalButtons, useSubmit } from "@/components/ui";
/**
* frps's config (central server) or frpc's (church server) from the Hub (2.11.0, agent 1.4.0):
@@ -42,18 +43,49 @@ function atLeast(have: string | null, need: string): boolean {
return true;
}
+/**
+ * Hub 2.17.0: the config file edited in a popup. Saving asks first (every tunnel drops while frp
+ * restarts) and needs a two-factor code.
+ */
+function FrpEditModal({ serverId, frp, read, onClose, onSent }: { serverId: string; frp: FrpState; read: FrpRead; onClose: () => void; onSent: (text: string) => void }) {
+ const [content, setContent] = useState(read.content ?? "");
+ const [restart, setRestart] = useState(true);
+ const [totp, setTotp] = useState("");
+ const { busy, error, run } = useSubmit();
+ const edited = content !== (read.content ?? "");
+ const save = (e: React.FormEvent) => {
+ e.preventDefault();
+ if (!read.path || !window.confirm(`Replace ${read.path} on the server${restart ? ` and restart ${frp.service}` : ""}? Every church site's tunnel drops for a few seconds while ${frp.service} restarts.`)) return;
+ run(async () => {
+ await api(`/api/admin/servers/${serverId}/frp/write`, { method: "POST", body: { content, restart, totp } });
+ onSent(`Sent: the agent checks it with ${frp.service} verify, keeps a backup${restart ? `, restarts ${frp.service}` : ""}, and puts the old file back if ${frp.service} doesn't start.`);
+ });
+ };
+ return (
+ Edit {read.path}>} onClose={onClose} dirty={edited} wide>
+
+
+ );
+}
+
export function FrpConfig({ serverId, agentVersion, frp, onChange }: { serverId: string; agentVersion: string | null; frp: FrpState; onChange: (m: Msg) => void }) {
const read = frp.read;
const [path, setPath] = useState(frp.path || read?.path || "");
- const [content, setContent] = useState(read?.content ?? "");
- const [restart, setRestart] = useState(true);
- const [totp, setTotp] = useState("");
const [busy, setBusy] = useState(false);
+ const [editing, setEditing] = useState(false);
const supported = atLeast(agentVersion, frp.minAgent);
- const edited = !!read?.found && content !== (read.content ?? "");
- // A new read replaces what's in the editor.
- useEffect(() => { setContent(read?.content ?? ""); }, [read?.readAt, read?.content]);
useEffect(() => { setPath(frp.path || read?.path || ""); }, [frp.path, read?.path]);
const go = async (url: string, body: Record, ok: string) => {
@@ -61,22 +93,21 @@ export function FrpConfig({ serverId, agentVersion, frp, onChange }: { serverId:
try {
await api(url, { method: "POST", body });
onChange({ type: "ok", text: ok });
- setTotp("");
} catch (e) { onChange({ type: "err", text: errorText(e) }); }
setBusy(false);
};
const readNow = (withPath: boolean) => go(`/api/admin/servers/${serverId}/frp/read`, withPath ? { path: path.trim() } : {}, "Asked the agent to read the config: it shows here within a minute (reload the page).");
- const save = (e: React.FormEvent) => {
- e.preventDefault();
- if (!read?.path || !window.confirm(`Replace ${read.path} on the server${restart ? ` and restart ${frp.service}` : ""}? Every church site's tunnel drops for a few seconds while ${frp.service} restarts.`)) return;
- go(`/api/admin/servers/${serverId}/frp/write`, { content, restart, totp }, `Sent: the agent checks it with ${frp.service} verify, keeps a backup${restart ? `, restarts ${frp.service}` : ""}, and puts the old file back if ${frp.service} doesn't start.`);
- };
return (
frp config ({frp.service})
- {frp.pending && {frp.pending.type === "frp-write" ? "A change" : "A read"} is on its way: {frp.pending.status}}
+
+ {frp.pending && {frp.pending.type === "frp-write" ? "A change" : "A read"} is on its way: {frp.pending.status}}
+ {read?.found && supported && (
+
+ )}
+
{!supported &&
The agent here is {agentVersion || "an unknown version"}; reading and changing frp's config needs agent {frp.minAgent} or later. Update the agent first.