From 0ef075b922179a48cd15816102c9ee325fb74001 Mon Sep 17 00:00:00 2001 From: Stephane de Labrusse Date: Tue, 8 Oct 2024 12:46:53 +0200 Subject: [PATCH] feat(openvpn): add download all user configurations option --- public/i18n/en/translation.json | 3 +- .../standalone/openvpn_rw/RWServerDetails.vue | 60 ++++++++++++++++++- .../standalone/vpn/OpenvpnRoadWarriorView.vue | 1 + 3 files changed, 62 insertions(+), 2 deletions(-) diff --git a/public/i18n/en/translation.json b/public/i18n/en/translation.json index 7799b00f8..a6e1f27f3 100644 --- a/public/i18n/en/translation.json +++ b/public/i18n/en/translation.json @@ -1624,7 +1624,8 @@ "dynamic_range_ip": "Dynamic range IP", "dynamic_range_ip_message": "You can reserve IP addresses to OpenVPN accounts outside the following range.", "dynamic_range_ip_start": "Dynamic range IP start", - "dynamic_range_ip_end": "Dynamic range IP end" + "dynamic_range_ip_end": "Dynamic range IP end", + "download_all_configs": "Download all user configurations" }, "openvpn_tunnel": { "title": "OpenVPN tunnel", diff --git a/src/components/standalone/openvpn_rw/RWServerDetails.vue b/src/components/standalone/openvpn_rw/RWServerDetails.vue index 50e933330..93ba83ca4 100644 --- a/src/components/standalone/openvpn_rw/RWServerDetails.vue +++ b/src/components/standalone/openvpn_rw/RWServerDetails.vue @@ -7,16 +7,65 @@ import { useI18n } from 'vue-i18n' import { NeDropdown } from '@nethesis/vue-components' import { NeButton } from '@nethesis/vue-components' +import { getAxiosErrorMessage } from '@nethesis/vue-components' import type { RWServer } from '@/views/standalone/vpn/OpenvpnRoadWarriorView.vue' - +import { ubusCall } from '@/lib/standalone/ubus' +import { ref } from 'vue' +import { downloadFile } from '@/lib/standalone/fileUpload' +import { deleteFile } from '@/lib/standalone/fileUpload' const { t } = useI18n() defineProps<{ server: RWServer connectedClients: number + instanceName: string }>() +const error = ref({ + notificationTitle: '', + notificationDescription: '', + notificationDetails: '' +}) + +const loadingDownload = ref(false) const emit = defineEmits(['delete-server', 'edit-server']) + +function cleanError() { + error.value = { + notificationTitle: '', + notificationDescription: '', + notificationDetails: '' + } +} + +async function downloadAllConfiguration(instanceName: string) { + cleanError() + try { + loadingDownload.value = true + let res = await ubusCall('ns.ovpnrw', 'download_all_user_configurations', { + instance: instanceName + }) + if (res?.data?.archive_path) { + //remove prefix /var/run/ns-api-server/downloads/ + res.data.archive_path = res.data.archive_path.replace('/var/run/ns-api-server/downloads/', '') + const file = await downloadFile(res.data.archive_path) + const fileURL = URL.createObjectURL(file) + let link = document.createElement('a') + link.href = fileURL + link.download = + res.data.archive_path.replace('.tar.gz', '') + '-' + Date.now().toString() + '.tar.gz' + link.click() + + await deleteFile(res.data.archive_path) + } + } catch (exception: any) { + error.value.notificationTitle = t('standalone.openvpn_rw.cannot_download_configuration') + error.value.notificationDescription = t(getAxiosErrorMessage(exception)) + error.value.notificationDetails = exception.toString() + } finally { + loadingDownload.value = false + } +}