Commit 4e12f34a authored by Johannes Zellner's avatar Johannes Zellner

Add ipv4 validation

parent 225bde7e
......@@ -29,11 +29,14 @@
</header>
<el-dialog title="Settings" :visible.sync="settings.visible" width="30%">
<el-form ref="form" :model="settings.data" label-position="left" label-width="120px" size="small">
<el-form-item label="Network Address">
<el-input v-model="settings.data.networkAddress"></el-input>
<el-form ref="form" :model="settings.data" :rules="settings.rules" label-position="left" label-width="120px" size="small">
<el-form-item label="Network Address" prop="address">
<el-input v-model="settings.data.address"></el-input>
</el-form-item>
<el-form-item label="DNS Server">
<el-form-item label="Netmask" prop="netmask">
<el-input v-model="settings.data.netmask"></el-input>
</el-form-item>
<el-form-item label="DNS Server" prop="dnsServer">
<el-input v-model="settings.data.dnsServer"></el-input>
</el-form-item>
<el-form-item label="">
......
......@@ -6,18 +6,42 @@
ELEMENT.locale(ELEMENT.lang.en);
function ipv4Validator(rule, value, callback) {
if (value.match(/^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/)) callback();
else callback(new Error('Must be a valid IPv4 address'));
}
window.app = new Vue({
el: '#app',
data: {
busy: true,
entries: [],
user: null,
loginForm: {username: '', password: ''},
loginForm: { username: '', password: '' },
connectedClients: {},
settings: {
busy: false,
visible: false,
data: {}
data: {
address: '',
netmask: '',
dnsServer: '',
allowICC: false
},
rules: {
address: [{
validator: ipv4Validator,
trigger: 'change'
}],
netmask: [{
validator: ipv4Validator,
trigger: 'change'
}],
dnsServer: [{
validator: ipv4Validator,
trigger: 'change'
}]
}
}
},
computed: {
......
......@@ -72,7 +72,8 @@ function getOpenVPNSetting() {
return tmp[idx].slice(prefix.length).trim().replace(/["]+$/g, '')
}
settings.networkAddress = findItem('server')
settings.address = findItem('server').split(' ')[0];
settings.netmask = findItem('server').split(' ')[1];
settings.dnsServer = findItem('push "dhcp-option DNS')
settings.allowICC = findItem('client-to-client') !== null
......@@ -98,9 +99,9 @@ function setOpenVPNSetting(settings) {
if (idx === -1) tmp.push(value)
else tmp[idx] = value
// networkAddress
// server
idx = tmp.findIndex((l) => { return l.indexOf('server ') !== -1 })
value = `server ${settings.networkAddress}`
value = `server ${settings.address} ${settings.netmask}`
if (idx === -1) tmp.push(value)
else tmp[idx] = value
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment