mirror of
https://github.com/Threnklyn/wg-ui.git
synced 2026-06-07 14:03:33 +02:00
Refactor server reconfiguration
This commit is contained in:
@@ -196,6 +196,20 @@ func (s *Server) allocateIP() net.IP {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Server) reconfigure() {
|
||||||
|
log.Debug("Reconfiguring")
|
||||||
|
|
||||||
|
err := s.Config.Write()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
err = s.configureWireguard()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (s *Server) configureWireguard() error {
|
func (s *Server) configureWireguard() error {
|
||||||
log.Debugf("Reconfiguring wireguard interface %s", *wgLinkName)
|
log.Debugf("Reconfiguring wireguard interface %s", *wgLinkName)
|
||||||
wg, err := wireguardctrl.New()
|
wg, err := wireguardctrl.New()
|
||||||
@@ -373,19 +387,7 @@ func (s *Server) DeleteDevice(w http.ResponseWriter, r *http.Request, ps httprou
|
|||||||
}
|
}
|
||||||
|
|
||||||
delete(usercfg.Devices, device)
|
delete(usercfg.Devices, device)
|
||||||
|
s.reconfigure()
|
||||||
err := s.Config.Write()
|
|
||||||
if err != nil {
|
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
err = s.configureWireguard()
|
|
||||||
if err != nil {
|
|
||||||
log.Error(err)
|
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
log.WithField("user", user).Debug("Deleted device: ", device)
|
log.WithField("user", user).Debug("Deleted device: ", device)
|
||||||
|
|
||||||
@@ -419,19 +421,10 @@ func (s *Server) CreateDevice(w http.ResponseWriter, r *http.Request, ps httprou
|
|||||||
ip := s.allocateIP()
|
ip := s.allocateIP()
|
||||||
device := NewDeviceConfig(ip)
|
device := NewDeviceConfig(ip)
|
||||||
c.Devices[strconv.Itoa(i)] = device
|
c.Devices[strconv.Itoa(i)] = device
|
||||||
err := s.Config.Write()
|
|
||||||
if err != nil {
|
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
err = s.configureWireguard()
|
s.reconfigure()
|
||||||
if err != nil {
|
|
||||||
log.Error(err)
|
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
|
||||||
}
|
|
||||||
|
|
||||||
err = json.NewEncoder(w).Encode(device)
|
err := json.NewEncoder(w).Encode(device)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(err)
|
log.Error(err)
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
|||||||
Reference in New Issue
Block a user