mirror of
https://github.com/h44z/wg-portal
synced 2025-02-26 05:49:14 +00:00
wip: update cfg file
This commit is contained in:
parent
c5cb22829d
commit
556d7bff4b
@ -4,6 +4,8 @@ import (
|
|||||||
"crypto/md5"
|
"crypto/md5"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/h44z/wg-portal/internal/common"
|
"github.com/h44z/wg-portal/internal/common"
|
||||||
@ -123,7 +125,7 @@ func (s *Server) CreateUser(user User) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return s.WriteWireGuardConfigFile()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) UpdateUser(user User, updateTime time.Time) error {
|
func (s *Server) UpdateUser(user User, updateTime time.Time) error {
|
||||||
@ -148,7 +150,7 @@ func (s *Server) UpdateUser(user User, updateTime time.Time) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return s.WriteWireGuardConfigFile()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) DeleteUser(user User) error {
|
func (s *Server) DeleteUser(user User) error {
|
||||||
@ -162,7 +164,7 @@ func (s *Server) DeleteUser(user User) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return s.WriteWireGuardConfigFile()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) RestoreWireGuardInterface() error {
|
func (s *Server) RestoreWireGuardInterface() error {
|
||||||
@ -178,3 +180,22 @@ func (s *Server) RestoreWireGuardInterface() error {
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Server) WriteWireGuardConfigFile() error {
|
||||||
|
if s.config.WG.WireGuardConfig == "" {
|
||||||
|
return nil // writing disabled
|
||||||
|
}
|
||||||
|
if err := syscall.Access(s.config.WG.WireGuardConfig, syscall.O_RDWR); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
device := s.users.GetDevice()
|
||||||
|
cfg, err := device.GetDeviceConfigFile(s.users.GetActiveUsers())
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := ioutil.WriteFile(s.config.WG.WireGuardConfig, cfg, 0644); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package wireguard
|
package wireguard
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
DeviceName string `yaml:"device" envconfig:"WG_DEVICE"`
|
DeviceName string `yaml:"device" envconfig:"WG_DEVICE"`
|
||||||
|
WireGuardConfig string `yaml:"configFile" envconfig:"WG_CONFIG_FILE"` // optional, if set, updates will be written to this file
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user