mirror of https://github.com/wg-easy/wg-easy
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
65 lines
1.9 KiB
65 lines
1.9 KiB
import { createDebug } from 'obug';
|
|
import packageJson from '@@/package.json';
|
|
|
|
export const RELEASE = 'v' + packageJson.version;
|
|
|
|
export const SERVER_DEBUG = createDebug('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;
|
|
}
|
|
|