AmneziaWG 2.0 (#2226)
* feat!: awg * feat: add description to fields, add I5 * fix: awg i18n * fix: types * minor fixes * Remove TODO comment from types.ts Removed TODO comment for more validation. --------- Co-authored-by: Bernd Storath <999999bst@gmail.com>
This commit is contained in:
committed by
GitHub
parent
a8ba7f7247
commit
6a282e6ab9
@@ -9,17 +9,7 @@ type Options = {
|
||||
enableIpv6?: boolean;
|
||||
};
|
||||
|
||||
let wgExecutable: 'awg' | 'wg' = 'wg';
|
||||
|
||||
if (WG_ENV.EXPERIMENTAL_AWG) {
|
||||
if (WG_ENV.OVERRIDE_AUTO_AWG !== undefined) {
|
||||
wgExecutable = WG_ENV.OVERRIDE_AUTO_AWG;
|
||||
} else {
|
||||
wgExecutable = await exec('modinfo amneziawg')
|
||||
.then(() => 'awg' as const)
|
||||
.catch(() => 'wg' as const);
|
||||
}
|
||||
}
|
||||
const wgExecutable = WG_ENV.WG_EXECUTABLE;
|
||||
|
||||
export const wg = {
|
||||
generateServerPeer: (
|
||||
@@ -62,6 +52,35 @@ AllowedIPs = ${allowedIps.join(', ')}${extraLines.length ? `\n${extraLines.join(
|
||||
`${ipv4Addr}/${cidr4.prefix}` +
|
||||
(enableIpv6 ? `, ${ipv6Addr}/${cidr6.prefix}` : '');
|
||||
|
||||
let awgLines: string[] = [];
|
||||
|
||||
if (wgExecutable === 'awg') {
|
||||
const parameters = {
|
||||
Jc: wgInterface.jC,
|
||||
Jmin: wgInterface.jMin,
|
||||
Jmax: wgInterface.jMax,
|
||||
S1: wgInterface.s1,
|
||||
S2: wgInterface.s2,
|
||||
S3: wgInterface.s3,
|
||||
S4: wgInterface.s4,
|
||||
i1: wgInterface.i1,
|
||||
i2: wgInterface.i2,
|
||||
i3: wgInterface.i3,
|
||||
i4: wgInterface.i4,
|
||||
i5: wgInterface.i5,
|
||||
H1: wgInterface.h1,
|
||||
H2: wgInterface.h2,
|
||||
H3: wgInterface.h3,
|
||||
H4: wgInterface.h4,
|
||||
} as const;
|
||||
|
||||
awgLines = Object.entries(parameters)
|
||||
.filter(([_, value]) => !!value)
|
||||
.map(([key, value]) => `${key} = ${value}`);
|
||||
}
|
||||
|
||||
const extraLines = [...awgLines].filter((v) => v !== null);
|
||||
|
||||
return `# Note: Do not edit this file directly.
|
||||
# Your changes will be overwritten!
|
||||
|
||||
@@ -71,6 +90,7 @@ PrivateKey = ${wgInterface.privateKey}
|
||||
Address = ${address}
|
||||
ListenPort = ${wgInterface.port}
|
||||
MTU = ${wgInterface.mtu}
|
||||
${extraLines.length ? `${extraLines.join('\n')}\n` : ''}
|
||||
PreUp = ${iptablesTemplate(hooks.preUp, wgInterface)}
|
||||
PostUp = ${iptablesTemplate(hooks.postUp, wgInterface)}
|
||||
PreDown = ${iptablesTemplate(hooks.preDown, wgInterface)}
|
||||
@@ -100,7 +120,36 @@ PostDown = ${iptablesTemplate(hooks.postDown, wgInterface)}`;
|
||||
const dnsLine =
|
||||
dnsServers.length > 0 ? `DNS = ${dnsServers.join(', ')}` : null;
|
||||
|
||||
const extraLines = [dnsLine, ...hookLines].filter((v) => v !== null);
|
||||
let awgLines: string[] = [];
|
||||
|
||||
if (wgExecutable === 'awg') {
|
||||
const parameters = {
|
||||
Jc: client.jC,
|
||||
Jmin: client.jMin,
|
||||
Jmax: client.jMax,
|
||||
S1: wgInterface.s1,
|
||||
S2: wgInterface.s2,
|
||||
S3: wgInterface.s3,
|
||||
S4: wgInterface.s4,
|
||||
i1: client.i1,
|
||||
i2: client.i2,
|
||||
i3: client.i3,
|
||||
i4: client.i4,
|
||||
i5: client.i5,
|
||||
H1: wgInterface.h1,
|
||||
H2: wgInterface.h2,
|
||||
H3: wgInterface.h3,
|
||||
H4: wgInterface.h4,
|
||||
} as const;
|
||||
|
||||
awgLines = Object.entries(parameters)
|
||||
.filter(([_, value]) => !!value)
|
||||
.map(([key, value]) => `${key} = ${value}`);
|
||||
}
|
||||
|
||||
const extraLines = [dnsLine, ...hookLines, ...awgLines].filter(
|
||||
(v) => v !== null
|
||||
);
|
||||
|
||||
return `[Interface]
|
||||
PrivateKey = ${client.privateKey}
|
||||
|
||||
Reference in New Issue
Block a user