Browse Source

Feat: Server Endpoint (#1785)

* add server endpoint to client

* be able to update endpoint over api
master
Bernd Storath 2 days ago
committed by GitHub
parent
commit
e92ee0464e
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 1
      src/server/database/migrations/0000_short_skin.sql
  2. 9
      src/server/database/migrations/meta/0000_snapshot.json
  3. 11
      src/server/database/migrations/meta/0001_snapshot.json
  4. 4
      src/server/database/migrations/meta/_journal.json
  5. 1
      src/server/database/repositories/client/schema.ts
  6. 1
      src/server/database/repositories/client/types.ts
  7. 2
      src/server/utils/WireGuard.ts
  8. 7
      src/server/utils/wgHelper.ts

1
src/server/database/migrations/0000_short_skin.sql

@ -17,6 +17,7 @@ CREATE TABLE `clients_table` (
`persistent_keepalive` integer NOT NULL,
`mtu` integer NOT NULL,
`dns` text,
`server_endpoint` text,
`enabled` integer NOT NULL,
`created_at` text DEFAULT (CURRENT_TIMESTAMP) NOT NULL,
`updated_at` text DEFAULT (CURRENT_TIMESTAMP) NOT NULL,

9
src/server/database/migrations/meta/0000_snapshot.json

@ -1,7 +1,7 @@
{
"version": "6",
"dialect": "sqlite",
"id": "91f8ccee-7842-4fd3-bb84-f43e00466b20",
"id": "b812341a-1ec2-49a6-8bc8-0332f5b32df4",
"prevId": "00000000-0000-0000-0000-000000000000",
"tables": {
"clients_table": {
@ -137,6 +137,13 @@
"notNull": false,
"autoincrement": false
},
"server_endpoint": {
"name": "server_endpoint",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"enabled": {
"name": "enabled",
"type": "integer",

11
src/server/database/migrations/meta/0001_snapshot.json

@ -1,6 +1,6 @@
{
"id": "0224c6a5-3456-402d-a40d-0821637015da",
"prevId": "91f8ccee-7842-4fd3-bb84-f43e00466b20",
"id": "c4c5bfb7-a66c-4e6b-a15c-232b16689dcf",
"prevId": "b812341a-1ec2-49a6-8bc8-0332f5b32df4",
"version": "6",
"dialect": "sqlite",
"tables": {
@ -137,6 +137,13 @@
"notNull": false,
"autoincrement": false
},
"server_endpoint": {
"name": "server_endpoint",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"enabled": {
"name": "enabled",
"type": "integer",

4
src/server/database/migrations/meta/_journal.json

@ -5,14 +5,14 @@
{
"idx": 0,
"version": "6",
"when": 1743490907551,
"when": 1743515334198,
"tag": "0000_short_skin",
"breakpoints": true
},
{
"idx": 1,
"version": "6",
"when": 1743490912488,
"when": 1743515338707,
"tag": "0001_classy_the_stranger",
"breakpoints": true
}

1
src/server/database/repositories/client/schema.ts

@ -31,6 +31,7 @@ export const client = sqliteTable('clients_table', {
persistentKeepalive: int('persistent_keepalive').notNull(),
mtu: int().notNull(),
dns: text({ mode: 'json' }).$type<string[]>(),
serverEndpoint: text('server_endpoint'),
enabled: int({ mode: 'boolean' }).notNull(),
createdAt: text('created_at')
.notNull()

1
src/server/database/repositories/client/types.ts

@ -65,6 +65,7 @@ export const ClientUpdateSchema = schemaForType<UpdateClientType>()(
serverAllowedIps: serverAllowedIps,
mtu: MtuSchema,
persistentKeepalive: PersistentKeepaliveSchema,
serverEndpoint: AddressSchema.nullable(),
dns: DnsSchema.nullable(),
})
);

2
src/server/utils/WireGuard.ts

@ -34,6 +34,8 @@ class WireGuard {
result.push(wg.generateServerPeer(client));
}
result.push('');
WG_DEBUG('Saving Config...');
await fs.writeFile(
`/etc/wireguard/${wgInterface.name}.conf`,

7
src/server/utils/wgHelper.ts

@ -13,11 +13,16 @@ export const wg = {
...(client.serverAllowedIps ?? []),
];
const extraLines = [];
if (client.serverEndpoint) {
extraLines.push(`Endpoint = ${client.serverEndpoint}`);
}
return `# Client: ${client.name} (${client.id})
[Peer]
PublicKey = ${client.publicKey}
PresharedKey = ${client.preSharedKey}
AllowedIPs = ${allowedIps.join(', ')}`;
AllowedIPs = ${allowedIps.join(', ')}${extraLines.length ? `\n${extraLines.join('\n')}` : ''}`;
},
generateServerInterface: (wgInterface: InterfaceType, hooks: HooksType) => {

Loading…
Cancel
Save