6a282e6ab9
* 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>
66 lines
1.9 KiB
TypeScript
66 lines
1.9 KiB
TypeScript
import debug from 'debug';
|
|
import packageJson from '@@/package.json';
|
|
|
|
export const RELEASE = 'v' + packageJson.version;
|
|
|
|
export const SERVER_DEBUG = debug('Server');
|
|
|
|
export const OLD_ENV = {
|
|
/** @deprecated Only for migration purposes */
|
|
PASSWORD: process.env.PASSWORD,
|
|
/** @deprecated Only for migration purposes */
|
|
PASSWORD_HASH: process.env.PASSWORD_HASH,
|
|
};
|
|
|
|
const detectAwg = async (): Promise<'awg' | 'wg'> => {
|
|
/** TODO: delete on next major version */
|
|
if (process.env.EXPERIMENTAL_AWG === 'true') {
|
|
const OVERRIDE_AUTO_AWG = process.env.OVERRIDE_AUTO_AWG?.toLowerCase();
|
|
|
|
if (
|
|
OVERRIDE_AUTO_AWG === ('wg' as const) ||
|
|
OVERRIDE_AUTO_AWG === ('awg' as const)
|
|
) {
|
|
return OVERRIDE_AUTO_AWG;
|
|
} else {
|
|
return await exec('modinfo amneziawg')
|
|
.then(() => 'awg' as const)
|
|
.catch(() => 'wg' as const);
|
|
}
|
|
} else return 'wg';
|
|
};
|
|
|
|
export const WG_ENV = {
|
|
/** UI is hosted on HTTP instead of HTTPS */
|
|
INSECURE: process.env.INSECURE === 'true',
|
|
/** Port the UI is listening on */
|
|
PORT: assertEnv('PORT'),
|
|
/** If IPv6 should be disabled */
|
|
DISABLE_IPV6: process.env.DISABLE_IPV6 === 'true',
|
|
WG_EXECUTABLE: await detectAwg(),
|
|
};
|
|
|
|
export const WG_INITIAL_ENV = {
|
|
ENABLED: process.env.INIT_ENABLED === 'true',
|
|
USERNAME: process.env.INIT_USERNAME,
|
|
PASSWORD: process.env.INIT_PASSWORD,
|
|
DNS: process.env.INIT_DNS?.split(',').map((x) => x.trim()),
|
|
IPV4_CIDR: process.env.INIT_IPV4_CIDR,
|
|
IPV6_CIDR: process.env.INIT_IPV6_CIDR,
|
|
ALLOWED_IPS: process.env.INIT_ALLOWED_IPS?.split(',').map((x) => x.trim()),
|
|
HOST: process.env.INIT_HOST,
|
|
PORT: process.env.INIT_PORT
|
|
? Number.parseInt(process.env.INIT_PORT, 10)
|
|
: undefined,
|
|
};
|
|
|
|
function assertEnv<T extends string>(env: T) {
|
|
const val = process.env[env];
|
|
|
|
if (!val) {
|
|
throw new Error(`Missing environment variable: ${env}`);
|
|
}
|
|
|
|
return val;
|
|
}
|