40 lines
No EOL
958 B
JavaScript
40 lines
No EOL
958 B
JavaScript
import {
|
|
wireguardInterface,
|
|
wireguardPeer,
|
|
addressObject,
|
|
accessPolicy,
|
|
natPolicy
|
|
} from "../models.mjs";
|
|
|
|
import path from "node:path";
|
|
import file from "node:fs";
|
|
import ejs from "ejs";
|
|
|
|
|
|
const configTemplatePath = path.join(process.cwd(), 'templates', 'nftables.ejs');
|
|
|
|
|
|
export async function generateNftablesConfig(interfaceId) {
|
|
const ifData = Object.values(wireguardInterface.getAll()).find(fi => fi.id == interfaceId);
|
|
const addressObjects = addressObject.getAll();
|
|
const accessPolicies = accessPolicy.getAll();
|
|
const natPolicies = natPolicy.getAll();
|
|
|
|
const configData = {
|
|
interface: ifData,
|
|
peerList
|
|
};
|
|
|
|
const configContent = await ejs.renderFile(
|
|
configTemplatePath,
|
|
configData,
|
|
{
|
|
async: true
|
|
}
|
|
);
|
|
|
|
file.writeFileSync(
|
|
path.join(process.cwd(), 'data', 'nftables', `${ifData.ifName}.conf`),
|
|
configContent
|
|
)
|
|
} |