Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
22 changes: 22 additions & 0 deletions ui/src/utils/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,25 @@ export function toCsv ({ keys = null, data = null, columnDelimiter = ',', lineDe

return result
}

export function isValidIPv4Cidr (rule, value) {
console.log('here')
return new Promise((resolve, reject) => {
if (!value) {
reject(new Error('Required input'))
return
}
const cidrRegex = /^(\d{1,3}\.){3}\d{1,3}\/([0-9]|[1-2][0-9]|3[0-2])$/
if (!cidrRegex.test(value)) {
reject(new Error('Invalid CIDR format'))
return
}
const ip = value.split('/')[0]
const octets = ip.split('.').map(Number)
if (octets.some(octet => octet < 0 || octet > 255)) {
reject(new Error('Invalid CIDR format'))
return
}
resolve()
})
}
4 changes: 3 additions & 1 deletion ui/src/views/network/CreateVpc.vue
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@
import { ref, reactive, toRaw } from 'vue'
import { getAPI, postAPI } from '@/api'
import { isAdmin, isAdminOrDomainAdmin } from '@/role'
import { isValidIPv4Cidr } from '@/utils/util.js'
import ResourceIcon from '@/components/view/ResourceIcon'
import TooltipLabel from '@/components/widgets/TooltipLabel'
import OwnershipSelection from '@/views/compute/wizard/OwnershipSelection.vue'
Expand Down Expand Up @@ -291,6 +292,7 @@ export default {
this.rules = reactive({
name: [{ required: true, message: this.$t('message.error.required.input') }],
zoneid: [{ required: true, message: this.$t('label.required') }],
cidr: [{ validator: isValidIPv4Cidr }],
vpcofferingid: [{ required: true, message: this.$t('label.required') }]
})
},
Expand Down Expand Up @@ -417,7 +419,7 @@ export default {
},
updateCidrRule () {
if (!this.selectedVpcOfferingHavingRoutedNetworkMode) {
this.rules.cidr = [{ required: true, message: this.$t('message.error.required.input') }]
this.rules.cidr = [{ validator: isValidIPv4Cidr }]
} else {
delete this.rules.cidr
}
Expand Down
Loading