Browse Source

added netmaker check on checkin

afeiszli 4 years ago
parent
commit
4385131bc6
3 changed files with 7 additions and 13 deletions
  1. 1 1
      controllers/common.go
  2. 5 0
      functions/helpers.go
  3. 1 12
      serverctl/wireguard.go

+ 1 - 1
controllers/common.go

@@ -45,7 +45,7 @@ func GetPeersList(networkName string) ([]models.PeersResponse, error) {
 			peer.EgressGatewayRanges = strings.Join(node.EgressGatewayRanges, ",")
 			peer.EgressGatewayRanges = strings.Join(node.EgressGatewayRanges, ",")
 		}
 		}
 		if node.Network == networkName && node.IsPending != "yes" {
 		if node.Network == networkName && node.IsPending != "yes" {
-			if node.UDPHolePunch == "yes" && errN == nil {
+			if node.UDPHolePunch == "yes" && errN == nil && functions.IsBase64(peer.PublicKey) && functions.CheckEndpoint(peer.Endpoint) {
 				endpointstring := udppeers[peer.PublicKey]
 				endpointstring := udppeers[peer.PublicKey]
 				endpointarr := strings.Split(endpointstring, ":")
 				endpointarr := strings.Split(endpointstring, ":")
 				log.Println("got values:",endpointstring,endpointarr)
 				log.Println("got values:",endpointstring,endpointarr)

+ 5 - 0
functions/helpers.go

@@ -20,6 +20,11 @@ import (
 	"github.com/gravitl/netmaker/servercfg"
 	"github.com/gravitl/netmaker/servercfg"
 )
 )
 
 
+func CheckEndpoint(endpoint string) bool {
+    endpointarr := strings.Split(endpoint,":")
+	return net.ParseIP(endpointarr[0]) == nil
+}
+
 func PrintUserLog(username string, message string, loglevel int) {
 func PrintUserLog(username string, message string, loglevel int) {
 	log.SetFlags(log.Flags() &^ (log.Llongfile | log.Lshortfile))
 	log.SetFlags(log.Flags() &^ (log.Llongfile | log.Lshortfile))
 	if int32(loglevel) <= servercfg.GetVerbose() && servercfg.GetVerbose() != 0 {
 	if int32(loglevel) <= servercfg.GetVerbose() && servercfg.GetVerbose() != 0 {

+ 1 - 12
serverctl/wireguard.go

@@ -9,8 +9,6 @@ import (
 	"net"
 	"net"
 	"os"
 	"os"
 	"strconv"
 	"strconv"
-	"strings"
-	"encoding/base64"
 	"github.com/gravitl/netmaker/database"
 	"github.com/gravitl/netmaker/database"
 	"github.com/gravitl/netmaker/functions"
 	"github.com/gravitl/netmaker/functions"
 	"github.com/gravitl/netmaker/models"
 	"github.com/gravitl/netmaker/models"
@@ -202,19 +200,10 @@ func GetPeers(networkName string) (map[string]string, error) {
 		return nil, err
 		return nil, err
 	}
 	}
 	for _, peer := range device.Peers {
 	for _, peer := range device.Peers {
-		if isBase64(peer.PublicKey.String()) && checkEndpoint(peer.Endpoint.String()) {
+		if functions.IsBase64(peer.PublicKey.String()) && functions.CheckEndpoint(peer.Endpoint.String()) {
 			peers[peer.PublicKey.String()] = peer.Endpoint.String()
 			peers[peer.PublicKey.String()] = peer.Endpoint.String()
 		}
 		}
 	}
 	}
 	return peers, nil
 	return peers, nil
 }
 }
 
 
-func checkEndpoint(endpoint string) bool {
-    endpointarr := strings.Split(endpoint,":")
-	return net.ParseIP(endpointarr[0]) == nil
-}
-
-func isBase64(s string) bool {
-	_, err := base64.StdEncoding.DecodeString(s)
-	return err == nil
-}