Feat: Server Endpoint (#1785)
* add server endpoint to client * be able to update endpoint over api
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -65,6 +65,7 @@ export const ClientUpdateSchema = schemaForType<UpdateClientType>()(
|
||||
serverAllowedIps: serverAllowedIps,
|
||||
mtu: MtuSchema,
|
||||
persistentKeepalive: PersistentKeepaliveSchema,
|
||||
serverEndpoint: AddressSchema.nullable(),
|
||||
dns: DnsSchema.nullable(),
|
||||
})
|
||||
);
|
||||
|
||||
@@ -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`,
|
||||
|
||||
@@ -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) => {
|
||||
|
||||
Reference in New Issue
Block a user