Compare commits
6 Commits
cffeade642
...
edbed6390a
Author | SHA1 | Date | |
---|---|---|---|
edbed6390a | |||
686383e4d1 | |||
c022baa97c | |||
589c3f2890 | |||
d526839bfa | |||
922e4c0580 |
@ -3,3 +3,8 @@ AUTH_DOMAIN=auth.lab.cazzzer.com
|
|||||||
AUTH_CLIENT_ID=
|
AUTH_CLIENT_ID=
|
||||||
AUTH_CLIENT_SECRET=
|
AUTH_CLIENT_SECRET=
|
||||||
AUTH_REDIRECT_URI=http://localhost:5173/auth/authentik/callback
|
AUTH_REDIRECT_URI=http://localhost:5173/auth/authentik/callback
|
||||||
|
|
||||||
|
OPNSENSE_API_URL=https://opnsense.home
|
||||||
|
OPNSENSE_API_KEY=
|
||||||
|
OPNSENSE_API_SECRET=
|
||||||
|
OPNSENSE_WG_IFNAME=wg2
|
||||||
|
9
bruno/bruno.json
Normal file
9
bruno/bruno.json
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"version": "1",
|
||||||
|
"name": "vpgen",
|
||||||
|
"type": "collection",
|
||||||
|
"ignore": [
|
||||||
|
"node_modules",
|
||||||
|
".git"
|
||||||
|
]
|
||||||
|
}
|
8
bruno/collection.bru
Normal file
8
bruno/collection.bru
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
auth {
|
||||||
|
mode: basic
|
||||||
|
}
|
||||||
|
|
||||||
|
auth:basic {
|
||||||
|
username: {{opnsense_key}}
|
||||||
|
password: {{opnsense_secret}}
|
||||||
|
}
|
8
bruno/environments/dev.bru
Normal file
8
bruno/environments/dev.bru
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
vars {
|
||||||
|
opnsense_key: 33NhXqaJwrWy1T4Qi60GK90RXJuS3PWIYwlwYPnQ8f5YPe/J1q/g6/l4bZ2/kJk71MFhwP+9mr+IiQPi
|
||||||
|
base: https://opnsense.home
|
||||||
|
}
|
||||||
|
vars:secret [
|
||||||
|
vpn_endpoint,
|
||||||
|
opnsense_secret
|
||||||
|
]
|
38
bruno/opnsense-api/Add Client Builder.bru
Normal file
38
bruno/opnsense-api/Add Client Builder.bru
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
meta {
|
||||||
|
name: Add Client Builder
|
||||||
|
type: http
|
||||||
|
seq: 9
|
||||||
|
}
|
||||||
|
|
||||||
|
post {
|
||||||
|
url: {{base}}/api/wireguard/client/addClientBuilder
|
||||||
|
body: json
|
||||||
|
auth: inherit
|
||||||
|
}
|
||||||
|
|
||||||
|
headers {
|
||||||
|
Content-Type: application/json
|
||||||
|
}
|
||||||
|
|
||||||
|
body:json {
|
||||||
|
{
|
||||||
|
"configbuilder": {
|
||||||
|
"enabled": "1",
|
||||||
|
"name": "{{clientName}}",
|
||||||
|
"pubkey": "{{clientPubkey}}",
|
||||||
|
"psk": "{{psk}}",
|
||||||
|
"tunneladdress": "{{clientTunnelAddress}}",
|
||||||
|
"keepalive": "",
|
||||||
|
"server": "{{serverUuid}}",
|
||||||
|
"endpoint": "{{vpn_endpoint}}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
vars:pre-request {
|
||||||
|
clientName: vpgen-test
|
||||||
|
clientPubkey: BJ5faPVJsDP4CCxNYilmKnwlQXOtXEOJjqIwb4U/CgM=
|
||||||
|
psk: 0LWopbrISXBNHUxr+WOhCSAg+0hD8j3TLmpyzHkBHCQ=
|
||||||
|
clientTunnelAddress: 10.18.11.101/32,fd00::1/128
|
||||||
|
serverUuid: 99f278fb-5b79-4fde-b3d8-afab19f1fc07
|
||||||
|
}
|
31
bruno/opnsense-api/Get Interfaces.bru
Normal file
31
bruno/opnsense-api/Get Interfaces.bru
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
meta {
|
||||||
|
name: Get Interfaces
|
||||||
|
type: http
|
||||||
|
seq: 2
|
||||||
|
}
|
||||||
|
|
||||||
|
post {
|
||||||
|
url: {{base}}/api/wireguard/service/show
|
||||||
|
body: json
|
||||||
|
auth: inherit
|
||||||
|
}
|
||||||
|
|
||||||
|
headers {
|
||||||
|
Content-Type: application/json
|
||||||
|
}
|
||||||
|
|
||||||
|
body:json {
|
||||||
|
{
|
||||||
|
"current": 1,
|
||||||
|
"rowCount": 7,
|
||||||
|
"sort": {},
|
||||||
|
"searchPhrase": "{{searchPhrase}}",
|
||||||
|
"type": [
|
||||||
|
"interface"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
vars:pre-request {
|
||||||
|
searchPhrase:
|
||||||
|
}
|
11
bruno/opnsense-api/Get Key Pair.bru
Normal file
11
bruno/opnsense-api/Get Key Pair.bru
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
meta {
|
||||||
|
name: Get Key Pair
|
||||||
|
type: http
|
||||||
|
seq: 7
|
||||||
|
}
|
||||||
|
|
||||||
|
get {
|
||||||
|
url: {{base}}/api/wireguard/server/key_pair
|
||||||
|
body: none
|
||||||
|
auth: inherit
|
||||||
|
}
|
11
bruno/opnsense-api/Get PSK.bru
Normal file
11
bruno/opnsense-api/Get PSK.bru
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
meta {
|
||||||
|
name: Get PSK
|
||||||
|
type: http
|
||||||
|
seq: 8
|
||||||
|
}
|
||||||
|
|
||||||
|
get {
|
||||||
|
url: {{base}}/api/wireguard/client/psk
|
||||||
|
body: none
|
||||||
|
auth: inherit
|
||||||
|
}
|
31
bruno/opnsense-api/Get Peers.bru
Normal file
31
bruno/opnsense-api/Get Peers.bru
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
meta {
|
||||||
|
name: Get Peers
|
||||||
|
type: http
|
||||||
|
seq: 1
|
||||||
|
}
|
||||||
|
|
||||||
|
post {
|
||||||
|
url: {{base}}/api/wireguard/service/show
|
||||||
|
body: json
|
||||||
|
auth: inherit
|
||||||
|
}
|
||||||
|
|
||||||
|
headers {
|
||||||
|
Content-Type: application/json
|
||||||
|
}
|
||||||
|
|
||||||
|
body:json {
|
||||||
|
{
|
||||||
|
"current": 1,
|
||||||
|
"rowCount": 7,
|
||||||
|
"sort": {},
|
||||||
|
"searchPhrase": "{{searchPhrase}}",
|
||||||
|
"type": [
|
||||||
|
"peer"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
vars:pre-request {
|
||||||
|
searchPhrase:
|
||||||
|
}
|
15
bruno/opnsense-api/Get Server Info.bru
Normal file
15
bruno/opnsense-api/Get Server Info.bru
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
meta {
|
||||||
|
name: Get Server Info
|
||||||
|
type: http
|
||||||
|
seq: 6
|
||||||
|
}
|
||||||
|
|
||||||
|
get {
|
||||||
|
url: {{base}}/api/wireguard/client/get_server_info/:server_uuid
|
||||||
|
body: none
|
||||||
|
auth: inherit
|
||||||
|
}
|
||||||
|
|
||||||
|
params:path {
|
||||||
|
server_uuid: 8799c789-b6fb-4aa8-9dac-edf18d860340
|
||||||
|
}
|
11
bruno/opnsense-api/List Servers.bru
Normal file
11
bruno/opnsense-api/List Servers.bru
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
meta {
|
||||||
|
name: List Servers
|
||||||
|
type: http
|
||||||
|
seq: 6
|
||||||
|
}
|
||||||
|
|
||||||
|
get {
|
||||||
|
url: {{base}}/api/wireguard/client/list_servers
|
||||||
|
body: none
|
||||||
|
auth: inherit
|
||||||
|
}
|
11
bruno/opnsense-api/Reconfigure.bru
Normal file
11
bruno/opnsense-api/Reconfigure.bru
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
meta {
|
||||||
|
name: Reconfigure
|
||||||
|
type: http
|
||||||
|
seq: 10
|
||||||
|
}
|
||||||
|
|
||||||
|
post {
|
||||||
|
url: {{base}}/api/wireguard/service/reconfigure
|
||||||
|
body: none
|
||||||
|
auth: inherit
|
||||||
|
}
|
30
bruno/opnsense-api/Search Client.bru
Normal file
30
bruno/opnsense-api/Search Client.bru
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
meta {
|
||||||
|
name: Search Client
|
||||||
|
type: http
|
||||||
|
seq: 5
|
||||||
|
}
|
||||||
|
|
||||||
|
post {
|
||||||
|
url: {{base}}/api/wireguard/client/searchClient
|
||||||
|
body: json
|
||||||
|
auth: inherit
|
||||||
|
}
|
||||||
|
|
||||||
|
headers {
|
||||||
|
Content-Type: application/json
|
||||||
|
}
|
||||||
|
|
||||||
|
body:json {
|
||||||
|
{
|
||||||
|
"current": 1,
|
||||||
|
"rowCount": 7,
|
||||||
|
"sort": {},
|
||||||
|
"servers": ["{{serverUuid}}"],
|
||||||
|
"searchPhrase": "{{searchPhrase}}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
vars:pre-request {
|
||||||
|
searchPhrase:
|
||||||
|
serverUuid: 64e1d6ec-980a-463d-8583-c863d8e9852b
|
||||||
|
}
|
28
bruno/opnsense-api/Search Server.bru
Normal file
28
bruno/opnsense-api/Search Server.bru
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
meta {
|
||||||
|
name: Search Server
|
||||||
|
type: http
|
||||||
|
seq: 4
|
||||||
|
}
|
||||||
|
|
||||||
|
post {
|
||||||
|
url: {{base}}/api/wireguard/server/searchServer
|
||||||
|
body: json
|
||||||
|
auth: inherit
|
||||||
|
}
|
||||||
|
|
||||||
|
headers {
|
||||||
|
Content-Type: application/json
|
||||||
|
}
|
||||||
|
|
||||||
|
body:json {
|
||||||
|
{
|
||||||
|
"current": 1,
|
||||||
|
"rowCount": 7,
|
||||||
|
"sort": {},
|
||||||
|
"searchPhrase": "{{searchPhrase}}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
vars:pre-request {
|
||||||
|
searchPhrase:
|
||||||
|
}
|
7
bruno/opnsense-api/folder.bru
Normal file
7
bruno/opnsense-api/folder.bru
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
meta {
|
||||||
|
name: opnsense-api
|
||||||
|
}
|
||||||
|
|
||||||
|
headers {
|
||||||
|
Accept: application/json
|
||||||
|
}
|
@ -34,6 +34,7 @@ const handleAuth: Handle = async ({ event, resolve }) => {
|
|||||||
const authRequired = new Set([
|
const authRequired = new Set([
|
||||||
'/user',
|
'/user',
|
||||||
'/connections',
|
'/connections',
|
||||||
|
'/api/connections',
|
||||||
]);
|
]);
|
||||||
const handleProtectedPaths: Handle = ({ event, resolve }) => {
|
const handleProtectedPaths: Handle = ({ event, resolve }) => {
|
||||||
if (authRequired.has(event.url.pathname) && !event.locals.user) {
|
if (authRequired.has(event.url.pathname) && !event.locals.user) {
|
||||||
|
18
src/lib/components/ui/badge/badge.svelte
Normal file
18
src/lib/components/ui/badge/badge.svelte
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { type Variant, badgeVariants } from "./index.js";
|
||||||
|
import { cn } from "$lib/utils.js";
|
||||||
|
|
||||||
|
let className: string | undefined | null = undefined;
|
||||||
|
export let href: string | undefined = undefined;
|
||||||
|
export let variant: Variant = "default";
|
||||||
|
export { className as class };
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<svelte:element
|
||||||
|
this={href ? "a" : "span"}
|
||||||
|
{href}
|
||||||
|
class={cn(badgeVariants({ variant, className }))}
|
||||||
|
{...$$restProps}
|
||||||
|
>
|
||||||
|
<slot />
|
||||||
|
</svelte:element>
|
21
src/lib/components/ui/badge/index.ts
Normal file
21
src/lib/components/ui/badge/index.ts
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
import { type VariantProps, tv } from "tailwind-variants";
|
||||||
|
export { default as Badge } from "./badge.svelte";
|
||||||
|
|
||||||
|
export const badgeVariants = tv({
|
||||||
|
base: "focus:ring-ring inline-flex select-none items-center rounded-full border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-offset-2",
|
||||||
|
variants: {
|
||||||
|
variant: {
|
||||||
|
default: "bg-primary text-primary-foreground hover:bg-primary/80 border-transparent",
|
||||||
|
secondary:
|
||||||
|
"bg-secondary text-secondary-foreground hover:bg-secondary/80 border-transparent",
|
||||||
|
destructive:
|
||||||
|
"bg-destructive text-destructive-foreground hover:bg-destructive/80 border-transparent",
|
||||||
|
outline: "text-foreground",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
defaultVariants: {
|
||||||
|
variant: "default",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
export type Variant = VariantProps<typeof badgeVariants>["variant"];
|
35
src/lib/components/ui/checkbox/checkbox.svelte
Normal file
35
src/lib/components/ui/checkbox/checkbox.svelte
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { Checkbox as CheckboxPrimitive } from "bits-ui";
|
||||||
|
import Check from "lucide-svelte/icons/check";
|
||||||
|
import Minus from "lucide-svelte/icons/minus";
|
||||||
|
import { cn } from "$lib/utils.js";
|
||||||
|
|
||||||
|
type $$Props = CheckboxPrimitive.Props;
|
||||||
|
type $$Events = CheckboxPrimitive.Events;
|
||||||
|
|
||||||
|
let className: $$Props["class"] = undefined;
|
||||||
|
export let checked: $$Props["checked"] = false;
|
||||||
|
export { className as class };
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<CheckboxPrimitive.Root
|
||||||
|
class={cn(
|
||||||
|
"border-primary ring-offset-background focus-visible:ring-ring data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground peer box-content h-4 w-4 shrink-0 rounded-sm border focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 data-[disabled=true]:cursor-not-allowed data-[disabled=true]:opacity-50",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
bind:checked
|
||||||
|
{...$$restProps}
|
||||||
|
on:click
|
||||||
|
>
|
||||||
|
<CheckboxPrimitive.Indicator
|
||||||
|
class={cn("flex h-4 w-4 items-center justify-center text-current")}
|
||||||
|
let:isChecked
|
||||||
|
let:isIndeterminate
|
||||||
|
>
|
||||||
|
{#if isChecked}
|
||||||
|
<Check class="h-3.5 w-3.5" />
|
||||||
|
{:else if isIndeterminate}
|
||||||
|
<Minus class="h-3.5 w-3.5" />
|
||||||
|
{/if}
|
||||||
|
</CheckboxPrimitive.Indicator>
|
||||||
|
</CheckboxPrimitive.Root>
|
6
src/lib/components/ui/checkbox/index.ts
Normal file
6
src/lib/components/ui/checkbox/index.ts
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
import Root from "./checkbox.svelte";
|
||||||
|
export {
|
||||||
|
Root,
|
||||||
|
//
|
||||||
|
Root as Checkbox,
|
||||||
|
};
|
28
src/lib/components/ui/table/index.ts
Normal file
28
src/lib/components/ui/table/index.ts
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
import Root from "./table.svelte";
|
||||||
|
import Body from "./table-body.svelte";
|
||||||
|
import Caption from "./table-caption.svelte";
|
||||||
|
import Cell from "./table-cell.svelte";
|
||||||
|
import Footer from "./table-footer.svelte";
|
||||||
|
import Head from "./table-head.svelte";
|
||||||
|
import Header from "./table-header.svelte";
|
||||||
|
import Row from "./table-row.svelte";
|
||||||
|
|
||||||
|
export {
|
||||||
|
Root,
|
||||||
|
Body,
|
||||||
|
Caption,
|
||||||
|
Cell,
|
||||||
|
Footer,
|
||||||
|
Head,
|
||||||
|
Header,
|
||||||
|
Row,
|
||||||
|
//
|
||||||
|
Root as Table,
|
||||||
|
Body as TableBody,
|
||||||
|
Caption as TableCaption,
|
||||||
|
Cell as TableCell,
|
||||||
|
Footer as TableFooter,
|
||||||
|
Head as TableHead,
|
||||||
|
Header as TableHeader,
|
||||||
|
Row as TableRow,
|
||||||
|
};
|
13
src/lib/components/ui/table/table-body.svelte
Normal file
13
src/lib/components/ui/table/table-body.svelte
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import type { HTMLAttributes } from "svelte/elements";
|
||||||
|
import { cn } from "$lib/utils.js";
|
||||||
|
|
||||||
|
type $$Props = HTMLAttributes<HTMLTableSectionElement>;
|
||||||
|
|
||||||
|
let className: $$Props["class"] = undefined;
|
||||||
|
export { className as class };
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<tbody class={cn("[&_tr:last-child]:border-0", className)} {...$$restProps}>
|
||||||
|
<slot />
|
||||||
|
</tbody>
|
13
src/lib/components/ui/table/table-caption.svelte
Normal file
13
src/lib/components/ui/table/table-caption.svelte
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import type { HTMLAttributes } from "svelte/elements";
|
||||||
|
import { cn } from "$lib/utils.js";
|
||||||
|
|
||||||
|
type $$Props = HTMLAttributes<HTMLTableCaptionElement>;
|
||||||
|
|
||||||
|
let className: $$Props["class"] = undefined;
|
||||||
|
export { className as class };
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<caption class={cn("text-muted-foreground mt-4 text-sm", className)} {...$$restProps}>
|
||||||
|
<slot />
|
||||||
|
</caption>
|
18
src/lib/components/ui/table/table-cell.svelte
Normal file
18
src/lib/components/ui/table/table-cell.svelte
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import type { HTMLTdAttributes } from "svelte/elements";
|
||||||
|
import { cn } from "$lib/utils.js";
|
||||||
|
|
||||||
|
type $$Props = HTMLTdAttributes;
|
||||||
|
|
||||||
|
let className: $$Props["class"] = undefined;
|
||||||
|
export { className as class };
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<td
|
||||||
|
class={cn("p-4 align-middle [&:has([role=checkbox])]:pr-0", className)}
|
||||||
|
{...$$restProps}
|
||||||
|
on:click
|
||||||
|
on:keydown
|
||||||
|
>
|
||||||
|
<slot />
|
||||||
|
</td>
|
13
src/lib/components/ui/table/table-footer.svelte
Normal file
13
src/lib/components/ui/table/table-footer.svelte
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import type { HTMLAttributes } from "svelte/elements";
|
||||||
|
import { cn } from "$lib/utils.js";
|
||||||
|
|
||||||
|
type $$Props = HTMLAttributes<HTMLTableSectionElement>;
|
||||||
|
|
||||||
|
let className: $$Props["class"] = undefined;
|
||||||
|
export { className as class };
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<tfoot class={cn("bg-muted/50 text-primary-foreground font-medium", className)} {...$$restProps}>
|
||||||
|
<slot />
|
||||||
|
</tfoot>
|
19
src/lib/components/ui/table/table-head.svelte
Normal file
19
src/lib/components/ui/table/table-head.svelte
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import type { HTMLThAttributes } from "svelte/elements";
|
||||||
|
import { cn } from "$lib/utils.js";
|
||||||
|
|
||||||
|
type $$Props = HTMLThAttributes;
|
||||||
|
|
||||||
|
let className: $$Props["class"] = undefined;
|
||||||
|
export { className as class };
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<th
|
||||||
|
class={cn(
|
||||||
|
"text-muted-foreground h-12 px-4 text-left align-middle font-medium [&:has([role=checkbox])]:pr-0",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
{...$$restProps}
|
||||||
|
>
|
||||||
|
<slot />
|
||||||
|
</th>
|
14
src/lib/components/ui/table/table-header.svelte
Normal file
14
src/lib/components/ui/table/table-header.svelte
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import type { HTMLAttributes } from "svelte/elements";
|
||||||
|
import { cn } from "$lib/utils.js";
|
||||||
|
|
||||||
|
type $$Props = HTMLAttributes<HTMLTableSectionElement>;
|
||||||
|
|
||||||
|
let className: $$Props["class"] = undefined;
|
||||||
|
export { className as class };
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<!-- svelte-ignore a11y-no-noninteractive-element-interactions -->
|
||||||
|
<thead class={cn("[&_tr]:border-b", className)} {...$$restProps} on:click on:keydown>
|
||||||
|
<slot />
|
||||||
|
</thead>
|
23
src/lib/components/ui/table/table-row.svelte
Normal file
23
src/lib/components/ui/table/table-row.svelte
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import type { HTMLAttributes } from "svelte/elements";
|
||||||
|
import { cn } from "$lib/utils.js";
|
||||||
|
|
||||||
|
type $$Props = HTMLAttributes<HTMLTableRowElement> & {
|
||||||
|
"data-state"?: unknown;
|
||||||
|
};
|
||||||
|
|
||||||
|
let className: $$Props["class"] = undefined;
|
||||||
|
export { className as class };
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<tr
|
||||||
|
class={cn(
|
||||||
|
"hover:bg-muted/50 data-[state=selected]:bg-muted border-b transition-colors",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
{...$$restProps}
|
||||||
|
on:click
|
||||||
|
on:keydown
|
||||||
|
>
|
||||||
|
<slot />
|
||||||
|
</tr>
|
15
src/lib/components/ui/table/table.svelte
Normal file
15
src/lib/components/ui/table/table.svelte
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import type { HTMLTableAttributes } from "svelte/elements";
|
||||||
|
import { cn } from "$lib/utils.js";
|
||||||
|
|
||||||
|
type $$Props = HTMLTableAttributes;
|
||||||
|
|
||||||
|
let className: $$Props["class"] = undefined;
|
||||||
|
export { className as class };
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div class="relative w-full overflow-auto">
|
||||||
|
<table class={cn("w-full caption-bottom text-sm", className)} {...$$restProps}>
|
||||||
|
<slot />
|
||||||
|
</table>
|
||||||
|
</div>
|
61
src/lib/opnsense/wg.ts
Normal file
61
src/lib/opnsense/wg.ts
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
export interface PeerRow {
|
||||||
|
if: string;
|
||||||
|
type: "peer";
|
||||||
|
'public-key': string;
|
||||||
|
endpoint: string;
|
||||||
|
'allowed-ips': string;
|
||||||
|
'latest-handshake': number;
|
||||||
|
'transfer-rx': number;
|
||||||
|
'transfer-tx': number;
|
||||||
|
'persistent-keepalive': string;
|
||||||
|
name: string;
|
||||||
|
ifname: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sample response from OPNsense WireGuard API
|
||||||
|
* ```json
|
||||||
|
* {
|
||||||
|
* "total": 17,
|
||||||
|
* "rowCount": 7,
|
||||||
|
* "current": 1,
|
||||||
|
* "rows": [
|
||||||
|
* {
|
||||||
|
* "if": "wg0",
|
||||||
|
* "type": "peer",
|
||||||
|
* "public-key": "iJa5JmJbMHNlbEluNwoB2Q8LyrPAfb7S/mluanMcI08=",
|
||||||
|
* "endpoint": "10.17.20.107:42516",
|
||||||
|
* "allowed-ips": "fd00::1/112,10.6.0.3/32",
|
||||||
|
* "latest-handshake": 1729319339,
|
||||||
|
* "transfer-rx": 1052194743,
|
||||||
|
* "transfer-tx": 25203263456,
|
||||||
|
* "persistent-keepalive": "off",
|
||||||
|
* "name": "Yura-TPX13",
|
||||||
|
* "ifname": "wg0"
|
||||||
|
* }
|
||||||
|
* ]
|
||||||
|
* }
|
||||||
|
* ```
|
||||||
|
*/
|
||||||
|
export interface OpnsenseWgPeers {
|
||||||
|
total: number;
|
||||||
|
rowCount: number;
|
||||||
|
current: number;
|
||||||
|
rows: PeerRow[];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sample request to OPNsense WireGuard API
|
||||||
|
* ```js
|
||||||
|
* const url = 'https://opnsense.home/api/wireguard/service/show';
|
||||||
|
* const options = {
|
||||||
|
* method: 'POST',
|
||||||
|
* headers: {
|
||||||
|
* Authorization: 'Basic ...',
|
||||||
|
* 'Content-Type': 'application/json',
|
||||||
|
* Accept: 'application/json',
|
||||||
|
* },
|
||||||
|
* body: '{"current":1,"rowCount":7,"sort":{},"searchPhrase":"","type":["peer"]}'
|
||||||
|
* };
|
||||||
|
* ```
|
||||||
|
*/
|
11
src/lib/server/opnsense.ts
Normal file
11
src/lib/server/opnsense.ts
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
import { env } from '$env/dynamic/private';
|
||||||
|
import assert from 'node:assert';
|
||||||
|
|
||||||
|
assert(env.OPNSENSE_API_URL, 'OPNSENSE_API_URL is not set');
|
||||||
|
assert(env.OPNSENSE_API_KEY, 'OPNSENSE_API_KEY is not set');
|
||||||
|
assert(env.OPNSENSE_API_SECRET, 'OPNSENSE_API_SECRET is not set');
|
||||||
|
assert(env.OPNSENSE_WG_IFNAME, 'OPNSENSE_WG_IFNAME is not set');
|
||||||
|
|
||||||
|
export const opnsenseUrl = env.OPNSENSE_API_URL;
|
||||||
|
export const opnsenseAuth = `Basic ${Buffer.from(`${env.OPNSENSE_API_KEY}:${env.OPNSENSE_API_SECRET}`).toString('base64')}`
|
||||||
|
export const opnsenseIfname = env.OPNSENSE_WG_IFNAME;
|
@ -5,16 +5,20 @@
|
|||||||
|
|
||||||
const { data, children } = $props();
|
const { data, children } = $props();
|
||||||
const { user } = data;
|
const { user } = data;
|
||||||
|
|
||||||
|
function getNavClass(path: string) {
|
||||||
|
return cn("hover:text-foreground/80 transition-colors",
|
||||||
|
$page.url.pathname === path ? "text-foreground" : "text-foreground/60");
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<header class="p-4 sm:flex">
|
<header class="p-4 sm:flex">
|
||||||
<span class=" mr-6 font-bold sm:inline-block">My App</span>
|
<span class=" mr-6 font-bold sm:inline-block">VPGen</span>
|
||||||
<nav class="flex items-center gap-6 text-sm">
|
<nav class="flex items-center gap-6 text-sm">
|
||||||
<a href="/" class={cn("hover:text-foreground/80 transition-colors",
|
<a href="/" class={getNavClass("/")}>Home</a>
|
||||||
$page.url.pathname === "/" ? "text-foreground" : "text-foreground/60")}>Home</a>
|
|
||||||
{#if user}
|
{#if user}
|
||||||
<a href="/user" class={cn("hover:text-foreground/80 transition-colors",
|
<a href="/user" class={getNavClass("/user")}>Profile</a>
|
||||||
$page.url.pathname === "/user" ? "text-foreground" : "text-foreground/60")}>Profile</a>
|
<a href="/connections" class={getNavClass("/connections")}>Connections</a>
|
||||||
{/if}
|
{/if}
|
||||||
</nav>
|
</nav>
|
||||||
</header>
|
</header>
|
||||||
|
@ -6,10 +6,10 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<svelte:head>
|
<svelte:head>
|
||||||
<title>VpGen</title>
|
<title>VPGen</title>
|
||||||
</svelte:head>
|
</svelte:head>
|
||||||
|
|
||||||
<h1>Welcome to SvelteKit</h1>
|
<h1>Welcome to VPGen</h1>
|
||||||
|
|
||||||
{#if user }
|
{#if user }
|
||||||
<p>Hi {user.name}</p>
|
<p>Hi {user.name}</p>
|
||||||
|
38
src/routes/api/connections/+server.ts
Normal file
38
src/routes/api/connections/+server.ts
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
import { error } from '@sveltejs/kit';
|
||||||
|
import type { RequestHandler } from './$types';
|
||||||
|
import { opnsenseAuth, opnsenseIfname, opnsenseUrl } from '$lib/server/opnsense';
|
||||||
|
import type { OpnsenseWgPeers } from '$lib/opnsense/wg';
|
||||||
|
|
||||||
|
export const GET: RequestHandler = async () => {
|
||||||
|
const apiUrl = `${opnsenseUrl}/api/wireguard/service/show`;
|
||||||
|
const options: RequestInit = {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
Authorization: opnsenseAuth,
|
||||||
|
Accept: 'application/json',
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
"current": 1,
|
||||||
|
// "rowCount": 7,
|
||||||
|
"sort": {},
|
||||||
|
"searchPhrase": "",
|
||||||
|
"type": ["peer"],
|
||||||
|
}),
|
||||||
|
};
|
||||||
|
console.log("Fetching peers from OPNsense WireGuard API: ", apiUrl, options)
|
||||||
|
|
||||||
|
const res = await fetch(apiUrl, options);
|
||||||
|
const peers = await res.json() as OpnsenseWgPeers;
|
||||||
|
peers.rows = peers.rows.filter(peer => peer['latest-handshake'] && peer.ifname === opnsenseIfname)
|
||||||
|
|
||||||
|
if (!peers) {
|
||||||
|
error(500, "Error getting info from OPNsense API");
|
||||||
|
}
|
||||||
|
return new Response(JSON.stringify(peers), {
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'Cache-Control': 'max-age=5',
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
69
src/routes/connections/+page.svelte
Normal file
69
src/routes/connections/+page.svelte
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import type { PageData } from './$types';
|
||||||
|
import { invalidate } from '$app/navigation';
|
||||||
|
import * as Table from '$lib/components/ui/table';
|
||||||
|
import { Badge } from '$lib/components/ui/badge';
|
||||||
|
|
||||||
|
const { data }: { data: PageData } = $props();
|
||||||
|
|
||||||
|
$effect(() => {
|
||||||
|
// refresh every 5 seconds
|
||||||
|
const interval = setInterval(() => {
|
||||||
|
console.log('Refreshing connections');
|
||||||
|
invalidate('/api/connections');
|
||||||
|
}, 5000);
|
||||||
|
|
||||||
|
return () => clearInterval(interval);
|
||||||
|
});
|
||||||
|
|
||||||
|
function getSize(size: number) {
|
||||||
|
let sizes = ['Bytes', 'KiB', 'MiB', 'GiB',
|
||||||
|
'TiB', 'PiB', 'EiB', 'ZiB', 'YiB'];
|
||||||
|
|
||||||
|
for (let i = 1; i < sizes.length; i++) {
|
||||||
|
if (size < Math.pow(1024, i))
|
||||||
|
return (Math.round((size / Math.pow(
|
||||||
|
1024, i - 1)) * 100) / 100) + ' ' + sizes[i - 1];
|
||||||
|
}
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<svelte:head>
|
||||||
|
<title>Connections</title>
|
||||||
|
</svelte:head>
|
||||||
|
|
||||||
|
<Table.Root class="bg-accent rounded-xl">
|
||||||
|
<Table.Header>
|
||||||
|
<Table.Head>Name</Table.Head>
|
||||||
|
<Table.Head>Public Key</Table.Head>
|
||||||
|
<Table.Head>Endpoint</Table.Head>
|
||||||
|
<Table.Head>Allowed IPs</Table.Head>
|
||||||
|
<Table.Head>Latest Handshake</Table.Head>
|
||||||
|
<Table.Head>RX</Table.Head>
|
||||||
|
<Table.Head>TX</Table.Head>
|
||||||
|
<Table.Head class="hidden">Persistent Keepalive</Table.Head>
|
||||||
|
<Table.Head class="hidden">Interface Name</Table.Head>
|
||||||
|
</Table.Header>
|
||||||
|
<Table.Body>
|
||||||
|
{#each data.peers.rows as peer}
|
||||||
|
<Table.Row class="border-y-2 border-background">
|
||||||
|
<Table.Cell>{peer.name}</Table.Cell>
|
||||||
|
<Table.Cell class="truncate max-w-[10ch]">{peer['public-key']}</Table.Cell>
|
||||||
|
<Table.Cell>{peer.endpoint}</Table.Cell>
|
||||||
|
<Table.Cell>
|
||||||
|
<div class="flex flex-wrap gap-1">
|
||||||
|
{#each peer['allowed-ips'].split(',') as addr}
|
||||||
|
<Badge class="bg-background" variant="secondary">{addr}</Badge>
|
||||||
|
{/each}
|
||||||
|
</div>
|
||||||
|
</Table.Cell>
|
||||||
|
<Table.Cell>{new Date(peer['latest-handshake'] * 1000).toLocaleString()}</Table.Cell>
|
||||||
|
<Table.Cell>{getSize(peer['transfer-rx'])}</Table.Cell>
|
||||||
|
<Table.Cell>{getSize(peer['transfer-tx'])}</Table.Cell>
|
||||||
|
<Table.Cell class="hidden">{peer['persistent-keepalive']}</Table.Cell>
|
||||||
|
<Table.Cell class="hidden">{peer.ifname}</Table.Cell>
|
||||||
|
</Table.Row>
|
||||||
|
{/each}
|
||||||
|
</Table.Body>
|
||||||
|
</Table.Root>
|
9
src/routes/connections/+page.ts
Normal file
9
src/routes/connections/+page.ts
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
import type { PageLoad } from './$types';
|
||||||
|
import type { OpnsenseWgPeers } from '$lib/opnsense/wg';
|
||||||
|
|
||||||
|
export const load: PageLoad = async ({ fetch }) => {
|
||||||
|
const res = await fetch('/api/connections');
|
||||||
|
const peers = await res.json() as OpnsenseWgPeers;
|
||||||
|
|
||||||
|
return { peers };
|
||||||
|
};
|
Loading…
x
Reference in New Issue
Block a user