Edit wireguard client (#19)

* Add the ability to modify an existing client
* Update client page using Ajax
This commit is contained in:
Khanh Ngo 2020-06-02 11:20:50 +07:00 committed by GitHub
parent 9169e75e88
commit cd7f6e500a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 445 additions and 76 deletions

View file

@ -173,7 +173,7 @@ func GetIPFromCIDR(cidr string) (string, error) {
}
// GetAllocatedIPs to get all ip addresses allocated to clients and server
func GetAllocatedIPs() ([]string, error) {
func GetAllocatedIPs(ignoreClientID string) ([]string, error) {
allocatedIPs := make([]string, 0)
// initialize database directory
@ -211,12 +211,14 @@ func GetAllocatedIPs() ([]string, error) {
return nil, err
}
for _, cidr := range client.AllocatedIPs {
ip, err := GetIPFromCIDR(cidr)
if err != nil {
return nil, err
if client.ID != ignoreClientID {
for _, cidr := range client.AllocatedIPs {
ip, err := GetIPFromCIDR(cidr)
if err != nil {
return nil, err
}
allocatedIPs = append(allocatedIPs, ip)
}
allocatedIPs = append(allocatedIPs, ip)
}
}