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

fix(openvpn): adding server-side validation #420

Merged
merged 1 commit into from
Nov 4, 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
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ import { NeToggle } from '@nethesis/vue-components'
import { useI18n } from 'vue-i18n'
import type { ServerTunnel, ClientTunnel } from './TunnelManager.vue'
import NeMultiTextInput from '../NeMultiTextInput.vue'
import { ubusCall } from '@/lib/standalone/ubus'
import { ubusCall, ValidationError } from '@/lib/standalone/ubus'
import { AxiosError } from 'axios'

type TunnelDefaults = {
secret: string
Expand Down Expand Up @@ -564,12 +565,16 @@ async function createOrEditTunnel() {
close()
}
} catch (err: any) {
error.value.notificationTitle = isEditing
? t('error.cannot_edit_tunnel')
: t('error.cannot_create_tunnel')
if (err instanceof ValidationError) {
validationErrorBag.value = err.errorBag
} else {
error.value.notificationTitle = isEditing
? t('error.cannot_edit_tunnel')
: t('error.cannot_create_tunnel')

error.value.notificationDescription = t(getAxiosErrorMessage(err))
error.value.notificationDetails = err.toString()
error.value.notificationDescription = t(getAxiosErrorMessage(err))
error.value.notificationDetails = err.toString()
}
} finally {
isSavingChanges.value = false
}
Expand Down Expand Up @@ -658,7 +663,7 @@ watch(
v-model="name"
:disabled="id != ''"
:label="t('standalone.openvpn_tunnel.tunnel_name')"
:invalid-message="validationErrorBag.getFirstFor('name')"
:invalid-message="t(validationErrorBag.getFirstI18nKeyFor('ns_name'))"
/>
<template v-if="!isClientTunnel">
<NeMultiTextInput
Expand Down
3 changes: 2 additions & 1 deletion src/i18n/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,8 @@
"cannot_retrieve_connected_client_by_hour": "Cannot retrieve connected clients by hour",
"cannot_retrieve_client_traffic_by_hour": "Cannot retrieve client traffic by hour",
"cannot_retrieve_talkers_list": "Cannot retrieve talkers list",
"invalid_number": "Invalid number"
"invalid_number": "Invalid number",
"network_conflict": "This name is already in use by another network interface"
},
"ne_text_input": {
"show_password": "Show password",
Expand Down