Feat: Global config override (#1720)
* be able to change dns. implement global override * link donate to readme * implement global config for allowed ips * change translations, fix generation * improve docs
This commit is contained in:
@@ -12,11 +12,11 @@ CREATE TABLE `clients_table` (
|
||||
`public_key` text NOT NULL,
|
||||
`pre_shared_key` text NOT NULL,
|
||||
`expires_at` text,
|
||||
`allowed_ips` text NOT NULL,
|
||||
`allowed_ips` text,
|
||||
`server_allowed_ips` text NOT NULL,
|
||||
`persistent_keepalive` integer NOT NULL,
|
||||
`mtu` integer NOT NULL,
|
||||
`dns` text NOT NULL,
|
||||
`dns` 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": "383501e4-f8de-4413-847f-a9082f6dc398",
|
||||
"id": "8c2af02b-c4bd-4880-a9ad-b38805636208",
|
||||
"prevId": "00000000-0000-0000-0000-000000000000",
|
||||
"tables": {
|
||||
"clients_table": {
|
||||
@@ -106,7 +106,7 @@
|
||||
"name": "allowed_ips",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"server_allowed_ips": {
|
||||
@@ -134,7 +134,7 @@
|
||||
"name": "dns",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"enabled": {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"id": "bf316694-e2ce-4e29-bd66-ce6c0a9d3c90",
|
||||
"prevId": "383501e4-f8de-4413-847f-a9082f6dc398",
|
||||
"id": "a61263b1-9af1-4d2e-99e9-80d08127b545",
|
||||
"prevId": "8c2af02b-c4bd-4880-a9ad-b38805636208",
|
||||
"version": "6",
|
||||
"dialect": "sqlite",
|
||||
"tables": {
|
||||
@@ -106,7 +106,7 @@
|
||||
"name": "allowed_ips",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"server_allowed_ips": {
|
||||
@@ -134,7 +134,7 @@
|
||||
"name": "dns",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"enabled": {
|
||||
|
||||
@@ -5,14 +5,14 @@
|
||||
{
|
||||
"idx": 0,
|
||||
"version": "6",
|
||||
"when": 1741335144499,
|
||||
"when": 1741355094140,
|
||||
"tag": "0000_short_skin",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 1,
|
||||
"version": "6",
|
||||
"when": 1741335153054,
|
||||
"when": 1741355098159,
|
||||
"tag": "0001_classy_the_stranger",
|
||||
"breakpoints": true
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@ import { int, sqliteTable, text } from 'drizzle-orm/sqlite-core';
|
||||
|
||||
import { oneTimeLink, user } from '../../schema';
|
||||
|
||||
/** null means use value from userConfig */
|
||||
|
||||
export const client = sqliteTable('clients_table', {
|
||||
id: int().primaryKey({ autoIncrement: true }),
|
||||
userId: int('user_id')
|
||||
@@ -22,13 +24,13 @@ export const client = sqliteTable('clients_table', {
|
||||
publicKey: text('public_key').notNull(),
|
||||
preSharedKey: text('pre_shared_key').notNull(),
|
||||
expiresAt: text('expires_at'),
|
||||
allowedIps: text('allowed_ips', { mode: 'json' }).$type<string[]>().notNull(),
|
||||
allowedIps: text('allowed_ips', { mode: 'json' }).$type<string[]>(),
|
||||
serverAllowedIps: text('server_allowed_ips', { mode: 'json' })
|
||||
.$type<string[]>()
|
||||
.notNull(),
|
||||
persistentKeepalive: int('persistent_keepalive').notNull(),
|
||||
mtu: int().notNull(),
|
||||
dns: text({ mode: 'json' }).$type<string[]>().notNull(),
|
||||
dns: text({ mode: 'json' }).$type<string[]>(),
|
||||
enabled: int({ mode: 'boolean' }).notNull(),
|
||||
createdAt: text('created_at')
|
||||
.notNull()
|
||||
|
||||
@@ -115,8 +115,6 @@ export class ClientService {
|
||||
ipv4Address,
|
||||
ipv6Address,
|
||||
mtu: clientConfig.defaultMtu,
|
||||
allowedIps: clientConfig.defaultAllowedIps,
|
||||
dns: clientConfig.defaultDns,
|
||||
persistentKeepalive: clientConfig.defaultPersistentKeepalive,
|
||||
serverAllowedIps: [],
|
||||
enabled: true,
|
||||
|
||||
@@ -61,11 +61,11 @@ export const ClientUpdateSchema = schemaForType<UpdateClientType>()(
|
||||
postUp: HookSchema,
|
||||
preDown: HookSchema,
|
||||
postDown: HookSchema,
|
||||
allowedIps: AllowedIpsSchema,
|
||||
allowedIps: AllowedIpsSchema.nullable(),
|
||||
serverAllowedIps: serverAllowedIps,
|
||||
mtu: MtuSchema,
|
||||
persistentKeepalive: PersistentKeepaliveSchema,
|
||||
dns: DnsSchema,
|
||||
dns: DnsSchema.nullable(),
|
||||
})
|
||||
);
|
||||
|
||||
|
||||
@@ -59,13 +59,13 @@ PostDown = ${iptablesTemplate(hooks.postDown, wgInterface)}`;
|
||||
return `[Interface]
|
||||
PrivateKey = ${client.privateKey}
|
||||
Address = ${client.ipv4Address}/${cidr4Block}, ${client.ipv6Address}/${cidr6Block}
|
||||
DNS = ${client.dns.join(', ')}
|
||||
DNS = ${(client.dns ?? userConfig.defaultDns).join(', ')}
|
||||
MTU = ${client.mtu}
|
||||
${hookLines.length ? `${hookLines.join('\n')}\n` : ''}
|
||||
[Peer]
|
||||
PublicKey = ${wgInterface.publicKey}
|
||||
PresharedKey = ${client.preSharedKey}
|
||||
AllowedIPs = ${client.allowedIps.join(', ')}
|
||||
AllowedIPs = ${(client.allowedIps ?? userConfig.defaultAllowedIps).join(', ')}
|
||||
PersistentKeepalive = ${client.persistentKeepalive}
|
||||
Endpoint = ${userConfig.host}:${userConfig.port}`;
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user