Compare commits
19 Commits
feature/op
...
feature/lo
Author | SHA1 | Date | |
---|---|---|---|
b38ab19c3e
|
|||
80acec720c
|
|||
29fbccc953
|
|||
76559d2931
|
|||
cc7c94417d
|
|||
d99ee9ef1e
|
|||
32ab4104a7
|
|||
923c24a93e
|
|||
3861c30ffd
|
|||
423165e105
|
|||
015bb7b05b
|
|||
62daabcd4c
|
|||
ea11bf8a72
|
|||
a40757c325
|
|||
b8279e3c43
|
|||
bc2cf3c7ca
|
|||
c734b445a8
|
|||
7b3c45d845
|
|||
3372575e9a
|
33
.dockerignore
Normal file
33
.dockerignore
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
node_modules
|
||||||
|
|
||||||
|
# Output
|
||||||
|
.output
|
||||||
|
.vercel
|
||||||
|
/.svelte-kit
|
||||||
|
/build
|
||||||
|
|
||||||
|
# OS
|
||||||
|
.DS_Store
|
||||||
|
Thumbs.db
|
||||||
|
|
||||||
|
# Env
|
||||||
|
.env
|
||||||
|
.env.*
|
||||||
|
!.env.example
|
||||||
|
!.env.test
|
||||||
|
|
||||||
|
# Vite
|
||||||
|
vite.config.js.timestamp-*
|
||||||
|
vite.config.ts.timestamp-*
|
||||||
|
|
||||||
|
# SQLite
|
||||||
|
*.db
|
||||||
|
|
||||||
|
# Git
|
||||||
|
/.git
|
||||||
|
|
||||||
|
# IntelliJ
|
||||||
|
/.idea
|
||||||
|
|
||||||
|
# Bruno (API Docs)
|
||||||
|
/bruno
|
@@ -2,9 +2,8 @@ DATABASE_URL=file:local.db
|
|||||||
AUTH_DOMAIN=auth.lab.cazzzer.com
|
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
|
|
||||||
|
|
||||||
OPNSENSE_API_URL=https://opnsense.home
|
OPNSENSE_API_URL=https://opnsense.cazzzer.com
|
||||||
OPNSENSE_API_KEY=
|
OPNSENSE_API_KEY=
|
||||||
OPNSENSE_API_SECRET=
|
OPNSENSE_API_SECRET=
|
||||||
OPNSENSE_WG_IFNAME=wg2
|
OPNSENSE_WG_IFNAME=wg2
|
||||||
@@ -16,3 +15,5 @@ IP_MAX_INDEX=100
|
|||||||
VPN_ENDPOINT=vpn.lab.cazzzer.com:51820
|
VPN_ENDPOINT=vpn.lab.cazzzer.com:51820
|
||||||
VPN_DNS=10.18.11.1,fd00:10:18:11::1
|
VPN_DNS=10.18.11.1,fd00:10:18:11::1
|
||||||
MAX_CLIENTS_PER_USER=20
|
MAX_CLIENTS_PER_USER=20
|
||||||
|
|
||||||
|
ORIGIN=http://localhost:5173
|
||||||
|
1
.gitattributes
vendored
Normal file
1
.gitattributes
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
*.mp4 filter=lfs diff=lfs merge=lfs -text
|
4
.idea/codeStyles/Project.xml
generated
4
.idea/codeStyles/Project.xml
generated
@@ -9,7 +9,7 @@
|
|||||||
<option name="SPACE_BEFORE_FUNCTION_LEFT_PARENTH" value="false" />
|
<option name="SPACE_BEFORE_FUNCTION_LEFT_PARENTH" value="false" />
|
||||||
<option name="USE_DOUBLE_QUOTES" value="false" />
|
<option name="USE_DOUBLE_QUOTES" value="false" />
|
||||||
<option name="FORCE_QUOTE_STYlE" value="true" />
|
<option name="FORCE_QUOTE_STYlE" value="true" />
|
||||||
<option name="ENFORCE_TRAILING_COMMA" value="WhenMultiline" />
|
<option name="ENFORCE_TRAILING_COMMA" value="Remove" />
|
||||||
<option name="SPACES_WITHIN_OBJECT_LITERAL_BRACES" value="true" />
|
<option name="SPACES_WITHIN_OBJECT_LITERAL_BRACES" value="true" />
|
||||||
<option name="SPACES_WITHIN_IMPORTS" value="true" />
|
<option name="SPACES_WITHIN_IMPORTS" value="true" />
|
||||||
</JSCodeStyleSettings>
|
</JSCodeStyleSettings>
|
||||||
@@ -120,7 +120,7 @@
|
|||||||
<option name="SPACE_BEFORE_FUNCTION_LEFT_PARENTH" value="false" />
|
<option name="SPACE_BEFORE_FUNCTION_LEFT_PARENTH" value="false" />
|
||||||
<option name="USE_DOUBLE_QUOTES" value="false" />
|
<option name="USE_DOUBLE_QUOTES" value="false" />
|
||||||
<option name="FORCE_QUOTE_STYlE" value="true" />
|
<option name="FORCE_QUOTE_STYlE" value="true" />
|
||||||
<option name="ENFORCE_TRAILING_COMMA" value="WhenMultiline" />
|
<option name="ENFORCE_TRAILING_COMMA" value="Remove" />
|
||||||
<option name="SPACES_WITHIN_OBJECT_LITERAL_BRACES" value="true" />
|
<option name="SPACES_WITHIN_OBJECT_LITERAL_BRACES" value="true" />
|
||||||
<option name="SPACES_WITHIN_IMPORTS" value="true" />
|
<option name="SPACES_WITHIN_IMPORTS" value="true" />
|
||||||
</TypeScriptCodeStyleSettings>
|
</TypeScriptCodeStyleSettings>
|
||||||
|
45
Dockerfile
Normal file
45
Dockerfile
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
# use the official Bun image
|
||||||
|
# see all versions at https://hub.docker.com/r/oven/bun/tags
|
||||||
|
FROM oven/bun:1-alpine AS base
|
||||||
|
WORKDIR /app
|
||||||
|
COPY package.json bun.lockb /app/
|
||||||
|
|
||||||
|
# install dependencies into temp directory
|
||||||
|
# this will cache them and speed up future builds
|
||||||
|
FROM base AS install
|
||||||
|
RUN mkdir -p /temp/dev
|
||||||
|
COPY package.json bun.lockb /temp/dev/
|
||||||
|
RUN cd /temp/dev && bun install --frozen-lockfile
|
||||||
|
|
||||||
|
# install with --production (exclude devDependencies)
|
||||||
|
RUN mkdir -p /temp/prod
|
||||||
|
COPY package.json bun.lockb /temp/prod/
|
||||||
|
RUN cd /temp/prod && bun install --frozen-lockfile --production
|
||||||
|
|
||||||
|
# copy node_modules from temp directory
|
||||||
|
# then copy all (non-ignored) project files into the image
|
||||||
|
FROM base AS builder
|
||||||
|
COPY --from=install /temp/dev/node_modules /app/node_modules
|
||||||
|
COPY . /app
|
||||||
|
RUN bun run build
|
||||||
|
|
||||||
|
FROM base
|
||||||
|
# Metadata
|
||||||
|
LABEL org.opencontainers.image.title="VPGen"
|
||||||
|
LABEL org.opencontainers.image.description="A VPN config generator built with SvelteKit."
|
||||||
|
LABEL org.opencontainers.image.url="https://gitea.cazzzer.com/CaZzzer/vpgen"
|
||||||
|
LABEL org.opencontainers.image.source="https://gitea.cazzzer.com/CaZzzer/vpgen"
|
||||||
|
LABEL org.opencontainers.image.version="0.1"
|
||||||
|
|
||||||
|
COPY ./entrypoint.sh /entrypoint.sh
|
||||||
|
COPY --from=install /temp/prod/node_modules /app/node_modules
|
||||||
|
COPY --from=builder /app/build /app/build
|
||||||
|
COPY --from=builder /app/drizzle /app/drizzle
|
||||||
|
COPY --from=builder /app/drizzle.config.ts /app/
|
||||||
|
|
||||||
|
EXPOSE 3000
|
||||||
|
|
||||||
|
# entrypoint for drizzle migrations
|
||||||
|
ENTRYPOINT ["sh", "/entrypoint.sh"]
|
||||||
|
|
||||||
|
CMD ["bun", "./build"]
|
@@ -36,3 +36,5 @@ npm run build
|
|||||||
You can preview the production build with `npm run preview`.
|
You can preview the production build with `npm run preview`.
|
||||||
|
|
||||||
> To deploy your app, you may need to install an [adapter](https://svelte.dev/docs/kit/adapters) for your target environment.
|
> To deploy your app, you may need to install an [adapter](https://svelte.dev/docs/kit/adapters) for your target environment.
|
||||||
|
|
||||||
|
When deploying, set `ORIGIN` to the URL of your site to prevent cross-site request errors.
|
||||||
|
1
bunfig.toml
Normal file
1
bunfig.toml
Normal file
@@ -0,0 +1 @@
|
|||||||
|
logLevel = "info"
|
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"$schema": "https://shadcn-svelte.com/schema.json",
|
"$schema": "https://next.shadcn-svelte.com/schema.json",
|
||||||
"style": "default",
|
"style": "default",
|
||||||
"tailwind": {
|
"tailwind": {
|
||||||
"config": "tailwind.config.ts",
|
"config": "tailwind.config.ts",
|
||||||
@@ -8,7 +8,10 @@
|
|||||||
},
|
},
|
||||||
"aliases": {
|
"aliases": {
|
||||||
"components": "$lib/components",
|
"components": "$lib/components",
|
||||||
"utils": "$lib/utils"
|
"utils": "$lib/utils",
|
||||||
|
"ui": "$lib/components/ui",
|
||||||
|
"hooks": "$lib/hooks"
|
||||||
},
|
},
|
||||||
"typescript": true
|
"typescript": true,
|
||||||
|
"registry": "https://next.shadcn-svelte.com/registry"
|
||||||
}
|
}
|
@@ -1,10 +1,22 @@
|
|||||||
CREATE TABLE `ip_allocations` (
|
CREATE TABLE `devices` (
|
||||||
`id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
|
`id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||||
`client_id` integer,
|
`user_id` text NOT NULL,
|
||||||
FOREIGN KEY (`client_id`) REFERENCES `wg_clients`(`id`) ON UPDATE no action ON DELETE set null
|
`name` text NOT NULL,
|
||||||
|
`opnsense_id` text,
|
||||||
|
`public_key` text NOT NULL,
|
||||||
|
`private_key` text,
|
||||||
|
`pre_shared_key` text,
|
||||||
|
FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON UPDATE no action ON DELETE no action
|
||||||
);
|
);
|
||||||
--> statement-breakpoint
|
--> statement-breakpoint
|
||||||
CREATE UNIQUE INDEX `ip_allocations_client_id_unique` ON `ip_allocations` (`client_id`);--> statement-breakpoint
|
CREATE UNIQUE INDEX `devices_public_key_unique` ON `devices` (`public_key`);--> statement-breakpoint
|
||||||
|
CREATE TABLE `ip_allocations` (
|
||||||
|
`id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||||
|
`device_id` integer,
|
||||||
|
FOREIGN KEY (`device_id`) REFERENCES `devices`(`id`) ON UPDATE no action ON DELETE set null
|
||||||
|
);
|
||||||
|
--> statement-breakpoint
|
||||||
|
CREATE UNIQUE INDEX `ip_allocations_device_id_unique` ON `ip_allocations` (`device_id`);--> statement-breakpoint
|
||||||
CREATE TABLE `sessions` (
|
CREATE TABLE `sessions` (
|
||||||
`id` text PRIMARY KEY NOT NULL,
|
`id` text PRIMARY KEY NOT NULL,
|
||||||
`user_id` text NOT NULL,
|
`user_id` text NOT NULL,
|
||||||
@@ -17,16 +29,3 @@ CREATE TABLE `users` (
|
|||||||
`username` text NOT NULL,
|
`username` text NOT NULL,
|
||||||
`name` text NOT NULL
|
`name` text NOT NULL
|
||||||
);
|
);
|
||||||
--> statement-breakpoint
|
|
||||||
CREATE TABLE `wg_clients` (
|
|
||||||
`id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
|
|
||||||
`user_id` text NOT NULL,
|
|
||||||
`name` text NOT NULL,
|
|
||||||
`opnsense_id` text,
|
|
||||||
`public_key` text NOT NULL,
|
|
||||||
`private_key` text,
|
|
||||||
`pre_shared_key` text,
|
|
||||||
FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON UPDATE no action ON DELETE no action
|
|
||||||
);
|
|
||||||
--> statement-breakpoint
|
|
||||||
CREATE UNIQUE INDEX `wg_clients_public_key_unique` ON `wg_clients` (`public_key`);
|
|
@@ -1,9 +1,90 @@
|
|||||||
{
|
{
|
||||||
"version": "6",
|
"version": "6",
|
||||||
"dialect": "sqlite",
|
"dialect": "sqlite",
|
||||||
"id": "29e6fd88-fa47-4f79-ad83-c52538bc36a6",
|
"id": "48b7ce55-58f1-4b97-a144-ca733576dba6",
|
||||||
"prevId": "00000000-0000-0000-0000-000000000000",
|
"prevId": "00000000-0000-0000-0000-000000000000",
|
||||||
"tables": {
|
"tables": {
|
||||||
|
"devices": {
|
||||||
|
"name": "devices",
|
||||||
|
"columns": {
|
||||||
|
"id": {
|
||||||
|
"name": "id",
|
||||||
|
"type": "integer",
|
||||||
|
"primaryKey": true,
|
||||||
|
"notNull": true,
|
||||||
|
"autoincrement": true
|
||||||
|
},
|
||||||
|
"user_id": {
|
||||||
|
"name": "user_id",
|
||||||
|
"type": "text",
|
||||||
|
"primaryKey": false,
|
||||||
|
"notNull": true,
|
||||||
|
"autoincrement": false
|
||||||
|
},
|
||||||
|
"name": {
|
||||||
|
"name": "name",
|
||||||
|
"type": "text",
|
||||||
|
"primaryKey": false,
|
||||||
|
"notNull": true,
|
||||||
|
"autoincrement": false
|
||||||
|
},
|
||||||
|
"opnsense_id": {
|
||||||
|
"name": "opnsense_id",
|
||||||
|
"type": "text",
|
||||||
|
"primaryKey": false,
|
||||||
|
"notNull": false,
|
||||||
|
"autoincrement": false
|
||||||
|
},
|
||||||
|
"public_key": {
|
||||||
|
"name": "public_key",
|
||||||
|
"type": "text",
|
||||||
|
"primaryKey": false,
|
||||||
|
"notNull": true,
|
||||||
|
"autoincrement": false
|
||||||
|
},
|
||||||
|
"private_key": {
|
||||||
|
"name": "private_key",
|
||||||
|
"type": "text",
|
||||||
|
"primaryKey": false,
|
||||||
|
"notNull": false,
|
||||||
|
"autoincrement": false
|
||||||
|
},
|
||||||
|
"pre_shared_key": {
|
||||||
|
"name": "pre_shared_key",
|
||||||
|
"type": "text",
|
||||||
|
"primaryKey": false,
|
||||||
|
"notNull": false,
|
||||||
|
"autoincrement": false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"indexes": {
|
||||||
|
"devices_public_key_unique": {
|
||||||
|
"name": "devices_public_key_unique",
|
||||||
|
"columns": [
|
||||||
|
"public_key"
|
||||||
|
],
|
||||||
|
"isUnique": true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"foreignKeys": {
|
||||||
|
"devices_user_id_users_id_fk": {
|
||||||
|
"name": "devices_user_id_users_id_fk",
|
||||||
|
"tableFrom": "devices",
|
||||||
|
"tableTo": "users",
|
||||||
|
"columnsFrom": [
|
||||||
|
"user_id"
|
||||||
|
],
|
||||||
|
"columnsTo": [
|
||||||
|
"id"
|
||||||
|
],
|
||||||
|
"onDelete": "no action",
|
||||||
|
"onUpdate": "no action"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"compositePrimaryKeys": {},
|
||||||
|
"uniqueConstraints": {},
|
||||||
|
"checkConstraints": {}
|
||||||
|
},
|
||||||
"ip_allocations": {
|
"ip_allocations": {
|
||||||
"name": "ip_allocations",
|
"name": "ip_allocations",
|
||||||
"columns": {
|
"columns": {
|
||||||
@@ -14,8 +95,8 @@
|
|||||||
"notNull": true,
|
"notNull": true,
|
||||||
"autoincrement": true
|
"autoincrement": true
|
||||||
},
|
},
|
||||||
"client_id": {
|
"device_id": {
|
||||||
"name": "client_id",
|
"name": "device_id",
|
||||||
"type": "integer",
|
"type": "integer",
|
||||||
"primaryKey": false,
|
"primaryKey": false,
|
||||||
"notNull": false,
|
"notNull": false,
|
||||||
@@ -23,21 +104,21 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"indexes": {
|
"indexes": {
|
||||||
"ip_allocations_client_id_unique": {
|
"ip_allocations_device_id_unique": {
|
||||||
"name": "ip_allocations_client_id_unique",
|
"name": "ip_allocations_device_id_unique",
|
||||||
"columns": [
|
"columns": [
|
||||||
"client_id"
|
"device_id"
|
||||||
],
|
],
|
||||||
"isUnique": true
|
"isUnique": true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"foreignKeys": {
|
"foreignKeys": {
|
||||||
"ip_allocations_client_id_wg_clients_id_fk": {
|
"ip_allocations_device_id_devices_id_fk": {
|
||||||
"name": "ip_allocations_client_id_wg_clients_id_fk",
|
"name": "ip_allocations_device_id_devices_id_fk",
|
||||||
"tableFrom": "ip_allocations",
|
"tableFrom": "ip_allocations",
|
||||||
"tableTo": "wg_clients",
|
"tableTo": "devices",
|
||||||
"columnsFrom": [
|
"columnsFrom": [
|
||||||
"client_id"
|
"device_id"
|
||||||
],
|
],
|
||||||
"columnsTo": [
|
"columnsTo": [
|
||||||
"id"
|
"id"
|
||||||
@@ -125,87 +206,6 @@
|
|||||||
"compositePrimaryKeys": {},
|
"compositePrimaryKeys": {},
|
||||||
"uniqueConstraints": {},
|
"uniqueConstraints": {},
|
||||||
"checkConstraints": {}
|
"checkConstraints": {}
|
||||||
},
|
|
||||||
"wg_clients": {
|
|
||||||
"name": "wg_clients",
|
|
||||||
"columns": {
|
|
||||||
"id": {
|
|
||||||
"name": "id",
|
|
||||||
"type": "integer",
|
|
||||||
"primaryKey": true,
|
|
||||||
"notNull": true,
|
|
||||||
"autoincrement": true
|
|
||||||
},
|
|
||||||
"user_id": {
|
|
||||||
"name": "user_id",
|
|
||||||
"type": "text",
|
|
||||||
"primaryKey": false,
|
|
||||||
"notNull": true,
|
|
||||||
"autoincrement": false
|
|
||||||
},
|
|
||||||
"name": {
|
|
||||||
"name": "name",
|
|
||||||
"type": "text",
|
|
||||||
"primaryKey": false,
|
|
||||||
"notNull": true,
|
|
||||||
"autoincrement": false
|
|
||||||
},
|
|
||||||
"opnsense_id": {
|
|
||||||
"name": "opnsense_id",
|
|
||||||
"type": "text",
|
|
||||||
"primaryKey": false,
|
|
||||||
"notNull": false,
|
|
||||||
"autoincrement": false
|
|
||||||
},
|
|
||||||
"public_key": {
|
|
||||||
"name": "public_key",
|
|
||||||
"type": "text",
|
|
||||||
"primaryKey": false,
|
|
||||||
"notNull": true,
|
|
||||||
"autoincrement": false
|
|
||||||
},
|
|
||||||
"private_key": {
|
|
||||||
"name": "private_key",
|
|
||||||
"type": "text",
|
|
||||||
"primaryKey": false,
|
|
||||||
"notNull": false,
|
|
||||||
"autoincrement": false
|
|
||||||
},
|
|
||||||
"pre_shared_key": {
|
|
||||||
"name": "pre_shared_key",
|
|
||||||
"type": "text",
|
|
||||||
"primaryKey": false,
|
|
||||||
"notNull": false,
|
|
||||||
"autoincrement": false
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"indexes": {
|
|
||||||
"wg_clients_public_key_unique": {
|
|
||||||
"name": "wg_clients_public_key_unique",
|
|
||||||
"columns": [
|
|
||||||
"public_key"
|
|
||||||
],
|
|
||||||
"isUnique": true
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"foreignKeys": {
|
|
||||||
"wg_clients_user_id_users_id_fk": {
|
|
||||||
"name": "wg_clients_user_id_users_id_fk",
|
|
||||||
"tableFrom": "wg_clients",
|
|
||||||
"tableTo": "users",
|
|
||||||
"columnsFrom": [
|
|
||||||
"user_id"
|
|
||||||
],
|
|
||||||
"columnsTo": [
|
|
||||||
"id"
|
|
||||||
],
|
|
||||||
"onDelete": "no action",
|
|
||||||
"onUpdate": "no action"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"compositePrimaryKeys": {},
|
|
||||||
"uniqueConstraints": {},
|
|
||||||
"checkConstraints": {}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"views": {},
|
"views": {},
|
||||||
|
@@ -5,8 +5,8 @@
|
|||||||
{
|
{
|
||||||
"idx": 0,
|
"idx": 0,
|
||||||
"version": "6",
|
"version": "6",
|
||||||
"when": 1735028333867,
|
"when": 1736295566569,
|
||||||
"tag": "0000_young_wong",
|
"tag": "0000_fair_tarantula",
|
||||||
"breakpoints": true
|
"breakpoints": true
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
8
entrypoint.sh
Normal file
8
entrypoint.sh
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
set -e
|
||||||
|
|
||||||
|
# Run database migrations
|
||||||
|
bun run db:migrate
|
||||||
|
|
||||||
|
# Execute the CMD passed to the container
|
||||||
|
exec "$@"
|
58
package.json
58
package.json
@@ -17,43 +17,45 @@
|
|||||||
"db:seed": "bun run ./src/lib/server/db/seed.ts"
|
"db:seed": "bun run ./src/lib/server/db/seed.ts"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@sveltejs/adapter-auto": "^3.0.0",
|
"@oslojs/crypto": "^1.0.1",
|
||||||
"@sveltejs/kit": "^2.0.0",
|
"@oslojs/encoding": "^1.1.0",
|
||||||
"@sveltejs/vite-plugin-svelte": "^4.0.0",
|
"@sveltejs/adapter-auto": "^3.3.1",
|
||||||
|
"@sveltejs/adapter-node": "^5.2.11",
|
||||||
|
"@sveltejs/kit": "^2.15.0",
|
||||||
|
"@sveltejs/vite-plugin-svelte": "^5.0.3",
|
||||||
"@tailwindcss/container-queries": "^0.1.1",
|
"@tailwindcss/container-queries": "^0.1.1",
|
||||||
"@tailwindcss/forms": "^0.5.9",
|
"@tailwindcss/forms": "^0.5.9",
|
||||||
"@tailwindcss/typography": "^0.5.15",
|
"@tailwindcss/typography": "^0.5.15",
|
||||||
"@types/better-sqlite3": "^7.6.11",
|
"@types/better-sqlite3": "^7.6.12",
|
||||||
"@types/eslint": "^9.6.0",
|
"@types/eslint": "^9.6.1",
|
||||||
"@types/qrcode-svg": "^1.1.5",
|
"@types/qrcode-svg": "^1.1.5",
|
||||||
|
"arctic": "^2.3.3",
|
||||||
"autoprefixer": "^10.4.20",
|
"autoprefixer": "^10.4.20",
|
||||||
"bits-ui": "^0.21.16",
|
"bits-ui": "^0.22.0",
|
||||||
"clsx": "^2.1.1",
|
"clsx": "^2.1.1",
|
||||||
"drizzle-kit": "^0.30.1",
|
"eslint": "^9.17.0",
|
||||||
"eslint": "^9.7.0",
|
|
||||||
"eslint-config-prettier": "^9.1.0",
|
"eslint-config-prettier": "^9.1.0",
|
||||||
"eslint-plugin-svelte": "^2.36.0",
|
"eslint-plugin-svelte": "^2.46.1",
|
||||||
"globals": "^15.0.0",
|
"globals": "^15.14.0",
|
||||||
"prettier": "^3.3.2",
|
"ip-address": "^10.0.1",
|
||||||
"prettier-plugin-svelte": "^3.2.6",
|
"lucide-svelte": "^0.469.0",
|
||||||
"prettier-plugin-tailwindcss": "^0.6.5",
|
"prettier": "^3.4.2",
|
||||||
"svelte": "^5.0.0",
|
"prettier-plugin-svelte": "^3.3.2",
|
||||||
"svelte-check": "^4.0.0",
|
"prettier-plugin-tailwindcss": "^0.6.9",
|
||||||
"tailwind-merge": "^2.5.4",
|
"qrcode-svg": "^1.1.0",
|
||||||
"tailwind-variants": "^0.2.1",
|
"svelte": "^5.16.0",
|
||||||
"tailwindcss": "^3.4.9",
|
"svelte-check": "^4.1.1",
|
||||||
"typescript": "^5.0.0",
|
"tailwind-merge": "^2.6.0",
|
||||||
"typescript-eslint": "^8.0.0",
|
"tailwind-variants": "^0.3.0",
|
||||||
"vite": "^5.0.3"
|
"tailwindcss": "^3.4.17",
|
||||||
|
"tailwindcss-animate": "^1.0.7",
|
||||||
|
"typescript": "^5.7.2",
|
||||||
|
"typescript-eslint": "^8.18.2",
|
||||||
|
"vite": "^6.0.6"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@libsql/client": "^0.14.0",
|
"@libsql/client": "^0.14.0",
|
||||||
"@oslojs/crypto": "^1.0.1",
|
"drizzle-kit": "^0.30.1",
|
||||||
"@oslojs/encoding": "^1.1.0",
|
"drizzle-orm": "^0.38.3"
|
||||||
"arctic": "^2.2.1",
|
|
||||||
"drizzle-orm": "^0.38.2",
|
|
||||||
"ip-address": "^10.0.1",
|
|
||||||
"lucide-svelte": "^0.454.0",
|
|
||||||
"qrcode-svg": "^1.1.0"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
31
src/app.css
31
src/app.css
@@ -26,6 +26,7 @@
|
|||||||
--secondary-foreground: 222.2 47.4% 11.2%;
|
--secondary-foreground: 222.2 47.4% 11.2%;
|
||||||
|
|
||||||
--accent: 210 26% 86%;
|
--accent: 210 26% 86%;
|
||||||
|
--accent-light: 210 26% 86%;
|
||||||
--accent-foreground: 222.2 47.4% 11.2%;
|
--accent-foreground: 222.2 47.4% 11.2%;
|
||||||
|
|
||||||
--destructive: 0 72.2% 50.6%;
|
--destructive: 0 72.2% 50.6%;
|
||||||
@@ -34,6 +35,17 @@
|
|||||||
--ring: 222.2 84% 4.9%;
|
--ring: 222.2 84% 4.9%;
|
||||||
|
|
||||||
--radius: 0.5rem;
|
--radius: 0.5rem;
|
||||||
|
|
||||||
|
--sidebar-background: 0 0% 98%;
|
||||||
|
--sidebar-foreground: 240 5.3% 26.1%;
|
||||||
|
--sidebar-primary: 240 5.9% 10%;
|
||||||
|
--sidebar-primary-foreground: 0 0% 98%;
|
||||||
|
--sidebar-accent: 240 4.8% 95.9%;
|
||||||
|
--sidebar-accent-foreground: 240 5.9% 10%;
|
||||||
|
--sidebar-border: 220 13% 91%;
|
||||||
|
--sidebar-ring: 217.2 91.2% 59.8%;
|
||||||
|
|
||||||
|
--surface: 210 26% 76%;
|
||||||
}
|
}
|
||||||
|
|
||||||
@media (prefers-color-scheme: dark) {
|
@media (prefers-color-scheme: dark) {
|
||||||
@@ -66,6 +78,17 @@
|
|||||||
--destructive-foreground: 210 40% 90%;
|
--destructive-foreground: 210 40% 90%;
|
||||||
|
|
||||||
--ring: 212.7 26.8% 83.9%;
|
--ring: 212.7 26.8% 83.9%;
|
||||||
|
|
||||||
|
--sidebar-background: 240 5.9% 10%;
|
||||||
|
--sidebar-foreground: 240 4.8% 95.9%;
|
||||||
|
--sidebar-primary: 224.3 76.3% 48%;
|
||||||
|
--sidebar-primary-foreground: 0 0% 100%;
|
||||||
|
--sidebar-accent: 240 3.7% 15.9%;
|
||||||
|
--sidebar-accent-foreground: 240 4.8% 95.9%;
|
||||||
|
--sidebar-border: 240 3.7% 15.9%;
|
||||||
|
--sidebar-ring: 217.2 91.2% 59.8%;
|
||||||
|
|
||||||
|
--surface: 217.2 40.6% 11.5%;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -78,4 +101,12 @@
|
|||||||
body {
|
body {
|
||||||
@apply bg-background text-foreground;
|
@apply bg-background text-foreground;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ol > li {
|
||||||
|
@apply flex flex-wrap gap-x-2;
|
||||||
|
counter-increment: counterName;
|
||||||
|
}
|
||||||
|
ol > li:before {
|
||||||
|
content: counter(counterName) '.';
|
||||||
|
}
|
||||||
}
|
}
|
@@ -6,7 +6,10 @@
|
|||||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||||
%sveltekit.head%
|
%sveltekit.head%
|
||||||
</head>
|
</head>
|
||||||
<body data-sveltekit-preload-data="hover">
|
<body
|
||||||
<div class="flex flex-col min-h-screen">%sveltekit.body%</div>
|
data-sveltekit-preload-data="hover"
|
||||||
|
class="flex min-h-screen flex-col items-center gap-8 p-4 max-sm:px-2"
|
||||||
|
>
|
||||||
|
%sveltekit.body%
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
@@ -1,7 +1,11 @@
|
|||||||
import { type Handle, redirect } from '@sveltejs/kit';
|
import { type Handle, redirect } from '@sveltejs/kit';
|
||||||
|
import { sequence } from '@sveltejs/kit/hooks';
|
||||||
import { dev } from '$app/environment';
|
import { dev } from '$app/environment';
|
||||||
import * as auth from '$lib/server/auth';
|
import * as auth from '$lib/server/auth';
|
||||||
import { sequence } from '@sveltejs/kit/hooks';
|
import { fetchOpnsenseServer } from '$lib/server/opnsense';
|
||||||
|
|
||||||
|
// fetch opnsense server info on startup
|
||||||
|
await fetchOpnsenseServer();
|
||||||
|
|
||||||
const handleAuth: Handle = async ({ event, resolve }) => {
|
const handleAuth: Handle = async ({ event, resolve }) => {
|
||||||
const sessionId = event.cookies.get(auth.sessionCookieName);
|
const sessionId = event.cookies.get(auth.sessionCookieName);
|
||||||
@@ -35,7 +39,7 @@ const authRequired = [
|
|||||||
/^\/api/,
|
/^\/api/,
|
||||||
/^\/user/,
|
/^\/user/,
|
||||||
/^\/connections/,
|
/^\/connections/,
|
||||||
/^\/clients/,
|
/^\/devices/,
|
||||||
];
|
];
|
||||||
const handleProtectedPaths: Handle = ({ event, resolve }) => {
|
const handleProtectedPaths: Handle = ({ event, resolve }) => {
|
||||||
const isProtected = authRequired.some((re) => re.test(event.url.pathname));
|
const isProtected = authRequired.some((re) => re.test(event.url.pathname));
|
||||||
|
BIN
src/lib/assets/GetItOnGooglePlay_Badge_Web_color_English.png
Normal file
BIN
src/lib/assets/GetItOnGooglePlay_Badge_Web_color_English.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.6 KiB |
BIN
src/lib/assets/guide-android.mp4
(Stored with Git LFS)
Normal file
BIN
src/lib/assets/guide-android.mp4
(Stored with Git LFS)
Normal file
Binary file not shown.
@@ -1,33 +0,0 @@
|
|||||||
import type { ClientDetails } from '$lib/types/clients';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Convert client details to WireGuard configuration.
|
|
||||||
*
|
|
||||||
* ```conf
|
|
||||||
* [Interface]
|
|
||||||
* PrivateKey = wPa07zR0H4wYoc1ljfeiqlSbR8Z28pPc6jplwE7zPms=
|
|
||||||
* Address = 10.18.11.100/32,fd00::1/128
|
|
||||||
* DNS = 10.18.11.1,fd00::0
|
|
||||||
*
|
|
||||||
* [Peer]
|
|
||||||
* PublicKey = BJ5faPVJsDP4CCxNYilmKnwlQXOtXEOJjqIwb4U/CgM=
|
|
||||||
* PresharedKey = uhZUVqXKF0oayP0BS6yPu6Gepgh68Nz9prtbE5Cuok0=
|
|
||||||
* Endpoint = vpn.lab.cazzzer.com:51820
|
|
||||||
* AllowedIPs = 0.0.0.0/0,::/0
|
|
||||||
* ```
|
|
||||||
* @param client
|
|
||||||
*/
|
|
||||||
export function clientDetailsToConfig(client: ClientDetails): string {
|
|
||||||
return `\
|
|
||||||
[Interface]
|
|
||||||
PrivateKey = ${client.privateKey}
|
|
||||||
Address = ${client.ips.join(', ')}
|
|
||||||
DNS = ${client.vpnDns}
|
|
||||||
|
|
||||||
[Peer]
|
|
||||||
PublicKey = ${client.vpnPublicKey}
|
|
||||||
PresharedKey = ${client.preSharedKey}
|
|
||||||
Endpoint = ${client.vpnEndpoint}
|
|
||||||
AllowedIPs = 0.0.0.0/0,::/0
|
|
||||||
`;
|
|
||||||
}
|
|
@@ -1,20 +1,29 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { LucideLoaderCircle } from 'lucide-svelte';
|
import { LucideLoaderCircle } from 'lucide-svelte';
|
||||||
import { Button } from "$lib/components/ui/button";
|
import { Button } from '$lib/components/ui/button';
|
||||||
import { cn } from "$lib/utils.js";
|
import { cn } from '$lib/utils.js';
|
||||||
|
|
||||||
let { class: className, ...rest }: {class: string | undefined | null, rest: { [p: string]: unknown }} = $props();
|
let { class: className, ...rest }: { class?: string; rest?: { [p: string]: unknown } } = $props();
|
||||||
|
|
||||||
let isLoading = $state(false);
|
let isLoading = $state(false);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class={cn("grid gap-6", className)} {...rest}>
|
<div class={cn('flex gap-6', className)} {...rest}>
|
||||||
<form method="get" action="/auth/authentik">
|
<form method="get" action="/auth/authentik">
|
||||||
<Button type="submit" onclick={() => {isLoading=true}}>
|
<Button
|
||||||
|
type="submit"
|
||||||
|
onclick={() => {
|
||||||
|
isLoading = true;
|
||||||
|
}}
|
||||||
|
>
|
||||||
{#if isLoading}
|
{#if isLoading}
|
||||||
<LucideLoaderCircle class="mr-2 h-4 w-4 animate-spin" />
|
<LucideLoaderCircle class="mr-2 h-4 w-4 animate-spin" />
|
||||||
{:else}
|
{:else}
|
||||||
<img class="mr-2 h-4 w-4" alt="Authentik Logo" src="https://auth.cazzzer.com/static/dist/assets/icons/icon.svg" />
|
<img
|
||||||
|
class="mr-2 h-4 w-4"
|
||||||
|
alt="Authentik Logo"
|
||||||
|
src="https://auth.cazzzer.com/static/dist/assets/icons/icon.svg"
|
||||||
|
/>
|
||||||
{/if}
|
{/if}
|
||||||
Sign in with Authentik
|
Sign in with Authentik
|
||||||
</Button>
|
</Button>
|
||||||
|
74
src/lib/components/app/code-snippet/code-snippet.svelte
Normal file
74
src/lib/components/app/code-snippet/code-snippet.svelte
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { Button } from '$lib/components/ui/button';
|
||||||
|
import { LucideClipboardCopy, LucideDownload } from 'lucide-svelte';
|
||||||
|
|
||||||
|
const {
|
||||||
|
data,
|
||||||
|
filename,
|
||||||
|
copy,
|
||||||
|
download,
|
||||||
|
}: {
|
||||||
|
data: string;
|
||||||
|
filename?: string;
|
||||||
|
copy?: boolean;
|
||||||
|
download?: boolean;
|
||||||
|
} = $props();
|
||||||
|
|
||||||
|
let wasCopied = $state(false);
|
||||||
|
|
||||||
|
const roundedPre = copy || download ? 'rounded-b-lg' : 'rounded-lg';
|
||||||
|
|
||||||
|
async function copyToClipboard() {
|
||||||
|
await navigator.clipboard.writeText(data);
|
||||||
|
wasCopied = true;
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div class="flex max-w-full flex-grow flex-col rounded-lg bg-accent">
|
||||||
|
{#if copy || download}
|
||||||
|
<!--Copy and download buttons-->
|
||||||
|
<div class="b flex flex-wrap items-center justify-between gap-4 rounded-t-lg p-2">
|
||||||
|
Configuration
|
||||||
|
<div class="flex gap-2">
|
||||||
|
{#if copy}
|
||||||
|
<Button
|
||||||
|
class="action-button group"
|
||||||
|
onclick={copyToClipboard}
|
||||||
|
onmouseleave={() => (wasCopied = false)}
|
||||||
|
>
|
||||||
|
<LucideClipboardCopy />
|
||||||
|
<span class="group-hover:block">
|
||||||
|
{wasCopied ? 'Copied' : 'Copy to clipboard'}
|
||||||
|
</span>
|
||||||
|
</Button>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
{#if download}
|
||||||
|
<a
|
||||||
|
class="contents"
|
||||||
|
href={`data:application/octet-stream;charset=utf-8,${encodeURIComponent(data)}`}
|
||||||
|
download={filename}
|
||||||
|
>
|
||||||
|
<Button class="action-button group">
|
||||||
|
<LucideDownload />
|
||||||
|
<span class="group-hover:block">Download</span>
|
||||||
|
</Button>
|
||||||
|
</a>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
<div class="bg-surface flex items-start overflow-x-auto {roundedPre} p-2">
|
||||||
|
<pre><code>{data}</code></pre>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
:global(.action-button) {
|
||||||
|
@apply relative size-auto p-2;
|
||||||
|
}
|
||||||
|
|
||||||
|
:global(.action-button > span) {
|
||||||
|
@apply absolute bottom-full mb-3 hidden rounded-lg bg-muted p-2 text-xs text-foreground;
|
||||||
|
}
|
||||||
|
</style>
|
7
src/lib/components/app/code-snippet/index.ts
Normal file
7
src/lib/components/app/code-snippet/index.ts
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
import Root from "./code-snippet.svelte";
|
||||||
|
|
||||||
|
export {
|
||||||
|
Root,
|
||||||
|
//
|
||||||
|
Root as CodeSnippet,
|
||||||
|
};
|
5
src/lib/components/app/wireguard-guide/index.ts
Normal file
5
src/lib/components/app/wireguard-guide/index.ts
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
import WireguardGuide from "./wireguard-guide.svelte";
|
||||||
|
|
||||||
|
export {
|
||||||
|
WireguardGuide
|
||||||
|
};
|
@@ -0,0 +1,85 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import * as Tabs from '$lib/components/ui/tabs';
|
||||||
|
import * as Card from '$lib/components/ui/card';
|
||||||
|
import getItOnGooglePlay from '$lib/assets/GetItOnGooglePlay_Badge_Web_color_English.png';
|
||||||
|
import guideVideoAndroid from '$lib/assets/guide-android.mp4';
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<Tabs.Root value="android">
|
||||||
|
<Tabs.List class="grid w-full grid-cols-3">
|
||||||
|
<Tabs.Trigger value="android">Android</Tabs.Trigger>
|
||||||
|
<Tabs.Trigger value="windows">Windows</Tabs.Trigger>
|
||||||
|
<Tabs.Trigger value="other">Other</Tabs.Trigger>
|
||||||
|
</Tabs.List>
|
||||||
|
<Tabs.Content value="android">
|
||||||
|
<Card.Root>
|
||||||
|
<Card.Header class="max-sm:px-4 max-sm:pt-4">
|
||||||
|
<Card.Title>WireGuard on Android</Card.Title>
|
||||||
|
</Card.Header>
|
||||||
|
<Card.Content class="max-sm:p-4">
|
||||||
|
<ol class="flex flex-col gap-2">
|
||||||
|
<li>
|
||||||
|
<div class="flex flex-col gap-2">
|
||||||
|
Install the WireGuard app
|
||||||
|
<a
|
||||||
|
class="contents"
|
||||||
|
href="https://play.google.com/store/apps/details?id=com.wireguard.android"
|
||||||
|
target="_blank"
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
>
|
||||||
|
<img class="size-min" alt="Get it on google play" src={getItOnGooglePlay} />
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<div class="flex flex-col gap-2">
|
||||||
|
<p>Download the configuration file and import it</p>
|
||||||
|
<aside>Alternatively, you can scan the QR code with the WireGuard app</aside>
|
||||||
|
<video autoplay loop controls muted preload="metadata" class="max-h-screen">
|
||||||
|
<source src={guideVideoAndroid} type="video/mp4" />
|
||||||
|
</video>
|
||||||
|
</div>
|
||||||
|
</li>
|
||||||
|
</ol>
|
||||||
|
</Card.Content>
|
||||||
|
</Card.Root>
|
||||||
|
</Tabs.Content>
|
||||||
|
<Tabs.Content value="windows">
|
||||||
|
<Card.Root>
|
||||||
|
<Card.Header>
|
||||||
|
<Card.Title>WireGuard on Windows</Card.Title>
|
||||||
|
</Card.Header>
|
||||||
|
<Card.Content>
|
||||||
|
<p>
|
||||||
|
<a
|
||||||
|
class="underline"
|
||||||
|
href="https://download.wireguard.com/windows-client/wireguard-installer.exe"
|
||||||
|
target="_blank"
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
>
|
||||||
|
Download WireGuard
|
||||||
|
</a>
|
||||||
|
</p>
|
||||||
|
</Card.Content>
|
||||||
|
</Card.Root>
|
||||||
|
</Tabs.Content>
|
||||||
|
<Tabs.Content value="other">
|
||||||
|
<Card.Root>
|
||||||
|
<Card.Header>
|
||||||
|
<Card.Title>WireGuard on Other Platforms</Card.Title>
|
||||||
|
</Card.Header>
|
||||||
|
<Card.Content>
|
||||||
|
<p>
|
||||||
|
You can download the WireGuard client from the <a
|
||||||
|
class="underline"
|
||||||
|
href="https://www.wireguard.com/install/"
|
||||||
|
target="_blank"
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
>
|
||||||
|
official website
|
||||||
|
</a>.
|
||||||
|
</p>
|
||||||
|
</Card.Content>
|
||||||
|
</Card.Root>
|
||||||
|
</Tabs.Content>
|
||||||
|
</Tabs.Root>
|
@@ -1,18 +1,50 @@
|
|||||||
|
<script lang="ts" module>
|
||||||
|
import { type VariantProps, tv } from "tailwind-variants";
|
||||||
|
|
||||||
|
export const badgeVariants = tv({
|
||||||
|
base: "focus:ring-ring inline-flex 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 BadgeVariant = VariantProps<typeof badgeVariants>["variant"];
|
||||||
|
</script>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { type Variant, badgeVariants } from "./index.js";
|
import type { WithElementRef } from "bits-ui";
|
||||||
|
import type { HTMLAnchorAttributes } from "svelte/elements";
|
||||||
import { cn } from "$lib/utils.js";
|
import { cn } from "$lib/utils.js";
|
||||||
|
|
||||||
let className: string | undefined | null = undefined;
|
let {
|
||||||
export let href: string | undefined = undefined;
|
ref = $bindable(null),
|
||||||
export let variant: Variant = "default";
|
href,
|
||||||
export { className as class };
|
class: className,
|
||||||
|
variant = "default",
|
||||||
|
children,
|
||||||
|
...restProps
|
||||||
|
}: WithElementRef<HTMLAnchorAttributes> & {
|
||||||
|
variant?: BadgeVariant;
|
||||||
|
} = $props();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<svelte:element
|
<svelte:element
|
||||||
this={href ? "a" : "span"}
|
this={href ? "a" : "span"}
|
||||||
|
bind:this={ref}
|
||||||
{href}
|
{href}
|
||||||
class={cn(badgeVariants({ variant, className }))}
|
class={cn(badgeVariants({ variant, className }))}
|
||||||
{...$$restProps}
|
{...restProps}
|
||||||
>
|
>
|
||||||
<slot />
|
{@render children?.()}
|
||||||
</svelte:element>
|
</svelte:element>
|
||||||
|
@@ -1,21 +1,2 @@
|
|||||||
import { type VariantProps, tv } from "tailwind-variants";
|
|
||||||
export { default as Badge } from "./badge.svelte";
|
export { default as Badge } from "./badge.svelte";
|
||||||
|
export { badgeVariants, type BadgeVariant } 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"];
|
|
||||||
|
@@ -1,25 +1,74 @@
|
|||||||
<script lang="ts">
|
<script lang="ts" module>
|
||||||
import { Button as ButtonPrimitive } from "bits-ui";
|
import type { WithElementRef } from "bits-ui";
|
||||||
import { type Events, type Props, buttonVariants } from "./index.js";
|
import type { HTMLAnchorAttributes, HTMLButtonAttributes } from "svelte/elements";
|
||||||
import { cn } from "$lib/utils.js";
|
import { type VariantProps, tv } from "tailwind-variants";
|
||||||
|
|
||||||
type $$Props = Props;
|
export const buttonVariants = tv({
|
||||||
type $$Events = Events;
|
base: "ring-offset-background focus-visible:ring-ring inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",
|
||||||
|
variants: {
|
||||||
|
variant: {
|
||||||
|
default: "bg-primary text-primary-foreground hover:bg-primary/90",
|
||||||
|
destructive: "bg-destructive text-destructive-foreground hover:bg-destructive/90",
|
||||||
|
outline:
|
||||||
|
"border-input bg-background hover:bg-accent hover:text-accent-foreground border",
|
||||||
|
secondary: "bg-secondary text-secondary-foreground hover:bg-secondary/80",
|
||||||
|
ghost: "hover:bg-accent hover:text-accent-foreground",
|
||||||
|
link: "text-primary underline-offset-4 hover:underline",
|
||||||
|
},
|
||||||
|
size: {
|
||||||
|
default: "h-10 px-4 py-2",
|
||||||
|
sm: "h-9 rounded-md px-3",
|
||||||
|
lg: "h-11 rounded-md px-8",
|
||||||
|
icon: "h-10 w-10",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
defaultVariants: {
|
||||||
|
variant: "default",
|
||||||
|
size: "default",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
let className: $$Props["class"] = undefined;
|
export type ButtonVariant = VariantProps<typeof buttonVariants>["variant"];
|
||||||
export let variant: $$Props["variant"] = "default";
|
export type ButtonSize = VariantProps<typeof buttonVariants>["size"];
|
||||||
export let size: $$Props["size"] = "default";
|
|
||||||
export let builders: $$Props["builders"] = [];
|
export type ButtonProps = WithElementRef<HTMLButtonAttributes> &
|
||||||
export { className as class };
|
WithElementRef<HTMLAnchorAttributes> & {
|
||||||
|
variant?: ButtonVariant;
|
||||||
|
size?: ButtonSize;
|
||||||
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<ButtonPrimitive.Root
|
<script lang="ts">
|
||||||
{builders}
|
import { cn } from "$lib/utils.js";
|
||||||
|
|
||||||
|
let {
|
||||||
|
class: className,
|
||||||
|
variant = "default",
|
||||||
|
size = "default",
|
||||||
|
ref = $bindable(null),
|
||||||
|
href = undefined,
|
||||||
|
type = "button",
|
||||||
|
children,
|
||||||
|
...restProps
|
||||||
|
}: ButtonProps = $props();
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{#if href}
|
||||||
|
<a
|
||||||
|
bind:this={ref}
|
||||||
class={cn(buttonVariants({ variant, size, className }))}
|
class={cn(buttonVariants({ variant, size, className }))}
|
||||||
type="button"
|
{href}
|
||||||
{...$$restProps}
|
{...restProps}
|
||||||
on:click
|
|
||||||
on:keydown
|
|
||||||
>
|
>
|
||||||
<slot />
|
{@render children?.()}
|
||||||
</ButtonPrimitive.Root>
|
</a>
|
||||||
|
{:else}
|
||||||
|
<button
|
||||||
|
bind:this={ref}
|
||||||
|
class={cn(buttonVariants({ variant, size, className }))}
|
||||||
|
{type}
|
||||||
|
{...restProps}
|
||||||
|
>
|
||||||
|
{@render children?.()}
|
||||||
|
</button>
|
||||||
|
{/if}
|
||||||
|
@@ -1,49 +1,17 @@
|
|||||||
import { type VariantProps, tv } from "tailwind-variants";
|
import Root, {
|
||||||
import type { Button as ButtonPrimitive } from "bits-ui";
|
type ButtonProps,
|
||||||
import Root from "./button.svelte";
|
type ButtonSize,
|
||||||
|
type ButtonVariant,
|
||||||
const buttonVariants = tv({
|
buttonVariants,
|
||||||
base: "ring-offset-background focus-visible:ring-ring inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50",
|
} from "./button.svelte";
|
||||||
variants: {
|
|
||||||
variant: {
|
|
||||||
default: "bg-primary text-primary-foreground hover:bg-primary/90",
|
|
||||||
destructive: "bg-destructive text-destructive-foreground hover:bg-destructive/90",
|
|
||||||
outline:
|
|
||||||
"border-input bg-background hover:bg-accent hover:text-accent-foreground border",
|
|
||||||
secondary: "bg-secondary text-secondary-foreground hover:bg-secondary/80",
|
|
||||||
ghost: "hover:bg-accent hover:text-accent-foreground",
|
|
||||||
link: "text-primary underline-offset-4 hover:underline",
|
|
||||||
},
|
|
||||||
size: {
|
|
||||||
default: "h-10 px-4 py-2",
|
|
||||||
sm: "h-9 rounded-md px-3",
|
|
||||||
lg: "h-11 rounded-md px-8",
|
|
||||||
icon: "h-10 w-10",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
defaultVariants: {
|
|
||||||
variant: "default",
|
|
||||||
size: "default",
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
type Variant = VariantProps<typeof buttonVariants>["variant"];
|
|
||||||
type Size = VariantProps<typeof buttonVariants>["size"];
|
|
||||||
|
|
||||||
type Props = ButtonPrimitive.Props & {
|
|
||||||
variant?: Variant;
|
|
||||||
size?: Size;
|
|
||||||
};
|
|
||||||
|
|
||||||
type Events = ButtonPrimitive.Events;
|
|
||||||
|
|
||||||
export {
|
export {
|
||||||
Root,
|
Root,
|
||||||
type Props,
|
type ButtonProps as Props,
|
||||||
type Events,
|
|
||||||
//
|
//
|
||||||
Root as Button,
|
Root as Button,
|
||||||
type Props as ButtonProps,
|
|
||||||
type Events as ButtonEvents,
|
|
||||||
buttonVariants,
|
buttonVariants,
|
||||||
|
type ButtonProps,
|
||||||
|
type ButtonSize,
|
||||||
|
type ButtonVariant,
|
||||||
};
|
};
|
||||||
|
16
src/lib/components/ui/card/card-content.svelte
Normal file
16
src/lib/components/ui/card/card-content.svelte
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import type { WithElementRef } from "bits-ui";
|
||||||
|
import type { HTMLAttributes } from "svelte/elements";
|
||||||
|
import { cn } from "$lib/utils.js";
|
||||||
|
|
||||||
|
let {
|
||||||
|
ref = $bindable(null),
|
||||||
|
class: className,
|
||||||
|
children,
|
||||||
|
...restProps
|
||||||
|
}: WithElementRef<HTMLAttributes<HTMLDivElement>> = $props();
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div bind:this={ref} class={cn("p-6", className)} {...restProps}>
|
||||||
|
{@render children?.()}
|
||||||
|
</div>
|
16
src/lib/components/ui/card/card-description.svelte
Normal file
16
src/lib/components/ui/card/card-description.svelte
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import type { WithElementRef } from "bits-ui";
|
||||||
|
import type { HTMLAttributes } from "svelte/elements";
|
||||||
|
import { cn } from "$lib/utils.js";
|
||||||
|
|
||||||
|
let {
|
||||||
|
ref = $bindable(null),
|
||||||
|
class: className,
|
||||||
|
children,
|
||||||
|
...restProps
|
||||||
|
}: WithElementRef<HTMLAttributes<HTMLParagraphElement>> = $props();
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<p bind:this={ref} class={cn("text-muted-foreground text-sm", className)} {...restProps}>
|
||||||
|
{@render children?.()}
|
||||||
|
</p>
|
16
src/lib/components/ui/card/card-footer.svelte
Normal file
16
src/lib/components/ui/card/card-footer.svelte
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import type { WithElementRef } from "bits-ui";
|
||||||
|
import type { HTMLAttributes } from "svelte/elements";
|
||||||
|
import { cn } from "$lib/utils.js";
|
||||||
|
|
||||||
|
let {
|
||||||
|
ref = $bindable(null),
|
||||||
|
class: className,
|
||||||
|
children,
|
||||||
|
...restProps
|
||||||
|
}: WithElementRef<HTMLAttributes<HTMLDivElement>> = $props();
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div bind:this={ref} class={cn("flex items-center p-6 pt-0", className)} {...restProps}>
|
||||||
|
{@render children?.()}
|
||||||
|
</div>
|
16
src/lib/components/ui/card/card-header.svelte
Normal file
16
src/lib/components/ui/card/card-header.svelte
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import type { WithElementRef } from "bits-ui";
|
||||||
|
import type { HTMLAttributes } from "svelte/elements";
|
||||||
|
import { cn } from "$lib/utils.js";
|
||||||
|
|
||||||
|
let {
|
||||||
|
ref = $bindable(null),
|
||||||
|
class: className,
|
||||||
|
children,
|
||||||
|
...restProps
|
||||||
|
}: WithElementRef<HTMLAttributes<HTMLDivElement>> = $props();
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div bind:this={ref} class={cn("flex flex-col space-y-1.5 p-6 pb-0", className)} {...restProps}>
|
||||||
|
{@render children?.()}
|
||||||
|
</div>
|
25
src/lib/components/ui/card/card-title.svelte
Normal file
25
src/lib/components/ui/card/card-title.svelte
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import type { WithElementRef } from "bits-ui";
|
||||||
|
import type { HTMLAttributes } from "svelte/elements";
|
||||||
|
import { cn } from "$lib/utils.js";
|
||||||
|
|
||||||
|
let {
|
||||||
|
ref = $bindable(null),
|
||||||
|
class: className,
|
||||||
|
level = 3,
|
||||||
|
children,
|
||||||
|
...restProps
|
||||||
|
}: WithElementRef<HTMLAttributes<HTMLDivElement>> & {
|
||||||
|
level?: 1 | 2 | 3 | 4 | 5 | 6;
|
||||||
|
} = $props();
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div
|
||||||
|
role="heading"
|
||||||
|
aria-level={level}
|
||||||
|
bind:this={ref}
|
||||||
|
class={cn("text-2xl font-semibold leading-none tracking-tight", className)}
|
||||||
|
{...restProps}
|
||||||
|
>
|
||||||
|
{@render children?.()}
|
||||||
|
</div>
|
20
src/lib/components/ui/card/card.svelte
Normal file
20
src/lib/components/ui/card/card.svelte
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import type { WithElementRef } from "bits-ui";
|
||||||
|
import type { HTMLAttributes } from "svelte/elements";
|
||||||
|
import { cn } from "$lib/utils.js";
|
||||||
|
|
||||||
|
let {
|
||||||
|
ref = $bindable(null),
|
||||||
|
class: className,
|
||||||
|
children,
|
||||||
|
...restProps
|
||||||
|
}: WithElementRef<HTMLAttributes<HTMLDivElement>> = $props();
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div
|
||||||
|
bind:this={ref}
|
||||||
|
class={cn("bg-card text-card-foreground rounded-lg border shadow-sm", className)}
|
||||||
|
{...restProps}
|
||||||
|
>
|
||||||
|
{@render children?.()}
|
||||||
|
</div>
|
22
src/lib/components/ui/card/index.ts
Normal file
22
src/lib/components/ui/card/index.ts
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
import Root from "./card.svelte";
|
||||||
|
import Content from "./card-content.svelte";
|
||||||
|
import Description from "./card-description.svelte";
|
||||||
|
import Footer from "./card-footer.svelte";
|
||||||
|
import Header from "./card-header.svelte";
|
||||||
|
import Title from "./card-title.svelte";
|
||||||
|
|
||||||
|
export {
|
||||||
|
Root,
|
||||||
|
Content,
|
||||||
|
Description,
|
||||||
|
Footer,
|
||||||
|
Header,
|
||||||
|
Title,
|
||||||
|
//
|
||||||
|
Root as Card,
|
||||||
|
Content as CardContent,
|
||||||
|
Description as CardDescription,
|
||||||
|
Footer as CardFooter,
|
||||||
|
Header as CardHeader,
|
||||||
|
Title as CardTitle,
|
||||||
|
};
|
@@ -1,35 +1,35 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { Checkbox as CheckboxPrimitive } from "bits-ui";
|
import { Checkbox as CheckboxPrimitive, type WithoutChildrenOrChild } from "bits-ui";
|
||||||
import Check from "lucide-svelte/icons/check";
|
import Check from "lucide-svelte/icons/check";
|
||||||
import Minus from "lucide-svelte/icons/minus";
|
import Minus from "lucide-svelte/icons/minus";
|
||||||
import { cn } from "$lib/utils.js";
|
import { cn } from "$lib/utils.js";
|
||||||
|
|
||||||
type $$Props = CheckboxPrimitive.Props;
|
let {
|
||||||
type $$Events = CheckboxPrimitive.Events;
|
ref = $bindable(null),
|
||||||
|
checked = $bindable(false),
|
||||||
let className: $$Props["class"] = undefined;
|
indeterminate = $bindable(false),
|
||||||
export let checked: $$Props["checked"] = false;
|
class: className,
|
||||||
export { className as class };
|
...restProps
|
||||||
|
}: WithoutChildrenOrChild<CheckboxPrimitive.RootProps> = $props();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<CheckboxPrimitive.Root
|
<CheckboxPrimitive.Root
|
||||||
|
bind:ref
|
||||||
class={cn(
|
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",
|
"border-primary ring-offset-background focus-visible:ring-ring data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground peer box-content size-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
|
className
|
||||||
)}
|
)}
|
||||||
bind:checked
|
bind:checked
|
||||||
{...$$restProps}
|
bind:indeterminate
|
||||||
on:click
|
{...restProps}
|
||||||
>
|
>
|
||||||
<CheckboxPrimitive.Indicator
|
{#snippet children({ checked, indeterminate })}
|
||||||
class={cn("flex h-4 w-4 items-center justify-center text-current")}
|
<div class="flex size-4 items-center justify-center text-current">
|
||||||
let:isChecked
|
{#if indeterminate}
|
||||||
let:isIndeterminate
|
<Minus class="size-3.5" />
|
||||||
>
|
{:else}
|
||||||
{#if isChecked}
|
<Check class={cn("size-3.5", !checked && "text-transparent")} />
|
||||||
<Check class="h-3.5 w-3.5" />
|
|
||||||
{:else if isIndeterminate}
|
|
||||||
<Minus class="h-3.5 w-3.5" />
|
|
||||||
{/if}
|
{/if}
|
||||||
</CheckboxPrimitive.Indicator>
|
</div>
|
||||||
|
{/snippet}
|
||||||
</CheckboxPrimitive.Root>
|
</CheckboxPrimitive.Root>
|
||||||
|
38
src/lib/components/ui/dialog/dialog-content.svelte
Normal file
38
src/lib/components/ui/dialog/dialog-content.svelte
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { Dialog as DialogPrimitive, type WithoutChildrenOrChild } from "bits-ui";
|
||||||
|
import X from "lucide-svelte/icons/x";
|
||||||
|
import type { Snippet } from "svelte";
|
||||||
|
import * as Dialog from "./index.js";
|
||||||
|
import { cn } from "$lib/utils.js";
|
||||||
|
|
||||||
|
let {
|
||||||
|
ref = $bindable(null),
|
||||||
|
class: className,
|
||||||
|
portalProps,
|
||||||
|
children,
|
||||||
|
...restProps
|
||||||
|
}: WithoutChildrenOrChild<DialogPrimitive.ContentProps> & {
|
||||||
|
portalProps?: DialogPrimitive.PortalProps;
|
||||||
|
children: Snippet;
|
||||||
|
} = $props();
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<Dialog.Portal {...portalProps}>
|
||||||
|
<Dialog.Overlay />
|
||||||
|
<DialogPrimitive.Content
|
||||||
|
bind:ref
|
||||||
|
class={cn(
|
||||||
|
"data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] bg-background fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border p-6 shadow-lg duration-200 sm:rounded-lg",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
{...restProps}
|
||||||
|
>
|
||||||
|
{@render children?.()}
|
||||||
|
<DialogPrimitive.Close
|
||||||
|
class="ring-offset-background focus:ring-ring absolute right-4 top-4 rounded-sm opacity-70 transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-offset-2 disabled:pointer-events-none"
|
||||||
|
>
|
||||||
|
<X class="size-4" />
|
||||||
|
<span class="sr-only">Close</span>
|
||||||
|
</DialogPrimitive.Close>
|
||||||
|
</DialogPrimitive.Content>
|
||||||
|
</Dialog.Portal>
|
19
src/lib/components/ui/dialog/dialog-description.svelte
Normal file
19
src/lib/components/ui/dialog/dialog-description.svelte
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { Dialog as DialogPrimitive } from "bits-ui";
|
||||||
|
import { cn } from "$lib/utils.js";
|
||||||
|
|
||||||
|
let {
|
||||||
|
ref = $bindable(null),
|
||||||
|
class: className,
|
||||||
|
children,
|
||||||
|
...restProps
|
||||||
|
}: DialogPrimitive.DescriptionProps = $props();
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<DialogPrimitive.Description
|
||||||
|
bind:ref
|
||||||
|
class={cn("text-muted-foreground text-sm", className)}
|
||||||
|
{...restProps}
|
||||||
|
>
|
||||||
|
{@render children?.()}
|
||||||
|
</DialogPrimitive.Description>
|
20
src/lib/components/ui/dialog/dialog-footer.svelte
Normal file
20
src/lib/components/ui/dialog/dialog-footer.svelte
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import type { WithElementRef } from "bits-ui";
|
||||||
|
import type { HTMLAttributes } from "svelte/elements";
|
||||||
|
import { cn } from "$lib/utils.js";
|
||||||
|
|
||||||
|
let {
|
||||||
|
ref = $bindable(null),
|
||||||
|
class: className,
|
||||||
|
children,
|
||||||
|
...restProps
|
||||||
|
}: WithElementRef<HTMLAttributes<HTMLDivElement>> = $props();
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div
|
||||||
|
bind:this={ref}
|
||||||
|
class={cn("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2", className)}
|
||||||
|
{...restProps}
|
||||||
|
>
|
||||||
|
{@render children?.()}
|
||||||
|
</div>
|
20
src/lib/components/ui/dialog/dialog-header.svelte
Normal file
20
src/lib/components/ui/dialog/dialog-header.svelte
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import type { HTMLAttributes } from "svelte/elements";
|
||||||
|
import type { WithElementRef } from "bits-ui";
|
||||||
|
import { cn } from "$lib/utils.js";
|
||||||
|
|
||||||
|
let {
|
||||||
|
ref = $bindable(null),
|
||||||
|
class: className,
|
||||||
|
children,
|
||||||
|
...restProps
|
||||||
|
}: WithElementRef<HTMLAttributes<HTMLDivElement>> = $props();
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div
|
||||||
|
bind:this={ref}
|
||||||
|
class={cn("flex flex-col space-y-1.5 text-center sm:text-left", className)}
|
||||||
|
{...restProps}
|
||||||
|
>
|
||||||
|
{@render children?.()}
|
||||||
|
</div>
|
22
src/lib/components/ui/dialog/dialog-overlay.svelte
Normal file
22
src/lib/components/ui/dialog/dialog-overlay.svelte
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { Dialog as DialogPrimitive } from "bits-ui";
|
||||||
|
import { cn } from "$lib/utils.js";
|
||||||
|
|
||||||
|
let {
|
||||||
|
ref = $bindable(null),
|
||||||
|
class: className,
|
||||||
|
children,
|
||||||
|
...restProps
|
||||||
|
}: DialogPrimitive.OverlayProps = $props();
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<DialogPrimitive.Overlay
|
||||||
|
bind:ref
|
||||||
|
class={cn(
|
||||||
|
"data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-50 bg-black/80",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
{...restProps}
|
||||||
|
>
|
||||||
|
{@render children?.()}
|
||||||
|
</DialogPrimitive.Overlay>
|
19
src/lib/components/ui/dialog/dialog-title.svelte
Normal file
19
src/lib/components/ui/dialog/dialog-title.svelte
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { Dialog as DialogPrimitive } from "bits-ui";
|
||||||
|
import { cn } from "$lib/utils.js";
|
||||||
|
|
||||||
|
let {
|
||||||
|
ref = $bindable(null),
|
||||||
|
class: className,
|
||||||
|
children,
|
||||||
|
...restProps
|
||||||
|
}: DialogPrimitive.TitleProps = $props();
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<DialogPrimitive.Title
|
||||||
|
bind:ref
|
||||||
|
class={cn("text-lg font-semibold leading-none tracking-tight", className)}
|
||||||
|
{...restProps}
|
||||||
|
>
|
||||||
|
{@render children?.()}
|
||||||
|
</DialogPrimitive.Title>
|
37
src/lib/components/ui/dialog/index.ts
Normal file
37
src/lib/components/ui/dialog/index.ts
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
import { Dialog as DialogPrimitive } from "bits-ui";
|
||||||
|
|
||||||
|
import Title from "./dialog-title.svelte";
|
||||||
|
import Footer from "./dialog-footer.svelte";
|
||||||
|
import Header from "./dialog-header.svelte";
|
||||||
|
import Overlay from "./dialog-overlay.svelte";
|
||||||
|
import Content from "./dialog-content.svelte";
|
||||||
|
import Description from "./dialog-description.svelte";
|
||||||
|
|
||||||
|
const Root = DialogPrimitive.Root;
|
||||||
|
const Trigger = DialogPrimitive.Trigger;
|
||||||
|
const Close = DialogPrimitive.Close;
|
||||||
|
const Portal = DialogPrimitive.Portal;
|
||||||
|
|
||||||
|
export {
|
||||||
|
Root,
|
||||||
|
Title,
|
||||||
|
Portal,
|
||||||
|
Footer,
|
||||||
|
Header,
|
||||||
|
Trigger,
|
||||||
|
Overlay,
|
||||||
|
Content,
|
||||||
|
Description,
|
||||||
|
Close,
|
||||||
|
//
|
||||||
|
Root as Dialog,
|
||||||
|
Title as DialogTitle,
|
||||||
|
Portal as DialogPortal,
|
||||||
|
Footer as DialogFooter,
|
||||||
|
Header as DialogHeader,
|
||||||
|
Trigger as DialogTrigger,
|
||||||
|
Overlay as DialogOverlay,
|
||||||
|
Content as DialogContent,
|
||||||
|
Description as DialogDescription,
|
||||||
|
Close as DialogClose,
|
||||||
|
};
|
@@ -1,27 +1,5 @@
|
|||||||
import Root from "./input.svelte";
|
import Root from "./input.svelte";
|
||||||
|
|
||||||
export type FormInputEvent<T extends Event = Event> = T & {
|
|
||||||
currentTarget: EventTarget & HTMLInputElement;
|
|
||||||
};
|
|
||||||
export type InputEvents = {
|
|
||||||
blur: FormInputEvent<FocusEvent>;
|
|
||||||
change: FormInputEvent<Event>;
|
|
||||||
click: FormInputEvent<MouseEvent>;
|
|
||||||
focus: FormInputEvent<FocusEvent>;
|
|
||||||
focusin: FormInputEvent<FocusEvent>;
|
|
||||||
focusout: FormInputEvent<FocusEvent>;
|
|
||||||
keydown: FormInputEvent<KeyboardEvent>;
|
|
||||||
keypress: FormInputEvent<KeyboardEvent>;
|
|
||||||
keyup: FormInputEvent<KeyboardEvent>;
|
|
||||||
mouseover: FormInputEvent<MouseEvent>;
|
|
||||||
mouseenter: FormInputEvent<MouseEvent>;
|
|
||||||
mouseleave: FormInputEvent<MouseEvent>;
|
|
||||||
mousemove: FormInputEvent<MouseEvent>;
|
|
||||||
paste: FormInputEvent<ClipboardEvent>;
|
|
||||||
input: FormInputEvent<InputEvent>;
|
|
||||||
wheel: FormInputEvent<WheelEvent>;
|
|
||||||
};
|
|
||||||
|
|
||||||
export {
|
export {
|
||||||
Root,
|
Root,
|
||||||
//
|
//
|
||||||
|
@@ -1,42 +1,22 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import type { HTMLInputAttributes } from "svelte/elements";
|
import type { HTMLInputAttributes } from "svelte/elements";
|
||||||
import type { InputEvents } from "./index.js";
|
import type { WithElementRef } from "bits-ui";
|
||||||
import { cn } from "$lib/utils.js";
|
import { cn } from "$lib/utils.js";
|
||||||
|
|
||||||
type $$Props = HTMLInputAttributes;
|
let {
|
||||||
type $$Events = InputEvents;
|
ref = $bindable(null),
|
||||||
|
value = $bindable(),
|
||||||
let className: $$Props["class"] = undefined;
|
class: className,
|
||||||
export let value: $$Props["value"] = undefined;
|
...restProps
|
||||||
export { className as class };
|
}: WithElementRef<HTMLInputAttributes> = $props();
|
||||||
|
|
||||||
// Workaround for https://github.com/sveltejs/svelte/issues/9305
|
|
||||||
// Fixed in Svelte 5, but not backported to 4.x.
|
|
||||||
export let readonly: $$Props["readonly"] = undefined;
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<input
|
<input
|
||||||
|
bind:this={ref}
|
||||||
class={cn(
|
class={cn(
|
||||||
"border-input bg-background ring-offset-background placeholder:text-muted-foreground focus-visible:ring-ring flex h-10 w-full rounded-md border px-3 py-2 text-sm file:border-0 file:bg-transparent file:text-sm file:font-medium focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",
|
"border-input bg-background ring-offset-background placeholder:text-muted-foreground focus-visible:ring-ring flex h-10 w-full rounded-md border px-3 py-2 text-base file:border-0 file:bg-transparent file:text-sm file:font-medium focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",
|
||||||
className
|
className
|
||||||
)}
|
)}
|
||||||
bind:value
|
bind:value
|
||||||
{readonly}
|
{...restProps}
|
||||||
on:blur
|
|
||||||
on:change
|
|
||||||
on:click
|
|
||||||
on:focus
|
|
||||||
on:focusin
|
|
||||||
on:focusout
|
|
||||||
on:keydown
|
|
||||||
on:keypress
|
|
||||||
on:keyup
|
|
||||||
on:mouseover
|
|
||||||
on:mouseenter
|
|
||||||
on:mouseleave
|
|
||||||
on:mousemove
|
|
||||||
on:paste
|
|
||||||
on:input
|
|
||||||
on:wheel|passive
|
|
||||||
{...$$restProps}
|
|
||||||
/>
|
/>
|
||||||
|
@@ -2,20 +2,21 @@
|
|||||||
import { Label as LabelPrimitive } from "bits-ui";
|
import { Label as LabelPrimitive } from "bits-ui";
|
||||||
import { cn } from "$lib/utils.js";
|
import { cn } from "$lib/utils.js";
|
||||||
|
|
||||||
type $$Props = LabelPrimitive.Props;
|
let {
|
||||||
type $$Events = LabelPrimitive.Events;
|
ref = $bindable(null),
|
||||||
|
class: className,
|
||||||
let className: $$Props["class"] = undefined;
|
children,
|
||||||
export { className as class };
|
...restProps
|
||||||
|
}: LabelPrimitive.RootProps = $props();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<LabelPrimitive.Root
|
<LabelPrimitive.Root
|
||||||
|
bind:ref
|
||||||
class={cn(
|
class={cn(
|
||||||
"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",
|
"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",
|
||||||
className
|
className
|
||||||
)}
|
)}
|
||||||
{...$$restProps}
|
{...restProps}
|
||||||
on:mousedown
|
|
||||||
>
|
>
|
||||||
<slot />
|
{@render children?.()}
|
||||||
</LabelPrimitive.Root>
|
</LabelPrimitive.Root>
|
||||||
|
@@ -1,13 +1,16 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import type { HTMLAttributes } from "svelte/elements";
|
import type { HTMLAttributes } from "svelte/elements";
|
||||||
|
import type { WithElementRef } from "bits-ui";
|
||||||
import { cn } from "$lib/utils.js";
|
import { cn } from "$lib/utils.js";
|
||||||
|
|
||||||
type $$Props = HTMLAttributes<HTMLTableSectionElement>;
|
let {
|
||||||
|
ref = $bindable(null),
|
||||||
let className: $$Props["class"] = undefined;
|
class: className,
|
||||||
export { className as class };
|
children,
|
||||||
|
...restProps
|
||||||
|
}: WithElementRef<HTMLAttributes<HTMLTableSectionElement>> = $props();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<tbody class={cn("[&_tr:last-child]:border-0", className)} {...$$restProps}>
|
<tbody bind:this={ref} class={cn("[&_tr:last-child]:border-0", className)} {...restProps}>
|
||||||
<slot />
|
{@render children?.()}
|
||||||
</tbody>
|
</tbody>
|
||||||
|
@@ -1,13 +1,16 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import type { HTMLAttributes } from "svelte/elements";
|
import type { HTMLAttributes } from "svelte/elements";
|
||||||
|
import type { WithElementRef } from "bits-ui";
|
||||||
import { cn } from "$lib/utils.js";
|
import { cn } from "$lib/utils.js";
|
||||||
|
|
||||||
type $$Props = HTMLAttributes<HTMLTableCaptionElement>;
|
let {
|
||||||
|
ref = $bindable(null),
|
||||||
let className: $$Props["class"] = undefined;
|
class: className,
|
||||||
export { className as class };
|
children,
|
||||||
|
...restProps
|
||||||
|
}: WithElementRef<HTMLAttributes<HTMLElement>> = $props();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<caption class={cn("text-muted-foreground mt-4 text-sm", className)} {...$$restProps}>
|
<caption bind:this={ref} class={cn("text-muted-foreground mt-4 text-sm", className)} {...restProps}>
|
||||||
<slot />
|
{@render children?.()}
|
||||||
</caption>
|
</caption>
|
||||||
|
@@ -1,18 +1,20 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import type { HTMLTdAttributes } from "svelte/elements";
|
import type { HTMLTdAttributes } from "svelte/elements";
|
||||||
|
import type { WithElementRef } from "bits-ui";
|
||||||
import { cn } from "$lib/utils.js";
|
import { cn } from "$lib/utils.js";
|
||||||
|
|
||||||
type $$Props = HTMLTdAttributes;
|
let {
|
||||||
|
ref = $bindable(null),
|
||||||
let className: $$Props["class"] = undefined;
|
class: className,
|
||||||
export { className as class };
|
children,
|
||||||
|
...restProps
|
||||||
|
}: WithElementRef<HTMLTdAttributes> = $props();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<td
|
<td
|
||||||
|
bind:this={ref}
|
||||||
class={cn("p-4 align-middle [&:has([role=checkbox])]:pr-0", className)}
|
class={cn("p-4 align-middle [&:has([role=checkbox])]:pr-0", className)}
|
||||||
{...$$restProps}
|
{...restProps}
|
||||||
on:click
|
|
||||||
on:keydown
|
|
||||||
>
|
>
|
||||||
<slot />
|
{@render children?.()}
|
||||||
</td>
|
</td>
|
||||||
|
@@ -1,13 +1,16 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import type { HTMLAttributes } from "svelte/elements";
|
import type { HTMLAttributes } from "svelte/elements";
|
||||||
|
import type { WithElementRef } from "bits-ui";
|
||||||
import { cn } from "$lib/utils.js";
|
import { cn } from "$lib/utils.js";
|
||||||
|
|
||||||
type $$Props = HTMLAttributes<HTMLTableSectionElement>;
|
let {
|
||||||
|
ref = $bindable(null),
|
||||||
let className: $$Props["class"] = undefined;
|
class: className,
|
||||||
export { className as class };
|
children,
|
||||||
|
...restProps
|
||||||
|
}: WithElementRef<HTMLAttributes<HTMLTableSectionElement>> = $props();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<tfoot class={cn("bg-muted/50 text-primary-foreground font-medium", className)} {...$$restProps}>
|
<tfoot bind:this={ref} class={cn("bg-muted/50 font-medium", className)} {...restProps}>
|
||||||
<slot />
|
{@render children?.()}
|
||||||
</tfoot>
|
</tfoot>
|
||||||
|
@@ -1,19 +1,23 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import type { HTMLThAttributes } from "svelte/elements";
|
import type { HTMLThAttributes } from "svelte/elements";
|
||||||
|
import type { WithElementRef } from "bits-ui";
|
||||||
import { cn } from "$lib/utils.js";
|
import { cn } from "$lib/utils.js";
|
||||||
|
|
||||||
type $$Props = HTMLThAttributes;
|
let {
|
||||||
|
ref = $bindable(null),
|
||||||
let className: $$Props["class"] = undefined;
|
class: className,
|
||||||
export { className as class };
|
children,
|
||||||
|
...restProps
|
||||||
|
}: WithElementRef<HTMLThAttributes> = $props();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<th
|
<th
|
||||||
|
bind:this={ref}
|
||||||
class={cn(
|
class={cn(
|
||||||
"text-muted-foreground h-12 px-4 text-left align-middle font-medium [&:has([role=checkbox])]:pr-0",
|
"text-muted-foreground h-12 px-4 text-left align-middle font-medium [&:has([role=checkbox])]:pr-0",
|
||||||
className
|
className
|
||||||
)}
|
)}
|
||||||
{...$$restProps}
|
{...restProps}
|
||||||
>
|
>
|
||||||
<slot />
|
{@render children?.()}
|
||||||
</th>
|
</th>
|
||||||
|
@@ -1,14 +1,16 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import type { HTMLAttributes } from "svelte/elements";
|
import type { HTMLAttributes } from "svelte/elements";
|
||||||
|
import type { WithElementRef } from "bits-ui";
|
||||||
import { cn } from "$lib/utils.js";
|
import { cn } from "$lib/utils.js";
|
||||||
|
|
||||||
type $$Props = HTMLAttributes<HTMLTableSectionElement>;
|
let {
|
||||||
|
ref = $bindable(null),
|
||||||
let className: $$Props["class"] = undefined;
|
class: className,
|
||||||
export { className as class };
|
children,
|
||||||
|
...restProps
|
||||||
|
}: WithElementRef<HTMLAttributes<HTMLTableSectionElement>> = $props();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<!-- svelte-ignore a11y-no-noninteractive-element-interactions -->
|
<thead bind:this={ref} class={cn("[&_tr]:border-b", className)} {...restProps}>
|
||||||
<thead class={cn("[&_tr]:border-b", className)} {...$$restProps} on:click on:keydown>
|
{@render children?.()}
|
||||||
<slot />
|
|
||||||
</thead>
|
</thead>
|
||||||
|
@@ -1,23 +1,23 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import type { HTMLAttributes } from "svelte/elements";
|
import type { HTMLAttributes } from "svelte/elements";
|
||||||
|
import type { WithElementRef } from "bits-ui";
|
||||||
import { cn } from "$lib/utils.js";
|
import { cn } from "$lib/utils.js";
|
||||||
|
|
||||||
type $$Props = HTMLAttributes<HTMLTableRowElement> & {
|
let {
|
||||||
"data-state"?: unknown;
|
ref = $bindable(null),
|
||||||
};
|
class: className,
|
||||||
|
children,
|
||||||
let className: $$Props["class"] = undefined;
|
...restProps
|
||||||
export { className as class };
|
}: WithElementRef<HTMLAttributes<HTMLTableRowElement>> = $props();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<tr
|
<tr
|
||||||
|
bind:this={ref}
|
||||||
class={cn(
|
class={cn(
|
||||||
"hover:bg-muted/50 data-[state=selected]:bg-muted border-b transition-colors",
|
"hover:bg-muted/50 data-[state=selected]:bg-muted border-b transition-colors",
|
||||||
className
|
className
|
||||||
)}
|
)}
|
||||||
{...$$restProps}
|
{...restProps}
|
||||||
on:click
|
|
||||||
on:keydown
|
|
||||||
>
|
>
|
||||||
<slot />
|
{@render children?.()}
|
||||||
</tr>
|
</tr>
|
||||||
|
@@ -1,15 +1,18 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import type { HTMLTableAttributes } from "svelte/elements";
|
import type { HTMLTableAttributes } from "svelte/elements";
|
||||||
|
import type { WithElementRef } from "bits-ui";
|
||||||
import { cn } from "$lib/utils.js";
|
import { cn } from "$lib/utils.js";
|
||||||
|
|
||||||
type $$Props = HTMLTableAttributes;
|
let {
|
||||||
|
ref = $bindable(null),
|
||||||
let className: $$Props["class"] = undefined;
|
class: className,
|
||||||
export { className as class };
|
children,
|
||||||
|
...restProps
|
||||||
|
}: WithElementRef<HTMLTableAttributes> = $props();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="relative w-full overflow-auto">
|
<div class="relative w-full overflow-auto">
|
||||||
<table class={cn("w-full caption-bottom text-sm", className)} {...$$restProps}>
|
<table bind:this={ref} class={cn("w-full caption-bottom text-sm", className)} {...restProps}>
|
||||||
<slot />
|
{@render children?.()}
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
18
src/lib/components/ui/tabs/index.ts
Normal file
18
src/lib/components/ui/tabs/index.ts
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
import { Tabs as TabsPrimitive } from "bits-ui";
|
||||||
|
import Content from "./tabs-content.svelte";
|
||||||
|
import List from "./tabs-list.svelte";
|
||||||
|
import Trigger from "./tabs-trigger.svelte";
|
||||||
|
|
||||||
|
const Root = TabsPrimitive.Root;
|
||||||
|
|
||||||
|
export {
|
||||||
|
Root,
|
||||||
|
Content,
|
||||||
|
List,
|
||||||
|
Trigger,
|
||||||
|
//
|
||||||
|
Root as Tabs,
|
||||||
|
Content as TabsContent,
|
||||||
|
List as TabsList,
|
||||||
|
Trigger as TabsTrigger,
|
||||||
|
};
|
22
src/lib/components/ui/tabs/tabs-content.svelte
Normal file
22
src/lib/components/ui/tabs/tabs-content.svelte
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { Tabs as TabsPrimitive } from "bits-ui";
|
||||||
|
import { cn } from "$lib/utils.js";
|
||||||
|
|
||||||
|
let {
|
||||||
|
ref = $bindable(null),
|
||||||
|
class: className,
|
||||||
|
children,
|
||||||
|
...restProps
|
||||||
|
}: TabsPrimitive.ContentProps = $props();
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<TabsPrimitive.Content
|
||||||
|
bind:ref
|
||||||
|
class={cn(
|
||||||
|
"ring-offset-background focus-visible:ring-ring mt-2 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-2",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
{...restProps}
|
||||||
|
>
|
||||||
|
{@render children?.()}
|
||||||
|
</TabsPrimitive.Content>
|
22
src/lib/components/ui/tabs/tabs-list.svelte
Normal file
22
src/lib/components/ui/tabs/tabs-list.svelte
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { Tabs as TabsPrimitive } from "bits-ui";
|
||||||
|
import { cn } from "$lib/utils.js";
|
||||||
|
|
||||||
|
let {
|
||||||
|
ref = $bindable(null),
|
||||||
|
class: className,
|
||||||
|
children,
|
||||||
|
...restProps
|
||||||
|
}: TabsPrimitive.ListProps = $props();
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<TabsPrimitive.List
|
||||||
|
bind:ref
|
||||||
|
class={cn(
|
||||||
|
"bg-muted text-muted-foreground inline-flex h-10 items-center justify-center rounded-md p-1",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
{...restProps}
|
||||||
|
>
|
||||||
|
{@render children?.()}
|
||||||
|
</TabsPrimitive.List>
|
22
src/lib/components/ui/tabs/tabs-trigger.svelte
Normal file
22
src/lib/components/ui/tabs/tabs-trigger.svelte
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { Tabs as TabsPrimitive } from "bits-ui";
|
||||||
|
import { cn } from "$lib/utils.js";
|
||||||
|
|
||||||
|
let {
|
||||||
|
ref = $bindable(null),
|
||||||
|
class: className,
|
||||||
|
children,
|
||||||
|
...restProps
|
||||||
|
}: TabsPrimitive.TriggerProps = $props();
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<TabsPrimitive.Trigger
|
||||||
|
bind:ref
|
||||||
|
class={cn(
|
||||||
|
"ring-offset-background focus-visible:ring-ring data-[state=active]:bg-background data-[state=active]:text-foreground inline-flex items-center justify-center whitespace-nowrap rounded-sm px-3 py-1.5 text-sm font-medium transition-all focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 data-[state=active]:shadow-sm",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
{...restProps}
|
||||||
|
>
|
||||||
|
{@render children?.()}
|
||||||
|
</TabsPrimitive.Trigger>
|
10
src/lib/connections.ts
Normal file
10
src/lib/connections.ts
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
export type ConnectionDetails = {
|
||||||
|
deviceId: number;
|
||||||
|
deviceName: string;
|
||||||
|
devicePublicKey: string;
|
||||||
|
deviceIps: string[];
|
||||||
|
endpoint: string;
|
||||||
|
transferRx: number;
|
||||||
|
transferTx: number;
|
||||||
|
latestHandshake: number;
|
||||||
|
};
|
43
src/lib/devices.ts
Normal file
43
src/lib/devices.ts
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
/**
|
||||||
|
* Convert device details to WireGuard configuration.
|
||||||
|
*
|
||||||
|
* ```conf
|
||||||
|
* [Interface]
|
||||||
|
* PrivateKey = wPa07zR0H4wYoc1ljfeiqlSbR8Z28pPc6jplwE7zPms=
|
||||||
|
* Address = 10.18.11.100/32,fd00::1/128
|
||||||
|
* DNS = 10.18.11.1,fd00::0
|
||||||
|
*
|
||||||
|
* [Peer]
|
||||||
|
* PublicKey = BJ5faPVJsDP4CCxNYilmKnwlQXOtXEOJjqIwb4U/CgM=
|
||||||
|
* PresharedKey = uhZUVqXKF0oayP0BS6yPu6Gepgh68Nz9prtbE5Cuok0=
|
||||||
|
* Endpoint = vpn.lab.cazzzer.com:51820
|
||||||
|
* AllowedIPs = 0.0.0.0/0,::/0
|
||||||
|
* ```
|
||||||
|
* @param device
|
||||||
|
*/
|
||||||
|
export function deviceDetailsToConfig(device: DeviceDetails): string {
|
||||||
|
return `\
|
||||||
|
[Interface]
|
||||||
|
PrivateKey = ${device.privateKey}
|
||||||
|
Address = ${device.ips.join(', ')}
|
||||||
|
DNS = ${device.vpnDns}
|
||||||
|
|
||||||
|
[Peer]
|
||||||
|
PublicKey = ${device.vpnPublicKey}
|
||||||
|
PresharedKey = ${device.preSharedKey}
|
||||||
|
Endpoint = ${device.vpnEndpoint}
|
||||||
|
AllowedIPs = 0.0.0.0/0,::/0
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type DeviceDetails = {
|
||||||
|
id: number;
|
||||||
|
name: string;
|
||||||
|
publicKey: string;
|
||||||
|
privateKey: string | null;
|
||||||
|
preSharedKey: string | null;
|
||||||
|
ips: string[];
|
||||||
|
vpnPublicKey: string;
|
||||||
|
vpnEndpoint: string;
|
||||||
|
vpnDns: string;
|
||||||
|
};
|
3
src/lib/opnsense/index.ts
Normal file
3
src/lib/opnsense/index.ts
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
export function opnsenseSanitezedUsername(username: string) {
|
||||||
|
return username.slice(0, 63).replace(/[^a-zA-Z0-9_-]/g, '_');
|
||||||
|
}
|
@@ -1,5 +1,5 @@
|
|||||||
import { drizzle } from 'drizzle-orm/libsql';
|
import { drizzle } from 'drizzle-orm/libsql';
|
||||||
import * as schema from './schema';
|
import * as schema from './schema';
|
||||||
import { DATABASE_URL } from '$env/static/private';
|
import { env } from '$env/dynamic/private';
|
||||||
|
|
||||||
export const db= drizzle(DATABASE_URL, { schema });
|
export const db= drizzle(env.DATABASE_URL, { schema });
|
||||||
|
@@ -8,7 +8,7 @@ export const users = sqliteTable('users', {
|
|||||||
});
|
});
|
||||||
|
|
||||||
export const usersRelations = relations(users, ({ many }) => ({
|
export const usersRelations = relations(users, ({ many }) => ({
|
||||||
wgClients: many(wgClients),
|
devices: many(devices),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
export const sessions = sqliteTable('sessions', {
|
export const sessions = sqliteTable('sessions', {
|
||||||
@@ -22,14 +22,14 @@ export const sessions = sqliteTable('sessions', {
|
|||||||
export const ipAllocations = sqliteTable('ip_allocations', {
|
export const ipAllocations = sqliteTable('ip_allocations', {
|
||||||
// for now, id will be the same as the ipIndex
|
// for now, id will be the same as the ipIndex
|
||||||
id: integer('id').primaryKey({ autoIncrement: true }),
|
id: integer('id').primaryKey({ autoIncrement: true }),
|
||||||
// clientId is nullable because allocations can remain after the client is deleted
|
// deviceId is nullable because allocations can remain after the device is deleted
|
||||||
// unique for now, only allowing one allocation per client
|
// unique for now, only allowing one allocation per device
|
||||||
clientId: integer('client_id')
|
deviceId: integer('device_id')
|
||||||
.unique()
|
.unique()
|
||||||
.references(() => wgClients.id, { onDelete: 'set null' }),
|
.references(() => devices.id, { onDelete: 'set null' }),
|
||||||
});
|
});
|
||||||
|
|
||||||
export const wgClients = sqliteTable('wg_clients', {
|
export const devices = sqliteTable('devices', {
|
||||||
id: integer().primaryKey({ autoIncrement: true }),
|
id: integer().primaryKey({ autoIncrement: true }),
|
||||||
userId: text('user_id')
|
userId: text('user_id')
|
||||||
.notNull()
|
.notNull()
|
||||||
@@ -38,7 +38,7 @@ export const wgClients = sqliteTable('wg_clients', {
|
|||||||
// questioning whether this should be nullable
|
// questioning whether this should be nullable
|
||||||
opnsenseId: text('opnsense_id'),
|
opnsenseId: text('opnsense_id'),
|
||||||
publicKey: text('public_key').notNull().unique(),
|
publicKey: text('public_key').notNull().unique(),
|
||||||
// nullable for the possibility of a client supplying their own private key
|
// nullable for the possibility of a user supplying their own private key
|
||||||
privateKey: text('private_key'),
|
privateKey: text('private_key'),
|
||||||
// nullable for the possibility of no psk
|
// nullable for the possibility of no psk
|
||||||
preSharedKey: text('pre_shared_key'),
|
preSharedKey: text('pre_shared_key'),
|
||||||
@@ -48,18 +48,18 @@ export const wgClients = sqliteTable('wg_clients', {
|
|||||||
// allowedIps: text('allowed_ips').notNull(),
|
// allowedIps: text('allowed_ips').notNull(),
|
||||||
});
|
});
|
||||||
|
|
||||||
export const wgClientsRelations = relations(wgClients, ({ one }) => ({
|
export const devicesRelations = relations(devices, ({ one }) => ({
|
||||||
user: one(users, {
|
user: one(users, {
|
||||||
fields: [wgClients.userId],
|
fields: [devices.userId],
|
||||||
references: [users.id],
|
references: [users.id],
|
||||||
}),
|
}),
|
||||||
ipAllocation: one(ipAllocations, {
|
ipAllocation: one(ipAllocations, {
|
||||||
fields: [wgClients.id],
|
fields: [devices.id],
|
||||||
references: [ipAllocations.clientId],
|
references: [ipAllocations.deviceId],
|
||||||
}),
|
}),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
export type WgClient = typeof wgClients.$inferSelect;
|
export type Device = typeof devices.$inferSelect;
|
||||||
|
|
||||||
export type Session = typeof sessions.$inferSelect;
|
export type Session = typeof sessions.$inferSelect;
|
||||||
|
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
import { ipAllocations, users, wgClients } from './schema';
|
import { ipAllocations, users, devices } from './schema';
|
||||||
import { eq } from 'drizzle-orm';
|
import { eq } from 'drizzle-orm';
|
||||||
import assert from 'node:assert';
|
import assert from 'node:assert';
|
||||||
import { drizzle } from 'drizzle-orm/libsql';
|
import { drizzle } from 'drizzle-orm/libsql';
|
||||||
@@ -11,10 +11,10 @@ async function seed() {
|
|||||||
const user = await db.query.users.findFirst({ where: eq(users.username, 'CaZzzer') });
|
const user = await db.query.users.findFirst({ where: eq(users.username, 'CaZzzer') });
|
||||||
assert(user, 'User not found');
|
assert(user, 'User not found');
|
||||||
|
|
||||||
const clients: typeof wgClients.$inferInsert[] = [
|
const newDevices: typeof devices.$inferInsert[] = [
|
||||||
{
|
{
|
||||||
userId: user.id,
|
userId: user.id,
|
||||||
name: 'Client1',
|
name: 'Device1',
|
||||||
publicKey: 'BJ5faPVJsDP4CCxNYilmKnwlQXOtXEOJjqIwb4U/CgM=',
|
publicKey: 'BJ5faPVJsDP4CCxNYilmKnwlQXOtXEOJjqIwb4U/CgM=',
|
||||||
privateKey: 'KKqsHDu30WCSrVsyzMkOKbE3saQ+wlx0sBwGs61UGXk=',
|
privateKey: 'KKqsHDu30WCSrVsyzMkOKbE3saQ+wlx0sBwGs61UGXk=',
|
||||||
preSharedKey: '0LWopbrISXBNHUxr+WOhCSAg+0hD8j3TLmpyzHkBHCQ=',
|
preSharedKey: '0LWopbrISXBNHUxr+WOhCSAg+0hD8j3TLmpyzHkBHCQ=',
|
||||||
@@ -22,10 +22,10 @@ async function seed() {
|
|||||||
// allowedIps: '10.18.11.101/32,fd00::1/112',
|
// allowedIps: '10.18.11.101/32,fd00::1/112',
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
const returned = await db.insert(wgClients).values(clients).returning({ insertedId: wgClients.id });
|
const returned = await db.insert(devices).values(newDevices).returning({ insertedId: devices.id });
|
||||||
|
|
||||||
const ipAllocation: typeof ipAllocations.$inferInsert = {
|
const ipAllocation: typeof ipAllocations.$inferInsert = {
|
||||||
clientId: returned[0].insertedId,
|
deviceId: returned[0].insertedId,
|
||||||
};
|
};
|
||||||
await db.insert(ipAllocations).values(ipAllocation);
|
await db.insert(ipAllocations).values(ipAllocation);
|
||||||
}
|
}
|
||||||
|
@@ -1,23 +1,16 @@
|
|||||||
import type { User } from '$lib/server/db/schema';
|
import type { User } from '$lib/server/db/schema';
|
||||||
|
import { ipAllocations, devices } from '$lib/server/db/schema';
|
||||||
import { db } from '$lib/server/db';
|
import { db } from '$lib/server/db';
|
||||||
import { wgClients, ipAllocations } from '$lib/server/db/schema';
|
|
||||||
import { opnsenseAuth, opnsenseUrl, serverPublicKey, serverUuid } from '$lib/server/opnsense';
|
import { opnsenseAuth, opnsenseUrl, serverPublicKey, serverUuid } from '$lib/server/opnsense';
|
||||||
import { Address4, Address6 } from 'ip-address';
|
import { Address4, Address6 } from 'ip-address';
|
||||||
import {
|
import { env } from '$env/dynamic/private';
|
||||||
IP_MAX_INDEX,
|
|
||||||
IPV4_STARTING_ADDR,
|
|
||||||
IPV6_CLIENT_PREFIX_SIZE,
|
|
||||||
IPV6_STARTING_ADDR,
|
|
||||||
MAX_CLIENTS_PER_USER,
|
|
||||||
VPN_DNS,
|
|
||||||
VPN_ENDPOINT,
|
|
||||||
} from '$env/static/private';
|
|
||||||
import { and, count, eq, isNull } from 'drizzle-orm';
|
import { and, count, eq, isNull } from 'drizzle-orm';
|
||||||
import { err, ok, type Result } from '$lib/types';
|
import { err, ok, type Result } from '$lib/types';
|
||||||
import type { ClientDetails } from '$lib/types/clients';
|
import type { DeviceDetails } from '$lib/devices';
|
||||||
|
import { opnsenseSanitezedUsername } from '$lib/opnsense';
|
||||||
|
|
||||||
export async function findClients(userId: string) {
|
export async function findDevices(userId: string) {
|
||||||
return db.query.wgClients.findMany({
|
return db.query.devices.findMany({
|
||||||
columns: {
|
columns: {
|
||||||
id: true,
|
id: true,
|
||||||
name: true,
|
name: true,
|
||||||
@@ -28,12 +21,12 @@ export async function findClients(userId: string) {
|
|||||||
with: {
|
with: {
|
||||||
ipAllocation: true,
|
ipAllocation: true,
|
||||||
},
|
},
|
||||||
where: eq(wgClients.userId, userId),
|
where: eq(devices.userId, userId),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function findClient(userId: string, clientId: number) {
|
export async function findDevice(userId: string, deviceId: number) {
|
||||||
return db.query.wgClients.findFirst({
|
return db.query.devices.findFirst({
|
||||||
columns: {
|
columns: {
|
||||||
id: true,
|
id: true,
|
||||||
name: true,
|
name: true,
|
||||||
@@ -44,56 +37,56 @@ export async function findClient(userId: string, clientId: number) {
|
|||||||
with: {
|
with: {
|
||||||
ipAllocation: true,
|
ipAllocation: true,
|
||||||
},
|
},
|
||||||
where: and(eq(wgClients.userId, userId), eq(wgClients.id, clientId)),
|
where: and(eq(devices.userId, userId), eq(devices.id, deviceId)),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function mapClientToDetails(
|
export function mapDeviceToDetails(
|
||||||
client: Awaited<ReturnType<typeof findClients>>[0],
|
device: Awaited<ReturnType<typeof findDevices>>[0],
|
||||||
): ClientDetails {
|
): DeviceDetails {
|
||||||
const ips = getIpsFromIndex(client.ipAllocation.id);
|
const ips = getIpsFromIndex(device.ipAllocation.id);
|
||||||
return {
|
return {
|
||||||
id: client.id,
|
id: device.id,
|
||||||
name: client.name,
|
name: device.name,
|
||||||
publicKey: client.publicKey,
|
publicKey: device.publicKey,
|
||||||
privateKey: client.privateKey,
|
privateKey: device.privateKey,
|
||||||
preSharedKey: client.preSharedKey,
|
preSharedKey: device.preSharedKey,
|
||||||
ips,
|
ips,
|
||||||
vpnPublicKey: serverPublicKey,
|
vpnPublicKey: serverPublicKey,
|
||||||
vpnEndpoint: VPN_ENDPOINT,
|
vpnEndpoint: env.VPN_ENDPOINT,
|
||||||
vpnDns: VPN_DNS,
|
vpnDns: env.VPN_DNS,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function createClient(params: {
|
export async function createDevice(params: {
|
||||||
name: string;
|
name: string;
|
||||||
user: User;
|
user: User;
|
||||||
}): Promise<Result<null, [400 | 500, string]>> {
|
}): Promise<Result<number, [400 | 500, string]>> {
|
||||||
// check if user exceeds the limit of clients
|
// check if user exceeds the limit of devices
|
||||||
const [{ clientCount }] = await db
|
const [{ deviceCount }] = await db
|
||||||
.select({ clientCount: count() })
|
.select({ deviceCount: count() })
|
||||||
.from(wgClients)
|
.from(devices)
|
||||||
.where(eq(wgClients.userId, params.user.id));
|
.where(eq(devices.userId, params.user.id));
|
||||||
if (clientCount >= parseInt(MAX_CLIENTS_PER_USER))
|
if (deviceCount >= parseInt(env.MAX_CLIENTS_PER_USER))
|
||||||
return err([400, 'Maximum number of clients reached'] as [400, string]);
|
return err([400, 'Maximum number of devices reached'] as [400, string]);
|
||||||
|
|
||||||
// this is going to be quite long
|
// this is going to be quite long
|
||||||
// 1. fetch params for new client from opnsense api
|
// 1. fetch params for new device from opnsense api
|
||||||
// 2.1 get an allocation for the client
|
// 2.1 get an allocation for the device
|
||||||
// 2.2. insert new client into db
|
// 2.2. insert new device into db
|
||||||
// 2.3. update the allocation with the client id
|
// 2.3. update the allocation with the device id
|
||||||
// 3. create the client in opnsense
|
// 3. create the client in opnsense
|
||||||
// 4. reconfigure opnsense to enable the new client
|
// 4. reconfigure opnsense to enable the new client
|
||||||
const error = await db.transaction(async (tx) => {
|
return await db.transaction(async (tx) => {
|
||||||
const [keys, availableAllocation, lastAllocation] = await Promise.all([
|
const [keys, availableAllocation, lastAllocation] = await Promise.all([
|
||||||
// fetch params for new client from opnsense api
|
// fetch params for new device from opnsense api
|
||||||
getKeys(),
|
getKeys(),
|
||||||
// find first unallocated IP
|
// find first unallocated IP
|
||||||
await tx.query.ipAllocations.findFirst({
|
await tx.query.ipAllocations.findFirst({
|
||||||
columns: {
|
columns: {
|
||||||
id: true,
|
id: true,
|
||||||
},
|
},
|
||||||
where: isNull(ipAllocations.clientId),
|
where: isNull(ipAllocations.deviceId),
|
||||||
}),
|
}),
|
||||||
// find last allocation to check if we have any IPs left
|
// find last allocation to check if we have any IPs left
|
||||||
await tx.query.ipAllocations.findFirst({
|
await tx.query.ipAllocations.findFirst({
|
||||||
@@ -105,7 +98,7 @@ export async function createClient(params: {
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
// check for existing allocation or if we have any IPs left
|
// check for existing allocation or if we have any IPs left
|
||||||
if (!availableAllocation && lastAllocation && lastAllocation.id >= parseInt(IP_MAX_INDEX)) {
|
if (!availableAllocation && lastAllocation && lastAllocation.id >= parseInt(env.IP_MAX_INDEX)) {
|
||||||
return err([500, 'No more IP addresses available'] as [500, string]);
|
return err([500, 'No more IP addresses available'] as [500, string]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -117,9 +110,9 @@ export async function createClient(params: {
|
|||||||
// transaction savepoint after creating a new IP allocation
|
// transaction savepoint after creating a new IP allocation
|
||||||
// TODO: not sure if this is needed
|
// TODO: not sure if this is needed
|
||||||
return await tx.transaction(async (tx2) => {
|
return await tx.transaction(async (tx2) => {
|
||||||
// create new client in db
|
// create new device in db
|
||||||
const [newClient] = await tx2
|
const [newDevice] = await tx2
|
||||||
.insert(wgClients)
|
.insert(devices)
|
||||||
.values({
|
.values({
|
||||||
userId: params.user.id,
|
userId: params.user.id,
|
||||||
name: params.name,
|
name: params.name,
|
||||||
@@ -127,12 +120,12 @@ export async function createClient(params: {
|
|||||||
privateKey: keys.privkey,
|
privateKey: keys.privkey,
|
||||||
preSharedKey: keys.psk,
|
preSharedKey: keys.psk,
|
||||||
})
|
})
|
||||||
.returning({ id: wgClients.id });
|
.returning({ id: devices.id });
|
||||||
|
|
||||||
// update IP allocation with client ID
|
// update IP allocation with device ID
|
||||||
await tx2
|
await tx2
|
||||||
.update(ipAllocations)
|
.update(ipAllocations)
|
||||||
.set({ clientId: newClient.id })
|
.set({ deviceId: newDevice.id })
|
||||||
.where(eq(ipAllocations.id, ipAllocationId));
|
.where(eq(ipAllocations.id, ipAllocationId));
|
||||||
|
|
||||||
// create client in opnsense
|
// create client in opnsense
|
||||||
@@ -151,10 +144,9 @@ export async function createClient(params: {
|
|||||||
|
|
||||||
// reconfigure opnsense
|
// reconfigure opnsense
|
||||||
await opnsenseReconfigure();
|
await opnsenseReconfigure();
|
||||||
|
return ok(newDevice.id);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
if (error) return error;
|
|
||||||
return ok(null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getKeys() {
|
async function getKeys() {
|
||||||
@@ -179,14 +171,14 @@ async function getKeys() {
|
|||||||
|
|
||||||
export function getIpsFromIndex(ipIndex: number) {
|
export function getIpsFromIndex(ipIndex: number) {
|
||||||
ipIndex -= 1; // 1-indexed in the db
|
ipIndex -= 1; // 1-indexed in the db
|
||||||
const v4StartingAddr = new Address4(IPV4_STARTING_ADDR);
|
const v4StartingAddr = new Address4(env.IPV4_STARTING_ADDR);
|
||||||
const v6StartingAddr = new Address6(IPV6_STARTING_ADDR);
|
const v6StartingAddr = new Address6(env.IPV6_STARTING_ADDR);
|
||||||
const v4Allowed = Address4.fromBigInt(v4StartingAddr.bigInt() + BigInt(ipIndex));
|
const v4Allowed = Address4.fromBigInt(v4StartingAddr.bigInt() + BigInt(ipIndex));
|
||||||
const v6Offset = BigInt(ipIndex) << (128n - BigInt(IPV6_CLIENT_PREFIX_SIZE));
|
const v6Offset = BigInt(ipIndex) << (128n - BigInt(env.IPV6_CLIENT_PREFIX_SIZE));
|
||||||
const v6Allowed = Address6.fromBigInt(v6StartingAddr.bigInt() + v6Offset);
|
const v6Allowed = Address6.fromBigInt(v6StartingAddr.bigInt() + v6Offset);
|
||||||
const v6AllowedShort = v6Allowed.parsedAddress.join(':');
|
const v6AllowedShort = v6Allowed.parsedAddress.join(':');
|
||||||
|
|
||||||
return [v4Allowed.address + '/32', v6AllowedShort + '/' + IPV6_CLIENT_PREFIX_SIZE];
|
return [v4Allowed.address + '/32', v6AllowedShort + '/' + env.IPV6_CLIENT_PREFIX_SIZE];
|
||||||
}
|
}
|
||||||
|
|
||||||
async function opnsenseCreateClient(params: {
|
async function opnsenseCreateClient(params: {
|
||||||
@@ -205,12 +197,12 @@ async function opnsenseCreateClient(params: {
|
|||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
configbuilder: {
|
configbuilder: {
|
||||||
enabled: '1',
|
enabled: '1',
|
||||||
name: `vpgen-${params.username}`,
|
name: `vpgen-${opnsenseSanitezedUsername(params.username)}`,
|
||||||
pubkey: params.pubkey,
|
pubkey: params.pubkey,
|
||||||
psk: params.psk,
|
psk: params.psk,
|
||||||
tunneladdress: params.allowedIps,
|
tunneladdress: params.allowedIps,
|
||||||
server: serverUuid,
|
server: serverUuid,
|
||||||
endpoint: VPN_ENDPOINT,
|
endpoint: env.VPN_ENDPOINT,
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
});
|
});
|
@@ -1,9 +1,9 @@
|
|||||||
import { Authentik } from 'arctic';
|
import { Authentik } from 'arctic';
|
||||||
import * as env from '$env/static/private';
|
import { env } from '$env/dynamic/private';
|
||||||
|
|
||||||
export const authentik = new Authentik(
|
export const authentik = new Authentik(
|
||||||
env.AUTH_DOMAIN,
|
env.AUTH_DOMAIN,
|
||||||
env.AUTH_CLIENT_ID,
|
env.AUTH_CLIENT_ID,
|
||||||
env.AUTH_CLIENT_SECRET,
|
env.AUTH_CLIENT_SECRET,
|
||||||
env.AUTH_REDIRECT_URI
|
`${env.ORIGIN}/auth/authentik/callback`,
|
||||||
);
|
);
|
||||||
|
@@ -4,11 +4,6 @@ import { encodeBasicCredentials } from 'arctic/dist/request';
|
|||||||
import { dev } from '$app/environment';
|
import { dev } from '$app/environment';
|
||||||
import type { OpnsenseWgServers } from '$lib/opnsense/wg';
|
import type { OpnsenseWgServers } from '$lib/opnsense/wg';
|
||||||
|
|
||||||
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 opnsenseUrl = env.OPNSENSE_API_URL;
|
||||||
export const opnsenseAuth =
|
export const opnsenseAuth =
|
||||||
'Basic ' + encodeBasicCredentials(env.OPNSENSE_API_KEY, env.OPNSENSE_API_SECRET);
|
'Basic ' + encodeBasicCredentials(env.OPNSENSE_API_KEY, env.OPNSENSE_API_SECRET);
|
||||||
@@ -17,6 +12,9 @@ export const opnsenseIfname = env.OPNSENSE_WG_IFNAME;
|
|||||||
// unset secret for security
|
// unset secret for security
|
||||||
if (!dev) env.OPNSENSE_API_SECRET = '';
|
if (!dev) env.OPNSENSE_API_SECRET = '';
|
||||||
|
|
||||||
|
export let serverUuid: string, serverPublicKey: string;
|
||||||
|
|
||||||
|
export async function fetchOpnsenseServer() {
|
||||||
// this might be pretty bad if the server is down and in a bunch of other cases
|
// this might be pretty bad if the server is down and in a bunch of other cases
|
||||||
// TODO: write a retry loop later
|
// TODO: write a retry loop later
|
||||||
const resServers = await fetch(`${opnsenseUrl}/api/wireguard/client/list_servers`, {
|
const resServers = await fetch(`${opnsenseUrl}/api/wireguard/client/list_servers`, {
|
||||||
@@ -29,9 +27,10 @@ const resServers = await fetch(`${opnsenseUrl}/api/wireguard/client/list_servers
|
|||||||
assert(resServers.ok, 'Failed to fetch OPNsense WireGuard servers');
|
assert(resServers.ok, 'Failed to fetch OPNsense WireGuard servers');
|
||||||
const servers = (await resServers.json()) as OpnsenseWgServers;
|
const servers = (await resServers.json()) as OpnsenseWgServers;
|
||||||
assert.equal(servers.status, 'ok', 'Failed to fetch OPNsense WireGuard servers');
|
assert.equal(servers.status, 'ok', 'Failed to fetch OPNsense WireGuard servers');
|
||||||
export const serverUuid = servers.rows.find((server) => server.name === opnsenseIfname)?.uuid;
|
const uuid = servers.rows.find((server) => server.name === opnsenseIfname)?.uuid;
|
||||||
assert(serverUuid, 'Failed to find server UUID for OPNsense WireGuard server');
|
assert(uuid, 'Failed to find server UUID for OPNsense WireGuard server');
|
||||||
console.log('OPNsense WireGuard server UUID:', serverUuid);
|
serverUuid = uuid;
|
||||||
|
console.info('OPNsense WireGuard server UUID:', serverUuid);
|
||||||
|
|
||||||
const resServerInfo = await fetch(
|
const resServerInfo = await fetch(
|
||||||
`${opnsenseUrl}/api/wireguard/client/get_server_info/${serverUuid}`,
|
`${opnsenseUrl}/api/wireguard/client/get_server_info/${serverUuid}`,
|
||||||
@@ -46,4 +45,5 @@ const resServerInfo = await fetch(
|
|||||||
assert(resServerInfo.ok, 'Failed to fetch OPNsense WireGuard server info');
|
assert(resServerInfo.ok, 'Failed to fetch OPNsense WireGuard server info');
|
||||||
const serverInfo = await resServerInfo.json();
|
const serverInfo = await resServerInfo.json();
|
||||||
assert.equal(serverInfo.status, 'ok', 'Failed to fetch OPNsense WireGuard server info');
|
assert.equal(serverInfo.status, 'ok', 'Failed to fetch OPNsense WireGuard server info');
|
||||||
export const serverPublicKey = serverInfo['pubkey'];
|
serverPublicKey = serverInfo['pubkey'];
|
||||||
|
}
|
||||||
|
@@ -1,11 +0,0 @@
|
|||||||
export type ClientDetails = {
|
|
||||||
id: number;
|
|
||||||
name: string;
|
|
||||||
publicKey: string;
|
|
||||||
privateKey: string | null;
|
|
||||||
preSharedKey: string | null;
|
|
||||||
ips: string[];
|
|
||||||
vpnPublicKey: string;
|
|
||||||
vpnEndpoint: string;
|
|
||||||
vpnDns: string;
|
|
||||||
};
|
|
@@ -1,62 +1,6 @@
|
|||||||
import { type ClassValue, clsx } from "clsx";
|
import { type ClassValue, clsx } from "clsx";
|
||||||
import { twMerge } from "tailwind-merge";
|
import { twMerge } from "tailwind-merge";
|
||||||
import { cubicOut } from "svelte/easing";
|
|
||||||
import type { TransitionConfig } from "svelte/transition";
|
|
||||||
|
|
||||||
export function cn(...inputs: ClassValue[]) {
|
export function cn(...inputs: ClassValue[]) {
|
||||||
return twMerge(clsx(inputs));
|
return twMerge(clsx(inputs));
|
||||||
}
|
}
|
||||||
|
|
||||||
type FlyAndScaleParams = {
|
|
||||||
y?: number;
|
|
||||||
x?: number;
|
|
||||||
start?: number;
|
|
||||||
duration?: number;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const flyAndScale = (
|
|
||||||
node: Element,
|
|
||||||
params: FlyAndScaleParams = { y: -8, x: 0, start: 0.95, duration: 150 }
|
|
||||||
): TransitionConfig => {
|
|
||||||
const style = getComputedStyle(node);
|
|
||||||
const transform = style.transform === "none" ? "" : style.transform;
|
|
||||||
|
|
||||||
const scaleConversion = (
|
|
||||||
valueA: number,
|
|
||||||
scaleA: [number, number],
|
|
||||||
scaleB: [number, number]
|
|
||||||
) => {
|
|
||||||
const [minA, maxA] = scaleA;
|
|
||||||
const [minB, maxB] = scaleB;
|
|
||||||
|
|
||||||
const percentage = (valueA - minA) / (maxA - minA);
|
|
||||||
const valueB = percentage * (maxB - minB) + minB;
|
|
||||||
|
|
||||||
return valueB;
|
|
||||||
};
|
|
||||||
|
|
||||||
const styleToString = (
|
|
||||||
style: Record<string, number | string | undefined>
|
|
||||||
): string => {
|
|
||||||
return Object.keys(style).reduce((str, key) => {
|
|
||||||
if (style[key] === undefined) return str;
|
|
||||||
return str + `${key}:${style[key]};`;
|
|
||||||
}, "");
|
|
||||||
};
|
|
||||||
|
|
||||||
return {
|
|
||||||
duration: params.duration ?? 200,
|
|
||||||
delay: 0,
|
|
||||||
css: (t) => {
|
|
||||||
const y = scaleConversion(t, [0, 1], [params.y ?? 5, 0]);
|
|
||||||
const x = scaleConversion(t, [0, 1], [params.x ?? 0, 0]);
|
|
||||||
const scale = scaleConversion(t, [0, 1], [params.start ?? 0.95, 1]);
|
|
||||||
|
|
||||||
return styleToString({
|
|
||||||
transform: `${transform} translate3d(${x}px, ${y}px, 0) scale(${scale})`,
|
|
||||||
opacity: t
|
|
||||||
});
|
|
||||||
},
|
|
||||||
easing: cubicOut
|
|
||||||
};
|
|
||||||
};
|
|
@@ -1,35 +1,44 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import '../app.css';
|
import '../app.css';
|
||||||
import { page } from '$app/stores';
|
|
||||||
import { cn } from '$lib/utils';
|
import { cn } from '$lib/utils';
|
||||||
|
import { page } from '$app/state';
|
||||||
|
|
||||||
const { data, children } = $props();
|
const { data, children } = $props();
|
||||||
const { user } = data;
|
const { user } = data;
|
||||||
|
|
||||||
function getNavClass(path: RegExp) {
|
function getNavClass(path: RegExp) {
|
||||||
return cn('hover:text-foreground/80 transition-colors',
|
return cn(
|
||||||
path.test($page.url.pathname) ? 'text-foreground' : 'text-foreground/60');
|
'hover:text-foreground/80 transition-colors',
|
||||||
|
path.test(page.url.pathname) ? 'text-foreground' : 'text-foreground/60',
|
||||||
|
);
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<header class="p-4 sm:flex">
|
<header class="flex w-full flex-wrap justify-between gap-x-6 gap-y-4 xl:max-w-screen-xl">
|
||||||
<span class=" mr-6 font-bold sm:inline-block">VPGen</span>
|
<a href="/" class="contents">
|
||||||
<nav class="flex items-center gap-6 text-sm">
|
<span class="font-bold sm:inline-block">VPGen</span>
|
||||||
<a href="/" class={getNavClass(/^\/$/)}>Home</a>
|
</a>
|
||||||
|
<nav class="max-w-full">
|
||||||
|
<ul class="flex items-center gap-6 overflow-x-auto text-sm">
|
||||||
|
<li><a href="/" class={getNavClass(/^\/$/)}>Home</a></li>
|
||||||
{#if user}
|
{#if user}
|
||||||
<a href="/user" class={getNavClass(/^\/user$/)}>Profile</a>
|
<li><a href="/user" class={getNavClass(/^\/user$/)}>Profile</a></li>
|
||||||
<a href="/connections" class={getNavClass(/^\/connections$/)}>Connections</a>
|
<li><a href="/connections" class={getNavClass(/^\/connections$/)}>Connections</a></li>
|
||||||
<a href="/clients" class={getNavClass(/^\/clients(\/\d+)?$/)}>Clients</a>
|
<li><a href="/devices" class={getNavClass(/^\/devices(\/\d+)?$/)}>Devices</a></li>
|
||||||
{/if}
|
{/if}
|
||||||
|
</ul>
|
||||||
</nav>
|
</nav>
|
||||||
</header>
|
</header>
|
||||||
<main class="flex flex-col flex-grow p-4">
|
<main class="flex min-w-full max-w-full flex-grow flex-col gap-4 xl:min-w-[78rem]">
|
||||||
{@render children()}
|
{@render children()}
|
||||||
</main>
|
</main>
|
||||||
|
|
||||||
<!--https://github.com/sveltejs/kit/discussions/7585#discussioncomment-9997936-->
|
<!--https://github.com/sveltejs/kit/discussions/7585#discussioncomment-9997936-->
|
||||||
<!--Some shenanings needed to be done to get the footer position to stick correctly,
|
<!--Some shenanings needed to be done to get the footer position to stick correctly,
|
||||||
didn't work with display: contents-->
|
didn't work with display: contents-->
|
||||||
<footer class="p-4 relative text-center inset-x-0 bottom-0">
|
<footer class="inset-x-0 bottom-0 w-full text-center">
|
||||||
<p>© 2024</p>
|
<p>© 2025</p>
|
||||||
</footer>
|
</footer>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
</style>
|
||||||
|
@@ -1,4 +1,5 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import { Button } from '$lib/components/ui/button';
|
||||||
import { AuthForm } from '$lib/components/app/auth-form';
|
import { AuthForm } from '$lib/components/app/auth-form';
|
||||||
|
|
||||||
const { data } = $props();
|
const { data } = $props();
|
||||||
@@ -9,10 +10,46 @@
|
|||||||
<title>VPGen</title>
|
<title>VPGen</title>
|
||||||
</svelte:head>
|
</svelte:head>
|
||||||
|
|
||||||
<h1>Welcome to VPGen</h1>
|
<h1 class="mb-2 scroll-m-20 text-center text-3xl font-extrabold tracking-tight lg:text-4xl">
|
||||||
|
Welcome to VPGen
|
||||||
|
</h1>
|
||||||
|
|
||||||
{#if user}
|
{#if user}
|
||||||
<p>Hi {user.name}</p>
|
<p>
|
||||||
|
Hi {user.name}!
|
||||||
|
</p>
|
||||||
|
<section id="get-started" class="border-l-2 pl-6">
|
||||||
|
<p>
|
||||||
|
To get started,
|
||||||
|
<Button class="ml-2" href="/devices?add=New+Device">Add a New Device</Button>
|
||||||
|
</p>
|
||||||
|
</section>
|
||||||
|
<!-- <section id="using-wireguard">-->
|
||||||
|
<!-- <details class="mt-10">-->
|
||||||
|
<!-- <summary class="relative flex flex-col gap-2 pl-10">-->
|
||||||
|
<!-- <h2 class="text-xl font-semibold">Using WireGuard</h2>-->
|
||||||
|
<!-- To use VPGen, you need to install the WireGuard app on your device.-->
|
||||||
|
<!-- </summary>-->
|
||||||
|
<!-- <WireguardGuide />-->
|
||||||
|
<!-- </details>-->
|
||||||
|
<!-- </section>-->
|
||||||
{:else}
|
{:else}
|
||||||
<AuthForm class="p-4" />
|
<AuthForm />
|
||||||
|
<!-- <p>VPGen is a VPN generator that allows you to create and manage VPN connections.</p>-->
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
|
<style>
|
||||||
|
p {
|
||||||
|
@apply my-2;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
summary::before {
|
||||||
|
content: '▶';
|
||||||
|
@apply absolute -left-0;
|
||||||
|
}
|
||||||
|
details[open] summary::before {
|
||||||
|
content: '▼';
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
</style>
|
||||||
|
@@ -1,20 +0,0 @@
|
|||||||
import { error } from '@sveltejs/kit';
|
|
||||||
import type { RequestHandler } from './$types';
|
|
||||||
import { findClient, mapClientToDetails } from '$lib/server/clients';
|
|
||||||
|
|
||||||
export const GET: RequestHandler = async (event) => {
|
|
||||||
if (!event.locals.user) {
|
|
||||||
return error(401, 'Unauthorized');
|
|
||||||
}
|
|
||||||
|
|
||||||
const { id } = event.params;
|
|
||||||
const clientId = parseInt(id);
|
|
||||||
if (isNaN(clientId)) {
|
|
||||||
return error(400, 'Invalid client ID');
|
|
||||||
}
|
|
||||||
const client = await findClient(event.locals.user.id, clientId);
|
|
||||||
if (!client) {
|
|
||||||
return error(404, 'Client not found');
|
|
||||||
}
|
|
||||||
return new Response(JSON.stringify(mapClientToDetails(client)));
|
|
||||||
};
|
|
@@ -2,13 +2,56 @@ import { error } from '@sveltejs/kit';
|
|||||||
import type { RequestHandler } from './$types';
|
import type { RequestHandler } from './$types';
|
||||||
import { opnsenseAuth, opnsenseUrl } from '$lib/server/opnsense';
|
import { opnsenseAuth, opnsenseUrl } from '$lib/server/opnsense';
|
||||||
import type { OpnsenseWgPeers } from '$lib/opnsense/wg';
|
import type { OpnsenseWgPeers } from '$lib/opnsense/wg';
|
||||||
|
import { findDevices } from '$lib/server/devices';
|
||||||
|
import type { ConnectionDetails } from '$lib/connections';
|
||||||
|
import { opnsenseSanitezedUsername } from '$lib/opnsense';
|
||||||
|
|
||||||
export const GET: RequestHandler = async (event) => {
|
export const GET: RequestHandler = async (event) => {
|
||||||
if (!event.locals.user) {
|
if (!event.locals.user) {
|
||||||
return error(401, 'Unauthorized');
|
return error(401, 'Unauthorized');
|
||||||
}
|
}
|
||||||
const apiUrl = `${opnsenseUrl}/api/wireguard/service/show`;
|
console.debug('/api/connections');
|
||||||
const options: RequestInit = {
|
const peers = await fetchOpnsensePeers(event.locals.user.username);
|
||||||
|
console.debug('/api/connections: fetched opnsense peers', peers.rowCount);
|
||||||
|
const devices = await findDevices(event.locals.user.id);
|
||||||
|
console.debug('/api/connections: fetched db devices');
|
||||||
|
|
||||||
|
if (!peers) {
|
||||||
|
return error(500, 'Error getting info from OPNsense API');
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: this is all garbage performance
|
||||||
|
// filter devices with no recent handshakes
|
||||||
|
peers.rows = peers.rows.filter((peer) => peer['latest-handshake']);
|
||||||
|
|
||||||
|
// start from devices, to treat db as the source of truth
|
||||||
|
const connections: ConnectionDetails[] = [];
|
||||||
|
for (const device of devices) {
|
||||||
|
const peerData = peers.rows.find((peer) => peer['public-key'] === device.publicKey);
|
||||||
|
if (!peerData) continue;
|
||||||
|
connections.push({
|
||||||
|
deviceId: device.id,
|
||||||
|
deviceName: device.name,
|
||||||
|
devicePublicKey: device.publicKey,
|
||||||
|
deviceIps: peerData['allowed-ips'].split(','),
|
||||||
|
endpoint: peerData['endpoint'],
|
||||||
|
// swap rx and tx, since the opnsense values are from the server perspective
|
||||||
|
transferRx: peerData['transfer-tx'],
|
||||||
|
transferTx: peerData['transfer-rx'],
|
||||||
|
latestHandshake: peerData['latest-handshake'] * 1000,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Response(JSON.stringify(connections), {
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'Cache-Control': 'max-age=5',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
async function fetchOpnsensePeers(username: string) {
|
||||||
|
const res = await fetch(`${opnsenseUrl}/api/wireguard/service/show`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: opnsenseAuth,
|
Authorization: opnsenseAuth,
|
||||||
@@ -16,28 +59,15 @@ export const GET: RequestHandler = async (event) => {
|
|||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
},
|
},
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
'current': 1,
|
current: 1,
|
||||||
// "rowCount": 7,
|
// "rowCount": 7,
|
||||||
'sort': {},
|
sort: {},
|
||||||
// TODO: use a more unique search phrase
|
// TODO: use a more unique search phrase
|
||||||
// unfortunately 64 character limit,
|
// unfortunately 64 character limit,
|
||||||
// but it should be fine if users can't change their own username
|
// but it should be fine if users can't change their own username
|
||||||
'searchPhrase': `vpgen-${event.locals.user.username}`,
|
searchPhrase: `vpgen-${opnsenseSanitezedUsername(username)}`,
|
||||||
'type': ['peer'],
|
type: ['peer'],
|
||||||
}),
|
}),
|
||||||
};
|
|
||||||
|
|
||||||
const res = await fetch(apiUrl, options);
|
|
||||||
const peers = await res.json() as OpnsenseWgPeers;
|
|
||||||
peers.rows = peers.rows.filter(peer => peer['latest-handshake'])
|
|
||||||
|
|
||||||
if (!peers) {
|
|
||||||
return error(500, 'Error getting info from OPNsense API');
|
|
||||||
}
|
|
||||||
return new Response(JSON.stringify(peers), {
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
'Cache-Control': 'max-age=5',
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
};
|
return (await res.json()) as OpnsenseWgPeers;
|
||||||
|
}
|
||||||
|
@@ -1,29 +1,29 @@
|
|||||||
import { error } from '@sveltejs/kit';
|
import { error } from '@sveltejs/kit';
|
||||||
import type { RequestHandler } from './$types';
|
import type { RequestHandler } from './$types';
|
||||||
import { createClient, findClients, mapClientToDetails } from '$lib/server/clients';
|
import { createDevice, findDevices, mapDeviceToDetails } from '$lib/server/devices';
|
||||||
|
|
||||||
export const GET: RequestHandler = async (event) => {
|
export const GET: RequestHandler = async (event) => {
|
||||||
if (!event.locals.user) {
|
if (!event.locals.user) {
|
||||||
return error(401, 'Unauthorized');
|
return error(401, 'Unauthorized');
|
||||||
}
|
}
|
||||||
|
|
||||||
const clients = await findClients(event.locals.user.id);
|
const devices = await findDevices(event.locals.user.id);
|
||||||
return new Response(
|
return new Response(
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
clients: clients.map(mapClientToDetails),
|
devices: devices.map(mapDeviceToDetails),
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
export type Clients = Awaited<ReturnType<typeof findClients>>;
|
export type Devices = Awaited<ReturnType<typeof findDevices>>;
|
||||||
|
|
||||||
export const POST: RequestHandler = async (event) => {
|
export const POST: RequestHandler = async (event) => {
|
||||||
if (!event.locals.user) {
|
if (!event.locals.user) {
|
||||||
return error(401, 'Unauthorized');
|
return error(401, 'Unauthorized');
|
||||||
}
|
}
|
||||||
const { name } = await event.request.json();
|
const { name } = await event.request.json();
|
||||||
const res = await createClient({
|
const res = await createDevice({
|
||||||
name,
|
name,
|
||||||
user: event.locals.user,
|
user: event.locals.user,
|
||||||
});
|
});
|
20
src/routes/api/devices/[id]/+server.ts
Normal file
20
src/routes/api/devices/[id]/+server.ts
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
import { error } from '@sveltejs/kit';
|
||||||
|
import type { RequestHandler } from './$types';
|
||||||
|
import { findDevice, mapDeviceToDetails } from '$lib/server/devices';
|
||||||
|
|
||||||
|
export const GET: RequestHandler = async (event) => {
|
||||||
|
if (!event.locals.user) {
|
||||||
|
return error(401, 'Unauthorized');
|
||||||
|
}
|
||||||
|
|
||||||
|
const { id } = event.params;
|
||||||
|
const deviceId = parseInt(id);
|
||||||
|
if (isNaN(deviceId)) {
|
||||||
|
return error(400, 'Invalid device ID');
|
||||||
|
}
|
||||||
|
const device = await findDevice(event.locals.user.id, deviceId);
|
||||||
|
if (!device) {
|
||||||
|
return error(404, 'Device not found');
|
||||||
|
}
|
||||||
|
return new Response(JSON.stringify(mapDeviceToDetails(device)));
|
||||||
|
};
|
@@ -34,8 +34,8 @@ export async function GET(event: RequestEvent): Promise<Response> {
|
|||||||
status: 400
|
status: 400
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
const claims = decodeIdToken(tokens.idToken());
|
const claims = decodeIdToken(tokens.idToken()) as { sub: string, preferred_username: string, name: string };
|
||||||
console.log("claims", claims);
|
console.info("claims", claims);
|
||||||
const userId: string = claims.sub;
|
const userId: string = claims.sub;
|
||||||
const username: string = claims.preferred_username;
|
const username: string = claims.preferred_username;
|
||||||
|
|
||||||
|
@@ -1,55 +0,0 @@
|
|||||||
<script lang="ts">
|
|
||||||
import * as Table from '$lib/components/ui/table';
|
|
||||||
import { Badge } from '$lib/components/ui/badge';
|
|
||||||
import { Button } from '$lib/components/ui/button';
|
|
||||||
import { Input } from '$lib/components/ui/input';
|
|
||||||
import type { PageData } from './$types';
|
|
||||||
import { LucidePlus } from 'lucide-svelte';
|
|
||||||
|
|
||||||
const { data }: { data: PageData } = $props();
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<svelte:head>
|
|
||||||
<title>Clients</title>
|
|
||||||
</svelte:head>
|
|
||||||
|
|
||||||
<Table.Root class="bg-accent rounded-lg overflow-hidden divide-y-2 divide-background">
|
|
||||||
<Table.Header>
|
|
||||||
<Table.Row>
|
|
||||||
<Table.Head scope="col">Name</Table.Head>
|
|
||||||
<Table.Head scope="col">Public Key</Table.Head>
|
|
||||||
<!-- <Table.Head scope="col">Private Key</Table.Head>-->
|
|
||||||
<!-- <Table.Head scope="col">Pre-Shared Key</Table.Head>-->
|
|
||||||
<Table.Head scope="col">IP Allocation</Table.Head>
|
|
||||||
</Table.Row>
|
|
||||||
</Table.Header>
|
|
||||||
<Table.Body class="divide-y-2 divide-background">
|
|
||||||
{#each data.clients as client}
|
|
||||||
<Table.Row class="hover:bg-background hover:bg-opacity-40 group">
|
|
||||||
<Table.Head scope="row">
|
|
||||||
<a href={`/clients/${client.id}`} class="flex items-center size-full group-hover:underline">
|
|
||||||
{client.name}
|
|
||||||
</a>
|
|
||||||
</Table.Head>
|
|
||||||
<Table.Cell class="truncate">{client.publicKey}</Table.Cell>
|
|
||||||
<!-- <Table.Cell class="truncate max-w-[10ch]">{client.privateKey}</Table.Cell>-->
|
|
||||||
<!-- <Table.Cell class="truncate max-w-[10ch]">{client.preSharedKey}</Table.Cell>-->
|
|
||||||
<Table.Cell class="flex flex-wrap gap-1">
|
|
||||||
{#each client.ips as ip}
|
|
||||||
<Badge class="bg-background select-auto" variant="secondary">{ip}</Badge>
|
|
||||||
{/each}
|
|
||||||
</Table.Cell>
|
|
||||||
</Table.Row>
|
|
||||||
{/each}
|
|
||||||
</Table.Body>
|
|
||||||
</Table.Root>
|
|
||||||
|
|
||||||
<!--Floating action button for adding a new client-->
|
|
||||||
<!--Not sure if this is the best place for the input field, will think about it later-->
|
|
||||||
<form class="flex self-end mt-auto pt-4" method="post" action="?/create">
|
|
||||||
<Input type="text" name="name" placeholder="New Client" class="mr-2" />
|
|
||||||
<Button type="submit">
|
|
||||||
<LucidePlus class="mr-2 h-4 w-4" />
|
|
||||||
Add Client
|
|
||||||
</Button>
|
|
||||||
</form>
|
|
@@ -1,9 +0,0 @@
|
|||||||
import type { PageLoad } from './$types';
|
|
||||||
import type { ClientDetails } from '$lib/types/clients';
|
|
||||||
|
|
||||||
export const load: PageLoad = async ({ fetch }) => {
|
|
||||||
const res = await fetch('/api/clients');
|
|
||||||
const { clients } = await res.json() as { clients: ClientDetails[] };
|
|
||||||
|
|
||||||
return { clients };
|
|
||||||
};
|
|
@@ -1,55 +0,0 @@
|
|||||||
<script lang="ts">
|
|
||||||
import type { PageData } from './$types';
|
|
||||||
import { LucideClipboardCopy } from 'lucide-svelte';
|
|
||||||
import { Button } from '$lib/components/ui/button';
|
|
||||||
import QRCode from 'qrcode-svg';
|
|
||||||
|
|
||||||
const { data }: { data: PageData } = $props();
|
|
||||||
|
|
||||||
let tooltipText = $state('Copy to clipboard');
|
|
||||||
let qrCode = new QRCode({
|
|
||||||
content: data.config,
|
|
||||||
join: true,
|
|
||||||
});
|
|
||||||
|
|
||||||
async function copyToClipboard() {
|
|
||||||
await navigator.clipboard.writeText(data.config);
|
|
||||||
tooltipText = 'Copied!';
|
|
||||||
}
|
|
||||||
|
|
||||||
function onMouseLeave() {
|
|
||||||
tooltipText = 'Copy to clipboard';
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<svelte:head>
|
|
||||||
<title></title>
|
|
||||||
</svelte:head>
|
|
||||||
|
|
||||||
<h1 class="bg-accent text-lg w-fit rounded-lg p-2 mb-4">{data.client.name}</h1>
|
|
||||||
|
|
||||||
<div class="flex flex-wrap gap-4">
|
|
||||||
<div class="relative bg-accent rounded-lg max-w-fit">
|
|
||||||
<div class="flex items-start p-2 overflow-x-auto">
|
|
||||||
<pre><code>{data.config}</code></pre>
|
|
||||||
|
|
||||||
<!--Copy button for the configuration-->
|
|
||||||
<!--Flex reverse for peer hover to work properly-->
|
|
||||||
<div class="absolute group flex flex-row-reverse items-center gap-1 right-2">
|
|
||||||
<Button class="peer size-10 p-2"
|
|
||||||
onclick={copyToClipboard}
|
|
||||||
onmouseleave={onMouseLeave}
|
|
||||||
>
|
|
||||||
<LucideClipboardCopy />
|
|
||||||
</Button>
|
|
||||||
<span class="hidden peer-hover:block bg-background text-xs rounded-lg p-2">
|
|
||||||
{tooltipText}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="rounded-lg overflow-hidden">
|
|
||||||
{@html qrCode.svg()}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
@@ -1,16 +0,0 @@
|
|||||||
import type { PageLoad } from './$types';
|
|
||||||
import type { ClientDetails } from '$lib/types/clients';
|
|
||||||
import { clientDetailsToConfig } from '$lib/clients';
|
|
||||||
import { error } from '@sveltejs/kit';
|
|
||||||
|
|
||||||
export const load: PageLoad = async ({ fetch, params }) => {
|
|
||||||
const res = await fetch(`/api/clients/${params.id}`);
|
|
||||||
const resJson = await res.json();
|
|
||||||
if (!res.ok) {
|
|
||||||
return error(res.status, resJson['message']);
|
|
||||||
}
|
|
||||||
const client = resJson as ClientDetails;
|
|
||||||
const config = clientDetailsToConfig(client);
|
|
||||||
|
|
||||||
return { client, config };
|
|
||||||
};
|
|
@@ -16,14 +16,12 @@
|
|||||||
return () => clearInterval(interval);
|
return () => clearInterval(interval);
|
||||||
});
|
});
|
||||||
|
|
||||||
function getSize(size: number) {
|
function toSizeString(size: number) {
|
||||||
let sizes = ['Bytes', 'KiB', 'MiB', 'GiB',
|
let sizes = ['Bytes', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB'];
|
||||||
'TiB', 'PiB', 'EiB', 'ZiB', 'YiB'];
|
|
||||||
|
|
||||||
for (let i = 1; i < sizes.length; i++) {
|
for (let i = 1; i < sizes.length; i++) {
|
||||||
if (size < Math.pow(1024, i))
|
if (size < Math.pow(1024, i))
|
||||||
return (Math.round((size / Math.pow(
|
return Math.round((size / Math.pow(1024, i - 1)) * 100) / 100 + ' ' + sizes[i - 1];
|
||||||
1024, i - 1)) * 100) / 100) + ' ' + sizes[i - 1];
|
|
||||||
}
|
}
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
@@ -33,38 +31,34 @@
|
|||||||
<title>Connections</title>
|
<title>Connections</title>
|
||||||
</svelte:head>
|
</svelte:head>
|
||||||
|
|
||||||
<Table.Root class="bg-accent rounded-lg overflow-hidden divide-y-2 divide-background">
|
<Table.Root class="divide-y-2 divide-background overflow-hidden rounded-lg bg-accent">
|
||||||
<Table.Header>
|
<Table.Header>
|
||||||
<Table.Row>
|
<Table.Row>
|
||||||
<Table.Head scope="col">Name</Table.Head>
|
<Table.Head scope="col">Device</Table.Head>
|
||||||
<Table.Head scope="col">Public Key</Table.Head>
|
<Table.Head scope="col">Public Key</Table.Head>
|
||||||
<Table.Head scope="col">Endpoint</Table.Head>
|
<Table.Head scope="col">Endpoint</Table.Head>
|
||||||
<Table.Head scope="col">Allowed IPs</Table.Head>
|
<Table.Head scope="col">Device IPs</Table.Head>
|
||||||
<Table.Head scope="col">Latest Handshake</Table.Head>
|
<Table.Head scope="col">Latest Handshake</Table.Head>
|
||||||
<Table.Head scope="col">RX</Table.Head>
|
<Table.Head scope="col">RX</Table.Head>
|
||||||
<Table.Head scope="col">TX</Table.Head>
|
<Table.Head scope="col">TX</Table.Head>
|
||||||
<Table.Head scope="col" class="hidden">Persistent Keepalive</Table.Head>
|
|
||||||
<Table.Head scope="col" class="hidden">Interface Name</Table.Head>
|
|
||||||
</Table.Row>
|
</Table.Row>
|
||||||
</Table.Header>
|
</Table.Header>
|
||||||
<Table.Body class="divide-y-2 divide-background">
|
<Table.Body class="divide-y-2 divide-background">
|
||||||
{#each data.peers.rows as peer}
|
{#each data.connections as conn}
|
||||||
<Table.Row class="hover:bg-background hover:bg-opacity-40">
|
<Table.Row class="hover:bg-surface">
|
||||||
<Table.Head scope="row">{peer.name}</Table.Head>
|
<Table.Head scope="row">{conn.deviceName}</Table.Head>
|
||||||
<Table.Cell class="truncate max-w-[10ch]">{peer['public-key']}</Table.Cell>
|
<Table.Cell class="max-w-[10ch] truncate">{conn.devicePublicKey}</Table.Cell>
|
||||||
<Table.Cell>{peer.endpoint}</Table.Cell>
|
<Table.Cell>{conn.endpoint}</Table.Cell>
|
||||||
<Table.Cell>
|
<Table.Cell>
|
||||||
<div class="flex flex-wrap gap-1">
|
<div class="flex flex-wrap gap-1">
|
||||||
{#each peer['allowed-ips'].split(',') as addr}
|
{#each conn.deviceIps as addr}
|
||||||
<Badge class="bg-background select-auto" variant="secondary">{addr}</Badge>
|
<Badge class="select-auto bg-background" variant="secondary">{addr}</Badge>
|
||||||
{/each}
|
{/each}
|
||||||
</div>
|
</div>
|
||||||
</Table.Cell>
|
</Table.Cell>
|
||||||
<Table.Cell>{new Date(peer['latest-handshake'] * 1000).toLocaleString()}</Table.Cell>
|
<Table.Cell>{new Date(conn.latestHandshake).toLocaleString()}</Table.Cell>
|
||||||
<Table.Cell>{getSize(peer['transfer-rx'])}</Table.Cell>
|
<Table.Cell>{toSizeString(conn.transferRx)}</Table.Cell>
|
||||||
<Table.Cell>{getSize(peer['transfer-tx'])}</Table.Cell>
|
<Table.Cell>{toSizeString(conn.transferTx)}</Table.Cell>
|
||||||
<Table.Cell class="hidden">{peer['persistent-keepalive']}</Table.Cell>
|
|
||||||
<Table.Cell class="hidden">{peer.ifname}</Table.Cell>
|
|
||||||
</Table.Row>
|
</Table.Row>
|
||||||
{/each}
|
{/each}
|
||||||
</Table.Body>
|
</Table.Body>
|
||||||
|
@@ -1,9 +1,9 @@
|
|||||||
import type { PageLoad } from './$types';
|
import type { PageLoad } from './$types';
|
||||||
import type { OpnsenseWgPeers } from '$lib/opnsense/wg';
|
import type { ConnectionDetails } from '$lib/connections';
|
||||||
|
|
||||||
export const load: PageLoad = async ({ fetch }) => {
|
export const load: PageLoad = async ({ fetch }) => {
|
||||||
const res = await fetch('/api/connections');
|
const res = await fetch('/api/connections');
|
||||||
const peers = await res.json() as OpnsenseWgPeers;
|
const connections = await res.json() as ConnectionDetails[];
|
||||||
|
|
||||||
return { peers };
|
return { connections };
|
||||||
};
|
};
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
import type { Actions } from './$types';
|
import type { Actions } from './$types';
|
||||||
import { createClient } from '$lib/server/clients';
|
import { createDevice } from '$lib/server/devices';
|
||||||
import { error } from '@sveltejs/kit';
|
import { error, redirect } from '@sveltejs/kit';
|
||||||
|
|
||||||
export const actions = {
|
export const actions = {
|
||||||
create: async (event) => {
|
create: async (event) => {
|
||||||
@@ -8,16 +8,14 @@ export const actions = {
|
|||||||
const formData = await event.request.formData();
|
const formData = await event.request.formData();
|
||||||
const name = formData.get('name');
|
const name = formData.get('name');
|
||||||
if (typeof name !== 'string' || name.trim() === '') return error(400, 'Invalid name');
|
if (typeof name !== 'string' || name.trim() === '') return error(400, 'Invalid name');
|
||||||
const res = await createClient({
|
const res = await createDevice({
|
||||||
name: name.trim(),
|
name: name.trim(),
|
||||||
user: event.locals.user,
|
user: event.locals.user,
|
||||||
});
|
});
|
||||||
|
|
||||||
switch (res._tag) {
|
switch (res._tag) {
|
||||||
case 'ok': {
|
case 'ok': {
|
||||||
return {
|
return redirect(303, `/devices/${res.value}`);
|
||||||
status: 201,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
case 'err': {
|
case 'err': {
|
||||||
const [status, message] = res.error;
|
const [status, message] = res.error;
|
99
src/routes/devices/+page.svelte
Normal file
99
src/routes/devices/+page.svelte
Normal file
@@ -0,0 +1,99 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import * as Table from '$lib/components/ui/table';
|
||||||
|
import * as Dialog from '$lib/components/ui/dialog';
|
||||||
|
import { Badge } from '$lib/components/ui/badge';
|
||||||
|
import { Button, buttonVariants } from '$lib/components/ui/button';
|
||||||
|
import { Input } from '$lib/components/ui/input';
|
||||||
|
import { LucideLoaderCircle, LucidePlus } from 'lucide-svelte';
|
||||||
|
import type { PageData } from './$types';
|
||||||
|
import { Label } from '$lib/components/ui/label';
|
||||||
|
import { page } from '$app/state';
|
||||||
|
|
||||||
|
const { data }: { data: PageData } = $props();
|
||||||
|
|
||||||
|
let dialogOpen = $state(page.url.searchParams.has('add'));
|
||||||
|
let dialogVal = $state(page.url.searchParams.get('add') ?? '');
|
||||||
|
let submitted = $state(false);
|
||||||
|
|
||||||
|
$effect(() => {
|
||||||
|
if (dialogOpen) page.url.searchParams.set('add', dialogVal);
|
||||||
|
else page.url.searchParams.delete('add');
|
||||||
|
|
||||||
|
window.history.replaceState(history.state, '', page.url);
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<svelte:head>
|
||||||
|
<title>Devices</title>
|
||||||
|
</svelte:head>
|
||||||
|
|
||||||
|
<Table.Root class="divide-y-2 divide-background overflow-hidden rounded-lg bg-accent">
|
||||||
|
<Table.Header>
|
||||||
|
<Table.Row>
|
||||||
|
<Table.Head scope="col">Name</Table.Head>
|
||||||
|
<Table.Head scope="col">Public Key</Table.Head>
|
||||||
|
<!-- <Table.Head scope="col">Private Key</Table.Head>-->
|
||||||
|
<!-- <Table.Head scope="col">Pre-Shared Key</Table.Head>-->
|
||||||
|
<Table.Head scope="col">IP Allocation</Table.Head>
|
||||||
|
</Table.Row>
|
||||||
|
</Table.Header>
|
||||||
|
<Table.Body class="divide-y-2 divide-background">
|
||||||
|
{#each data.devices as device}
|
||||||
|
<Table.Row class="hover:bg-surface group">
|
||||||
|
<Table.Head scope="row">
|
||||||
|
<a
|
||||||
|
href="/devices/{device.id}"
|
||||||
|
class="flex size-full items-center group-hover:underline"
|
||||||
|
>
|
||||||
|
{device.name}
|
||||||
|
</a>
|
||||||
|
</Table.Head>
|
||||||
|
<Table.Cell class="truncate">{device.publicKey}</Table.Cell>
|
||||||
|
<!-- <Table.Cell class="truncate max-w-[10ch]">{device.privateKey}</Table.Cell>-->
|
||||||
|
<!-- <Table.Cell class="truncate max-w-[10ch]">{device.preSharedKey}</Table.Cell>-->
|
||||||
|
<Table.Cell class="flex flex-wrap gap-1">
|
||||||
|
{#each device.ips as ip}
|
||||||
|
<Badge class="select-auto bg-background" variant="secondary">{ip}</Badge>
|
||||||
|
{/each}
|
||||||
|
</Table.Cell>
|
||||||
|
</Table.Row>
|
||||||
|
{/each}
|
||||||
|
</Table.Body>
|
||||||
|
</Table.Root>
|
||||||
|
|
||||||
|
<!--Floating action button for adding a new device-->
|
||||||
|
<Dialog.Root bind:open={dialogOpen}>
|
||||||
|
<div class="mt-auto flex self-end pt-4">
|
||||||
|
<Dialog.Trigger class={buttonVariants({ variant: 'default' }) + ' flex gap-4'}>
|
||||||
|
<LucidePlus />
|
||||||
|
New Device
|
||||||
|
</Dialog.Trigger>
|
||||||
|
</div>
|
||||||
|
<Dialog.Content class="max-w-xs">
|
||||||
|
<form class="contents" method="post" onsubmit={() => submitted = true} action="?/create">
|
||||||
|
<Dialog.Header class="">
|
||||||
|
<Dialog.Title>Add a new device</Dialog.Title>
|
||||||
|
</Dialog.Header>
|
||||||
|
<div class="flex flex-wrap items-center justify-between gap-4">
|
||||||
|
<Label for="name">Name</Label>
|
||||||
|
<Input
|
||||||
|
bind:value={dialogVal}
|
||||||
|
required
|
||||||
|
pattern=".*[^\s]+.*"
|
||||||
|
type="text"
|
||||||
|
name="name"
|
||||||
|
placeholder="New Device"
|
||||||
|
class="max-w-[20ch]"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<Dialog.Footer>
|
||||||
|
<Button type="submit" disabled={submitted}>
|
||||||
|
{#if submitted}
|
||||||
|
<LucideLoaderCircle class="size-4 mr-2 animate-spin" />
|
||||||
|
{/if}
|
||||||
|
Add
|
||||||
|
</Button>
|
||||||
|
</Dialog.Footer>
|
||||||
|
</form>
|
||||||
|
</Dialog.Content>
|
||||||
|
</Dialog.Root>
|
9
src/routes/devices/+page.ts
Normal file
9
src/routes/devices/+page.ts
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
import type { PageLoad } from './$types';
|
||||||
|
import type { DeviceDetails } from '$lib/devices';
|
||||||
|
|
||||||
|
export const load: PageLoad = async ({ fetch }) => {
|
||||||
|
const res = await fetch('/api/devices');
|
||||||
|
const { devices } = await res.json() as { devices: DeviceDetails[] };
|
||||||
|
|
||||||
|
return { devices };
|
||||||
|
};
|
41
src/routes/devices/[id]/+page.svelte
Normal file
41
src/routes/devices/[id]/+page.svelte
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import type { PageData } from './$types';
|
||||||
|
import QRCode from 'qrcode-svg';
|
||||||
|
import { CodeSnippet } from '$lib/components/app/code-snippet';
|
||||||
|
import { WireguardGuide } from '$lib/components/app/wireguard-guide';
|
||||||
|
|
||||||
|
const { data }: { data: PageData } = $props();
|
||||||
|
|
||||||
|
// Clean the device name for the wg config filename,
|
||||||
|
// things can break otherwise (too long or invalid characters)
|
||||||
|
// https://github.com/pirate/wireguard-docs
|
||||||
|
const deviceWgCleanedName =
|
||||||
|
data.device.name.slice(0, 15).replace(/[^a-zA-Z0-9_=+.-]/g, '_') + '.conf';
|
||||||
|
|
||||||
|
let qrCode = new QRCode({
|
||||||
|
content: data.config,
|
||||||
|
join: true,
|
||||||
|
background: 'hsl(var(--accent-light))',
|
||||||
|
width: 296,
|
||||||
|
height: 296,
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<svelte:head>
|
||||||
|
<title>{data.device.name}</title>
|
||||||
|
</svelte:head>
|
||||||
|
|
||||||
|
<h1 class="w-fit rounded-lg bg-accent p-2 text-lg">{data.device.name}</h1>
|
||||||
|
|
||||||
|
<section id="device-configuration" class="flex flex-wrap items-center justify-center gap-4">
|
||||||
|
<CodeSnippet data={data.config} filename={deviceWgCleanedName} copy download />
|
||||||
|
|
||||||
|
<div class="size-fit overflow-auto rounded-lg">
|
||||||
|
{@html qrCode.svg()}
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
<section id="usage" class="flex w-full flex-col gap-2">
|
||||||
|
<h2 class="text-xl font-semibold">Usage</h2>
|
||||||
|
<p>To use VPGen, you need to install the WireGuard app on your device.</p>
|
||||||
|
<WireguardGuide />
|
||||||
|
</section>
|
15
src/routes/devices/[id]/+page.ts
Normal file
15
src/routes/devices/[id]/+page.ts
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
import type { PageLoad } from './$types';
|
||||||
|
import { type DeviceDetails, deviceDetailsToConfig } from '$lib/devices';
|
||||||
|
import { error } from '@sveltejs/kit';
|
||||||
|
|
||||||
|
export const load: PageLoad = async ({ fetch, params }) => {
|
||||||
|
const res = await fetch(`/api/devices/${params.id}`);
|
||||||
|
const resJson = await res.json();
|
||||||
|
if (!res.ok) {
|
||||||
|
return error(res.status, resJson['message']);
|
||||||
|
}
|
||||||
|
const device = resJson as DeviceDetails;
|
||||||
|
const config = deviceDetailsToConfig(device);
|
||||||
|
|
||||||
|
return { device, config };
|
||||||
|
};
|
@@ -2,6 +2,7 @@
|
|||||||
import { invalidate, invalidateAll } from '$app/navigation';
|
import { invalidate, invalidateAll } from '$app/navigation';
|
||||||
import { Button } from '$lib/components/ui/button';
|
import { Button } from '$lib/components/ui/button';
|
||||||
import { LucideLoaderCircle, LucideLogOut, LucideRefreshCw } from 'lucide-svelte';
|
import { LucideLoaderCircle, LucideLogOut, LucideRefreshCw } from 'lucide-svelte';
|
||||||
|
import { CodeSnippet } from '$lib/components/app/code-snippet/index.js';
|
||||||
|
|
||||||
let { data } = $props();
|
let { data } = $props();
|
||||||
let isLoadingSignOut = $state(false);
|
let isLoadingSignOut = $state(false);
|
||||||
@@ -16,11 +17,8 @@
|
|||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<svelte:head>
|
<div class="flex flex-col gap-2">
|
||||||
<title>User Profile</title>
|
<CodeSnippet data={JSON.stringify(data.user, null, 2)} />
|
||||||
</svelte:head>
|
|
||||||
|
|
||||||
<pre>{JSON.stringify(data.user, null, 2)}</pre>
|
|
||||||
|
|
||||||
<div class="flex gap-2">
|
<div class="flex gap-2">
|
||||||
<Button onclick={refetch}>
|
<Button onclick={refetch}>
|
||||||
@@ -28,7 +26,12 @@
|
|||||||
Invalidate Data
|
Invalidate Data
|
||||||
</Button>
|
</Button>
|
||||||
<form class="inline-flex" method="post" action="/auth?/logout">
|
<form class="inline-flex" method="post" action="/auth?/logout">
|
||||||
<Button type="submit" onclick={() => {isLoadingSignOut = true}}>
|
<Button
|
||||||
|
type="submit"
|
||||||
|
onclick={() => {
|
||||||
|
isLoadingSignOut = true;
|
||||||
|
}}
|
||||||
|
>
|
||||||
{#if isLoadingSignOut}
|
{#if isLoadingSignOut}
|
||||||
<LucideLoaderCircle class="mr-2 h-4 w-4 animate-spin" />
|
<LucideLoaderCircle class="mr-2 h-4 w-4 animate-spin" />
|
||||||
{:else}
|
{:else}
|
||||||
@@ -38,3 +41,4 @@
|
|||||||
</Button>
|
</Button>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
import adapter from '@sveltejs/adapter-auto';
|
import adapter from '@sveltejs/adapter-node';
|
||||||
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';
|
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';
|
||||||
|
|
||||||
/** @type {import('@sveltejs/kit').Config} */
|
/** @type {import('@sveltejs/kit').Config} */
|
||||||
|
@@ -1,64 +1,97 @@
|
|||||||
import { fontFamily } from "tailwindcss/defaultTheme";
|
import { fontFamily } from 'tailwindcss/defaultTheme';
|
||||||
import type { Config } from "tailwindcss";
|
import type { Config } from 'tailwindcss';
|
||||||
|
import tailwindcssAnimate from 'tailwindcss-animate';
|
||||||
|
|
||||||
const config: Config = {
|
const config: Config = {
|
||||||
darkMode: ["class"],
|
darkMode: ['media'],
|
||||||
content: ["./src/**/*.{html,js,svelte,ts}"],
|
content: ['./src/**/*.{html,js,svelte,ts}'],
|
||||||
safelist: ["dark"],
|
safelist: ['dark'],
|
||||||
theme: {
|
theme: {
|
||||||
container: {
|
container: {
|
||||||
center: true,
|
center: true,
|
||||||
padding: "2rem",
|
padding: '2rem',
|
||||||
screens: {
|
screens: {
|
||||||
"2xl": "1400px"
|
'2xl': '1400px',
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
extend: {
|
extend: {
|
||||||
colors: {
|
colors: {
|
||||||
border: "hsl(var(--border) / <alpha-value>)",
|
border: 'hsl(var(--border) / <alpha-value>)',
|
||||||
input: "hsl(var(--input) / <alpha-value>)",
|
input: 'hsl(var(--input) / <alpha-value>)',
|
||||||
ring: "hsl(var(--ring) / <alpha-value>)",
|
ring: 'hsl(var(--ring) / <alpha-value>)',
|
||||||
background: "hsl(var(--background) / <alpha-value>)",
|
background: 'hsl(var(--background) / <alpha-value>)',
|
||||||
foreground: "hsl(var(--foreground) / <alpha-value>)",
|
foreground: 'hsl(var(--foreground) / <alpha-value>)',
|
||||||
primary: {
|
primary: {
|
||||||
DEFAULT: "hsl(var(--primary) / <alpha-value>)",
|
DEFAULT: 'hsl(var(--primary) / <alpha-value>)',
|
||||||
foreground: "hsl(var(--primary-foreground) / <alpha-value>)"
|
foreground: 'hsl(var(--primary-foreground) / <alpha-value>)',
|
||||||
},
|
},
|
||||||
secondary: {
|
secondary: {
|
||||||
DEFAULT: "hsl(var(--secondary) / <alpha-value>)",
|
DEFAULT: 'hsl(var(--secondary) / <alpha-value>)',
|
||||||
foreground: "hsl(var(--secondary-foreground) / <alpha-value>)"
|
foreground: 'hsl(var(--secondary-foreground) / <alpha-value>)',
|
||||||
},
|
},
|
||||||
destructive: {
|
destructive: {
|
||||||
DEFAULT: "hsl(var(--destructive) / <alpha-value>)",
|
DEFAULT: 'hsl(var(--destructive) / <alpha-value>)',
|
||||||
foreground: "hsl(var(--destructive-foreground) / <alpha-value>)"
|
foreground: 'hsl(var(--destructive-foreground) / <alpha-value>)',
|
||||||
},
|
},
|
||||||
muted: {
|
muted: {
|
||||||
DEFAULT: "hsl(var(--muted) / <alpha-value>)",
|
DEFAULT: 'hsl(var(--muted) / <alpha-value>)',
|
||||||
foreground: "hsl(var(--muted-foreground) / <alpha-value>)"
|
foreground: 'hsl(var(--muted-foreground) / <alpha-value>)',
|
||||||
},
|
},
|
||||||
accent: {
|
accent: {
|
||||||
DEFAULT: "hsl(var(--accent) / <alpha-value>)",
|
DEFAULT: 'hsl(var(--accent) / <alpha-value>)',
|
||||||
foreground: "hsl(var(--accent-foreground) / <alpha-value>)"
|
foreground: 'hsl(var(--accent-foreground) / <alpha-value>)',
|
||||||
},
|
},
|
||||||
popover: {
|
popover: {
|
||||||
DEFAULT: "hsl(var(--popover) / <alpha-value>)",
|
DEFAULT: 'hsl(var(--popover) / <alpha-value>)',
|
||||||
foreground: "hsl(var(--popover-foreground) / <alpha-value>)"
|
foreground: 'hsl(var(--popover-foreground) / <alpha-value>)',
|
||||||
},
|
},
|
||||||
card: {
|
card: {
|
||||||
DEFAULT: "hsl(var(--card) / <alpha-value>)",
|
DEFAULT: 'hsl(var(--card) / <alpha-value>)',
|
||||||
foreground: "hsl(var(--card-foreground) / <alpha-value>)"
|
foreground: 'hsl(var(--card-foreground) / <alpha-value>)',
|
||||||
}
|
},
|
||||||
|
sidebar: {
|
||||||
|
DEFAULT: 'hsl(var(--sidebar-background))',
|
||||||
|
foreground: 'hsl(var(--sidebar-foreground))',
|
||||||
|
primary: 'hsl(var(--sidebar-primary))',
|
||||||
|
'primary-foreground': 'hsl(var(--sidebar-primary-foreground))',
|
||||||
|
accent: 'hsl(var(--sidebar-accent))',
|
||||||
|
'accent-foreground': 'hsl(var(--sidebar-accent-foreground))',
|
||||||
|
border: 'hsl(var(--sidebar-border))',
|
||||||
|
ring: 'hsl(var(--sidebar-ring))',
|
||||||
|
},
|
||||||
|
surface: 'hsl(var(--surface) / <alpha-value>)',
|
||||||
},
|
},
|
||||||
borderRadius: {
|
borderRadius: {
|
||||||
lg: "var(--radius)",
|
xl: 'calc(var(--radius) + 4px)',
|
||||||
md: "calc(var(--radius) - 2px)",
|
lg: 'var(--radius)',
|
||||||
sm: "calc(var(--radius) - 4px)"
|
md: 'calc(var(--radius) - 2px)',
|
||||||
|
sm: 'calc(var(--radius) - 4px)',
|
||||||
},
|
},
|
||||||
fontFamily: {
|
fontFamily: {
|
||||||
sans: [...fontFamily.sans]
|
sans: [...fontFamily.sans],
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
keyframes: {
|
||||||
|
'accordion-down': {
|
||||||
|
from: { height: '0' },
|
||||||
|
to: { height: 'var(--bits-accordion-content-height)' },
|
||||||
|
},
|
||||||
|
'accordion-up': {
|
||||||
|
from: { height: 'var(--bits-accordion-content-height)' },
|
||||||
|
to: { height: '0' },
|
||||||
|
},
|
||||||
|
'caret-blink': {
|
||||||
|
'0%,70%,100%': { opacity: '1' },
|
||||||
|
'20%,50%': { opacity: '0' },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
animation: {
|
||||||
|
'accordion-down': 'accordion-down 0.2s ease-out',
|
||||||
|
'accordion-up': 'accordion-up 0.2s ease-out',
|
||||||
|
'caret-blink': 'caret-blink 1.25s ease-out infinite',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
plugins: [tailwindcssAnimate],
|
||||||
};
|
};
|
||||||
|
|
||||||
export default config;
|
export default config;
|
||||||
|
Reference in New Issue
Block a user