This commit is contained in:
Kekskurse 2021-06-01 18:00:09 +02:00
parent c8a240ae35
commit c6de5b82e9
Signed by: kekskurse
GPG Key ID: 728ACCB59341E7E4
2 changed files with 43 additions and 3 deletions

View File

@ -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
View File

@ -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)