mirror of
https://github.com/fosrl/pangolin.git
synced 2025-08-30 14:39:29 +02:00
Move to org id
This commit is contained in:
parent
8cd6cbb5ac
commit
2d754c4279
18 changed files with 44 additions and 10 deletions
|
@ -32,8 +32,9 @@ import {
|
||||||
PopoverTrigger,
|
PopoverTrigger,
|
||||||
} from "@/components/ui/popover"
|
} from "@/components/ui/popover"
|
||||||
import { generateKeypair } from "./wireguard-config";
|
import { generateKeypair } from "./wireguard-config";
|
||||||
import { NewtConfig } from "./newt-config";
|
import React, { useState, useEffect } from "react";
|
||||||
import { useState } from "react"
|
import { api } from "@/api";
|
||||||
|
import { AxiosResponse } from "axios"
|
||||||
|
|
||||||
const method = [
|
const method = [
|
||||||
{ label: "Wireguard", value: "wg" },
|
{ label: "Wireguard", value: "wg" },
|
||||||
|
@ -63,13 +64,23 @@ const defaultValues: Partial<AccountFormValues> = {
|
||||||
|
|
||||||
export function CreateSiteForm() {
|
export function CreateSiteForm() {
|
||||||
const [methodValue, setMethodValue] = useState("wg");
|
const [methodValue, setMethodValue] = useState("wg");
|
||||||
|
const [keypair, setKeypair] = useState<{ publicKey: string; privateKey: string } | null>(null);
|
||||||
|
const [isLoading, setIsLoading] = useState(true);
|
||||||
|
|
||||||
const form = useForm<AccountFormValues>({
|
const form = useForm<AccountFormValues>({
|
||||||
resolver: zodResolver(accountFormSchema),
|
resolver: zodResolver(accountFormSchema),
|
||||||
defaultValues,
|
defaultValues,
|
||||||
});
|
});
|
||||||
|
|
||||||
function onSubmit(data: AccountFormValues) {
|
useEffect(() => {
|
||||||
|
if (typeof window !== "undefined") {
|
||||||
|
const generatedKeypair = generateKeypair();
|
||||||
|
setKeypair(generatedKeypair);
|
||||||
|
setIsLoading(false);
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
async function onSubmit(data: AccountFormValues) {
|
||||||
toast({
|
toast({
|
||||||
title: "You submitted the following values:",
|
title: "You submitted the following values:",
|
||||||
description: (
|
description: (
|
||||||
|
@ -78,11 +89,23 @@ export function CreateSiteForm() {
|
||||||
</pre>
|
</pre>
|
||||||
),
|
),
|
||||||
});
|
});
|
||||||
|
// const res = await api
|
||||||
|
// .post<AxiosResponse<any>>(`/org/:orgId/site/:siteId/resource`, {
|
||||||
|
// email,
|
||||||
|
// password,
|
||||||
|
// })
|
||||||
|
// .catch((e) => {
|
||||||
|
// console.error(e);
|
||||||
|
// setError(
|
||||||
|
// e.response?.data?.message ||
|
||||||
|
// "An error occurred while logging in",
|
||||||
|
// );
|
||||||
|
// });
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const keypair = generateKeypair();
|
const wgConfig = keypair
|
||||||
|
? `[Interface]
|
||||||
const config = `[Interface]
|
|
||||||
Address = 10.0.0.2/24
|
Address = 10.0.0.2/24
|
||||||
ListenPort = 51820
|
ListenPort = 51820
|
||||||
PrivateKey = ${keypair.privateKey}
|
PrivateKey = ${keypair.privateKey}
|
||||||
|
@ -91,8 +114,11 @@ export function CreateSiteForm() {
|
||||||
PublicKey = ${keypair.publicKey}
|
PublicKey = ${keypair.publicKey}
|
||||||
AllowedIPs = 0.0.0.0/0, ::/0
|
AllowedIPs = 0.0.0.0/0, ::/0
|
||||||
Endpoint = myserver.dyndns.org:51820
|
Endpoint = myserver.dyndns.org:51820
|
||||||
PersistentKeepalive = 5`;
|
PersistentKeepalive = 5`
|
||||||
|
: "";
|
||||||
|
|
||||||
|
const newtConfig = `curl -fsSL https://get.docker.com -o get-docker.sh
|
||||||
|
sh get-docker.sh`;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
@ -178,12 +204,20 @@ export function CreateSiteForm() {
|
||||||
</FormItem>
|
</FormItem>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
|
{methodValue === "wg" && !isLoading ? (
|
||||||
|
<pre className="mt-2 w-full rounded-md bg-slate-950 p-4 overflow-x-auto">
|
||||||
|
<code className="text-white whitespace-pre-wrap">{wgConfig}</code>
|
||||||
|
</pre>
|
||||||
|
) : methodValue === "wg" && isLoading ? (
|
||||||
|
<p>Loading WireGuard configuration...</p>
|
||||||
|
) : (
|
||||||
|
<pre className="mt-2 w-full rounded-md bg-slate-950 p-4 overflow-x-auto">
|
||||||
|
<code className="text-white whitespace-pre-wrap">{newtConfig}</code>
|
||||||
|
</pre>
|
||||||
|
)}
|
||||||
<Button type="submit">Create Site</Button>
|
<Button type="submit">Create Site</Button>
|
||||||
</form>
|
</form>
|
||||||
</Form>
|
</Form>
|
||||||
{methodValue === "wg" ? <pre className="mt-2 w-full rounded-md bg-slate-950 p-4 overflow-x-auto">
|
|
||||||
<code className="text-white whitespace-pre-wrap">{config}</code>
|
|
||||||
</pre> : <NewtConfig />}
|
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue