From 4a9dd7c546e1a0e8d6c20e2f124f39e3430511f5 Mon Sep 17 00:00:00 2001 From: Stephane de Labrusse Date: Tue, 8 Oct 2024 16:30:14 +0200 Subject: [PATCH] feat(openvpn): add download all user configurations option (#392) --- public/i18n/en/translation.json | 3 +- .../openvpn_rw/RWAccountsManager.vue | 52 ++++++++++++++++--- 2 files changed, 48 insertions(+), 7 deletions(-) diff --git a/public/i18n/en/translation.json b/public/i18n/en/translation.json index 79a4d63d9..45617d5d2 100644 --- a/public/i18n/en/translation.json +++ b/public/i18n/en/translation.json @@ -1627,7 +1627,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 configurations" }, "openvpn_tunnel": { "title": "OpenVPN tunnel", diff --git a/src/components/standalone/openvpn_rw/RWAccountsManager.vue b/src/components/standalone/openvpn_rw/RWAccountsManager.vue index 64846bd2c..0085cdfb1 100644 --- a/src/components/standalone/openvpn_rw/RWAccountsManager.vue +++ b/src/components/standalone/openvpn_rw/RWAccountsManager.vue @@ -26,6 +26,8 @@ import DeleteRWAccountModal from './DeleteRWAccountModal.vue' import CreateOrEditRWAccountDrawer from './CreateOrEditRWAccountDrawer.vue' import RenewCertificateDrawer from './RenewCertificateDrawer.vue' import { useNotificationsStore } from '@/stores/notifications' +import { downloadFile, deleteFile } from '@/lib/standalone/fileUpload' +import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome' type ConnectionFilter = 'all' | 'connected' | 'not_connected' type ExpirationFilter = 'all' | 'expired' | 'not_expired' @@ -151,6 +153,32 @@ async function downloadCertificate(account: RWAccount) { } } +async function downloadAllConfigurations() { + cleanError() + try { + let res = await ubusCall('ns.ovpnrw', 'download_all_user_configurations', { + instance: props.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() + } +} + async function downloadQrCode(account: RWAccount) { cleanError() try { @@ -285,12 +313,24 @@ function clearFilters() { {{ t('common.clear_filters') }} - - - {{ t('standalone.openvpn_rw.add_vpn_account') }} - +
+ + + {{ t('standalone.openvpn_rw.download_all_configs') }} + + + + {{ t('standalone.openvpn_rw.add_vpn_account') }} + +