feat: change hooks to textareas (#2522)
* hooks are now textareas * remove newlines in client config
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
// ! Auto Imports are not supported in this file
|
||||
|
||||
import type { InterfaceType } from '#db/repositories/interface/types';
|
||||
|
||||
/**
|
||||
@@ -9,6 +11,10 @@ export function template(templ: string, values: Record<string, string>) {
|
||||
});
|
||||
}
|
||||
|
||||
export function removeNewlines(templ: string) {
|
||||
return templ.replace(/\r\n|\r|\n/g, ' ');
|
||||
}
|
||||
|
||||
/**
|
||||
* Available keys:
|
||||
* - ipv4Cidr: IPv4 CIDR
|
||||
@@ -18,7 +24,7 @@ export function template(templ: string, values: Record<string, string>) {
|
||||
* - uiPort: UI port number
|
||||
*/
|
||||
export function iptablesTemplate(templ: string, wgInterface: InterfaceType) {
|
||||
return template(templ, {
|
||||
return template(removeNewlines(templ), {
|
||||
ipv4Cidr: wgInterface.ipv4Cidr,
|
||||
ipv6Cidr: wgInterface.ipv6Cidr,
|
||||
device: wgInterface.device,
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
// ! Auto Imports are not supported in this file
|
||||
|
||||
import { parseCidr } from 'cidr-tools';
|
||||
import { stringifyIp } from 'ip-bigint';
|
||||
import { removeNewlines } from './template';
|
||||
|
||||
import type { ClientType } from '#db/repositories/client/types';
|
||||
import type { InterfaceType } from '#db/repositories/interface/types';
|
||||
import type { UserConfigType } from '#db/repositories/userConfig/types';
|
||||
@@ -112,10 +116,10 @@ PostDown = ${iptablesTemplate(hooks.postDown, wgInterface)}`;
|
||||
(enableIpv6 ? `, ${client.ipv6Address}/128` : '');
|
||||
|
||||
const hookLines = [
|
||||
client.preUp ? `PreUp = ${client.preUp}` : null,
|
||||
client.postUp ? `PostUp = ${client.postUp}` : null,
|
||||
client.preDown ? `PreDown = ${client.preDown}` : null,
|
||||
client.postDown ? `PostDown = ${client.postDown}` : null,
|
||||
client.preUp ? `PreUp = ${removeNewlines(client.preUp)}` : null,
|
||||
client.postUp ? `PostUp = ${removeNewlines(client.postUp)}` : null,
|
||||
client.preDown ? `PreDown = ${removeNewlines(client.preDown)}` : null,
|
||||
client.postDown ? `PostDown = ${removeNewlines(client.postDown)}` : null,
|
||||
];
|
||||
|
||||
const dnsServers = client.dns ?? userConfig.defaultDns;
|
||||
|
||||
Reference in New Issue
Block a user