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 a01fa33
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 7 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 configurations"
},
"openvpn_tunnel": {
"title": "OpenVPN tunnel",
Expand Down
51 changes: 45 additions & 6 deletions src/components/standalone/openvpn_rw/RWAccountsManager.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ 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'

type ConnectionFilter = 'all' | 'connected' | 'not_connected'
type ExpirationFilter = 'all' | 'expired' | 'not_expired'
Expand Down Expand Up @@ -151,6 +152,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 {
Expand Down Expand Up @@ -285,12 +312,24 @@ function clearFilters() {
{{ t('common.clear_filters') }}
</NeButton>
</div>
<NeButton kind="secondary" @click="openCreateEditDrawer()">
<template #prefix>
<font-awesome-icon :icon="['fas', 'circle-plus']" class="h-4 w-4" aria-hidden="true" />
</template>
{{ t('standalone.openvpn_rw.add_vpn_account') }}
</NeButton>
<div class="flex flex-row gap-x-3">
<NeButton kind="tertiary" @click="downloadAllConfigurations()">
<template #prefix>
<font-awesome-icon
:icon="['fas', 'fa-circle-arrow-down']"
class="h-4 w-4"
aria-hidden="true"
/>
</template>
{{ t('standalone.openvpn_rw.download_all_configs') }}
</NeButton>
<NeButton kind="secondary" @click="openCreateEditDrawer()">
<template #prefix>
<font-awesome-icon :icon="['fas', 'circle-plus']" class="h-4 w-4" aria-hidden="true" />
</template>
{{ t('standalone.openvpn_rw.add_vpn_account') }}
</NeButton>
</div>
</div>
<RWAccountsTable
v-if="filteredUsers.length > 0"
Expand Down

0 comments on commit a01fa33

Please sign in to comment.