Files
wg-easy-ca-lose/src/server/utils/template.ts
T
Bernd StorathandGitHub 2af5cd04b4 chore: disable auto imports (#2672)
* disable auto imports

* fix imports

* improve cli imports

* fix imports

* fix import cycle

* fix imports
2026-06-19 15:24:42 +02:00

34 lines
937 B
TypeScript

import { WG_ENV } from '#server/utils/config';
import type { InterfaceType } from '#db/repositories/interface/types';
/**
* Replace all {{key}} in the template with the values[key]
*/
export function template(templ: string, values: Record<string, string>) {
return templ.replace(/\{\{(\w+)\}\}/g, (match, key) => {
return values[key] !== undefined ? values[key] : match;
});
}
export function removeNewlines(templ: string) {
return templ.replace(/\r\n|\r|\n/g, ' ');
}
/**
* Available keys:
* - ipv4Cidr: IPv4 CIDR
* - ipv6Cidr: IPv6 CIDR
* - device: Network device
* - port: Port number
* - uiPort: UI port number
*/
export function iptablesTemplate(templ: string, wgInterface: InterfaceType) {
return template(removeNewlines(templ), {
ipv4Cidr: wgInterface.ipv4Cidr,
ipv6Cidr: wgInterface.ipv6Cidr,
device: wgInterface.device,
port: wgInterface.port.toString(),
uiPort: WG_ENV.PORT,
});
}