@ -25,6 +25,7 @@ const {
WG_POST_UP ,
WG_PRE_DOWN ,
WG_POST_DOWN ,
WG_INTERFACE ,
} = require ( '../config' ) ;
module . exports = class WireGuard {
@ -63,10 +64,10 @@ module.exports = class WireGuard {
}
await this . __ saveConfig ( config ) ;
await Util . exec ( 'wg-quick down wg0' ) . catch ( ( ) => { } ) ;
await Util . exec ( 'wg-quick up wg0' ) . catch ( ( err ) => {
if ( err && err . message && err . message . includes ( 'Cannot find device "wg0"' ) ) {
throw new Error ( 'WireGuard exited with the error: Cannot find device "wg0"\nThis usually means that your host\'s kernel does not support WireGuard!' ) ;
await Util . exec ( ` wg-quick down ${ WG_INTERFACE } ` ) . catch ( ( ) => { } ) ;
await Util . exec ( ` wg-quick up ${ WG_INTERFACE } ` ) . catch ( ( err ) => {
if ( err && err . message && err . message . includes ( ` Cannot find device ${ WG_INTERFACE } ` ) ) {
throw new Error ( ` WireGuard exited with the error: Cannot find device ${ WG_INTERFACE } \n This usually means that your host's kernel does not support WireGuard! ` ) ;
}
throw err ;
@ -118,7 +119,7 @@ AllowedIPs = ${client.address}/32, ${client.address6}/128`;
await fs . writeFile ( path . join ( WG_PATH , 'wg0.json' ) , JSON . stringify ( config , false , 2 ) , {
mode : 0o660 ,
} ) ;
await fs . writeFile ( path . join ( WG_PATH , 'wg0.conf' ) , result , {
await fs . writeFile ( path . join ( WG_PATH , ` ${ WG_INTERFACE } .conf ` ) , result , {
mode : 0o600 ,
} ) ;
debug ( 'Config saved.' ) ;
@ -126,7 +127,7 @@ AllowedIPs = ${client.address}/32, ${client.address6}/128`;
async __ syncConfig ( ) {
debug ( 'Config syncing...' ) ;
await Util . exec ( 'wg syncconf wg0 <(wg-quick strip wg0)' ) ;
await Util . exec ( ` wg syncconf ${ WG_INTERFACE } <(wg-quick strip ${ WG_INTERFACE } ) ` ) ;
debug ( 'Config synced.' ) ;
}
@ -150,7 +151,7 @@ AllowedIPs = ${client.address}/32, ${client.address6}/128`;
} ) ) ;
// Loop WireGuard status
const dump = await Util . exec ( 'wg show wg0 dump' , {
const dump = await Util . exec ( ` wg show ${ WG_INTERFACE } dump ` , {
log : false ,
} ) ;
dump