Stuff
This commit is contained in:
parent
c8a240ae35
commit
c6de5b82e9
2 changed files with 43 additions and 3 deletions
|
@ -26,8 +26,6 @@ func DevicesList() ([]Device, error) {
|
|||
return nil, fmt.Errorf("Can't get list of devices: %w", err)
|
||||
}
|
||||
|
||||
fmt.Println(devices)
|
||||
|
||||
var devList []Device
|
||||
|
||||
for _, d := range devices {
|
||||
|
@ -44,7 +42,7 @@ func DevicesList() ([]Device, error) {
|
|||
func DevicesGet(name string) (Device, error) {
|
||||
client, err := wgctrl.New()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Can't create wgctrl Client: %w", err)
|
||||
return Device{}, fmt.Errorf("Can't create wgctrl Client: %w", err)
|
||||
}
|
||||
|
||||
device, err := client.Device(name)
|
||||
|
|
42
peer.go
42
peer.go
|
@ -7,6 +7,46 @@ import (
|
|||
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
|
||||
)
|
||||
|
||||
func RemovePeer(deviceName, PeerPublicKey string) (error) {
|
||||
client, err := wgctrl.New()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Cant create wgctrl: %w", err)
|
||||
}
|
||||
|
||||
pubKey, err := wgtypes.ParseKey(PeerPublicKey)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Cant parse public key: %e", err)
|
||||
}
|
||||
|
||||
peerConfig := wgtypes.PeerConfig{
|
||||
PublicKey: pubKey,
|
||||
Remove: true,
|
||||
UpdateOnly: false,
|
||||
PresharedKey: nil,
|
||||
Endpoint: nil,
|
||||
PersistentKeepaliveInterval: nil,
|
||||
ReplaceAllowedIPs: true,
|
||||
AllowedIPs: nil,
|
||||
}
|
||||
var peerConfigs []wgtypes.PeerConfig
|
||||
peerConfigs = append(peerConfigs, peerConfig)
|
||||
|
||||
config := wgtypes.Config{
|
||||
PrivateKey: nil,
|
||||
ListenPort: nil,
|
||||
FirewallMark: nil,
|
||||
ReplacePeers: true,
|
||||
Peers: peerConfigs,
|
||||
}
|
||||
|
||||
err = client.ConfigureDevice(deviceName, config)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Cant add peer: %e", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func PeerAdd(deviceName string, PeerPublicKey string, PeerPresharedKey string, ipList []net.IPNet, endpoint *net.UDPAddr) (error) {
|
||||
client, err := wgctrl.New()
|
||||
if err != nil {
|
||||
|
@ -37,6 +77,8 @@ func PeerAdd(deviceName string, PeerPublicKey string, PeerPresharedKey string, i
|
|||
ReplaceAllowedIPs: true,
|
||||
AllowedIPs: ipList,
|
||||
}
|
||||
|
||||
fmt.Println(peerConfig)
|
||||
var peerConfigs []wgtypes.PeerConfig
|
||||
peerConfigs = append(peerConfigs, peerConfig)
|
||||
|
||||
|
|
Loading…
Reference in a new issue