Browse Source

feat: detect wireguard executable

pull/2102/head
cany748 1 month ago
parent
commit
6d63658138
  1. 26
      src/server/utils/wgHelper.ts

26
src/server/utils/wgHelper.ts

@ -9,6 +9,10 @@ type Options = {
enableIpv6?: boolean;
};
const wgExecutable = await exec('modinfo amneziawg')
.then(() => 'awg' as const)
.catch(() => 'wg' as const);
export const wg = {
generateServerPeer: (
client: Omit<ClientType, 'createdAt' | 'updatedAt'>,
@ -107,37 +111,41 @@ Endpoint = ${userConfig.host}:${userConfig.port}`;
},
generatePrivateKey: () => {
return exec('wg genkey');
return exec(`${wgExecutable} genkey`);
},
getPublicKey: (privateKey: string) => {
return exec(`echo ${privateKey} | wg pubkey`, {
log: 'echo ***hidden*** | wg pubkey',
return exec(`echo ${privateKey} | ${wgExecutable} pubkey`, {
log: `echo ***hidden*** | ${wgExecutable} pubkey`,
});
},
generatePreSharedKey: () => {
return exec('wg genpsk');
return exec(`${wgExecutable} genpsk`);
},
up: (infName: string) => {
return exec(`wg-quick up ${infName}`);
return exec(`${wgExecutable}-quick up ${infName}`);
},
down: (infName: string) => {
return exec(`wg-quick down ${infName}`);
return exec(`${wgExecutable}-quick down ${infName}`);
},
restart: (infName: string) => {
return exec(`wg-quick down ${infName}; wg-quick up ${infName}`);
return exec(
`${wgExecutable}-quick down ${infName}; ${wgExecutable}-quick up ${infName}`
);
},
sync: (infName: string) => {
return exec(`wg syncconf ${infName} <(wg-quick strip ${infName})`);
return exec(
`${wgExecutable} syncconf ${infName} <(${wgExecutable}-quick strip ${infName})`
);
},
dump: async (infName: string) => {
const rawDump = await exec(`wg show ${infName} dump`, {
const rawDump = await exec(`${wgExecutable} show ${infName} dump`, {
log: false,
});

Loading…
Cancel
Save