mirror of
https://github.com/vx3r/wg-gen-web.git
synced 2024-11-23 02:42:07 +01:00
Merge pull request #34 from sphen13/client_allowed_ips
default client allowed ips in server config
This commit is contained in:
commit
9e4b22d0ef
@ -36,6 +36,10 @@ func ReadServer() (*model.Server, error) {
|
|||||||
server.Dns = append(server.Dns, "fd9f::10:0:0:2")
|
server.Dns = append(server.Dns, "fd9f::10:0:0:2")
|
||||||
server.Dns = append(server.Dns, "10.0.0.2")
|
server.Dns = append(server.Dns, "10.0.0.2")
|
||||||
|
|
||||||
|
server.AllowedIPs = make([]string, 0)
|
||||||
|
server.AllowedIPs = append(server.AllowedIPs, "0.0.0.0/0")
|
||||||
|
server.AllowedIPs = append(server.AllowedIPs, "::/0")
|
||||||
|
|
||||||
server.PersistentKeepalive = 16
|
server.PersistentKeepalive = 16
|
||||||
server.Mtu = 0
|
server.Mtu = 0
|
||||||
server.PreUp = "echo WireGuard PreUp"
|
server.PreUp = "echo WireGuard PreUp"
|
||||||
|
@ -16,6 +16,7 @@ type Server struct {
|
|||||||
Endpoint string `json:"endpoint"`
|
Endpoint string `json:"endpoint"`
|
||||||
PersistentKeepalive int `json:"persistentKeepalive"`
|
PersistentKeepalive int `json:"persistentKeepalive"`
|
||||||
Dns []string `json:"dns"`
|
Dns []string `json:"dns"`
|
||||||
|
AllowedIPs []string `json:"allowedips"`
|
||||||
PreUp string `json:"preUp"`
|
PreUp string `json:"preUp"`
|
||||||
PostUp string `json:"postUp"`
|
PostUp string `json:"postUp"`
|
||||||
PreDown string `json:"preDown"`
|
PreDown string `json:"preDown"`
|
||||||
@ -59,6 +60,12 @@ func (a Server) IsValid() []error {
|
|||||||
errs = append(errs, fmt.Errorf("dns %s is invalid", dns))
|
errs = append(errs, fmt.Errorf("dns %s is invalid", dns))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// check if the allowedIPs are valid
|
||||||
|
for _, allowedIP := range a.AllowedIPs {
|
||||||
|
if !util.IsValidCidr(allowedIP) {
|
||||||
|
errs = append(errs, fmt.Errorf("allowedIP %s is invalid", allowedIP))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return errs
|
return errs
|
||||||
}
|
}
|
||||||
|
@ -382,7 +382,7 @@
|
|||||||
name: "",
|
name: "",
|
||||||
email: "",
|
email: "",
|
||||||
enable: true,
|
enable: true,
|
||||||
allowedIPs: ["0.0.0.0/0", "::/0"],
|
allowedIPs: this.server.allowedips,
|
||||||
address: this.server.address,
|
address: this.server.address,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -85,6 +85,26 @@
|
|||||||
</v-chip>
|
</v-chip>
|
||||||
</template>
|
</template>
|
||||||
</v-combobox>
|
</v-combobox>
|
||||||
|
<v-combobox
|
||||||
|
v-model="server.allowedips"
|
||||||
|
chips
|
||||||
|
hint="Write IPv4 or IPv6 address and hit enter"
|
||||||
|
label="Default Allowed IPs for clients"
|
||||||
|
multiple
|
||||||
|
dark
|
||||||
|
>
|
||||||
|
<template v-slot:selection="{ attrs, item, select, selected }">
|
||||||
|
<v-chip
|
||||||
|
v-bind="attrs"
|
||||||
|
:input-value="selected"
|
||||||
|
close
|
||||||
|
@click="select"
|
||||||
|
@click:close="server.allowedips.splice(server.allowedips.indexOf(item), 1)"
|
||||||
|
>
|
||||||
|
<strong>{{ item }}</strong>
|
||||||
|
</v-chip>
|
||||||
|
</template>
|
||||||
|
</v-combobox>
|
||||||
<v-text-field
|
<v-text-field
|
||||||
type="number"
|
type="number"
|
||||||
v-model="server.mtu"
|
v-model="server.mtu"
|
||||||
@ -218,6 +238,18 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// check client AllowedIPs
|
||||||
|
if (this.server.allowedips.length < 1) {
|
||||||
|
this.notify('error', 'Please provide at least one valid CIDR address for client allowed IPs');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (let i = 0; i < this.server.allowedips.length; i++){
|
||||||
|
if (this.$isCidr(this.server.allowedips[i]) === 0) {
|
||||||
|
this.notify('error', 'Invalid CIDR detected, please correct before submitting');
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
this.api.patch('/server', this.server).then((res) => {
|
this.api.patch('/server', this.server).then((res) => {
|
||||||
this.notify('success', "Server successfully updated");
|
this.notify('success', "Server successfully updated");
|
||||||
this.server = res;
|
this.server = res;
|
||||||
|
Loading…
Reference in New Issue
Block a user