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,
|
`persistent_keepalive` integer NOT NULL,
|
||||||
`mtu` integer NOT NULL,
|
`mtu` integer NOT NULL,
|
||||||
`dns` text,
|
`dns` text,
|
||||||
|
`server_endpoint` text,
|
||||||
`enabled` integer NOT NULL,
|
`enabled` integer NOT NULL,
|
||||||
`created_at` text DEFAULT (CURRENT_TIMESTAMP) NOT NULL,
|
`created_at` text DEFAULT (CURRENT_TIMESTAMP) NOT NULL,
|
||||||
`updated_at` text DEFAULT (CURRENT_TIMESTAMP) NOT NULL,
|
`updated_at` text DEFAULT (CURRENT_TIMESTAMP) NOT NULL,
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"version": "6",
|
"version": "6",
|
||||||
"dialect": "sqlite",
|
"dialect": "sqlite",
|
||||||
"id": "91f8ccee-7842-4fd3-bb84-f43e00466b20",
|
"id": "b812341a-1ec2-49a6-8bc8-0332f5b32df4",
|
||||||
"prevId": "00000000-0000-0000-0000-000000000000",
|
"prevId": "00000000-0000-0000-0000-000000000000",
|
||||||
"tables": {
|
"tables": {
|
||||||
"clients_table": {
|
"clients_table": {
|
||||||
@@ -137,6 +137,13 @@
|
|||||||
"notNull": false,
|
"notNull": false,
|
||||||
"autoincrement": false
|
"autoincrement": false
|
||||||
},
|
},
|
||||||
|
"server_endpoint": {
|
||||||
|
"name": "server_endpoint",
|
||||||
|
"type": "text",
|
||||||
|
"primaryKey": false,
|
||||||
|
"notNull": false,
|
||||||
|
"autoincrement": false
|
||||||
|
},
|
||||||
"enabled": {
|
"enabled": {
|
||||||
"name": "enabled",
|
"name": "enabled",
|
||||||
"type": "integer",
|
"type": "integer",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"id": "0224c6a5-3456-402d-a40d-0821637015da",
|
"id": "c4c5bfb7-a66c-4e6b-a15c-232b16689dcf",
|
||||||
"prevId": "91f8ccee-7842-4fd3-bb84-f43e00466b20",
|
"prevId": "b812341a-1ec2-49a6-8bc8-0332f5b32df4",
|
||||||
"version": "6",
|
"version": "6",
|
||||||
"dialect": "sqlite",
|
"dialect": "sqlite",
|
||||||
"tables": {
|
"tables": {
|
||||||
@@ -137,6 +137,13 @@
|
|||||||
"notNull": false,
|
"notNull": false,
|
||||||
"autoincrement": false
|
"autoincrement": false
|
||||||
},
|
},
|
||||||
|
"server_endpoint": {
|
||||||
|
"name": "server_endpoint",
|
||||||
|
"type": "text",
|
||||||
|
"primaryKey": false,
|
||||||
|
"notNull": false,
|
||||||
|
"autoincrement": false
|
||||||
|
},
|
||||||
"enabled": {
|
"enabled": {
|
||||||
"name": "enabled",
|
"name": "enabled",
|
||||||
"type": "integer",
|
"type": "integer",
|
||||||
|
|||||||
@@ -5,14 +5,14 @@
|
|||||||
{
|
{
|
||||||
"idx": 0,
|
"idx": 0,
|
||||||
"version": "6",
|
"version": "6",
|
||||||
"when": 1743490907551,
|
"when": 1743515334198,
|
||||||
"tag": "0000_short_skin",
|
"tag": "0000_short_skin",
|
||||||
"breakpoints": true
|
"breakpoints": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"idx": 1,
|
"idx": 1,
|
||||||
"version": "6",
|
"version": "6",
|
||||||
"when": 1743490912488,
|
"when": 1743515338707,
|
||||||
"tag": "0001_classy_the_stranger",
|
"tag": "0001_classy_the_stranger",
|
||||||
"breakpoints": true
|
"breakpoints": true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ export const client = sqliteTable('clients_table', {
|
|||||||
persistentKeepalive: int('persistent_keepalive').notNull(),
|
persistentKeepalive: int('persistent_keepalive').notNull(),
|
||||||
mtu: int().notNull(),
|
mtu: int().notNull(),
|
||||||
dns: text({ mode: 'json' }).$type<string[]>(),
|
dns: text({ mode: 'json' }).$type<string[]>(),
|
||||||
|
serverEndpoint: text('server_endpoint'),
|
||||||
enabled: int({ mode: 'boolean' }).notNull(),
|
enabled: int({ mode: 'boolean' }).notNull(),
|
||||||
createdAt: text('created_at')
|
createdAt: text('created_at')
|
||||||
.notNull()
|
.notNull()
|
||||||
|
|||||||
@@ -65,6 +65,7 @@ export const ClientUpdateSchema = schemaForType<UpdateClientType>()(
|
|||||||
serverAllowedIps: serverAllowedIps,
|
serverAllowedIps: serverAllowedIps,
|
||||||
mtu: MtuSchema,
|
mtu: MtuSchema,
|
||||||
persistentKeepalive: PersistentKeepaliveSchema,
|
persistentKeepalive: PersistentKeepaliveSchema,
|
||||||
|
serverEndpoint: AddressSchema.nullable(),
|
||||||
dns: DnsSchema.nullable(),
|
dns: DnsSchema.nullable(),
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -34,6 +34,8 @@ class WireGuard {
|
|||||||
result.push(wg.generateServerPeer(client));
|
result.push(wg.generateServerPeer(client));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
result.push('');
|
||||||
|
|
||||||
WG_DEBUG('Saving Config...');
|
WG_DEBUG('Saving Config...');
|
||||||
await fs.writeFile(
|
await fs.writeFile(
|
||||||
`/etc/wireguard/${wgInterface.name}.conf`,
|
`/etc/wireguard/${wgInterface.name}.conf`,
|
||||||
|
|||||||
@@ -13,11 +13,16 @@ export const wg = {
|
|||||||
...(client.serverAllowedIps ?? []),
|
...(client.serverAllowedIps ?? []),
|
||||||
];
|
];
|
||||||
|
|
||||||
|
const extraLines = [];
|
||||||
|
if (client.serverEndpoint) {
|
||||||
|
extraLines.push(`Endpoint = ${client.serverEndpoint}`);
|
||||||
|
}
|
||||||
|
|
||||||
return `# Client: ${client.name} (${client.id})
|
return `# Client: ${client.name} (${client.id})
|
||||||
[Peer]
|
[Peer]
|
||||||
PublicKey = ${client.publicKey}
|
PublicKey = ${client.publicKey}
|
||||||
PresharedKey = ${client.preSharedKey}
|
PresharedKey = ${client.preSharedKey}
|
||||||
AllowedIPs = ${allowedIps.join(', ')}`;
|
AllowedIPs = ${allowedIps.join(', ')}${extraLines.length ? `\n${extraLines.join('\n')}` : ''}`;
|
||||||
},
|
},
|
||||||
|
|
||||||
generateServerInterface: (wgInterface: InterfaceType, hooks: HooksType) => {
|
generateServerInterface: (wgInterface: InterfaceType, hooks: HooksType) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user