improved Database & Models

This commit is contained in:
Kai Waggeling 2025-12-06 20:04:11 +01:00
commit 0bbe91bec3
18 changed files with 956 additions and 0 deletions

45
lib/wireguard/process.mjs Normal file
View file

@ -0,0 +1,45 @@
import {
execSync as execCommand
} from "node:child_process";
import {
wireguardInterface
} from "../models.mjs";
export async function startWireguardInterface(interfaceid) {
try {
const ifData = wireguardInterface.getById(interfaceid);
const ifLink = getInterfaceLink(ifData.ifName);
if (ifLink.operstate == 'UP') {
console.log(`Reloading interface ${ifData.ifName}`);
console.log(`» reloading interface ${ifData.ifName}`);
execCommand(`wg-quick up ${ifData.ifName}`, { stdio: 'inherit' });
console.log(`✓ reloaded interface ${ifData.ifName}`);
} else {
console.log(`» starting interface ${ifData.ifName}`);
execCommand(`wg-quick up ${ifData.ifName}`, { stdio: 'inherit' });
console.log(`✓ started interface ${ifData.ifName}`);
}
} catch (error) {
console.error(`✕ failed to start interface ${iface}:`, error.message);
}
}
export async function getInterfaceLink(ifName) {
try {
let result = JSON.parse(
execCommand(`ip -j link show`, { stdio: 'inherit' })
).find(linkResult => linkResult.ifname == ifName);
if (!result) { return undefined; }
return result;
} catch (error) {
console.error(`failed to get interface link for ${ifName}:`, error.message);
return undefined;
}
}