From efbb166e5125317d63970d4672063a681fce3412 Mon Sep 17 00:00:00 2001 From: Matthew R Kasun Date: Wed, 19 Jan 2022 15:12:09 -0500 Subject: [PATCH] fix UpdateWgPeers to enable multiple peer sections --- netclient/wireguard/common.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/netclient/wireguard/common.go b/netclient/wireguard/common.go index 94742eb9..9e3c6dc7 100644 --- a/netclient/wireguard/common.go +++ b/netclient/wireguard/common.go @@ -339,15 +339,20 @@ func WriteWgConfig(cfg config.ClientConfig, privateKey string, peers []wgtypes.P // UpdateWgPeers - updates the peers of a network func UpdateWgPeers(wgInterface string, peers []wgtypes.PeerConfig) error { + options := ini.LoadOptions{ + AllowNonUniqueSections: true, + AllowShadows: true, + } file := ncutils.GetNetclientPathSpecific() + wgInterface + ".conf" ncutils.Log("updating " + file) - wireguard, err := ini.ShadowLoad(file) + wireguard, err := ini.LoadSources(options, file) if err != nil { return err } //delete the peers sections as they are going to be replaced wireguard.DeleteSection(section_peers) for i, peer := range peers { + ncutils.Log("adding peer section for peer #: " + string(i) + peer.PublicKey.String()) wireguard.SectionWithIndex(section_peers, i).Key("PublicKey").SetValue(peer.PublicKey.String()) //if peer.PresharedKey.String() != "" { //wireguard.SectionWithIndex(section_peers, i).Key("PreSharedKey").SetValue(peer.PresharedKey.String())