Skip to content

Commit

Permalink
feat(openvpn): add download all user configurations option
Browse files Browse the repository at this point in the history
  • Loading branch information
stephdl committed Oct 8, 2024
1 parent c4673b2 commit 0ef075b
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 2 deletions.
3 changes: 2 additions & 1 deletion public/i18n/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
60 changes: 59 additions & 1 deletion src/components/standalone/openvpn_rw/RWServerDetails.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
</script>

<template>
Expand Down Expand Up @@ -92,6 +141,15 @@ const emit = defineEmits(['delete-server', 'edit-server'])
action: () => {
emit('delete-server')
}
},
{
id: 'download_all_configs',
label: t('standalone.openvpn_rw.download_all_configs'),
iconStyle: 'fas',
icon: 'fa-circle-arrow-down',
action: () => {
downloadAllConfiguration(instanceName)
}
}
]"
:align-to-right="true"
Expand Down
1 change: 1 addition & 0 deletions src/views/standalone/vpn/OpenvpnRoadWarriorView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ onUnmounted(() => {
v-else
:connected-clients="connectedClients"
:server="instanceData"
:instance-name="instanceName"
@delete-server="showDeleteServerModal = true"
@edit-server="showCreateOrEditServerModal = true"
/>
Expand Down

0 comments on commit 0ef075b

Please sign in to comment.