diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml index 9b191b34..8f9dad6e 100644 --- a/docker-compose.dev.yml +++ b/docker-compose.dev.yml @@ -16,7 +16,7 @@ services: - NET_ADMIN - SYS_MODULE environment: - - INIT_ENABLED=false + - INIT_ENABLED=true - INIT_HOST=test - INIT_PORT=51820 - INIT_USERNAME=testtest diff --git a/src/app/components/Admin/RestartInterfaceDialog.vue b/src/app/components/Admin/RestartInterfaceDialog.vue new file mode 100644 index 00000000..e6c92473 --- /dev/null +++ b/src/app/components/Admin/RestartInterfaceDialog.vue @@ -0,0 +1,24 @@ + + + diff --git a/src/app/pages/admin/interface.vue b/src/app/pages/admin/interface.vue index 63309c45..18988943 100644 --- a/src/app/pages/admin/interface.vue +++ b/src/app/pages/admin/interface.vue @@ -34,8 +34,19 @@ + + + @@ -82,4 +93,20 @@ const _changeCidr = useSubmit( async function changeCidr(ipv4Cidr: string, ipv6Cidr: string) { await _changeCidr({ ipv4Cidr, ipv6Cidr }); } + +const _restartInterface = useSubmit( + `/api/admin/interface/restart`, + { + method: 'post', + }, + { + revert, + successMsg: t('admin.interface.restartSuccess'), + errorMsg: t('admin.interface.restartError'), + } +); + +async function restartInterface() { + await _restartInterface(undefined); +} diff --git a/src/i18n/locales/en.json b/src/i18n/locales/en.json index 71b10925..f429034f 100644 --- a/src/i18n/locales/en.json +++ b/src/i18n/locales/en.json @@ -159,7 +159,12 @@ "deviceDesc": "Ethernet device the wireguard traffic should be forwarded through", "mtuDesc": "MTU WireGuard will use", "portDesc": "UDP Port WireGuard will listen on (you probably want to change Config Port too)", - "changeCidr": "Change CIDR" + "changeCidr": "Change CIDR", + "restart": "Restart Interface", + "restartDesc": "Restart the WireGuard interface", + "restartWarn": "Are you sure to restart the interface? This will disconnect all clients.", + "restartSuccess": "Interface restarted", + "restartError": "Failed to restart interface" }, "introText": "Welcome to the admin panel.\n\nHere you can manage the general settings, the configuration, the interface settings and the hooks.\n\nStart by choosing one of the sections in the sidebar." }, diff --git a/src/server/api/admin/interface/restart.post.ts b/src/server/api/admin/interface/restart.post.ts new file mode 100644 index 00000000..aaf7ae39 --- /dev/null +++ b/src/server/api/admin/interface/restart.post.ts @@ -0,0 +1,5 @@ +export default definePermissionEventHandler('admin', 'any', async () => { + await WireGuard.Restart(); + + return { success: true }; +}); diff --git a/src/server/utils/WireGuard.ts b/src/server/utils/WireGuard.ts index 1fa931b0..a5a16aca 100644 --- a/src/server/utils/WireGuard.ts +++ b/src/server/utils/WireGuard.ts @@ -193,6 +193,11 @@ class WireGuard { await wg.down(wgInterface.name).catch(() => {}); } + async Restart() { + const wgInterface = await Database.interfaces.get(); + await wg.restart(wgInterface.name); + } + async cronJob() { const clients = await Database.clients.getAll(); // Expires Feature diff --git a/src/server/utils/wgHelper.ts b/src/server/utils/wgHelper.ts index 170a140f..ab79109d 100644 --- a/src/server/utils/wgHelper.ts +++ b/src/server/utils/wgHelper.ts @@ -92,6 +92,10 @@ Endpoint = ${userConfig.host}:${userConfig.port}`; return exec(`wg-quick down ${infName}`); }, + restart: (infName: string) => { + return exec(`wg-quick down ${infName}; wg-quick up ${infName}`); + }, + sync: (infName: string) => { return exec(`wg syncconf ${infName} <(wg-quick strip ${infName})`); },