mirror of
https://github.com/ngoduykhanh/wireguard-ui.git
synced 2025-07-24 19:52:56 +03:00
Full implementation of subnet ranges for a new client, fixes
fix: free ip search was stopping after no free ip on the first interface fix: toast obstructing the buttons fix: stuck apply config button
This commit is contained in:
parent
92333a08d8
commit
53eaab0079
5 changed files with 134 additions and 16 deletions
|
@ -988,6 +988,13 @@ func MachineIPAddresses() echo.HandlerFunc {
|
|||
}
|
||||
}
|
||||
|
||||
// GetOrderedSubnetRanges handler to get the ordered list of subnet ranges
|
||||
func GetOrderedSubnetRanges() echo.HandlerFunc {
|
||||
return func(c echo.Context) error {
|
||||
return c.JSON(http.StatusOK, util.SubnetRangesOrder)
|
||||
}
|
||||
}
|
||||
|
||||
// SuggestIPAllocation handler to get the list of ip address for client
|
||||
func SuggestIPAllocation(db store.IStore) echo.HandlerFunc {
|
||||
return func(c echo.Context) error {
|
||||
|
@ -1009,15 +1016,27 @@ func SuggestIPAllocation(db store.IStore) echo.HandlerFunc {
|
|||
false, "Cannot suggest ip allocation: failed to get list of allocated ip addresses",
|
||||
})
|
||||
}
|
||||
for _, cidr := range server.Interface.Addresses {
|
||||
ip, err := util.GetAvailableIP(cidr, allocatedIPs)
|
||||
|
||||
sr := c.QueryParam("sr")
|
||||
searchCIDRList := make([]string, 0)
|
||||
found := false
|
||||
|
||||
// Use subnet range or default to interface addresses
|
||||
if util.SubnetRanges[sr] != nil {
|
||||
for _, cidr := range util.SubnetRanges[sr] {
|
||||
searchCIDRList = append(searchCIDRList, cidr.String())
|
||||
}
|
||||
} else {
|
||||
searchCIDRList = append(searchCIDRList, server.Interface.Addresses...)
|
||||
}
|
||||
|
||||
for _, cidr := range searchCIDRList {
|
||||
ip, err := util.GetAvailableIP(cidr, allocatedIPs, server.Interface.Addresses)
|
||||
if err != nil {
|
||||
log.Error("Failed to get available ip from a CIDR: ", err)
|
||||
return c.JSON(http.StatusInternalServerError, jsonHTTPResponse{
|
||||
false,
|
||||
fmt.Sprintf("Cannot suggest ip allocation: failed to get available ip from network %s", cidr),
|
||||
})
|
||||
continue
|
||||
}
|
||||
found = true
|
||||
if strings.Contains(ip, ":") {
|
||||
suggestedIPs = append(suggestedIPs, fmt.Sprintf("%s/128", ip))
|
||||
} else {
|
||||
|
@ -1025,6 +1044,13 @@ func SuggestIPAllocation(db store.IStore) echo.HandlerFunc {
|
|||
}
|
||||
}
|
||||
|
||||
if !found {
|
||||
return c.JSON(http.StatusInternalServerError, jsonHTTPResponse{
|
||||
false,
|
||||
"Cannot suggest ip allocation: failed to get available ip. Try a different subnet or deallocate some ips.",
|
||||
})
|
||||
}
|
||||
|
||||
return c.JSON(http.StatusOK, suggestedIPs)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue