mirror of
https://github.com/luckjiawei/podux.git
synced 2026-12-02 18:16:50 +00:00
🚧 Cloudflare tunnel support.
This commit is contained in:
1 parent
8578c204ab
commit
f1d4c7385d
12 files changed
+772
-152
No files matched your search
@@ -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)
|
||||
})
|
||||
}
|
||||
@@ -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)
|
||||
})
|
||||
}
|
||||
@@ -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)
|
||||
})
|
||||
}
|
||||
@@ -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)
|
||||
})
|
||||
}
|
||||
@@ -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)
|
||||
})
|
||||
}
|
||||
@@ -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)
|
||||
})
|
||||
}
|
||||
@@ -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() {
|
||||
<Route path="/servers/:id/logs" element={<ServerLogPage />} />
|
||||
<Route path="/settings" element={<SettingsPage />} />
|
||||
<Route path="/import" element={<ImportPage />} />
|
||||
<Route path="/integrations" element={<IntegrationsPage />} />
|
||||
<Route path="/integrations/new" element={<IntegrationFormPage />} />
|
||||
<Route path="/integrations/:id/edit" element={<IntegrationFormPage />} />
|
||||
{/* <Route path="/versions" element={<VersionPage />} /> */}
|
||||
</Route>
|
||||
|
||||
|
||||
@@ -213,7 +213,14 @@ export function ProxiesView({
|
||||
<Text weight="medium">{proxy.name || <Text color="gray">-</Text>}</Text>
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
<Badge variant="surface">{proxy.proxyType.toUpperCase()}</Badge>
|
||||
{proxy.type === "cloudflare" ? (
|
||||
<Badge variant="surface" color="orange">
|
||||
<Icon icon="simple-icons:cloudflare" width="10" height="10" />
|
||||
Cloudflare
|
||||
</Badge>
|
||||
) : (
|
||||
<Badge variant="surface">{proxy.proxyType?.toUpperCase() ?? "FRP"}</Badge>
|
||||
)}
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
{(proxy as { expand?: { serverId?: { serverName?: string } } }).expand?.serverId ? (
|
||||
|
||||
@@ -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<Record<keyof ProxyFormData, string>>;
|
||||
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<HTMLDivElement>(null);
|
||||
@@ -115,62 +128,144 @@ export function ProxyFormPageView({
|
||||
<section>
|
||||
<SectionHeading id="section-basic" title={t("proxy.sectionBasic")} icon="lucide:info" />
|
||||
<Flex direction="column" gap="4">
|
||||
<FormItem label={t("proxy.selectServer")} required>
|
||||
<Select.Root
|
||||
value={formData.serverId}
|
||||
onValueChange={(v) => onChange("serverId", v)}
|
||||
disabled={loadingServers || servers.length === 0}
|
||||
>
|
||||
<Select.Trigger
|
||||
placeholder={
|
||||
loadingServers
|
||||
? t("common.loading")
|
||||
: servers.length === 0
|
||||
? t("proxy.noServersAvailable")
|
||||
: t("proxy.selectServerPlaceholder")
|
||||
}
|
||||
style={{ width: "100%" }}
|
||||
/>
|
||||
<Select.Content>
|
||||
{servers.map((s) => (
|
||||
<Select.Item key={s.id} value={s.id}>
|
||||
<Flex align="center" gap="2">
|
||||
<span
|
||||
className={`inline-block h-1.5 w-1.5 shrink-0 rounded-full ${
|
||||
s.bootStatus === "running" ? "bg-[var(--green-9)]" : "bg-[var(--gray-7)]"
|
||||
}`}
|
||||
/>
|
||||
<Text size="2">{s.serverName}</Text>
|
||||
<ServerLatency networkStatus={s.networkStatus} size="1" />
|
||||
</Flex>
|
||||
</Select.Item>
|
||||
))}
|
||||
</Select.Content>
|
||||
</Select.Root>
|
||||
{servers.length === 0 && !loadingServers && (
|
||||
<Callout.Root size="1" color="orange" mt="2">
|
||||
<Callout.Icon>
|
||||
<Icon icon="lucide:triangle-alert" width="14" height="14" />
|
||||
</Callout.Icon>
|
||||
<Callout.Text>
|
||||
<Flex align="center" justify="between" gap="2">
|
||||
<Text size="1">{t("proxy.noServersAvailable")}</Text>
|
||||
<Button
|
||||
size="1"
|
||||
variant="ghost"
|
||||
color="orange"
|
||||
className="cursor-pointer shrink-0"
|
||||
onClick={onNavigateToServers}
|
||||
>
|
||||
{t("proxy.goAddServer")}
|
||||
<Icon icon="lucide:arrow-right" width="12" height="12" />
|
||||
</Button>
|
||||
</Flex>
|
||||
</Callout.Text>
|
||||
</Callout.Root>
|
||||
)}
|
||||
<FormItem label={t("proxy.proxyBackend")} required>
|
||||
<RadioCardGroup
|
||||
options={backendOptions}
|
||||
value={formData.proxyBackend}
|
||||
onChange={(v) => onChange("proxyBackend", v as ProxyFormData["proxyBackend"])}
|
||||
comingSoonLabel={t("common.comingSoon")}
|
||||
/>
|
||||
</FormItem>
|
||||
|
||||
<AnimatePresence mode="wait">
|
||||
{isCloudflare ? (
|
||||
<motion.div
|
||||
key="integration-selector"
|
||||
initial={{ opacity: 0, height: 0 }}
|
||||
animate={{ opacity: 1, height: "auto" }}
|
||||
exit={{ opacity: 0, height: 0 }}
|
||||
transition={{ duration: 0.2, ease: "easeInOut" }}
|
||||
style={{ overflow: "hidden" }}
|
||||
>
|
||||
<FormItem label={t("proxy.selectIntegration")} required error={errors.integrationId}>
|
||||
<Select.Root
|
||||
value={formData.integrationId}
|
||||
onValueChange={(v) => onChange("integrationId", v)}
|
||||
disabled={loadingIntegrations || integrations.length === 0}
|
||||
>
|
||||
<Select.Trigger
|
||||
placeholder={
|
||||
loadingIntegrations
|
||||
? t("common.loading")
|
||||
: integrations.length === 0
|
||||
? t("proxy.noIntegrationsAvailable")
|
||||
: t("proxy.selectIntegrationPlaceholder")
|
||||
}
|
||||
style={{ width: "100%" }}
|
||||
/>
|
||||
<Select.Content>
|
||||
{integrations.map((i) => (
|
||||
<Select.Item key={i.id} value={i.id}>
|
||||
<Flex align="center" gap="2">
|
||||
<Icon icon="lucide:plug" width="12" height="12" />
|
||||
<Text size="2">{i.name}</Text>
|
||||
</Flex>
|
||||
</Select.Item>
|
||||
))}
|
||||
</Select.Content>
|
||||
</Select.Root>
|
||||
{integrations.length === 0 && !loadingIntegrations && (
|
||||
<Callout.Root size="1" color="orange" mt="2">
|
||||
<Callout.Icon>
|
||||
<Icon icon="lucide:triangle-alert" width="14" height="14" />
|
||||
</Callout.Icon>
|
||||
<Callout.Text>
|
||||
<Flex align="center" justify="between" gap="2">
|
||||
<Text size="1">{t("proxy.noIntegrationsAvailable")}</Text>
|
||||
<Button
|
||||
size="1"
|
||||
variant="ghost"
|
||||
color="orange"
|
||||
className="cursor-pointer shrink-0"
|
||||
onClick={onNavigateToIntegrations}
|
||||
>
|
||||
{t("proxy.goAddIntegration")}
|
||||
<Icon icon="lucide:arrow-right" width="12" height="12" />
|
||||
</Button>
|
||||
</Flex>
|
||||
</Callout.Text>
|
||||
</Callout.Root>
|
||||
)}
|
||||
</FormItem>
|
||||
</motion.div>
|
||||
) : (
|
||||
<motion.div
|
||||
key="server-selector"
|
||||
initial={{ opacity: 0, height: 0 }}
|
||||
animate={{ opacity: 1, height: "auto" }}
|
||||
exit={{ opacity: 0, height: 0 }}
|
||||
transition={{ duration: 0.2, ease: "easeInOut" }}
|
||||
style={{ overflow: "hidden" }}
|
||||
>
|
||||
<FormItem label={t("proxy.selectServer")} required error={errors.serverId}>
|
||||
<Select.Root
|
||||
value={formData.serverId}
|
||||
onValueChange={(v) => onChange("serverId", v)}
|
||||
disabled={loadingServers || servers.length === 0}
|
||||
>
|
||||
<Select.Trigger
|
||||
placeholder={
|
||||
loadingServers
|
||||
? t("common.loading")
|
||||
: servers.length === 0
|
||||
? t("proxy.noServersAvailable")
|
||||
: t("proxy.selectServerPlaceholder")
|
||||
}
|
||||
style={{ width: "100%" }}
|
||||
/>
|
||||
<Select.Content>
|
||||
{servers.map((s) => (
|
||||
<Select.Item key={s.id} value={s.id}>
|
||||
<Flex align="center" gap="2">
|
||||
<span
|
||||
className={`inline-block h-1.5 w-1.5 shrink-0 rounded-full ${
|
||||
s.bootStatus === "running" ? "bg-[var(--green-9)]" : "bg-[var(--gray-7)]"
|
||||
}`}
|
||||
/>
|
||||
<Text size="2">{s.serverName}</Text>
|
||||
<ServerLatency networkStatus={s.networkStatus} size="1" />
|
||||
</Flex>
|
||||
</Select.Item>
|
||||
))}
|
||||
</Select.Content>
|
||||
</Select.Root>
|
||||
{servers.length === 0 && !loadingServers && (
|
||||
<Callout.Root size="1" color="orange" mt="2">
|
||||
<Callout.Icon>
|
||||
<Icon icon="lucide:triangle-alert" width="14" height="14" />
|
||||
</Callout.Icon>
|
||||
<Callout.Text>
|
||||
<Flex align="center" justify="between" gap="2">
|
||||
<Text size="1">{t("proxy.noServersAvailable")}</Text>
|
||||
<Button
|
||||
size="1"
|
||||
variant="ghost"
|
||||
color="orange"
|
||||
className="cursor-pointer shrink-0"
|
||||
onClick={onNavigateToServers}
|
||||
>
|
||||
{t("proxy.goAddServer")}
|
||||
<Icon icon="lucide:arrow-right" width="12" height="12" />
|
||||
</Button>
|
||||
</Flex>
|
||||
</Callout.Text>
|
||||
</Callout.Root>
|
||||
)}
|
||||
</FormItem>
|
||||
</motion.div>
|
||||
)}
|
||||
</AnimatePresence>
|
||||
|
||||
<FormItem label={t("proxy.proxyName")} required error={errors.name}>
|
||||
<TextField.Root
|
||||
size="2"
|
||||
@@ -181,14 +276,16 @@ export function ProxyFormPageView({
|
||||
/>
|
||||
</FormItem>
|
||||
|
||||
<FormItem label={t("proxy.proxyType")} required>
|
||||
<RadioCardGroup
|
||||
options={proxyTypes}
|
||||
value={formData.type}
|
||||
onChange={(v) => onChange("type", v as ProxyFormData["type"])}
|
||||
comingSoonLabel={t("common.comingSoon")}
|
||||
/>
|
||||
</FormItem>
|
||||
{!isCloudflare && (
|
||||
<FormItem label={t("proxy.proxyType")} required>
|
||||
<RadioCardGroup
|
||||
options={proxyTypes}
|
||||
value={formData.type}
|
||||
onChange={(v) => onChange("type", v as ProxyFormData["type"])}
|
||||
comingSoonLabel={t("common.comingSoon")}
|
||||
/>
|
||||
</FormItem>
|
||||
)}
|
||||
</Flex>
|
||||
</section>
|
||||
|
||||
@@ -198,55 +295,43 @@ export function ProxyFormPageView({
|
||||
<section>
|
||||
<SectionHeading id="section-network" title={t("proxy.sectionNetwork")} icon="lucide:network" />
|
||||
<Flex direction="column" gap="4">
|
||||
<AnimatePresence>
|
||||
{!isSocks5Plugin && (
|
||||
<motion.div
|
||||
key="local-addr"
|
||||
initial={{ opacity: 0, height: 0 }}
|
||||
animate={{ opacity: 1, height: "auto" }}
|
||||
exit={{ opacity: 0, height: 0 }}
|
||||
transition={{ duration: 0.2, ease: "easeInOut" }}
|
||||
style={{ overflow: "hidden" }}
|
||||
>
|
||||
<Flex gap="3">
|
||||
<Box className="flex-[2]">
|
||||
<FormItem label={t("proxy.localAddress")} required error={errors.localIp}>
|
||||
<TextField.Root
|
||||
size="2"
|
||||
placeholder={t("proxy.localAddressPlaceholder")}
|
||||
value={formData.localIp}
|
||||
onChange={(e) => onChange("localIp", e.target.value)}
|
||||
color={errors.localIp ? "red" : undefined}
|
||||
/>
|
||||
</FormItem>
|
||||
</Box>
|
||||
<Box className="flex-1">
|
||||
<FormItem label={t("proxy.localPort")} required error={errors.localPort}>
|
||||
<TextField.Root
|
||||
size="2"
|
||||
placeholder={t("proxy.localPortPlaceholder")}
|
||||
type="number"
|
||||
value={formData.localPort}
|
||||
onChange={(e) => onChange("localPort", e.target.value)}
|
||||
color={errors.localPort ? "red" : undefined}
|
||||
/>
|
||||
</FormItem>
|
||||
</Box>
|
||||
</Flex>
|
||||
</motion.div>
|
||||
)}
|
||||
</AnimatePresence>
|
||||
|
||||
{isHttpType ? (
|
||||
{isCloudflare ? (
|
||||
<>
|
||||
<FormItem label={t("proxy.customDomainsLabel")}>
|
||||
{/* Cloudflare: local service + public hostnames */}
|
||||
<Flex gap="3">
|
||||
<Box className="flex-[2]">
|
||||
<FormItem label={t("proxy.localAddress")} required error={errors.localIp}>
|
||||
<TextField.Root
|
||||
size="2"
|
||||
placeholder={t("proxy.localAddressPlaceholder")}
|
||||
value={formData.localIp}
|
||||
onChange={(e) => onChange("localIp", e.target.value)}
|
||||
color={errors.localIp ? "red" : undefined}
|
||||
/>
|
||||
</FormItem>
|
||||
</Box>
|
||||
<Box className="flex-1">
|
||||
<FormItem label={t("proxy.localPort")} required error={errors.localPort}>
|
||||
<TextField.Root
|
||||
size="2"
|
||||
placeholder={t("proxy.localPortPlaceholder")}
|
||||
type="number"
|
||||
value={formData.localPort}
|
||||
onChange={(e) => onChange("localPort", e.target.value)}
|
||||
color={errors.localPort ? "red" : undefined}
|
||||
/>
|
||||
</FormItem>
|
||||
</Box>
|
||||
</Flex>
|
||||
|
||||
<FormItem label={t("proxy.publicHostnames")} required error={errors.customDomains}>
|
||||
<Flex direction="column" gap="2">
|
||||
{formData.customDomains.map((domain, index) => (
|
||||
<Flex key={index} gap="2" align="center">
|
||||
<TextField.Root
|
||||
size="2"
|
||||
style={{ flex: 1 }}
|
||||
placeholder={`example.com`}
|
||||
placeholder="app.example.com"
|
||||
value={domain}
|
||||
onChange={(e) => {
|
||||
const next = [...formData.customDomains];
|
||||
@@ -275,44 +360,134 @@ export function ProxyFormPageView({
|
||||
onClick={() => onChange("customDomains", [...formData.customDomains, ""])}
|
||||
>
|
||||
<Icon icon="lucide:plus" />
|
||||
{t("proxy.addCustomDomain")}
|
||||
{t("proxy.addHostname")}
|
||||
</Button>
|
||||
</Flex>
|
||||
</FormItem>
|
||||
<FormItem label={t("proxy.subdomain")}>
|
||||
<TextField.Root
|
||||
size="2"
|
||||
placeholder={t("proxy.subdomainPlaceholder")}
|
||||
value={formData.subdomain}
|
||||
onChange={(e) => onChange("subdomain", e.target.value)}
|
||||
/>
|
||||
<Text size="1" color="gray" mt="1">
|
||||
{t("proxy.subdomainDesc")}
|
||||
{t("proxy.publicHostnamesDesc")}
|
||||
</Text>
|
||||
</FormItem>
|
||||
</>
|
||||
) : (
|
||||
<FormItem label={t("proxy.remotePortLabel")} required error={errors.remotePort}>
|
||||
<TextField.Root
|
||||
size="2"
|
||||
placeholder={t("proxy.remotePortPlaceholder")}
|
||||
type="number"
|
||||
value={formData.remotePort}
|
||||
onChange={(e) => onChange("remotePort", e.target.value)}
|
||||
color={errors.remotePort ? "red" : undefined}
|
||||
/>
|
||||
<Text size="1" color="gray" mt="1">
|
||||
{t("proxy.remotePortDesc")}
|
||||
</Text>
|
||||
</FormItem>
|
||||
<>
|
||||
{/* FRP: local addr + remote port or domain */}
|
||||
<AnimatePresence>
|
||||
{!isSocks5Plugin && (
|
||||
<motion.div
|
||||
key="local-addr"
|
||||
initial={{ opacity: 0, height: 0 }}
|
||||
animate={{ opacity: 1, height: "auto" }}
|
||||
exit={{ opacity: 0, height: 0 }}
|
||||
transition={{ duration: 0.2, ease: "easeInOut" }}
|
||||
style={{ overflow: "hidden" }}
|
||||
>
|
||||
<Flex gap="3">
|
||||
<Box className="flex-[2]">
|
||||
<FormItem label={t("proxy.localAddress")} required error={errors.localIp}>
|
||||
<TextField.Root
|
||||
size="2"
|
||||
placeholder={t("proxy.localAddressPlaceholder")}
|
||||
value={formData.localIp}
|
||||
onChange={(e) => onChange("localIp", e.target.value)}
|
||||
color={errors.localIp ? "red" : undefined}
|
||||
/>
|
||||
</FormItem>
|
||||
</Box>
|
||||
<Box className="flex-1">
|
||||
<FormItem label={t("proxy.localPort")} required error={errors.localPort}>
|
||||
<TextField.Root
|
||||
size="2"
|
||||
placeholder={t("proxy.localPortPlaceholder")}
|
||||
type="number"
|
||||
value={formData.localPort}
|
||||
onChange={(e) => onChange("localPort", e.target.value)}
|
||||
color={errors.localPort ? "red" : undefined}
|
||||
/>
|
||||
</FormItem>
|
||||
</Box>
|
||||
</Flex>
|
||||
</motion.div>
|
||||
)}
|
||||
</AnimatePresence>
|
||||
|
||||
{isHttpType ? (
|
||||
<>
|
||||
<FormItem label={t("proxy.customDomainsLabel")}>
|
||||
<Flex direction="column" gap="2">
|
||||
{formData.customDomains.map((domain, index) => (
|
||||
<Flex key={index} gap="2" align="center">
|
||||
<TextField.Root
|
||||
size="2"
|
||||
style={{ flex: 1 }}
|
||||
placeholder="example.com"
|
||||
value={domain}
|
||||
onChange={(e) => {
|
||||
const next = [...formData.customDomains];
|
||||
next[index] = e.target.value;
|
||||
onChange("customDomains", next);
|
||||
}}
|
||||
/>
|
||||
<Button
|
||||
type="button"
|
||||
size="2"
|
||||
variant="soft"
|
||||
color="red"
|
||||
onClick={() => {
|
||||
const next = formData.customDomains.filter((_, i) => i !== index);
|
||||
onChange("customDomains", next);
|
||||
}}
|
||||
>
|
||||
<Icon icon="lucide:x" />
|
||||
</Button>
|
||||
</Flex>
|
||||
))}
|
||||
<Button
|
||||
type="button"
|
||||
size="2"
|
||||
variant="soft"
|
||||
onClick={() => onChange("customDomains", [...formData.customDomains, ""])}
|
||||
>
|
||||
<Icon icon="lucide:plus" />
|
||||
{t("proxy.addCustomDomain")}
|
||||
</Button>
|
||||
</Flex>
|
||||
</FormItem>
|
||||
<FormItem label={t("proxy.subdomain")}>
|
||||
<TextField.Root
|
||||
size="2"
|
||||
placeholder={t("proxy.subdomainPlaceholder")}
|
||||
value={formData.subdomain}
|
||||
onChange={(e) => onChange("subdomain", e.target.value)}
|
||||
/>
|
||||
<Text size="1" color="gray" mt="1">
|
||||
{t("proxy.subdomainDesc")}
|
||||
</Text>
|
||||
</FormItem>
|
||||
</>
|
||||
) : (
|
||||
<FormItem label={t("proxy.remotePortLabel")} required error={errors.remotePort}>
|
||||
<TextField.Root
|
||||
size="2"
|
||||
placeholder={t("proxy.remotePortPlaceholder")}
|
||||
type="number"
|
||||
value={formData.remotePort}
|
||||
onChange={(e) => onChange("remotePort", e.target.value)}
|
||||
color={errors.remotePort ? "red" : undefined}
|
||||
/>
|
||||
<Text size="1" color="gray" mt="1">
|
||||
{t("proxy.remotePortDesc")}
|
||||
</Text>
|
||||
</FormItem>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</Flex>
|
||||
</section>
|
||||
|
||||
<Separator size="4" />
|
||||
{!isCloudflare && <Separator size="4" />}
|
||||
|
||||
{/* 传输选项 */}
|
||||
<section>
|
||||
{!isCloudflare && <section>
|
||||
<SectionHeading id="section-transport" title={t("proxy.sectionTransport")} icon="lucide:shield" />
|
||||
<Flex direction="column" gap="3">
|
||||
<Flex justify="between" align="center">
|
||||
@@ -339,12 +514,12 @@ export function ProxyFormPageView({
|
||||
/>
|
||||
</Flex>
|
||||
</Flex>
|
||||
</section>
|
||||
</section>}
|
||||
|
||||
<Separator size="4" />
|
||||
{!isCloudflare && <Separator size="4" />}
|
||||
|
||||
{/* 插件 */}
|
||||
<section>
|
||||
{!isCloudflare && <section>
|
||||
<SectionHeading id="section-plugin" title={t("proxy.sectionPlugin")} icon="lucide:puzzle" />
|
||||
<Flex direction="column" gap="4">
|
||||
<Flex justify="between" align="center">
|
||||
@@ -414,7 +589,7 @@ export function ProxyFormPageView({
|
||||
)}
|
||||
</AnimatePresence>
|
||||
</Flex>
|
||||
</section>
|
||||
</section>}
|
||||
|
||||
<Separator size="4" />
|
||||
|
||||
|
||||
@@ -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")}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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<ProxyFormData>(DEFAULT_FORM);
|
||||
const [servers, setServers] = useState<ServerOption[]>([]);
|
||||
const [integrations, setIntegrations] = useState<IntegrationOption[]>([]);
|
||||
const [loadingServers, setLoadingServers] = useState(false);
|
||||
const [loadingIntegrations, setLoadingIntegrations] = useState(false);
|
||||
const [loadingProxy, setLoadingProxy] = useState(isEditing);
|
||||
const [submitting, setSubmitting] = useState(false);
|
||||
const [errors, setErrors] = useState<Partial<Record<keyof ProxyFormData, string>>>({});
|
||||
@@ -86,6 +99,24 @@ export function useProxyForm() {
|
||||
fetchServers();
|
||||
}, [isEditing]);
|
||||
|
||||
useEffect(() => {
|
||||
const fetchIntegrations = async () => {
|
||||
try {
|
||||
setLoadingIntegrations(true);
|
||||
const result = await pb.collection("fh_integrations").getFullList<IntegrationOption>({
|
||||
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<string, string> | 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<Record<keyof ProxyFormData, string>> = {};
|
||||
|
||||
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,
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user