diff --git a/src/lib/Server.js b/src/lib/Server.js
index 52534a2..315679c 100644
--- a/src/lib/Server.js
+++ b/src/lib/Server.js
@@ -270,15 +270,15 @@ module.exports = class Server {
app.use(router3);
router3
- .get('/api/wireguard/dl', defineEventHandler(async (event) => {
- const config = await WireGuard.downloadConfiguration();
+ .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/upload', defineEventHandler(async (event) => {
+ .put('/api/wireguard/restore', defineEventHandler(async (event) => {
const { file } = await readBody(event);
- await WireGuard.uploadConfiguration(file);
+ await WireGuard.restoreConfiguration(file);
return { success: true };
}));
diff --git a/src/lib/WireGuard.js b/src/lib/WireGuard.js
index 716c538..215d0d5 100644
--- a/src/lib/WireGuard.js
+++ b/src/lib/WireGuard.js
@@ -319,15 +319,18 @@ Endpoint = ${WG_HOST}:${WG_CONFIG_PORT}`;
await this.saveConfig();
}
- async uploadConfiguration(config) {
- const _config = JSON.parse(config);
- await this.__saveConfig(_config);
- // force restart
+ async ___forceRestart() {
this.__configPromise = null;
await this.saveConfig();
}
- async downloadConfiguration() {
+ 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);
}
diff --git a/src/www/index.html b/src/www/index.html
index 2fe8800..4c32ae0 100644
--- a/src/www/index.html
+++ b/src/www/index.html
@@ -96,29 +96,30 @@
{{$t("clients")}}
-
-