mirror of
https://github.com/ngoduykhanh/wireguard-ui.git
synced 2025-05-24 00:24:06 +03:00
Adjustment to have enable/disable client on UI
This commit is contained in:
parent
e52ffaf686
commit
dbb85cb759
6 changed files with 138 additions and 4 deletions
|
@ -139,6 +139,39 @@ func NewClient() echo.HandlerFunc {
|
|||
}
|
||||
}
|
||||
|
||||
// SetClientStatus handler to enable / disable a client
|
||||
func SetClientStatus() echo.HandlerFunc {
|
||||
return func(c echo.Context) error {
|
||||
data := make(map[string]interface{})
|
||||
err := json.NewDecoder(c.Request().Body).Decode(&data)
|
||||
|
||||
if err != nil {
|
||||
return c.JSON(http.StatusBadRequest, jsonHTTPResponse{false, "Bad post data"})
|
||||
}
|
||||
|
||||
clientID := data["id"].(string)
|
||||
status := data["status"].(bool)
|
||||
|
||||
// initialize database directory
|
||||
dir := "./db"
|
||||
db, err := scribble.New(dir, nil)
|
||||
if err != nil {
|
||||
log.Error("Cannot initialize the database: ", err)
|
||||
}
|
||||
|
||||
client := model.Client{}
|
||||
if err := db.Read("clients", clientID, &client); err != nil {
|
||||
log.Error("Cannot fetch server interface config from database: ", err)
|
||||
}
|
||||
|
||||
client.Enabled = status
|
||||
db.Write("clients", clientID, &client)
|
||||
log.Infof("Change client %s to status %b", client.ID, status)
|
||||
|
||||
return c.JSON(http.StatusOK, jsonHTTPResponse{true, "ok"})
|
||||
}
|
||||
}
|
||||
|
||||
// RemoveClient handler
|
||||
func RemoveClient() echo.HandlerFunc {
|
||||
return func(c echo.Context) error {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue