Browse Source

remove backup / restore

pull/1665/head
Bernd Storath 6 months ago
parent
commit
c2d8662fd8
  1. 10
      src/app/components/Clients/BackupConfig.vue
  2. 34
      src/app/components/Clients/RestoreConfig.vue
  3. 18
      src/app/stores/clients.ts
  4. 24
      src/app/utils/api.ts
  5. 4
      src/i18n/locales/en.json
  6. 21
      src/server/utils/WireGuard.ts

10
src/app/components/Clients/BackupConfig.vue

@ -1,10 +0,0 @@
<template>
<BaseButton
as="a"
href="./api/wireguard/backup"
:title="$t('titleBackupConfig')"
>
<IconsStack class="w-4 md:mr-2" />
<span class="text-sm max-md:hidden">{{ $t('backup') }}</span>
</BaseButton>
</template>

34
src/app/components/Clients/RestoreConfig.vue

@ -1,34 +0,0 @@
<template>
<BaseButton as="label" for="inputRC" :title="$t('titleRestoreConfig')">
<IconsArrowInf class="w-4 md:mr-2" />
<span class="text-sm max-md:hidden">{{ $t('restore') }}</span>
<input
id="inputRC"
type="file"
name="configurationfile"
accept="text/*,.json"
class="hidden"
@change="restoreConfig"
/>
</BaseButton>
</template>
<script setup lang="ts">
function restoreConfig(e: Event) {
e.preventDefault();
const file = (e.currentTarget as HTMLInputElement).files?.item(0);
if (file) {
file
.text()
.then((content) => {
api
.restoreConfiguration(content)
.then(() => alert('The configuration was updated.'))
.catch((err) => alert(err.message || err.toString()));
})
.catch((err) => alert(err.message || err.toString()));
} else {
alert('Failed to load your file!');
}
}
</script>

18
src/app/stores/clients.ts

@ -1,7 +1,14 @@
import { defineStore } from 'pinia';
import { sha256 } from 'js-sha256';
import type { TypedInternalResponse } from 'nitropack/types';
export type LocalClient = WGClient & {
type WGClientReturn = TypedInternalResponse<
'/api/client',
unknown,
'get'
>[number];
export type LocalClient = WGClientReturn & {
avatar?: string;
transferMax?: number;
} & Omit<ClientPersist, 'transferRxPrevious' | 'transferTxPrevious'>;
@ -24,8 +31,13 @@ export const useClientsStore = defineStore('Clients', () => {
const clients = ref<null | LocalClient[]>(null);
const clientsPersist = ref<Record<string, ClientPersist>>({});
const { data: _clients, refresh: _refresh } = useFetch('/api/client', {
method: 'get',
});
// TODO: rewrite
async function refresh({ updateCharts = false } = {}) {
const { data: _clients } = await api.getClients();
await _refresh();
let transformedClients = _clients.value?.map((client) => {
let avatar = undefined;
if (client.name.includes('@') && client.name.includes('.')) {
@ -118,5 +130,5 @@ export const useClientsStore = defineStore('Clients', () => {
clients.value = transformedClients ?? null;
}
return { clients, clientsPersist, refresh };
return { clients, clientsPersist, refresh, _clients };
});

24
src/app/utils/api.ts

@ -1,24 +0,0 @@
class API {
async getClients() {
return useFetch('/api/client', {
method: 'get',
});
}
async restoreConfiguration(file: string) {
return $fetch('/api/wireguard/restore', {
method: 'put',
body: { file },
});
}
}
type WGClientReturn = Awaited<
ReturnType<typeof API.prototype.getClients>
>['data']['value'];
export type WGClient = WGClientReturn extends (infer U)[] | undefined
? U
: never;
export default new API();

4
src/i18n/locales/en.json

@ -69,10 +69,6 @@
"light": "Light theme",
"system": "System theme"
},
"restore": "Restore",
"backup": "Backup",
"titleRestoreConfig": "Restore your configuration",
"titleBackupConfig": "Backup your configuration",
"rememberMe": "Remember me",
"titleRememberMe": "Stay logged after closing the browser",
"sort": "Sort",

21
src/server/utils/WireGuard.ts

@ -135,25 +135,6 @@ class WireGuard {
});
}
// TODO: reimplement database restore
async restoreConfiguration(_config: string) {
/* DEBUG('Starting configuration restore process.');
// TODO: sanitize config
const _config = JSON.parse(config);
await this.__saveConfig(_config);
await this.__reloadConfig();
DEBUG('Configuration restore process completed.'); */
}
// TODO: reimplement database restore
async backupConfiguration() {
/* DEBUG('Starting configuration backup.');
const config = await this.getConfig();
const backup = JSON.stringify(config, null, 2);
DEBUG('Configuration backup completed.');
return backup; */
}
async Startup() {
WG_DEBUG('Starting WireGuard...');
// let as it has to refetch if keys change
@ -253,4 +234,6 @@ Please follow the instructions on https://wg-easy.github.io/wg-easy/ to migrate
);
}
// TODO: make static or object
export default new WireGuard();

Loading…
Cancel
Save