Browse Source

fix UpdateWgPeers to enable multiple peer sections

Matthew R Kasun 3 years ago
parent
commit
56a5a928ab
1 changed files with 6 additions and 1 deletions
  1. 6 1
      netclient/wireguard/common.go

+ 6 - 1
netclient/wireguard/common.go

@@ -348,15 +348,20 @@ func WriteWgConfig(cfg config.ClientConfig, privateKey string, peers []wgtypes.P
 
 
 // UpdateWgPeers - updates the peers of a network
 // UpdateWgPeers - updates the peers of a network
 func UpdateWgPeers(wgInterface string, peers []wgtypes.PeerConfig) error {
 func UpdateWgPeers(wgInterface string, peers []wgtypes.PeerConfig) error {
+	options := ini.LoadOptions{
+		AllowNonUniqueSections: true,
+		AllowShadows:           true,
+	}
 	file := ncutils.GetNetclientPathSpecific() + wgInterface + ".conf"
 	file := ncutils.GetNetclientPathSpecific() + wgInterface + ".conf"
 	ncutils.Log("updating " + file)
 	ncutils.Log("updating " + file)
-	wireguard, err := ini.ShadowLoad(file)
+	wireguard, err := ini.LoadSources(options, file)
 	if err != nil {
 	if err != nil {
 		return err
 		return err
 	}
 	}
 	//delete the peers sections as they are going to be replaced
 	//delete the peers sections as they are going to be replaced
 	wireguard.DeleteSection(section_peers)
 	wireguard.DeleteSection(section_peers)
 	for i, peer := range 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())
 		wireguard.SectionWithIndex(section_peers, i).Key("PublicKey").SetValue(peer.PublicKey.String())
 		//if peer.PresharedKey.String() != "" {
 		//if peer.PresharedKey.String() != "" {
 		//wireguard.SectionWithIndex(section_peers, i).Key("PreSharedKey").SetValue(peer.PresharedKey.String())
 		//wireguard.SectionWithIndex(section_peers, i).Key("PreSharedKey").SetValue(peer.PresharedKey.String())