improved Database & Models
This commit is contained in:
commit
0bbe91bec3
18 changed files with 956 additions and 0 deletions
34
lib/wireguard/config.mjs
Normal file
34
lib/wireguard/config.mjs
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
import {
|
||||
wireguardInterface,
|
||||
wireguardPeer
|
||||
} from "../models.mjs";
|
||||
|
||||
import path from "node:path";
|
||||
import file from "node:fs";
|
||||
import ejs from "ejs";
|
||||
|
||||
|
||||
const serverTemplatePath = path.join(process.cwd(), 'templates', 'wg_server.ejs');
|
||||
const clientTemplatePath = path.join(process.cwd(), 'templates', 'wg_client.ejs');
|
||||
|
||||
|
||||
export async function generateInterfaceConfig(interfaceId) {
|
||||
const ifData = Object.values(wireguardInterface.getAll()).find(fi => fi.id == interfaceId);
|
||||
const peerList = Object.values(wireguardPeer.getAll()).filter(fi => fi.interface == interfaceId);
|
||||
|
||||
let configData = await ejs.renderFile(
|
||||
serverTemplatePath,
|
||||
{
|
||||
interface: ifData,
|
||||
peerList
|
||||
},
|
||||
{
|
||||
async: true
|
||||
}
|
||||
);
|
||||
|
||||
file.writeFileSync(
|
||||
path.join(process.cwd(), 'data', 'wireguard', `${ifData.ifName}.conf`),
|
||||
configData
|
||||
)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue