mirror of
https://github.com/Threnklyn/wg-ui.git
synced 2026-06-03 20:28:28 +02:00
Implemented deleting a device
This commit is contained in:
@@ -256,6 +256,7 @@ func (s *Server) Start() error {
|
|||||||
router := httprouter.New()
|
router := httprouter.New()
|
||||||
router.GET("/", s.Index)
|
router.GET("/", s.Index)
|
||||||
router.GET("/api/v1/users/:user/devices/:device", s.withAuth(s.GetDevice))
|
router.GET("/api/v1/users/:user/devices/:device", s.withAuth(s.GetDevice))
|
||||||
|
router.DELETE("/api/v1/users/:user/devices/:device", s.withAuth(s.DeleteDevice))
|
||||||
router.GET("/api/v1/users/:user/devices", s.withAuth(s.GetDevices))
|
router.GET("/api/v1/users/:user/devices", s.withAuth(s.GetDevices))
|
||||||
router.POST("/api/v1/users/:user/devices", s.withAuth(s.CreateDevice))
|
router.POST("/api/v1/users/:user/devices", s.withAuth(s.CreateDevice))
|
||||||
|
|
||||||
@@ -366,15 +367,28 @@ func (s *Server) DeleteDevice(w http.ResponseWriter, r *http.Request, ps httprou
|
|||||||
}
|
}
|
||||||
|
|
||||||
device := ps.ByName("device")
|
device := ps.ByName("device")
|
||||||
|
if usercfg.Devices[device] == nil {
|
||||||
|
w.WriteHeader(http.StatusNotFound)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
delete(usercfg.Devices, device)
|
delete(usercfg.Devices, device)
|
||||||
|
|
||||||
err := s.configureWireguard()
|
err := s.Config.Write()
|
||||||
|
if err != nil {
|
||||||
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
err = s.configureWireguard()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(err)
|
log.Error(err)
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.WithField("user", user).Debug("Deleted device: ", device)
|
||||||
|
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -423,5 +437,4 @@ func (s *Server) CreateDevice(w http.ResponseWriter, r *http.Request, ps httprou
|
|||||||
w.WriteHeader(http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user