From f1d4c7385d489ab7da46b2faf9591ad92c096e65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E5=98=89=E4=BC=9F?= <8473136@qq.com> Date: Fri, 27 Mar 2026 17:26:41 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=A7=20Cloudflare=20tunnel=20support.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- migrations/1774597341_created_th_tunnels.go | 101 ++++ migrations/1774597352_updated_th_tunnels.go | 48 ++ migrations/1774597585_updated_th_tunnels.go | 45 ++ migrations/1774597885_updated_fh_proxies.go | 64 +++ migrations/1774601124_updated_fh_servers.go | 63 +++ migrations/1774601219_updated_th_tunnels.go | 48 ++ site/src/App.tsx | 9 + site/src/pages/Proxies/ProxiesPage.view.tsx | 9 +- .../ProxyFormPage/ProxyFormPage.view.tsx | 443 ++++++++++++------ .../src/pages/Proxies/ProxyFormPage/index.tsx | 4 + .../Proxies/ProxyFormPage/useProxyForm.ts | 88 +++- site/src/pages/Proxies/useProxies.ts | 2 + 12 files changed, 772 insertions(+), 152 deletions(-) create mode 100644 migrations/1774597341_created_th_tunnels.go create mode 100644 migrations/1774597352_updated_th_tunnels.go create mode 100644 migrations/1774597585_updated_th_tunnels.go create mode 100644 migrations/1774597885_updated_fh_proxies.go create mode 100644 migrations/1774601124_updated_fh_servers.go create mode 100644 migrations/1774601219_updated_th_tunnels.go diff --git a/migrations/1774597341_created_th_tunnels.go b/migrations/1774597341_created_th_tunnels.go new file mode 100644 index 0000000..fe915e4 --- /dev/null +++ b/migrations/1774597341_created_th_tunnels.go @@ -0,0 +1,101 @@ +package migrations + +import ( + "encoding/json" + + "github.com/pocketbase/pocketbase/core" + m "github.com/pocketbase/pocketbase/migrations" +) + +func init() { + m.Register(func(app core.App) error { + jsonData := `{ + "createRule": null, + "deleteRule": null, + "fields": [ + { + "autogeneratePattern": "[a-z0-9]{15}", + "hidden": false, + "id": "text3208210256", + "max": 15, + "min": 15, + "name": "id", + "pattern": "^[a-z0-9]+$", + "presentable": false, + "primaryKey": true, + "required": true, + "system": true, + "type": "text" + }, + { + "cascadeDelete": false, + "collectionId": "pbc_3738798621", + "hidden": false, + "id": "relation2665642495", + "maxSelect": 1, + "minSelect": 0, + "name": "serverId", + "presentable": false, + "required": false, + "system": false, + "type": "relation" + }, + { + "cascadeDelete": false, + "collectionId": "pbc_1339991802", + "hidden": false, + "id": "relation2332815407", + "maxSelect": 1, + "minSelect": 0, + "name": "integrationId", + "presentable": false, + "required": false, + "system": false, + "type": "relation" + }, + { + "hidden": false, + "id": "autodate2990389176", + "name": "created", + "onCreate": true, + "onUpdate": false, + "presentable": false, + "system": false, + "type": "autodate" + }, + { + "hidden": false, + "id": "autodate3332085495", + "name": "updated", + "onCreate": true, + "onUpdate": true, + "presentable": false, + "system": false, + "type": "autodate" + } + ], + "id": "pbc_2035192674", + "indexes": [], + "listRule": "", + "name": "th_tunnels", + "system": false, + "type": "base", + "updateRule": null, + "viewRule": null + }` + + collection := &core.Collection{} + if err := json.Unmarshal([]byte(jsonData), &collection); err != nil { + return err + } + + return app.Save(collection) + }, func(app core.App) error { + collection, err := app.FindCollectionByNameOrId("pbc_2035192674") + if err != nil { + return err + } + + return app.Delete(collection) + }) +} diff --git a/migrations/1774597352_updated_th_tunnels.go b/migrations/1774597352_updated_th_tunnels.go new file mode 100644 index 0000000..8e1641b --- /dev/null +++ b/migrations/1774597352_updated_th_tunnels.go @@ -0,0 +1,48 @@ +package migrations + +import ( + "encoding/json" + + "github.com/pocketbase/pocketbase/core" + m "github.com/pocketbase/pocketbase/migrations" +) + +func init() { + m.Register(func(app core.App) error { + collection, err := app.FindCollectionByNameOrId("pbc_2035192674") + if err != nil { + return err + } + + // update collection data + if err := json.Unmarshal([]byte(`{ + "createRule": "@request.auth.id != ''", + "deleteRule": "@request.auth.id != ''", + "listRule": "@request.auth.id != ''", + "updateRule": "@request.auth.id != ''", + "viewRule": "@request.auth.id != ''" + }`), &collection); err != nil { + return err + } + + return app.Save(collection) + }, func(app core.App) error { + collection, err := app.FindCollectionByNameOrId("pbc_2035192674") + if err != nil { + return err + } + + // update collection data + if err := json.Unmarshal([]byte(`{ + "createRule": null, + "deleteRule": null, + "listRule": "", + "updateRule": null, + "viewRule": null + }`), &collection); err != nil { + return err + } + + return app.Save(collection) + }) +} diff --git a/migrations/1774597585_updated_th_tunnels.go b/migrations/1774597585_updated_th_tunnels.go new file mode 100644 index 0000000..d46f0b5 --- /dev/null +++ b/migrations/1774597585_updated_th_tunnels.go @@ -0,0 +1,45 @@ +package migrations + +import ( + "github.com/pocketbase/pocketbase/core" + m "github.com/pocketbase/pocketbase/migrations" +) + +func init() { + m.Register(func(app core.App) error { + collection, err := app.FindCollectionByNameOrId("pbc_2035192674") + if err != nil { + return err + } + + // add field + if err := collection.Fields.AddMarshaledJSONAt(3, []byte(`{ + "hidden": false, + "id": "select2363381545", + "maxSelect": 1, + "name": "type", + "presentable": false, + "required": false, + "system": false, + "type": "select", + "values": [ + "frp", + "cloudflare" + ] + }`)); err != nil { + return err + } + + return app.Save(collection) + }, func(app core.App) error { + collection, err := app.FindCollectionByNameOrId("pbc_2035192674") + if err != nil { + return err + } + + // remove field + collection.Fields.RemoveById("select2363381545") + + return app.Save(collection) + }) +} diff --git a/migrations/1774597885_updated_fh_proxies.go b/migrations/1774597885_updated_fh_proxies.go new file mode 100644 index 0000000..a3f5e0c --- /dev/null +++ b/migrations/1774597885_updated_fh_proxies.go @@ -0,0 +1,64 @@ +package migrations + +import ( + "github.com/pocketbase/pocketbase/core" + m "github.com/pocketbase/pocketbase/migrations" +) + +func init() { + m.Register(func(app core.App) error { + collection, err := app.FindCollectionByNameOrId("pbc_2245327697") + if err != nil { + return err + } + + // remove field + collection.Fields.RemoveById("relation3461722399") + + // add field + if err := collection.Fields.AddMarshaledJSONAt(14, []byte(`{ + "cascadeDelete": false, + "collectionId": "pbc_2035192674", + "hidden": false, + "id": "relation3250945265", + "maxSelect": 1, + "minSelect": 0, + "name": "tunnelId", + "presentable": false, + "required": false, + "system": false, + "type": "relation" + }`)); err != nil { + return err + } + + return app.Save(collection) + }, func(app core.App) error { + collection, err := app.FindCollectionByNameOrId("pbc_2245327697") + if err != nil { + return err + } + + // add field + if err := collection.Fields.AddMarshaledJSONAt(14, []byte(`{ + "cascadeDelete": false, + "collectionId": "pbc_1339991802", + "hidden": false, + "id": "relation3461722399", + "maxSelect": 1, + "minSelect": 0, + "name": "integrationId", + "presentable": false, + "required": false, + "system": false, + "type": "relation" + }`)); err != nil { + return err + } + + // remove field + collection.Fields.RemoveById("relation3250945265") + + return app.Save(collection) + }) +} diff --git a/migrations/1774601124_updated_fh_servers.go b/migrations/1774601124_updated_fh_servers.go new file mode 100644 index 0000000..608081c --- /dev/null +++ b/migrations/1774601124_updated_fh_servers.go @@ -0,0 +1,63 @@ +package migrations + +import ( + "encoding/json" + + "github.com/pocketbase/pocketbase/core" + m "github.com/pocketbase/pocketbase/migrations" +) + +func init() { + m.Register(func(app core.App) error { + collection, err := app.FindCollectionByNameOrId("pbc_3738798621") + if err != nil { + return err + } + + // update collection data + if err := json.Unmarshal([]byte(`{ + "indexes": [] + }`), &collection); err != nil { + return err + } + + // remove field + collection.Fields.RemoveById("text1774220776") + + return app.Save(collection) + }, func(app core.App) error { + collection, err := app.FindCollectionByNameOrId("pbc_3738798621") + if err != nil { + return err + } + + // update collection data + if err := json.Unmarshal([]byte(`{ + "indexes": [ + "CREATE INDEX ` + "`" + `idx_wNtroMytle` + "`" + ` ON ` + "`" + `fh_servers` + "`" + ` (` + "`" + `bootStatus` + "`" + `)" + ] + }`), &collection); err != nil { + return err + } + + // add field + if err := collection.Fields.AddMarshaledJSONAt(10, []byte(`{ + "autogeneratePattern": "stopped", + "hidden": false, + "id": "text1774220776", + "max": 0, + "min": 0, + "name": "bootStatus", + "pattern": "", + "presentable": false, + "primaryKey": false, + "required": true, + "system": false, + "type": "text" + }`)); err != nil { + return err + } + + return app.Save(collection) + }) +} diff --git a/migrations/1774601219_updated_th_tunnels.go b/migrations/1774601219_updated_th_tunnels.go new file mode 100644 index 0000000..d287053 --- /dev/null +++ b/migrations/1774601219_updated_th_tunnels.go @@ -0,0 +1,48 @@ +package migrations + +import ( + "github.com/pocketbase/pocketbase/core" + m "github.com/pocketbase/pocketbase/migrations" +) + +func init() { + m.Register(func(app core.App) error { + collection, err := app.FindCollectionByNameOrId("pbc_2035192674") + if err != nil { + return err + } + + // add field + if err := collection.Fields.AddMarshaledJSONAt(4, []byte(`{ + "hidden": false, + "id": "select2063623452", + "maxSelect": 1, + "name": "status", + "presentable": false, + "required": false, + "system": false, + "type": "select", + "values": [ + "active", + "inactive", + "error", + "pending", + "deleting" + ] + }`)); err != nil { + return err + } + + return app.Save(collection) + }, func(app core.App) error { + collection, err := app.FindCollectionByNameOrId("pbc_2035192674") + if err != nil { + return err + } + + // remove field + collection.Fields.RemoveById("select2063623452") + + return app.Save(collection) + }) +} diff --git a/site/src/App.tsx b/site/src/App.tsx index c14ed88..cd0225c 100644 --- a/site/src/App.tsx +++ b/site/src/App.tsx @@ -32,6 +32,12 @@ const ServerFormPage = lazy(() => const ServerLogPage = lazy(() => import("./pages/ServerLog/ServerLogPage").then((m) => ({ default: m.ServerLogPage })) ); +const IntegrationsPage = lazy(() => + import("./pages/Integrations").then((m) => ({ default: m.IntegrationsPage })) +); +const IntegrationFormPage = lazy(() => + import("./pages/Integrations/IntegrationFormPage").then((m) => ({ default: m.IntegrationFormPage })) +); function AuthenticatedLayout() { console.log("AuthenticatedLayout rendered"); @@ -77,6 +83,9 @@ function App() { } /> } /> } /> + } /> + } /> + } /> {/* } /> */} diff --git a/site/src/pages/Proxies/ProxiesPage.view.tsx b/site/src/pages/Proxies/ProxiesPage.view.tsx index ebf7900..22200de 100644 --- a/site/src/pages/Proxies/ProxiesPage.view.tsx +++ b/site/src/pages/Proxies/ProxiesPage.view.tsx @@ -213,7 +213,14 @@ export function ProxiesView({ {proxy.name || -} - {proxy.proxyType.toUpperCase()} + {proxy.type === "cloudflare" ? ( + + + Cloudflare + + ) : ( + {proxy.proxyType?.toUpperCase() ?? "FRP"} + )} {(proxy as { expand?: { serverId?: { serverName?: string } } }).expand?.serverId ? ( diff --git a/site/src/pages/Proxies/ProxyFormPage/ProxyFormPage.view.tsx b/site/src/pages/Proxies/ProxyFormPage/ProxyFormPage.view.tsx index 9b716da..0f4809d 100644 --- a/site/src/pages/Proxies/ProxyFormPage/ProxyFormPage.view.tsx +++ b/site/src/pages/Proxies/ProxyFormPage/ProxyFormPage.view.tsx @@ -21,7 +21,12 @@ import { PageHeader } from "../../../components/PageHeader"; import { SectionHeading } from "../../../components/SectionHeading"; import { RadioCardGroup } from "../../../components/RadioCardGroup"; import { ServerLatency } from "../../../components/ServerLatency"; -import { type ProxyFormData, type ServerOption } from "./useProxyForm"; +import { type ProxyFormData, type ServerOption, type IntegrationOption } from "./useProxyForm"; + +const backendOptions = [ + { value: "frp", label: "FRP", icon: "lucide:server", comingSoon: false }, + { value: "cloudflare", label: "Cloudflare", icon: "simple-icons:cloudflare", comingSoon: false }, +]; const proxyTypes = [ { value: "tcp", label: "TCP", icon: "lucide:arrow-right-left", comingSoon: false }, @@ -51,34 +56,42 @@ interface ProxyFormPageViewProps { isEditing: boolean; formData: ProxyFormData; servers: ServerOption[]; + integrations: IntegrationOption[]; loadingServers: boolean; + loadingIntegrations: boolean; loadingProxy: boolean; submitting: boolean; errors: Partial>; isHttpType: boolean; isSocks5Plugin: boolean; + isCloudflare: boolean; mounted: boolean; onChange: (field: keyof ProxyFormData, value: string | boolean | string[]) => void; onSubmit: () => void; onCancel: () => void; onNavigateToServers: () => void; + onNavigateToIntegrations: () => void; } export function ProxyFormPageView({ isEditing, formData, servers, + integrations, loadingServers, + loadingIntegrations, loadingProxy, submitting, errors, isHttpType, isSocks5Plugin, + isCloudflare, mounted, onChange, onSubmit, onCancel, onNavigateToServers, + onNavigateToIntegrations, }: ProxyFormPageViewProps) { const { t } = useTranslation(); const scrollContainerRef = useRef(null); @@ -115,62 +128,144 @@ export function ProxyFormPageView({
- - onChange("serverId", v)} - disabled={loadingServers || servers.length === 0} - > - - - {servers.map((s) => ( - - - - {s.serverName} - - - - ))} - - - {servers.length === 0 && !loadingServers && ( - - - - - - - {t("proxy.noServersAvailable")} - - - - - )} + + onChange("proxyBackend", v as ProxyFormData["proxyBackend"])} + comingSoonLabel={t("common.comingSoon")} + /> + + {isCloudflare ? ( + + + onChange("integrationId", v)} + disabled={loadingIntegrations || integrations.length === 0} + > + + + {integrations.map((i) => ( + + + + {i.name} + + + ))} + + + {integrations.length === 0 && !loadingIntegrations && ( + + + + + + + {t("proxy.noIntegrationsAvailable")} + + + + + )} + + + ) : ( + + + onChange("serverId", v)} + disabled={loadingServers || servers.length === 0} + > + + + {servers.map((s) => ( + + + + {s.serverName} + + + + ))} + + + {servers.length === 0 && !loadingServers && ( + + + + + + + {t("proxy.noServersAvailable")} + + + + + )} + + + )} + + - - onChange("type", v as ProxyFormData["type"])} - comingSoonLabel={t("common.comingSoon")} - /> - + {!isCloudflare && ( + + onChange("type", v as ProxyFormData["type"])} + comingSoonLabel={t("common.comingSoon")} + /> + + )}
@@ -198,55 +295,43 @@ export function ProxyFormPageView({
- - {!isSocks5Plugin && ( - - - - - onChange("localIp", e.target.value)} - color={errors.localIp ? "red" : undefined} - /> - - - - - onChange("localPort", e.target.value)} - color={errors.localPort ? "red" : undefined} - /> - - - - - )} - - - {isHttpType ? ( + {isCloudflare ? ( <> - + {/* Cloudflare: local service + public hostnames */} + + + + onChange("localIp", e.target.value)} + color={errors.localIp ? "red" : undefined} + /> + + + + + onChange("localPort", e.target.value)} + color={errors.localPort ? "red" : undefined} + /> + + + + + {formData.customDomains.map((domain, index) => ( { const next = [...formData.customDomains]; @@ -275,44 +360,134 @@ export function ProxyFormPageView({ onClick={() => onChange("customDomains", [...formData.customDomains, ""])} > - {t("proxy.addCustomDomain")} + {t("proxy.addHostname")} - - - onChange("subdomain", e.target.value)} - /> - {t("proxy.subdomainDesc")} + {t("proxy.publicHostnamesDesc")} ) : ( - - onChange("remotePort", e.target.value)} - color={errors.remotePort ? "red" : undefined} - /> - - {t("proxy.remotePortDesc")} - - + <> + {/* FRP: local addr + remote port or domain */} + + {!isSocks5Plugin && ( + + + + + onChange("localIp", e.target.value)} + color={errors.localIp ? "red" : undefined} + /> + + + + + onChange("localPort", e.target.value)} + color={errors.localPort ? "red" : undefined} + /> + + + + + )} + + + {isHttpType ? ( + <> + + + {formData.customDomains.map((domain, index) => ( + + { + const next = [...formData.customDomains]; + next[index] = e.target.value; + onChange("customDomains", next); + }} + /> + + + ))} + + + + + onChange("subdomain", e.target.value)} + /> + + {t("proxy.subdomainDesc")} + + + + ) : ( + + onChange("remotePort", e.target.value)} + color={errors.remotePort ? "red" : undefined} + /> + + {t("proxy.remotePortDesc")} + + + )} + )}
- + {!isCloudflare && } {/* 传输选项 */} -
+ {!isCloudflare &&
@@ -339,12 +514,12 @@ export function ProxyFormPageView({ /> -
+
} - + {!isCloudflare && } {/* 插件 */} -
+ {!isCloudflare &&
@@ -414,7 +589,7 @@ export function ProxyFormPageView({ )} -
+
} diff --git a/site/src/pages/Proxies/ProxyFormPage/index.tsx b/site/src/pages/Proxies/ProxyFormPage/index.tsx index b56a1fe..38be5e8 100644 --- a/site/src/pages/Proxies/ProxyFormPage/index.tsx +++ b/site/src/pages/Proxies/ProxyFormPage/index.tsx @@ -16,17 +16,21 @@ export function ProxyFormPage() { isEditing={form.isEditing} formData={form.formData} servers={form.servers} + integrations={form.integrations} loadingServers={form.loadingServers} + loadingIntegrations={form.loadingIntegrations} loadingProxy={form.loadingProxy} submitting={form.submitting} errors={form.errors} isHttpType={form.isHttpType} isSocks5Plugin={form.isSocks5Plugin} + isCloudflare={form.isCloudflare} mounted={mounted} onChange={form.handleChange} onSubmit={form.handleSubmit} onCancel={() => form.navigate("/proxies")} onNavigateToServers={() => form.navigate("/servers")} + onNavigateToIntegrations={() => form.navigate("/integrations")} /> ); } diff --git a/site/src/pages/Proxies/ProxyFormPage/useProxyForm.ts b/site/src/pages/Proxies/ProxyFormPage/useProxyForm.ts index ab6f716..9f1cd7d 100644 --- a/site/src/pages/Proxies/ProxyFormPage/useProxyForm.ts +++ b/site/src/pages/Proxies/ProxyFormPage/useProxyForm.ts @@ -6,8 +6,17 @@ import { apiGet } from "../../../lib/api"; import { toast } from "sonner"; import { REGEX } from "../../../lib/regex"; +export interface IntegrationOption { + id: string; + name: string; + integrationsType: string; + status: string; +} + export interface ProxyFormData { + proxyBackend: "frp" | "cloudflare"; serverId: string; + integrationId: string; name: string; type: "tcp" | "udp" | "http" | "https" | "tcpmux" | "stcp" | "sudp" | "xtcp"; localIp: string; @@ -25,7 +34,9 @@ export interface ProxyFormData { } const DEFAULT_FORM: ProxyFormData = { + proxyBackend: "frp", serverId: "", + integrationId: "", name: "", type: "tcp", localIp: "127.0.0.1", @@ -60,7 +71,9 @@ export function useProxyForm() { const [formData, setFormData] = useState(DEFAULT_FORM); const [servers, setServers] = useState([]); + const [integrations, setIntegrations] = useState([]); const [loadingServers, setLoadingServers] = useState(false); + const [loadingIntegrations, setLoadingIntegrations] = useState(false); const [loadingProxy, setLoadingProxy] = useState(isEditing); const [submitting, setSubmitting] = useState(false); const [errors, setErrors] = useState>>({}); @@ -86,6 +99,24 @@ export function useProxyForm() { fetchServers(); }, [isEditing]); + useEffect(() => { + const fetchIntegrations = async () => { + try { + setLoadingIntegrations(true); + const result = await pb.collection("fh_integrations").getFullList({ + sort: "name", + fields: "id,name,integrationsType,status", + }); + setIntegrations(result); + } catch (err) { + console.error("Failed to fetch integrations:", err); + } finally { + setLoadingIntegrations(false); + } + }; + fetchIntegrations(); + }, []); + useEffect(() => { if (!id) return; const fetchProxy = async () => { @@ -94,7 +125,9 @@ export function useProxyForm() { const record = await pb.collection("fh_proxies").getOne(id); const plugin = record.plugin as Record | null | undefined; setFormData({ - serverId: record.serverId as string, + proxyBackend: (record.type as ProxyFormData["proxyBackend"]) || "frp", + serverId: (record.serverId as string) || "", + integrationId: (record.integrationId as string) || "", name: (record.name as string) || "", type: record.proxyType as ProxyFormData["type"], localIp: (record.localIP as string) || "127.0.0.1", @@ -154,29 +187,42 @@ export function useProxyForm() { }; const validate = (data: ProxyFormData): boolean => { + const isCloudflare = data.proxyBackend === "cloudflare"; const isHttp = data.type === "http" || data.type === "https"; const isSocks5 = data.pluginEnabled && data.pluginType === "socks5"; const newErrors: Partial> = {}; - if (!data.serverId) newErrors.serverId = t("proxy.errorRequired"); if (!data.name) newErrors.name = t("proxy.errorRequired"); else if (!REGEX.PROXY_NAME.test(data.name)) newErrors.name = t("proxy.errorInvalidName"); - if (!isSocks5) { + if (isCloudflare) { + if (!data.integrationId) newErrors.integrationId = t("proxy.errorRequired"); if (!data.localIp) newErrors.localIp = t("proxy.errorRequired"); else if (!REGEX.IP_OR_HOSTNAME.test(data.localIp)) newErrors.localIp = t("proxy.errorInvalidIP"); - if (!data.localPort) newErrors.localPort = t("proxy.errorRequired"); else if (!REGEX.PORT.test(data.localPort)) newErrors.localPort = t("proxy.errorInvalidPort"); - } + if (data.customDomains.length === 0 || data.customDomains.every((d) => !d.trim())) { + newErrors.customDomains = t("proxy.errorHostnameRequired"); + } + } else { + if (!data.serverId) newErrors.serverId = t("proxy.errorRequired"); - if (!isHttp && !isSocks5) { - if (!data.remotePort) newErrors.remotePort = t("proxy.errorRequired"); - else if (!REGEX.PORT.test(data.remotePort)) newErrors.remotePort = t("proxy.errorInvalidPort"); - } + if (!isSocks5) { + if (!data.localIp) newErrors.localIp = t("proxy.errorRequired"); + else if (!REGEX.IP_OR_HOSTNAME.test(data.localIp)) newErrors.localIp = t("proxy.errorInvalidIP"); - if (isHttp && !data.subdomain && data.customDomains.length === 0) { - newErrors.subdomain = t("proxy.errorSubdomainRequired"); + if (!data.localPort) newErrors.localPort = t("proxy.errorRequired"); + else if (!REGEX.PORT.test(data.localPort)) newErrors.localPort = t("proxy.errorInvalidPort"); + } + + if (!isHttp && !isSocks5) { + if (!data.remotePort) newErrors.remotePort = t("proxy.errorRequired"); + else if (!REGEX.PORT.test(data.remotePort)) newErrors.remotePort = t("proxy.errorInvalidPort"); + } + + if (isHttp && !data.subdomain && data.customDomains.length === 0) { + newErrors.subdomain = t("proxy.errorSubdomainRequired"); + } } setErrors(newErrors); @@ -194,20 +240,24 @@ export function useProxyForm() { } : null; + const isCloudflare = formData.proxyBackend === "cloudflare"; + const payload = { - serverId: formData.serverId, + type: formData.proxyBackend, + serverId: isCloudflare ? "" : formData.serverId, + integrationId: isCloudflare ? formData.integrationId : "", proxyType: formData.type, name: formData.name, - localIP: formData.localIp, - localPort: formData.localPort, - remotePort: formData.remotePort, + localIP: isCloudflare ? "" : formData.localIp, + localPort: isCloudflare ? "" : formData.localPort, + remotePort: isCloudflare ? "" : formData.remotePort, subdomain: formData.subdomain, customDomains: formData.customDomains, - transport: { + transport: isCloudflare ? null : { use_encryption: formData.encryption, use_compression: formData.compression, }, - plugin, + plugin: isCloudflare ? null : plugin, description: formData.description, status: "enabled", }; @@ -231,17 +281,21 @@ export function useProxyForm() { const isHttpType = formData.type === "http" || formData.type === "https"; const isSocks5Plugin = formData.pluginEnabled && formData.pluginType === "socks5"; + const isCloudflare = formData.proxyBackend === "cloudflare"; return { isEditing, formData, servers, + integrations, loadingServers, + loadingIntegrations, loadingProxy, submitting, errors, isHttpType, isSocks5Plugin, + isCloudflare, handleChange, handleSubmit, navigate, diff --git a/site/src/pages/Proxies/useProxies.ts b/site/src/pages/Proxies/useProxies.ts index bf31ee4..e10cef8 100644 --- a/site/src/pages/Proxies/useProxies.ts +++ b/site/src/pages/Proxies/useProxies.ts @@ -5,7 +5,9 @@ import { toast } from "sonner"; export interface Proxy { id: string; + type: "frp" | "cloudflare"; serverId: string; + integrationId?: string; proxyType: "tcp" | "udp" | "http" | "https"; name?: string; localIP?: string;