diff --git a/assets/screenshot.png b/assets/screenshot.png index c5b73cc..6f87a64 100644 Binary files a/assets/screenshot.png and b/assets/screenshot.png differ diff --git a/src/lib/Server.js b/src/lib/Server.js index 40341ee..d995bb6 100644 --- a/src/lib/Server.js +++ b/src/lib/Server.js @@ -265,6 +265,23 @@ module.exports = class Server { }); }; + // backup_restore + const router3 = createRouter(); + app.use(router3); + + router3 + .get('/api/wireguard/backup', defineEventHandler(async (event) => { + const config = await WireGuard.backupConfiguration(); + setHeader(event, 'Content-Disposition', 'attachment; filename="wg0.json"'); + setHeader(event, 'Content-Type', 'text/json'); + return config; + })) + .put('/api/wireguard/restore', defineEventHandler(async (event) => { + const { file } = await readBody(event); + await WireGuard.restoreConfiguration(file); + return { success: true }; + })); + // Static assets const publicDir = '/app/www'; app.use( diff --git a/src/lib/WireGuard.js b/src/lib/WireGuard.js index d4f32c5..215d0d5 100644 --- a/src/lib/WireGuard.js +++ b/src/lib/WireGuard.js @@ -319,6 +319,22 @@ Endpoint = ${WG_HOST}:${WG_CONFIG_PORT}`; await this.saveConfig(); } + async ___forceRestart() { + this.__configPromise = null; + await this.saveConfig(); + } + + async restoreConfiguration(config) { + const _config = JSON.parse(config); + await this.__saveConfig(_config); + await this.___forceRestart(); + } + + async backupConfiguration() { + const config = await this.getConfig(); + return JSON.stringify(config, null, 2); + } + // Shutdown wireguard async Shutdown() { await Util.exec('wg-quick down wg0').catch(() => { }); diff --git a/src/www/css/app.css b/src/www/css/app.css index ead6439..472b2ac 100644 --- a/src/www/css/app.css +++ b/src/www/css/app.css @@ -1458,6 +1458,10 @@ video { border-bottom-width: 0px; } +.hover\:cursor-pointer:hover { + cursor: pointer; +} + .hover\:border-red-800:hover { --tw-border-opacity: 1; border-color: rgb(153 27 27 / var(--tw-border-opacity)); diff --git a/src/www/index.html b/src/www/index.html index 7204472..314e7fb 100644 --- a/src/www/index.html +++ b/src/www/index.html @@ -91,6 +91,26 @@

{{$t("clients")}}

+ + + + + + + + + {{$t("backup")}} + +