mirror of
https://github.com/ngoduykhanh/wireguard-ui.git
synced 2025-07-07 17:23:14 +03:00
fix private subnets bug
This commit is contained in:
parent
2b7a8d01c7
commit
a89fb34555
5 changed files with 52 additions and 15 deletions
|
@ -157,6 +157,12 @@ func NewClient() echo.HandlerFunc {
|
|||
return c.JSON(http.StatusBadRequest, jsonHTTPResponse{false, "Allowed IPs must be in CIDR format"})
|
||||
}
|
||||
|
||||
// validate the input PrivateSubnets
|
||||
if util.ValidatePrivateSubnets(client.PrivateSubnets) == false {
|
||||
log.Warnf("Invalid Private Subnets input from user: %v", client.PrivateSubnets)
|
||||
return c.JSON(http.StatusBadRequest, jsonHTTPResponse{false, "Private Subnets must be in CIDR format"})
|
||||
}
|
||||
|
||||
// gen ID
|
||||
guid := xid.New()
|
||||
client.ID = guid.String()
|
||||
|
@ -180,6 +186,14 @@ func NewClient() echo.HandlerFunc {
|
|||
client.CreatedAt = time.Now().UTC()
|
||||
client.UpdatedAt = client.CreatedAt
|
||||
|
||||
client.HasPrivateSubnet = false
|
||||
for _, privateSubnet := range client.PrivateSubnets {
|
||||
if privateSubnet != "" {
|
||||
client.HasPrivateSubnet = true
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// write client to the database
|
||||
db.Write("clients", client.ID, client)
|
||||
log.Infof("Created wireguard client: %v", client)
|
||||
|
@ -229,14 +243,28 @@ func UpdateClient() echo.HandlerFunc {
|
|||
return c.JSON(http.StatusBadRequest, jsonHTTPResponse{false, "Allowed IPs must be in CIDR format"})
|
||||
}
|
||||
|
||||
// validate the input PrivateSubnets
|
||||
if util.ValidatePrivateSubnets(_client.PrivateSubnets) == false {
|
||||
log.Warnf("Invalid Private Subnets input from user: %v", _client.PrivateSubnets)
|
||||
return c.JSON(http.StatusBadRequest, jsonHTTPResponse{false, "Private Subnets must be in CIDR format"})
|
||||
}
|
||||
|
||||
// map new data
|
||||
client.Name = _client.Name
|
||||
client.Email = _client.Email
|
||||
client.Enabled = _client.Enabled
|
||||
client.AllocatedIPs = _client.AllocatedIPs
|
||||
client.AllowedIPs = _client.AllowedIPs
|
||||
client.PrivateSubnets = _client.PrivateSubnets
|
||||
client.UpdatedAt = time.Now().UTC()
|
||||
|
||||
client.HasPrivateSubnet = false
|
||||
for _, privateSubnet := range client.PrivateSubnets {
|
||||
if privateSubnet != "" {
|
||||
client.HasPrivateSubnet = true
|
||||
}
|
||||
}
|
||||
|
||||
// write to the database
|
||||
db.Write("clients", client.ID, &client)
|
||||
log.Infof("Updated client information successfully => %v", client)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue