Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to download all user configurations in OpenVPN #392

Merged
merged 2 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
52 changes: 46 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,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'
stephdl marked this conversation as resolved.
Show resolved Hide resolved
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome'

type ConnectionFilter = 'all' | 'connected' | 'not_connected'
type ExpirationFilter = 'all' | 'expired' | 'not_expired'
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -285,12 +313,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