added netmaker check on checkin

This commit is contained in:
afeiszli 2021-08-02 14:41:43 -04:00
parent eb1b79f898
commit 23df004620
2 changed files with 16 additions and 3 deletions

View file

@ -68,7 +68,7 @@ func Insert(key string, value string, tableName string) error {
}
func InsertPeer(key string, value string) error {
if key != "" && value != "" {
if key != "" && value != "" && isJSONString(value) {
_, err := Database.WriteOne("INSERT OR REPLACE INTO " + PEERS_TABLE_NAME + " (key, value) VALUES ('" + key + "', '" + value + "')")
if err != nil {
return err

View file

@ -9,7 +9,8 @@ import (
"net"
"os"
"strconv"
"strings"
"encoding/base64"
"github.com/gravitl/netmaker/database"
"github.com/gravitl/netmaker/functions"
"github.com/gravitl/netmaker/models"
@ -201,7 +202,19 @@ func GetPeers(networkName string) (map[string]string, error) {
return nil, err
}
for _, peer := range device.Peers {
peers[peer.PublicKey.String()] = peer.Endpoint.String()
if isBase64(peer.PublicKey.String()) && checkEndpoint(peer.Endpoint.String()) {
peers[peer.PublicKey.String()] = peer.Endpoint.String()
}
}
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
}