new clients page
This commit is contained in:
@@ -67,3 +67,41 @@ export interface OpnsenseWgServers {
|
||||
uuid: string;
|
||||
}[];
|
||||
}
|
||||
|
||||
/**
|
||||
* Sample response for OPNsense WireGuard clients
|
||||
* ```json
|
||||
* {
|
||||
* "rows": [
|
||||
* {
|
||||
* "uuid": "d99334de-7671-4ca7-9c9b-5f5578acae70",
|
||||
* "enabled": "1",
|
||||
* "name": "Yura-TPX13",
|
||||
* "pubkey": "iJa5JmJbMHNlbEluNwoB2Q8LyrPAfb7S/mluanMcI08=",
|
||||
* "tunneladdress": "fd00::1/112,10.6.0.3/32",
|
||||
* "serveraddress": "",
|
||||
* "serverport": "",
|
||||
* "servers": "wg0"
|
||||
* }
|
||||
* ],
|
||||
* "rowCount": 1,
|
||||
* "total": 10,
|
||||
* "current": 1
|
||||
* }
|
||||
* ```
|
||||
*/
|
||||
export interface OpnsenseWgClients {
|
||||
rowCount: number;
|
||||
total: number;
|
||||
current: number;
|
||||
rows: {
|
||||
uuid: string;
|
||||
enabled: string;
|
||||
name: string;
|
||||
pubkey: string;
|
||||
tunneladdress: string;
|
||||
serveraddress: string;
|
||||
serverport: string;
|
||||
servers: string;
|
||||
}[];
|
||||
}
|
||||
|
@@ -49,7 +49,14 @@ export const wgClients = sqliteTable('wg_clients', {
|
||||
});
|
||||
|
||||
export const wgClientsRelations = relations(wgClients, ({ one }) => ({
|
||||
ipAllocation: one(ipAllocations),
|
||||
user: one(users, {
|
||||
fields: [wgClients.userId],
|
||||
references: [users.id],
|
||||
}),
|
||||
ipAllocation: one(ipAllocations, {
|
||||
fields: [wgClients.id],
|
||||
references: [ipAllocations.clientId],
|
||||
}),
|
||||
}));
|
||||
|
||||
export type WgClient = typeof wgClients.$inferSelect;
|
||||
|
@@ -1,4 +1,4 @@
|
||||
import { users, wgClients } from './schema';
|
||||
import { ipAllocations, users, wgClients } from './schema';
|
||||
import { eq } from 'drizzle-orm';
|
||||
import assert from 'node:assert';
|
||||
import { drizzle } from 'drizzle-orm/libsql';
|
||||
@@ -7,23 +7,27 @@ import * as schema from '$lib/server/db/schema';
|
||||
assert(process.env.DATABASE_URL, 'DATABASE_URL is not set');
|
||||
const db = drizzle(process.env.DATABASE_URL, { schema });
|
||||
|
||||
export async function seed() {
|
||||
async function seed() {
|
||||
const user = await db.query.users.findFirst({ where: eq(users.username, 'CaZzzer') });
|
||||
assert(user, 'User not found');
|
||||
|
||||
const clients = [
|
||||
const clients: typeof wgClients.$inferInsert[] = [
|
||||
{
|
||||
userId: user.id,
|
||||
name: 'Client1',
|
||||
publicKey: 'BJ5faPVJsDP4CCxNYilmKnwlQXOtXEOJjqIwb4U/CgM=',
|
||||
privateKey: 'KKqsHDu30WCSrVsyzMkOKbE3saQ+wlx0sBwGs61UGXk=',
|
||||
preSharedKey: '0LWopbrISXBNHUxr+WOhCSAg+0hD8j3TLmpyzHkBHCQ=',
|
||||
ipIndex: 1,
|
||||
// ipIndex: 1,
|
||||
// allowedIps: '10.18.11.101/32,fd00::1/112',
|
||||
}
|
||||
]
|
||||
},
|
||||
];
|
||||
const returned = await db.insert(wgClients).values(clients).returning({ insertedId: wgClients.id });
|
||||
|
||||
await db.insert(wgClients).values(clients);
|
||||
const ipAllocation: typeof ipAllocations.$inferInsert = {
|
||||
clientId: returned[0].insertedId,
|
||||
};
|
||||
await db.insert(ipAllocations).values(ipAllocation);
|
||||
}
|
||||
|
||||
seed();
|
||||
|
Reference in New Issue
Block a user