mirror of
https://github.com/ngoduykhanh/wireguard-ui.git
synced 2025-06-07 00:46:58 +03:00
add preshared key validator
This commit is contained in:
parent
24d8a4044b
commit
98edcd0d04
1 changed files with 15 additions and 8 deletions
|
@ -187,15 +187,22 @@ func NewClient(db store.IStore) echo.HandlerFunc {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
presharedKey, err := wgtypes.GenerateKey()
|
if client.PresharedKey == "" {
|
||||||
if err != nil {
|
presharedKey, err := wgtypes.GenerateKey()
|
||||||
log.Error("Cannot generated preshared key: ", err)
|
if err != nil {
|
||||||
return c.JSON(http.StatusInternalServerError, jsonHTTPResponse{
|
log.Error("Cannot generated preshared key: ", err)
|
||||||
false, "Cannot generate Wireguard preshared key",
|
return c.JSON(http.StatusInternalServerError, jsonHTTPResponse{
|
||||||
})
|
false, "Cannot generate Wireguard preshared key",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
client.PresharedKey = presharedKey.String()
|
||||||
|
} else {
|
||||||
|
_, err := wgtypes.ParseKey(client.PresharedKey)
|
||||||
|
if err != nil {
|
||||||
|
log.Error("Cannot verify wireguard preshared key: ", err)
|
||||||
|
return c.JSON(http.StatusInternalServerError, jsonHTTPResponse{false, "Cannot verify Wireguard preshared key"})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
client.PresharedKey = presharedKey.String()
|
|
||||||
client.CreatedAt = time.Now().UTC()
|
client.CreatedAt = time.Now().UTC()
|
||||||
client.UpdatedAt = client.CreatedAt
|
client.UpdatedAt = client.CreatedAt
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue