Browse Source

hotfixes for repo. Now works.

afeiszli 4 years ago
parent
commit
e489a18492

BIN
controllers/.nodeHttpController.go.swp


+ 3 - 2
controllers/authGrpc.go

@@ -79,7 +79,8 @@ func grpcAuthorize(ctx context.Context) error {
                 groupexists, err := functions.GroupExists(group)
 
 		if err != nil {
-			return err
+			return status.Errorf(codes.Unauthenticated, "Unauthorized. Group does not exist: " + group)
+
 		}
 		emptynode := models.Node{}
 		node, err := functions.GetNodeByMacAddress(group, mac)
@@ -122,7 +123,7 @@ func (s *NodeServiceServer) Login(ctx context.Context, req *nodepb.LoginRequest)
             //Search DB for node with Mac Address. Ignore pending nodes (they should not be able to authenticate with API untill approved).
             collection := mongoconn.Client.Database("wirecat").Collection("nodes")
             ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
-            var err = collection.FindOne(ctx, bson.M{ "macaddress": macaddress, "ispending": false }).Decode(&result)
+            var err = collection.FindOne(ctx, bson.M{ "macaddress": macaddress}).Decode(&result)
 
             defer cancel()
 

+ 1 - 3
controllers/common.go

@@ -1,7 +1,6 @@
 package controller
 
 import (
-//    "github.com/davecgh/go-spew/spew"
     "gopkg.in/go-playground/validator.v9"
     "log"
     "fmt"
@@ -345,7 +344,6 @@ func CreateNode(node models.Node, groupName string) (models.Node, error) {
 
 func NodeCheckIn(node models.Node, groupName string) (models.CheckInResponse, error) {
 
-
 	var response models.CheckInResponse
 
 	parentgroup, err := functions.GetParentGroup(groupName)
@@ -360,6 +358,7 @@ func NodeCheckIn(node models.Node, groupName string) (models.CheckInResponse, er
                 return response, err
         }
 	if parentnode.IsPending {
+                err = fmt.Errorf("%w; Node checking in is still pending: " + node.MacAddress, err)
 		response.IsPending = true
 		return response, err
 	}
@@ -377,7 +376,6 @@ func NodeCheckIn(node models.Node, groupName string) (models.CheckInResponse, er
 	if parentnodelm < grouplm {
 		response.NeedConfigUpdate = true
 	}
-
 	if peerlistlm < peerslm {
 		response.NeedPeerUpdate = true
 	}

+ 5 - 10
controllers/nodeGrpcController.go

@@ -1,17 +1,11 @@
 package controller
 
 import (
-//        "github.com/davecgh/go-spew/spew"
-	"context"
+        "context"
 	"fmt"
-//	"errors"
-//	"time"
-//	"go.mongodb.org/mongo-driver/bson"
-//	"golang.org/x/crypto/bcrypt"
 	nodepb "github.com/gravitl/netmaker/grpc"
 	"github.com/gravitl/netmaker/models"
 	"github.com/gravitl/netmaker/functions"
-//	"github.com/gravitl/netmaker/mongoconn"
 	"go.mongodb.org/mongo-driver/mongo"
 	"google.golang.org/grpc/codes"
 	"google.golang.org/grpc/status"
@@ -145,7 +139,7 @@ func (s *NodeServiceServer) CreateNode(ctx context.Context, req *nodepb.CreateNo
 func (s *NodeServiceServer) CheckIn(ctx context.Context, req *nodepb.CheckInReq) (*nodepb.CheckInRes, error) {
 	// Get the protobuf node type from the protobuf request type
         // Essentially doing req.Node to access the struct with a nil check
-        data := req.GetNode()
+	data := req.GetNode()
 	//postchanges := req.GetPostchanges()
 	// Now we have to convert this into a NodeItem type to convert into BSON
         node := models.Node{
@@ -164,12 +158,13 @@ func (s *NodeServiceServer) CheckIn(ctx context.Context, req *nodepb.CheckInReq)
 	checkinresponse, err := NodeCheckIn(node, node.Group)
 
         if err != nil {
-		err = fmt.Errorf("%w; Couldnt Check in", err)
                 // return internal gRPC error to be handled later
+		if checkinresponse == (models.CheckInResponse{}) || !checkinresponse.IsPending {
                 return nil, status.Errorf(
                         codes.Internal,
                         fmt.Sprintf("Internal error: %v", err),
                 )
+		}
         }
         // return the node in a CreateNodeRes type
         response := &nodepb.CheckInRes{
@@ -268,7 +263,7 @@ func (s *NodeServiceServer) DeleteNode(ctx context.Context, req *nodepb.DeleteNo
 		return nil, status.Errorf(codes.NotFound, fmt.Sprintf("Could not find/delete node with mac address %s", macaddress))
 	}
 
-	fmt.Println("updating group last modified of" + req.GetGroupName())
+	fmt.Println("updating group last modified of " + req.GetGroupName())
 	err = SetGroupNodesLastModified(req.GetGroupName())
         if err != nil {
 		fmt.Println("Error updating Group")

+ 16 - 2
controllers/nodeHttpController.go

@@ -150,8 +150,14 @@ func authorize(groupCheck bool, authGroup string, next http.Handler) http.Handle
 
                 if len(tokenSplit) > 1 {
                         authToken = tokenSplit[1]
+                }  else {
+                        errorResponse = models.ErrorResponse{
+                                Code: http.StatusUnauthorized, Message: "W1R3: Missing Auth Token.",
+                        }
+                        returnErrorResponse(w, r, errorResponse)
                 }
 
+
 		//This checks if
 		//A: the token is the master password
 		//B: the token corresponds to a mac address, and if so, which one
@@ -159,7 +165,10 @@ func authorize(groupCheck bool, authGroup string, next http.Handler) http.Handle
 		macaddress, _, err := functions.VerifyToken(authToken)
 
 		if err != nil {
-			return
+                        errorResponse = models.ErrorResponse{
+                                Code: http.StatusUnauthorized, Message: "W1R3: Error Verifying Auth Token.",
+                        }
+                        returnErrorResponse(w, r, errorResponse)
 		}
 
 		var isAuthorized = false
@@ -179,7 +188,10 @@ func authorize(groupCheck bool, authGroup string, next http.Handler) http.Handle
                         case "group":
                                 node, err := functions.GetNodeByMacAddress(params["group"], macaddress)
 		                if err != nil {
-				        return
+					errorResponse = models.ErrorResponse{
+					Code: http.StatusUnauthorized, Message: "W1R3: Missing Auth Token.",
+					}
+					returnErrorResponse(w, r, errorResponse)
 		                }
                                 isAuthorized = (node.Group == params["group"])
 			case "node":
@@ -567,6 +579,8 @@ func uncordonNode(w http.ResponseWriter, r *http.Request) {
                 mongoconn.GetError(errN, w)
                 return
         }
+        fmt.Println("Node " + node.Name + " uncordoned.")
+
 
         json.NewEncoder(w).Encode("SUCCESS")
 }

+ 10 - 3
controllers/userHttpController.go

@@ -129,7 +129,12 @@ func authorizeUser(next http.Handler) http.HandlerFunc {
 
                 if len(tokenSplit) > 1 {
                         authToken = tokenSplit[1]
-                }
+                } else {
+                        errorResponse = models.ErrorResponse{
+                                Code: http.StatusUnauthorized, Message: "W1R3: Missing Auth Token.",
+                        }
+                        returnErrorResponse(w, r, errorResponse)
+		}
 
 		//This checks if
 		//A: the token is the master password
@@ -138,8 +143,10 @@ func authorizeUser(next http.Handler) http.HandlerFunc {
 		username, _, err := functions.VerifyUserToken(authToken)
 
 		if err != nil {
-			json.NewEncoder(w).Encode(err)
-			return
+                        errorResponse = models.ErrorResponse{
+                                Code: http.StatusUnauthorized, Message: "W1R3: Error Verifying Auth Token.",
+                        }
+                        returnErrorResponse(w, r, errorResponse)
 		}
 
 		isAuthorized := username != ""

+ 1 - 1
defaultvalues.sh

@@ -3,7 +3,7 @@
 # if i've done my work correctly, this file will be defunct
 #  refer to config folder for new method
 export API_PORT=8081
-export GRPC_PORT=5051
+export GRPC_PORT=50051
 export MONGO_USER=mongoadmin
 export MONGO_PASS=mongopass
 export MONGO_HOST=localhost

+ 2 - 1
functions/helpers.go

@@ -66,7 +66,8 @@ func GroupExists(name string) (bool, error) {
 		if err == mongo.ErrNoDocuments {
 			return false, err
 		}
-		log.Fatal(err)
+		fmt.Println("ERROR RETRIEVING GROUP!")
+		fmt.Println(err)
 	}
 	return true, err
 }

+ 5 - 7
go.mod

@@ -6,7 +6,7 @@ require (
 	github.com/davecgh/go-spew v1.1.1
 	github.com/dgrijalva/jwt-go v3.2.0+incompatible
 	github.com/go-playground/universal-translator v0.17.0 // indirect
-	github.com/golang/protobuf v1.4.3
+	github.com/golang/protobuf v1.5.1
 	github.com/gorilla/handlers v1.5.1
 	github.com/gorilla/mux v1.8.0
 	github.com/grpc-ecosystem/go-grpc-middleware v1.0.0
@@ -18,14 +18,12 @@ require (
 	github.com/takama/daemon v1.0.0
 	github.com/vishvananda/netlink v1.1.0
 	go.mongodb.org/mongo-driver v1.4.3
-	golang.org/x/crypto v0.0.0-20200204104054-c9f3fb736b72
-	golang.org/x/net v0.0.0-20210119194325-5f4716e94777 // indirect
-	golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c // indirect
+	golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9
+	golang.org/x/net v0.0.0-20210324205630-d1beb07c2056 // indirect
 	golang.org/x/text v0.3.5 // indirect
 	golang.zx2c4.com/wireguard/wgctrl v0.0.0-20200609130330-bd2cb7843e1b
-	google.golang.org/genproto v0.0.0-20210201151548-94839c025ad4 // indirect
-	google.golang.org/grpc v1.35.0
-	google.golang.org/protobuf v1.25.0 // indirect
+	google.golang.org/genproto v0.0.0-20210325141258-5636347f2b14 // indirect
+	google.golang.org/grpc v1.36.0
 	gopkg.in/go-playground/validator.v9 v9.31.0
 	gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c
 )

+ 35 - 0
go.sum

@@ -105,6 +105,9 @@ github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QD
 github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
 github.com/golang/protobuf v1.4.3 h1:JjCZWpVbqXDqFVmTfYWEVTMIYrL/NPdPSCHPJ0T/raM=
 github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
+github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
+github.com/golang/protobuf v1.5.1 h1:jAbXjIeW2ZSW2AwFxlGTDoc2CjI2XujLkV3ArsZFCvc=
+github.com/golang/protobuf v1.5.1/go.mod h1:DopwsBzvsk0Fs44TXzsVbJyPhcCPeIwnvohx4u74HPM=
 github.com/golang/snappy v0.0.1 h1:Qgr9rKW7uDUkrbSmQeiDsGa8SjGyCOGtuasMWwvp2P4=
 github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
 github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
@@ -115,6 +118,7 @@ github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMyw
 github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
 github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
 github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
+github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
 github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=
 github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc=
 github.com/google/pprof v0.0.0-20190515194954-54271f7e092f/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc=
@@ -279,6 +283,7 @@ github.com/xdg/scram v0.0.0-20180814205039-7eeb5667e42c/go.mod h1:lB8K/P019DLNhe
 github.com/xdg/stringprep v0.0.0-20180714160509-73f8eece6fdc h1:n+nNi93yXLkJvKwXNP9d55HC7lGK4H/SRcwB5IaUZLo=
 github.com/xdg/stringprep v0.0.0-20180714160509-73f8eece6fdc/go.mod h1:Jhud4/sHMO4oL310DaZAKk9ZaJ08SJfe+sJh0HrGL1Y=
 github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
+github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
 go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
 go.mongodb.org/mongo-driver v1.4.3 h1:moga+uhicpVshTyaqY9L23E6QqwcHRUv1sqyOsoyOO8=
 go.mongodb.org/mongo-driver v1.4.3/go.mod h1:WcMNYLx/IlOxLe6JRJiv2uXuCz6zBLndR4SoGjYphSc=
@@ -297,8 +302,11 @@ golang.org/x/crypto v0.0.0-20190530122614-20be4c3c3ed5/go.mod h1:yigFU9vqHzYiE8U
 golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5 h1:58fnuSXlxZmFdJyvtTFVmVhcMLU6v5fEb/ok4wyqtNU=
 golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
 golang.org/x/crypto v0.0.0-20191002192127-34f69633bfdc/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
+golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
 golang.org/x/crypto v0.0.0-20200204104054-c9f3fb736b72 h1:+ELyKg6m8UBf0nPFSqD0mi7zUfwPyXo23HNjMnXPz7w=
 golang.org/x/crypto v0.0.0-20200204104054-c9f3fb736b72/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
+golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 h1:psW17arqaxU48Z5kZ0CQnkZWQJsqcURM6tKiBApRjXI=
+golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
 golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
 golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
 golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
@@ -313,10 +321,13 @@ golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHl
 golang.org/x/lint v0.0.0-20190409202823-959b441ac422/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
 golang.org/x/lint v0.0.0-20190909230951-414d861bb4ac/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
 golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
+golang.org/x/lint v0.0.0-20201208152925-83fdc39ff7b5/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
 golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE=
 golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o=
 golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc=
 golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY=
+golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
+golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
 golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
 golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
 golang.org/x/net v0.0.0-20181023162649-9b4f9f5ad519/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
@@ -336,8 +347,12 @@ golang.org/x/net v0.0.0-20191003171128-d98b1b443823/go.mod h1:z5CRVTTTmAJ677TzLL
 golang.org/x/net v0.0.0-20191007182048-72f939374954/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
 golang.org/x/net v0.0.0-20200202094626-16171245cfb2 h1:CCH4IOTTfewWjGOlSp+zGcjutRKlBEZQ6wTn8ozI/nI=
 golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
+golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
 golang.org/x/net v0.0.0-20210119194325-5f4716e94777 h1:003p0dJM77cxMSyCPFphvZf/Y5/NXf5fzg6ufd1/Oew=
 golang.org/x/net v0.0.0-20210119194325-5f4716e94777/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
+golang.org/x/net v0.0.0-20210316092652-d523dce5a7f4/go.mod h1:RBQZq4jEuRlivfhVLdyRGr576XBO4/greRjx4P4O3yc=
+golang.org/x/net v0.0.0-20210324205630-d1beb07c2056 h1:sANdAef76Ioam9aQUUdcAqricwY/WUaMc4+7LY4eGg8=
+golang.org/x/net v0.0.0-20210324205630-d1beb07c2056/go.mod h1:uSPa2vr4CLtc/ILN5odXGNXS6mhrKVzTaCXzk9m6W3k=
 golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
 golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
 golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
@@ -349,6 +364,8 @@ golang.org/x/sync v0.0.0-20190412183630-56d357773e84/go.mod h1:RxMgew5VJxzue5/jJ
 golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
 golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e h1:vcxGaoTs7kV8m5Np9uUNQin4BrLOthgV7252N8V+FwY=
 golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
+golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9 h1:SQFwaSi55rU7vdNs9Yr0Z324VNlrF+0wMqRXT4St8ck=
+golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
 golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
 golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
 golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
@@ -374,9 +391,15 @@ golang.org/x/sys v0.0.0-20191003212358-c178f38b412c/go.mod h1:h1NjWce9XRLGQEsW7w
 golang.org/x/sys v0.0.0-20191008105621-543471e840be/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 golang.org/x/sys v0.0.0-20200722175500-76b94024e4b6/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c h1:VwygUrnw9jn88c4u8GD3rZQbqrP/tgas88tPUbBxQrk=
 golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20210315160823-c6e025ad8005/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20210320140829-1e4c9ba3b0c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20210324051608-47abb6519492 h1:Paq34FxTluEPvVyayQqMPgHm+vTOrIifmcYxFBx9TLg=
+golang.org/x/sys v0.0.0-20210324051608-47abb6519492/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
 golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
 golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
@@ -409,8 +432,13 @@ golang.org/x/tools v0.0.0-20190816200558-6889da9d5479/go.mod h1:b+2E5dAYhXwXZwtn
 golang.org/x/tools v0.0.0-20190911174233-4f2ddba30aff/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
 golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
 golang.org/x/tools v0.0.0-20191112195655-aa38f8e97acc/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
+golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
+golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
+golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0=
 golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
+golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
 golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
+golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
 golang.zx2c4.com/wireguard v0.0.20200121 h1:vcswa5Q6f+sylDfjqyrVNNrjsFUUbPsgAQTBCAg/Qf8=
 golang.zx2c4.com/wireguard v0.0.20200121/go.mod h1:P2HsVp8SKwZEufsnezXZA4GRX/T49/HlU7DGuelXsU4=
 golang.zx2c4.com/wireguard v0.0.20201119 h1:WJ4IKfT3SLG+YbM9aeZlgYB+X7hKzO66GEGBmxJPhjE=
@@ -438,6 +466,8 @@ google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 h1:+kGHl1aib/qcwaR
 google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo=
 google.golang.org/genproto v0.0.0-20210201151548-94839c025ad4 h1:HPkKL4eEh/nemF/FRzYMrFsAh1ZPm5t8NqKBI/Ejlg0=
 google.golang.org/genproto v0.0.0-20210201151548-94839c025ad4/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no=
+google.golang.org/genproto v0.0.0-20210325141258-5636347f2b14 h1:0VNRpy5TroA/6mYt3pPEq+E3oomxLJ+FUit3+oIsUy4=
+google.golang.org/genproto v0.0.0-20210325141258-5636347f2b14/go.mod h1:f2Bd7+2PlaVKmvKQ52aspJZXIDaRQBVdOOBfJ5i8OEs=
 google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
 google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38=
 google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM=
@@ -447,6 +477,8 @@ google.golang.org/grpc v1.27.0 h1:rRYRFMVgRv6E0D70Skyfsr28tDXIuuPZyWGMPdMcnXg=
 google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
 google.golang.org/grpc v1.35.0 h1:TwIQcH3es+MojMVojxxfQ3l3OF2KzlRxML2xZq0kRo8=
 google.golang.org/grpc v1.35.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU=
+google.golang.org/grpc v1.36.0 h1:o1bcQ6imQMIOpdrO3SWf2z5RV72WbDwdXuK0MDlc8As=
+google.golang.org/grpc v1.36.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU=
 google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
 google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
 google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
@@ -459,6 +491,9 @@ google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpAD
 google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGjtUeSXeh4=
 google.golang.org/protobuf v1.25.0 h1:Ejskq+SyPohKW+1uil0JJMtmHCgJPJ/qWTxr8qp+R4c=
 google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
+google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
+google.golang.org/protobuf v1.26.0 h1:bxAC2xTBsZGibn2RTntX0oH50xLsqy1OxA9tTL3p/lk=
+google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
 gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
 gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
 gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=

+ 0 - 12
main.go

@@ -1,6 +1,4 @@
-//TODO: er is the wrapper of the service method implementation. It is the resUpdate README with new functions
 //TODO: Harden. Add failover for every method and agent calls
-//TODO: Make configurable. Use the config file for settings
 //TODO: Figure out why mongodb keeps failing (log rotation?)
 
 package main
@@ -32,16 +30,10 @@ func main() {
 		go runGRPC(&waitgroup)
 	}
 
-	//TODO: We need  to break up this package for clarity
-	//We need groupController and nodeController, and then 
-	//here we will call some third package with HandleRequests
-	//which will just set up and call  the other 2
-
 	if config.Config.Server.RestBackend {
 		waitgroup.Add(1)
 		controller.HandleRESTRequests(&waitgroup)
 	}
-
 	if !config.Config.Server.RestBackend && !config.Config.Server.AgentBackend {
 		fmt.Println("Oops! No Server Mode selected. Nothing being served.")
 	}
@@ -75,14 +67,10 @@ func runGRPC(wg *sync.WaitGroup) {
                 log.Fatalf("Unable to listen on port" + grpcport + ": %v", err)
         }
 
-         // Set options, here we can configure things like TLS support 
-         //opts := []grpc.ServerOption{}
-         // Create new gRPC server with (blank) options
          s := grpc.NewServer(
 		 authServerUnaryInterceptor(),
 		 authServerStreamInterceptor(),
 	 )
-         //s := grpc.NewServer(opts...)
          // Create NodeService type 
          srv := &service.NodeServiceServer{}
 

+ 35 - 26
netclient/config/config.go

@@ -6,7 +6,7 @@ import (
   "fmt"
   "log"
   "gopkg.in/yaml.v3"
-  homedir "github.com/mitchellh/go-homedir"
+  //homedir "github.com/mitchellh/go-homedir"
 )
 
 var Config *ClientConfig
@@ -42,15 +42,23 @@ type NodeConfig struct {
 //reading in the env file
 func Write(config *ClientConfig) error{
 	nofile := false
-        home, err := homedir.Dir()
+        //home, err := homedir.Dir()
+        _, err := os.Stat("/etc/netclient") 
+	if os.IsNotExist(err) {
+		      os.Mkdir("/etc/netclient", 744)
+	} else if err != nil {
+                return err
+        }
+	home := "/etc/netclient"
+
         if err != nil {
                 log.Fatal(err)
         }
-        file := fmt.Sprintf(home + "/.wcconfig")
+        file := fmt.Sprintf(home + "/.netconfig")
         f, err := os.OpenFile(file, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, os.ModePerm)
         if err != nil {
                 nofile = true
-                //fmt.Println("Could not access " + home + "/.wcconfig,  proceeding...")
+                //fmt.Println("Could not access " + home + "/.netconfig,  proceeding...")
         }
         defer f.Close()
 
@@ -62,7 +70,7 @@ func Write(config *ClientConfig) error{
                 }
         } else {
 
-		newf, err := os.Create(home + "/.wcconfig")
+		newf, err := os.Create(home + "/.netconfig")
 		err = yaml.NewEncoder(newf).Encode(config)
 		defer newf.Close()
 		if err != nil {
@@ -75,17 +83,22 @@ func Write(config *ClientConfig) error{
 }
 func WriteServer(server string, accesskey string) error{
         nofile := false
-        home, err := homedir.Dir()
-        if err != nil {
-		fmt.Println("couldnt find home dir")
+        //home, err := homedir.Dir()
+        _, err := os.Stat("/etc/netclient")
+	if os.IsNotExist(err) {
+                os.Mkdir("/etc/netclient", 744)
+        } else if err != nil {
+		fmt.Println("couldnt find or create /etc/netclient")
                 return err
         }
-        file := fmt.Sprintf(home + "/.wcconfig")
+        home := "/etc/netclient"
+
+	file := fmt.Sprintf(home + "/.netconfig")
         //f, err := os.Open(file)
         f, err := os.OpenFile(file, os.O_CREATE|os.O_RDWR, 0666)
 	//f, err := ioutil.ReadFile(file)
         if err != nil {
-		fmt.Println("couldnt open wcconfig")
+		fmt.Println("couldnt open netconfig")
 		fmt.Println(err)
                 nofile = true
 		//err = nil
@@ -97,7 +110,7 @@ func WriteServer(server string, accesskey string) error{
 	var cfg ClientConfig
 
         if !nofile {
-		fmt.Println("Writing to existing config file at " + home + "/.wcconfig")
+		fmt.Println("Writing to existing config file at " + home + "/.netconfig")
                 decoder := yaml.NewDecoder(f)
                 err = decoder.Decode(&cfg)
 		//err = yaml.Unmarshal(f, &cfg)
@@ -108,7 +121,7 @@ func WriteServer(server string, accesskey string) error{
 		f.Close()
 		f, err = os.OpenFile(file, os.O_CREATE|os.O_RDWR|os.O_TRUNC, 0666)
 	        if err != nil {
-			fmt.Println("couldnt open wcconfig")
+			fmt.Println("couldnt open netconfig")
 			fmt.Println(err)
 			nofile = true
 			//err = nil
@@ -131,12 +144,12 @@ func WriteServer(server string, accesskey string) error{
                         return err
                 }
 	} else {
-                fmt.Println("Creating new config file at " + home + "/.wcconfig")
+                fmt.Println("Creating new config file at " + home + "/.netconfig")
 
                 cfg.Server.Address = server
                 cfg.Server.AccessKey = accesskey
 
-                newf, err := os.Create(home + "/.wcconfig")
+                newf, err := os.Create(home + "/.netconfig")
                 err = yaml.NewEncoder(newf).Encode(cfg)
                 defer newf.Close()
                 if err != nil {
@@ -152,18 +165,16 @@ func WriteServer(server string, accesskey string) error{
 func(config *ClientConfig) ReadConfig() {
 
 	nofile := false
-	home, err := homedir.Dir()
-	if err != nil {
-		log.Fatal(err)
-	}
-	file := fmt.Sprintf(home + "/.wcconfig")
+	//home, err := homedir.Dir()
+	home := "/etc/netclient"
+	file := fmt.Sprintf(home + "/.netconfig")
 	//f, err := os.Open(file)
         f, err := os.OpenFile(file, os.O_RDONLY, 0666)
 	if err != nil {
 		fmt.Println("trouble opening file")
 		fmt.Println(err)
 		nofile = true
-		//fmt.Println("Could not access " + home + "/.wcconfig,  proceeding...")
+		//fmt.Println("Could not access " + home + "/.netconfig,  proceeding...")
 	}
 	defer f.Close()
 
@@ -185,15 +196,13 @@ func(config *ClientConfig) ReadConfig() {
 
 func readConfig() *ClientConfig {
 	nofile := false
-	home, err := homedir.Dir()
-	if err != nil {
-		log.Fatal(err)
-	}
-	file := fmt.Sprintf(home + "/.wcconfig")
+	//home, err := homedir.Dir()
+	home := "/etc/netclient"
+	file := fmt.Sprintf(home + "/.netconfig")
 	f, err := os.Open(file)
 	if err != nil {
 		nofile = true
-		fmt.Println("Could not access " + home + "/.wcconfig,  proceeding...")
+		fmt.Println("Could not access " + home + "/.netconfig,  proceeding...")
 	}
 	defer f.Close()
 

BIN
netclient/functions/.common.go.swp


+ 8 - 7
netclient/functions/auth.go

@@ -3,7 +3,7 @@ package functions
 import (
     "github.com/gravitl/netmaker/netclient/config"
     "fmt"
-    "os"
+//    "os"
     "context"
     "io/ioutil"
     "google.golang.org/grpc/metadata"
@@ -15,15 +15,16 @@ import (
 
 // CreateJWT func will used to create the JWT while signing in and signing out
 func SetJWT(client nodepb.NodeServiceClient) (context.Context, error) {
-		home, err := os.UserHomeDir()
-                tokentext, err := ioutil.ReadFile(home + "/.wctoken")
+		//home, err := os.UserHomeDir()
+		home := "/etc/netclient"
+		tokentext, err := ioutil.ReadFile(home + "/.nettoken")
                 if err != nil {
 			fmt.Println("Error reading token. Logging in to retrieve new token.")
 			err = AutoLogin(client)
 			if err != nil {
                                 return nil, status.Errorf(codes.Unauthenticated, fmt.Sprintf("Something went wrong with Auto Login: %v", err))
                         }
-			tokentext, err = ioutil.ReadFile(home + "/.wctoken")
+			tokentext, err = ioutil.ReadFile(home + "/.nettoken")
 			if err != nil {
 				return nil, status.Errorf(codes.Unauthenticated, fmt.Sprintf("Something went wrong: %v", err))
 			}
@@ -38,7 +39,8 @@ func SetJWT(client nodepb.NodeServiceClient) (context.Context, error) {
 }
 
 func AutoLogin(client nodepb.NodeServiceClient) error {
-	        home, err := os.UserHomeDir()
+	        //home, err := os.UserHomeDir()
+		home := "/etc/netclient"
 		nodecfg := config.Config.Node
                 login := &nodepb.LoginRequest{
                         Password: nodecfg.Password,
@@ -49,9 +51,8 @@ func AutoLogin(client nodepb.NodeServiceClient) error {
                 if err != nil {
                         return err
                 }
-                fmt.Printf("Token: %s\n", res.Accesstoken)
                 tokenstring := []byte(res.Accesstoken)
-                err = ioutil.WriteFile(home + "/.wctoken", tokenstring, 0644)
+                err = ioutil.WriteFile(home + "/.nettoken", tokenstring, 0644)
                 if err != nil {
                         return err
                 }

+ 60 - 22
netclient/functions/common.go

@@ -20,7 +20,7 @@ import (
         "google.golang.org/grpc"
 	"google.golang.org/grpc/metadata"
 	"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
-	homedir "github.com/mitchellh/go-homedir"
+	//homedir "github.com/mitchellh/go-homedir"
 )
 
 var (
@@ -241,7 +241,7 @@ func Install(accesskey string, password string, server string, group string, noa
                 Endpoint: endpoint,
         }
 
-       fmt.Println("Writing node settings to wcconfig file.")
+       fmt.Println("Writing node settings to netconfig file.")
         err = modConfig(postnode)
         if err != nil {
                 return err
@@ -284,7 +284,7 @@ func Install(accesskey string, password string, server string, group string, noa
 		fmt.Println("Node is marked as PENDING.")
 		fmt.Println("Awaiting approval from Admin before configuring WireGuard.")
 	        if !noauto {
-			fmt.Println("Configuring WireCat Service.")
+			fmt.Println("Configuring Netmaker Service.")
 			err = ConfigureSystemD()
 			return err
 		}
@@ -555,14 +555,17 @@ func CheckIn() error {
 	node := getNode()
         nodecfg := config.Config.Node
 	servercfg := config.Config.Server
+	fmt.Println("Checking into server: " + servercfg.Address)
+
+	setupcheck := true
 
         var wcclient nodepb.NodeServiceClient
         var requestOpts grpc.DialOption
         requestOpts = grpc.WithInsecure()
         conn, err := grpc.Dial(servercfg.Address, requestOpts)
         if err != nil {
+		fmt.Printf("Cant dial GRPC server: %v", err)
 		return err
-                log.Fatalf("Unable to establish client connection to localhost:50051: %v", err)
         }
         wcclient = nodepb.NewNodeServiceClient(conn)
 
@@ -570,10 +573,11 @@ func CheckIn() error {
         fmt.Println("Authenticating with GRPC Server")
         ctx, err = SetJWT(wcclient)
         if err != nil {
+                fmt.Printf("Failed to authenticate: %v", err)
 		return err
-		log.Fatalf("Failed to authenticate: %v", err)
 	}
         fmt.Println("Authenticated")
+        fmt.Println("Checking In.")
 
         var header metadata.MD
 
@@ -585,16 +589,14 @@ func CheckIn() error {
 		grpc.Header(&header),
         )
         if err != nil {
+        if  checkinres != nil && checkinres.Checkinresponse.Ispending {
+                fmt.Println("Node is in pending status. Waiting for Admin approval of  node before making furtherupdates.")
+                return nil
+        }
+                fmt.Printf("Unable to process Check In request: %v", err)
 		return err
-                log.Fatalf("Unable to process Check In request: %v", err)
         }
 	fmt.Println("Checked in.")
-	/*
-	if nodecfg.PostChanges && checkinres.Checkinresponse.Nodeupdated {
-		nodecfg.PostChanges = false
-		modConfig(readres, false)
-	}
-	*/
 	if  checkinres.Checkinresponse.Ispending {
 		fmt.Println("Node is in pending status. Waiting for Admin approval of  node before making furtherupdates.")
 		return err
@@ -621,10 +623,12 @@ func CheckIn() error {
 			return err
                         log.Fatalf("Error: %v", err)
                 }
+		setupcheck = false
 	} else if nodecfg.PostChanges == "true" {
                 fmt.Println("Node has requested to update remote config.")
                 fmt.Println("Posting local config to remote server.")
 		postnode := getNode()
+		currentinterface := postnode.Interface
 		req := &nodepb.UpdateNodeReq{
                                Node: &postnode,
                         }
@@ -634,16 +638,24 @@ func CheckIn() error {
 			log.Fatalf("Error: %v", err)
                 }
 		res.Node.Postchanges = "false"
+		newinterface := res.Node.Interface
 		err = modConfig(res.Node)
                 if err != nil {
 			return err
                         log.Fatalf("Error: %v", err)
                 }
+		if currentinterface != newinterface {
+			err := DeleteInterface(currentinterface)
+			if err != nil {
+				fmt.Println("ERROR DELETING INTERFACE: " + currentinterface)
+			}
+		}
 		err = setWGConfig()
                 if err != nil {
 			return err
                         log.Fatalf("Error: %v", err)
                 }
+		setupcheck = false
 	}
         if checkinres.Checkinresponse.Needpeerupdate {
                 fmt.Println("Server has requested that node update peer list.")
@@ -653,7 +665,20 @@ func CheckIn() error {
 			return err
                         log.Fatalf("Unable to process Set Peers request: %v", err)
                 }
+		setupcheck = false
         }
+	if setupcheck {
+	iface := nodecfg.Interface
+	_, err := net.InterfaceByName(iface)
+        if err != nil {
+		fmt.Println("interface " + iface + " does not currently exist. Setting up WireGuard.")
+                err = setWGConfig()
+                if err != nil {
+                        return err
+                        log.Fatalf("Error: %v", err)
+                }
+	}
+	}
 	return nil
 }
 func getNode() nodepb.Node {
@@ -694,9 +719,9 @@ func Remove() error {
         var requestOpts grpc.DialOption
         requestOpts = grpc.WithInsecure()
         conn, err := grpc.Dial(servercfg.Address, requestOpts)
-        if err != nil {
-                return err
-                log.Fatalf("Unable to establish client connection to localhost:50051: %v", err)
+	if err != nil {
+                log.Printf("Unable to establish client connection to " + servercfg.Address + ": %v", err)
+		return err
         }
         wcclient = nodepb.NewNodeServiceClient(conn)
 
@@ -745,15 +770,13 @@ func WipeLocal() error{
         nodecfg := config.Config.Node
         ifacename := nodecfg.Interface
 
-        home, err := homedir.Dir()
-        if err != nil {
-                log.Fatal(err)
-        }
-        err = os.Remove(home + "/.wcconfig")
+        //home, err := homedir.Dir()
+	home := "/etc/netclient"
+	err := os.Remove(home + "/.netconfig")
         if  err  !=  nil {
                 fmt.Println(err)
         }
-        err = os.Remove(home + "/.wctoken")
+        err = os.Remove(home + "/.nettoken")
         if  err  !=  nil {
                 fmt.Println(err)
         }
@@ -773,6 +796,21 @@ func WipeLocal() error{
 
 }
 
+func DeleteInterface(ifacename string) error{
+        ipExec, err := exec.LookPath("ip")
+
+        cmdIPLinkDel := &exec.Cmd {
+                Path: ipExec,
+                Args: []string{ ipExec, "link", "del", ifacename },
+                Stdout: os.Stdout,
+                Stderr: os.Stdout,
+        }
+        err = cmdIPLinkDel.Run()
+        if  err  !=  nil {
+                fmt.Println(err)
+        }
+        return err
+}
 
 func getPeers(macaddress string, group string, server string) ([]wgtypes.PeerConfig, error) {
         //need to  implement checkin on server side
@@ -784,7 +822,7 @@ func getPeers(macaddress string, group string, server string) ([]wgtypes.PeerCon
 	keepalive := nodecfg.KeepAlive
 	keepalivedur, err := time.ParseDuration(strconv.FormatInt(int64(keepalive), 10) + "s")
         if err != nil {
-                log.Fatalf("Issue with format of keepalive value. Please update wcconfig: %v", err)
+                log.Fatalf("Issue with format of keepalive value. Please update netconfig: %v", err)
         }
 
 

+ 35 - 28
netclient/functions/local.go

@@ -18,9 +18,17 @@ func ConfigureSystemD() error {
 		return err
 	}
 
-	binarypath := path  + "/meshclient"
+	binarypath := path  + "/netclient"
 
-	_, err = copy(binarypath, "/usr/local/bin/meshclient")
+        _, err = os.Stat("/etc/netclient")
+        if os.IsNotExist(err) {
+                os.Mkdir("/etc/netclient", 744)
+        } else if err != nil {
+                fmt.Println("couldnt find or create /etc/netclient")
+                return err
+        }
+
+	_, err = copy(binarypath, "/etc/netclient/netclient")
 	if err != nil {
 		log.Println(err)
 		return err
@@ -29,22 +37,22 @@ func ConfigureSystemD() error {
 
 	systemservice := `[Unit]
 Description=Regularly checks for updates in peers and local config
-Wants=wirecat.timer
+Wants=netclient.timer
 
 [Service]
 Type=oneshot
-ExecStart=/usr/local/bin/meshclient -c checkin
+ExecStart=/etc/netclient/netclient -c checkin
 
 [Install]
 WantedBy=multi-user.target
 `
 
 	systemtimer := `[Unit]
-Description=Calls the WireCat Mesh Client Service
-Requires=wirecat.service
+Description=Calls the Netmaker Mesh Client Service
+Requires=netmaker.service
 
 [Timer]
-Unit=wirecat.service
+Unit=netmaker.service
 OnCalendar=*:*:0/30
 
 [Install]
@@ -54,13 +62,13 @@ WantedBy=timers.target
 	servicebytes := []byte(systemservice)
 	timerbytes := []byte(systemtimer)
 
-	err = ioutil.WriteFile("/etc/systemd/system/wirecat.service", servicebytes, 0644)
+	err = ioutil.WriteFile("/etc/systemd/system/netmaker.service", servicebytes, 0644)
         if err != nil {
                 log.Println(err)
                 return err
         }
 
-        err = ioutil.WriteFile("/etc/systemd/system/wirecat.timer", timerbytes, 0644)
+        err = ioutil.WriteFile("/etc/systemd/system/netmaker.timer", timerbytes, 0644)
         if err != nil {
                 log.Println(err)
                 return err
@@ -70,13 +78,13 @@ WantedBy=timers.target
 
         cmdSysEnableService := &exec.Cmd {
                 Path: sysExec,
-                Args: []string{ sysExec, "enable", "wirecat.service" },
+                Args: []string{ sysExec, "enable", "netmaker.service" },
                 Stdout: os.Stdout,
                 Stderr: os.Stdout,
         }
         cmdSysStartService := &exec.Cmd {
                 Path: sysExec,
-                Args: []string{ sysExec, "start", "wirecat.service"},
+                Args: []string{ sysExec, "start", "netmaker.service"},
                 Stdout: os.Stdout,
                 Stderr: os.Stdout,
         }
@@ -88,25 +96,25 @@ WantedBy=timers.target
         }
         cmdSysEnableTimer := &exec.Cmd {
                 Path: sysExec,
-                Args: []string{ sysExec, "enable", "wirecat.timer" },
+                Args: []string{ sysExec, "enable", "netmaker.timer" },
                 Stdout: os.Stdout,
                 Stderr: os.Stdout,
         }
         cmdSysStartTimer := &exec.Cmd {
                 Path: sysExec,
-		Args: []string{ sysExec, "start", "wirecat.timer"},
+		Args: []string{ sysExec, "start", "netmaker.timer"},
                 Stdout: os.Stdout,
                 Stderr: os.Stdout,
         }
 
         err = cmdSysEnableService.Run()
         if  err  !=  nil {
-                fmt.Println("Error enabling wirecat.service. Please investigate.")
+                fmt.Println("Error enabling netmaker.service. Please investigate.")
                 fmt.Println(err)
         }
         err = cmdSysStartService.Run()
         if  err  !=  nil {
-                fmt.Println("Error starting wirecat.service. Please investigate.")
+                fmt.Println("Error starting netmaker.service. Please investigate.")
                 fmt.Println(err)
         }
         err = cmdSysDaemonReload.Run()
@@ -116,12 +124,12 @@ WantedBy=timers.target
         }
         err = cmdSysEnableTimer.Run()
         if  err  !=  nil {
-                fmt.Println("Error enabling wirecat.timer. Please investigate.")
+                fmt.Println("Error enabling netmaker.timer. Please investigate.")
                 fmt.Println(err)
         }
         err = cmdSysStartTimer.Run()
         if  err  !=  nil {
-                fmt.Println("Error starting wirecat.timer. Please investigate.")
+                fmt.Println("Error starting netmaker.timer. Please investigate.")
                 fmt.Println(err)
         }
 	return nil
@@ -132,13 +140,13 @@ func RemoveSystemDServices() error {
 
         cmdSysStopService := &exec.Cmd {
                 Path: sysExec,
-                Args: []string{ sysExec, "stop", "wirecat.service" },
+                Args: []string{ sysExec, "stop", "netmaker.service" },
                 Stdout: os.Stdout,
                 Stderr: os.Stdout,
         }
         cmdSysDisableService := &exec.Cmd {
                 Path: sysExec,
-                Args: []string{ sysExec, "disable", "wirecat.service"},
+                Args: []string{ sysExec, "disable", "netmaker.service"},
                 Stdout: os.Stdout,
                 Stderr: os.Stdout,
         }
@@ -150,41 +158,40 @@ func RemoveSystemDServices() error {
         }
         cmdSysStopTimer := &exec.Cmd {
                 Path: sysExec,
-                Args: []string{ sysExec, "stop", "wirecat.timer" },
+                Args: []string{ sysExec, "stop", "netmaker.timer" },
                 Stdout: os.Stdout,
                 Stderr: os.Stdout,
         }
         cmdSysDisableTimer := &exec.Cmd {
                 Path: sysExec,
-                Args: []string{ sysExec, "disable", "wirecat.timer"},
+                Args: []string{ sysExec, "disable", "netmaker.timer"},
                 Stdout: os.Stdout,
                 Stderr: os.Stdout,
         }
 
         err = cmdSysStopService.Run()
         if  err  !=  nil {
-                fmt.Println("Error stopping wirecat.service. Please investigate.")
+                fmt.Println("Error stopping netmaker.service. Please investigate.")
                 fmt.Println(err)
         }
         err = cmdSysDisableService.Run()
         if  err  !=  nil {
-                fmt.Println("Error disabling wirecat.service. Please investigate.")
+                fmt.Println("Error disabling netmaker.service. Please investigate.")
                 fmt.Println(err)
         }
         err = cmdSysStopTimer.Run()
         if  err  !=  nil {
-                fmt.Println("Error stopping wirecat.timer. Please investigate.")
+                fmt.Println("Error stopping netmaker.timer. Please investigate.")
                 fmt.Println(err)
         }
         err = cmdSysDisableTimer.Run()
         if  err  !=  nil {
-                fmt.Println("Error disabling wirecat.timer. Please investigate.")
+                fmt.Println("Error disabling netmaker.timer. Please investigate.")
                 fmt.Println(err)
         }
 
-	err = os.Remove("/etc/systemd/system/wirecat.service")
-	err = os.Remove("/etc/systemd/system/wirecat.timer")
-        //err = os.Remove("/usr/local/bin/meshclient")
+	err = os.Remove("/etc/systemd/system/netmaker.service")
+	err = os.Remove("/etc/systemd/system/netmaker.timer")
 	if err != nil {
                 fmt.Println("Error removing file. Please investigate.")
                 fmt.Println(err)

+ 0 - 99
netclient/functions/old/create.go

@@ -1,99 +0,0 @@
-/*
-Copyright © 2021 NAME HERE <EMAIL ADDRESS>
-
-Licensed under the Apache License, Version 2.0 (the "License");
-you may not use this file except in compliance with the License.
-You may obtain a copy of the License at
-
-    http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS,
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-See the License for the specific language governing permissions and
-limitations under the License.
-*/
-package cmd
-
-import (
-	"fmt"
-	"context"
-	"net/http"
-	"io/ioutil"
-        nodepb "github.com/gravitl/netmaker/grpc"
-	"github.com/spf13/cobra"
-)
-
-// createCmd represents the create command
-var createCmd = &cobra.Command{
-	Use:   "create",
-	Short: "Create a new node",
-	Long: `hi`,
-	SilenceUsage: true,
-	RunE: func(cmd *cobra.Command, args []string) error {
-    // Get the data from our flags 
-		nodegroup, err := cmd.Flags().GetString("nodegroup")
-		password, err := cmd.Flags().GetString("password")
-		macaddress, err := cmd.Flags().GetString("macaddress")
-		name, err := cmd.Flags().GetString("name")
-		listenport, err := cmd.Flags().GetInt32("listenport")
-		publickey, err := cmd.Flags().GetString("publickey")
-		endpoint, err := cmd.Flags().GetString("endpoint")
-		if err != nil {
-			return err
-		}
-		if endpoint == "" {
-			resp, err := http.Get("https://ifconfig.me")
-			if err != nil {
-				return err
-			}
-			defer resp.Body.Close()
-			if resp.StatusCode == http.StatusOK {
-				bodyBytes, err := ioutil.ReadAll(resp.Body)
-			if err != nil {
-				return err
-			}
-			endpoint = string(bodyBytes)
-			}
-		}
-    // Create a blog protobuffer message  
-		node := &nodepb.Node{
-			Password: password,
-			Macaddress:    macaddress,
-			Nodegroup:  nodegroup,
-			Listenport: listenport,
-			Publickey: publickey,
-			Name: name,
-			Endpoint: endpoint,
-		}
-    // RPC call
-		res, err := client.CreateNode(
-			context.TODO(),
-      // wrap the blog message in a CreateBlog request message
-			&nodepb.CreateNodeReq{
-				Node: node,
-			},
-		)
-		if err != nil {
-			return err
-		}
-		fmt.Printf("Node created: %s\n", res.Node.Id)
-		return err
-	},
-}
-
-func init() {
-
-	createCmd.Flags().StringP("name", "n", "", "The node name")
-	createCmd.Flags().StringP("listenport", "l", "", "The wireguard port")
-	createCmd.Flags().StringP("endpoint", "e", "", "The public IP")
-	createCmd.Flags().StringP("macaddress", "m", "", "The local macaddress")
-	createCmd.Flags().StringP("password", "p", "", "The password")
-	createCmd.Flags().StringP("nodegroup", "g", "", "The group this will be added to")
-	createCmd.Flags().StringP("publickey", "k", "", "The wireguard public key")
-	createCmd.MarkFlagRequired("nodegroup")
-	createCmd.MarkFlagRequired("password")
-	createCmd.MarkFlagRequired("macaddress")
-	rootCmd.AddCommand(createCmd)
-
-}

+ 0 - 66
netclient/functions/old/delete.go

@@ -1,66 +0,0 @@
-/*
-Copyright © 2021 NAME HERE <EMAIL ADDRESS>
-
-Licensed under the Apache License, Version 2.0 (the "License");
-you may not use this file except in compliance with the License.
-You may obtain a copy of the License at
-
-    http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS,
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-See the License for the specific language governing permissions and
-limitations under the License.
-*/
-package cmd
-
-import (
-	"fmt"
-	"context"
-        "github.com/gravitl/netmaker/wcagent/functions"
-	nodepb "github.com/gravitl/netmaker/grpc"
-	"github.com/spf13/cobra"
-        "google.golang.org/grpc/metadata"
-        "google.golang.org/grpc"
-)
-
-var deleteCmd = &cobra.Command{
-	Use:   "delete",
-	Short: "Delete a Nodeby its MAC",
-	Long: `Delete a node post by it's macaddress in mongodb.
-	
-	If no node is found with the MAC it will return a 'Not Found' error`,
-	SilenceUsage: true,
-	RunE: func(cmd *cobra.Command, args []string) error {
-		macaddress, err := cmd.Flags().GetString("macaddress")
-		if err != nil {
-			return err
-		}
-		req := &nodepb.DeleteNodeReq{
-			Macaddress: macaddress,
-		}
-                ctx := context.Background()
-                ctx, err = functions.SetJWT(client)
-                if err != nil {
-                        return err
-                }
-
-                var header metadata.MD
-
-                _, err = client.DeleteNode(ctx, req, grpc.Header(&header))
-		if err != nil {
-			return err
-		}
-		fmt.Printf("Succesfully deleted the node with macaddress %s\n", macaddress)
-		return nil
-	},
-}
-
-func init() {
-	deleteCmd.Flags().StringP("macaddress", "m", "", "The macaddress of the node")
-	deleteCmd.MarkFlagRequired("macaddress")
-	rootCmd.AddCommand(deleteCmd)
-}
-
-

+ 0 - 97
netclient/functions/old/getpeers.go

@@ -1,97 +0,0 @@
-/*
-Copyright © 2021 NAME HERE <EMAIL ADDRESS>
-
-Licensed under the Apache License, Version 2.0 (the "License");
-you may not use this file except in compliance with the License.
-You may obtain a copy of the License at
-
-    http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS,
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-See the License for the specific language governing permissions and
-limitations under the License.
-*/
-package cmd
-
-import (
-	"fmt"
-        nodepb "github.com/gravitl/netmaker/grpc"
-	"context"
-	"io"
-	"github.com/spf13/cobra"
-        "github.com/gravitl/netmaker/wcagent/functions"
-        "google.golang.org/grpc/metadata"
-        "google.golang.org/grpc"
-
-)
-
-// getpeersCmd represents the getpeers command
-var getpeersCmd = &cobra.Command{
-	Use:   "getpeers",
-	Short: "A brief description of your command",
-	Long: `A longer description that spans multiple lines and likely contains examples
-and usage of using your command. For example:
-
-Cobra is a CLI library for Go that empowers applications.
-This application is a tool to generate the needed files
-to quickly create a Cobra application.`,
-	SilenceUsage: true,
-        RunE: func(cmd *cobra.Command, args []string) error {
-                fmt.Println("read called")
-                group, err := cmd.Flags().GetString("group")
-                if err != nil {
-                        return err
-                }
-                req := &nodepb.GetPeersReq{
-                        Group: group,
-                }
-                ctx := context.Background()
-                ctx, err = functions.SetJWT(client)
-                if err != nil {
-                        return err
-                }
-
-                var header metadata.MD
-
-                stream, err := client.GetPeers(ctx, req, grpc.Header(&header))
-                if err != nil {
-                        return err
-                }
-                //fmt.Println(res)
-
-		for {
-			// stream.Recv returns a pointer to a ListBlogRes at the current iteration
-			res, err := stream.Recv()
-			// If end of stream, break the loop
-			if err == io.EOF {
-				break
-			}
-			// if err, return an error
-			if err != nil {
-				return err
-			}
-			// If everything went well use the generated getter to print the blog message
-			fmt.Println(res.Peers)
-		}
-
-                return nil
-        },
-}
-
-func init() {
-        getpeersCmd.Flags().StringP("group", "g", "", "The group of the node")
-        getpeersCmd.MarkFlagRequired("group")
-	rootCmd.AddCommand(getpeersCmd)
-
-	// Here you will define your flags and configuration settings.
-
-	// Cobra supports Persistent Flags which will work for this command
-	// and all subcommands, e.g.:
-	// getpeersCmd.PersistentFlags().String("foo", "", "A help for foo")
-
-	// Cobra supports local flags which will only run when this command
-	// is called directly, e.g.:
-	// getpeersCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
-}

+ 0 - 83
netclient/functions/old/login.go

@@ -1,83 +0,0 @@
-/*
-Copyright © 2021 NAME HERE <EMAIL ADDRESS>
-
-Licensed under the Apache License, Version 2.0 (the "License");
-you may not use this file except in compliance with the License.
-You may obtain a copy of the License at
-
-    http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS,
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-See the License for the specific language governing permissions and
-limitations under the License.
-*/
-package cmd
-
-import (
-	"fmt"
-	"os"
-	"encoding/json"
-	"io/ioutil"
-        nodepb "github.com/gravitl/netmaker/grpc"
-	"context"
-	"github.com/spf13/cobra"
-)
-
-// loginCmd represents the login command
-var loginCmd = &cobra.Command{
-	Use:   "login",
-	Short: "Get auth token",
-	Long: `Get auth token`,
-        SilenceUsage: true,
-	RunE: func(cmd *cobra.Command, args []string) error {
-                password, err := cmd.Flags().GetString("password")
-                macaddress, err := cmd.Flags().GetString("macaddress")
-                if err != nil {
-                        return err
-                }
-                home, err := os.UserHomeDir()
-		data := SetConfiguration{
-			MacAddress: macaddress,
-			Password: password,
-		}
-		file, err := json.MarshalIndent(data, "", " ")
-		err = ioutil.WriteFile(home + "/.wcconfig", file, 0644)
-		if err != nil {
-                        return err
-                }
-                login := &nodepb.LoginRequest{
-                        Password: password,
-                        Macaddress:    macaddress,
-                }
-    // RPC call
-                res, err := client.Login(context.TODO(), login)
-                if err != nil {
-                        return err
-                }
-                fmt.Printf("Token: %s\n", res.Accesstoken)
-		tokenstring := []byte(res.Accesstoken)
-		err = ioutil.WriteFile(home + "/.wctoken", tokenstring, 0644)
-		if err != nil {
-			return err
-		}
-                return err
-
-	},
-}
-
-func init() {
-
-        loginCmd.Flags().StringP("macaddress", "m", "", "The local macaddress")
-        loginCmd.Flags().StringP("password", "p", "", "The password")
-
-        loginCmd.MarkFlagRequired("password")
-        loginCmd.MarkFlagRequired("macaddress")
-	rootCmd.AddCommand(loginCmd)
-}
-
-type SetConfiguration struct {
-        MacAddress string
-        Password string
-}

+ 0 - 82
netclient/functions/old/read.go

@@ -1,82 +0,0 @@
-/*
-Copyright © 2021 NAME HERE <EMAIL ADDRESS>
-
-Licensed under the Apache License, Version 2.0 (the "License");
-you may not use this file except in compliance with the License.
-You may obtain a copy of the License at
-
-    http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS,
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-See the License for the specific language governing permissions and
-limitations under the License.
-*/
-package cmd
-
-import (
-	"fmt"
-	"context"
-	nodepb "github.com/gravitl/netmaker/grpc"
-	"github.com/gravitl/netmaker/wcagent/functions"
-	"github.com/spf13/cobra"
-        "google.golang.org/grpc/metadata"
-	"google.golang.org/grpc"
-)
-
-// readCmd represents the read command
-var readCmd = &cobra.Command{
-	Use:   "read",
-	Short: "Find a Node by its Mac Address",
-	Long: `Find a node by it's macaddress, stored in mongoDB.
-	
-	If no node is found with the corresponding MAC it will return a 'Not Found' error`,
-	SilenceUsage: true,
-	RunE: func(cmd *cobra.Command, args []string) error {
-		fmt.Println("read called")
-		macaddress, err := cmd.Flags().GetString("macaddress")
-                group, err := cmd.Flags().GetString("group")
-		if err != nil {
-			return err
-		}
-		req := &nodepb.ReadNodeReq{
-			Macaddress: macaddress,
-			Group: group,
-		}
-		ctx := context.Background()
-		ctx, err = functions.SetJWT(client)
-                if err != nil {
-                        return err
-                }
-
-		var header metadata.MD
-
-		res, err := client.ReadNode(ctx, req, grpc.Header(&header))
-		if err != nil {
-			return err
-		}
-		fmt.Println(res)
-		return nil
-	},
-}
-
-func init() {
-
-
-	readCmd.Flags().StringP("macaddress", "m", "", "The macaddress of the node")
-	readCmd.Flags().StringP("group", "g", "", "The group of the node")
-	readCmd.MarkFlagRequired("macaddress")
-	readCmd.MarkFlagRequired("group")
-	rootCmd.AddCommand(readCmd)
-
-	// Here you will define your flags and configuration settings.
-
-	// Cobra supports Persistent Flags which will work for this command
-	// and all subcommands, e.g.:
-	// readCmd.PersistentFlags().String("foo", "", "A help for foo")
-
-	// Cobra supports local flags which will only run when this command
-	// is called directly, e.g.:
-	// readCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
-}

+ 0 - 113
netclient/functions/old/root.go

@@ -1,113 +0,0 @@
-/*
-Copyright © 2021 NAME HERE <EMAIL ADDRESS>
-
-Licensed under the Apache License, Version 2.0 (the "License");
-you may not use this file except in compliance with the License.
-You may obtain a copy of the License at
-
-    http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS,
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-See the License for the specific language governing permissions and
-limitations under the License.
-*/
-package cmd
-
-import (
-  "fmt"
-  "os"
-  "github.com/spf13/cobra"
-  "context"
-  homedir "github.com/mitchellh/go-homedir"
-  "github.com/spf13/viper"
-  "time"
-  "log"
-  nodepb "github.com/gravitl/netmaker/grpc"
-  "google.golang.org/grpc"
-
-)
-
-
-var cfgFile string
-
-
-var client nodepb.NodeServiceClient
-var requestCtx context.Context
-var requestOpts grpc.DialOption
-
-// rootCmd represents the base command when called without any subcommands
-var rootCmd = &cobra.Command{
-  Use:   "grpc-test",
-  Short: "A test cli which may or may not turn into a real one",
-  Long: `huh. this isn't very long at all, is it?`,
-  // Uncomment the following line if your bare application
-  // has an action associated with it:
-  //	Run: func(cmd *cobra.Command, args []string) { },
-}
-
-// Execute adds all child commands to the root command and sets flags appropriately.
-// This is called by main.main(). It only needs to happen once to the rootCmd.
-func Execute() {
-  if err := rootCmd.Execute(); err != nil {
-    fmt.Println(err)
-    os.Exit(1)
-  }
-}
-
-func init() {
-  cobra.OnInitialize(initConfig)
-
-  // Here you will define your flags and configuration settings.
-  // Cobra supports persistent flags, which, if defined here,
-  // will be global for your application.
-
-	rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.blogclient.yaml)")
-
-	// Cobra also supports local flags, which will only run
-	// when this action is called directly.
-	rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
-
-  fmt.Println("Starting Node Service Client")
-
-  // Establish context to timeout after 10 seconds if server does not respond
-  requestCtx, _ = context.WithTimeout(context.Background(), 10*time.Second)
-  // Establish insecure grpc options (no TLS)
-  requestOpts = grpc.WithInsecure()
-  // Dial the server, returns a client connection
-  conn, err := grpc.Dial("localhost:50051", requestOpts)
-  if err != nil {
-	log.Fatalf("Unable to establish client connection to localhost:50051: %v", err)
-  }
-  // Instantiate the BlogServiceClient with our client connection to the server
-  client = nodepb.NewNodeServiceClient(conn)
-}
-
-
-// initConfig reads in config file and ENV variables if set.
-func initConfig() {
-  if cfgFile != "" {
-    // Use config file from the flag.
-    viper.SetConfigFile(cfgFile)
-  } else {
-    // Find home directory.
-    home, err := homedir.Dir()
-    if err != nil {
-      fmt.Println(err)
-      os.Exit(1)
-    }
-
-    // Search config in home directory with name ".grpc-test" (without extension).
-    viper.AddConfigPath(home)
-    viper.SetConfigName(".grpc-test")
-  }
-
-  viper.AutomaticEnv() // read in environment variables that match
-
-  // If a config file is found, read it in.
-  if err := viper.ReadInConfig(); err == nil {
-    fmt.Println("Using config file:", viper.ConfigFileUsed())
-  }
-}
-

+ 0 - 88
netclient/functions/old/update.go

@@ -1,88 +0,0 @@
-/*
-Copyright © 2021 NAME HERE <EMAIL ADDRESS>
-
-Licensed under the Apache License, Version 2.0 (the "License");
-you may not use this file except in compliance with the License.
-You may obtain a copy of the License at
-
-    http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS,
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-See the License for the specific language governing permissions and
-limitations under the License.
-*/
-package cmd
-
-import (
-	"fmt"
-        "context"
-        nodepb "github.com/gravitl/netmaker/grpc"
-	"github.com/spf13/cobra"
-        "github.com/gravitl/netmaker/wcagent/functions"
-        "google.golang.org/grpc/metadata"
-        "google.golang.org/grpc"
-
-)
-
-var updateCmd = &cobra.Command{
-	Use:   "update",
-	Short: "Find a Node by its Macaddress",
-	Long: `Find a node by it's mongoDB Unique macaddressentifier.
-
-	If no node is found for the Macaddress it will return a 'Not Found' error`,
-	SilenceUsage: true,
-	RunE: func(cmd *cobra.Command, args []string) error {
-		// Get the flags from CLI
-                nodegroup, err := cmd.Flags().GetString("nodegroup")
-                password, err := cmd.Flags().GetString("password")
-                macaddress, err := cmd.Flags().GetString("macaddress")
-                name, err := cmd.Flags().GetString("name")
-                listenport, err := cmd.Flags().GetInt32("listenport")
-                publickey, err := cmd.Flags().GetString("publickey")
-                endpoint, err := cmd.Flags().GetString("endpoint")
-		// Create an UpdateNodeRequest
-		node := &nodepb.Node{
-				Password: password,
-				Macaddress:    macaddress,
-				Nodegroup:  nodegroup,
-				Listenport: listenport,
-				Publickey: publickey,
-				Name: name,
-				Endpoint: endpoint,
-			}
-		req := &nodepb.UpdateNodeReq{
-				Node: node,
-			}
-                ctx := context.Background()
-                ctx, err = functions.SetJWT(client)
-                if err != nil {
-                        return err
-                }
-
-                var header metadata.MD
-
-		res, err := client.UpdateNode(ctx, req, grpc.Header(&header))
-		if err != nil {
-			return err
-		}
-
-		fmt.Println(res)
-		return nil
-	},
-}
-
-func init() {
-        updateCmd.Flags().StringP("name", "n", "", "The node name")
-        updateCmd.Flags().StringP("listenport", "l", "", "The wireguard port")
-        updateCmd.Flags().StringP("endpoint", "e", "", "The public IP")
-        updateCmd.Flags().StringP("macaddress", "m", "", "The local macaddress")
-        updateCmd.Flags().StringP("password", "p", "", "The password")
-        updateCmd.Flags().StringP("nodegroup", "g", "", "The group this will be added to")
-        updateCmd.Flags().StringP("publickey", "k", "", "The wireguard public key")
-        updateCmd.MarkFlagRequired("nodegroup")
-        updateCmd.MarkFlagRequired("password")
-        updateCmd.MarkFlagRequired("macaddress")
-	rootCmd.AddCommand(updateCmd)
-}

+ 14 - 3
netclient/main.go

@@ -34,7 +34,7 @@ func main() {
 	taccesskey := flag.String("k", "badkey", "an access key generated by the server and used for one-time access (install only)")
 	tserver := flag.String("s", "localhost:50051", "The location (including port) of the remote gRPC server.")
 	tgroup := flag.String("g", "badgroup", "The node group you are attempting to join.")
-	tnoauto := flag.Bool("na", false, "No auto mode. If true, wirecat will not be installed as a system service and you will have to retrieve updates manually via checkin command.")
+	tnoauto := flag.Bool("na", false, "No auto mode. If true, netmaker will not be installed as a system service and you will have to retrieve updates manually via checkin command.")
 	command := flag.String("c", "required", "The command to run")
 
 
@@ -51,10 +51,15 @@ func main() {
 			err := functions.Install(*taccesskey, *tpassword, *tserver, *tgroup, *tnoauto)
 			if err != nil {
 				fmt.Println("Error installing: ", err)
-				fmt.Println("Removing artifacts")
+				fmt.Println("Cleaning up (uninstall)")
 				err = functions.Remove()
 				if err != nil {
-					fmt.Println("Error removing artifacts: ", err)
+                                        fmt.Println("Error uninstalling: ", err)
+                                        fmt.Println("Wiping local.")
+					err = functions.WipeLocal()
+					if err != nil {
+						fmt.Println("Error removing artifacts: ", err)
+					}
 				}
 				os.Exit(1)
 			}
@@ -83,6 +88,12 @@ func main() {
                         fmt.Println("Beginning node cleanup.")
 			err := functions.Remove()
                         if err != nil {
+                                        fmt.Println("Error uninstalling: ", err)
+                                        fmt.Println("Wiping local.")
+                                        err = functions.WipeLocal()
+                                        if err != nil {
+                                                fmt.Println("Error removing artifacts: ", err)
+                                        }
                                 fmt.Println("Error deleting node: ", err)
                                 os.Exit(1)
                         }

+ 2 - 2
netclient/test/delscript.sh

@@ -3,8 +3,8 @@ sudo ip link del wc-skynet
 
 curl -X DELETE -H "Authorization: Bearer secretkey" -H 'Content-Type: application/json' localhost:8081/api/skynet/nodes/8c:89:a5:03:f0:d7 | jq
 
-sudo cp /root/.wcconfig.bkup /root/.wcconfig
-sudo rm /root/.wctoken
+sudo cp /root/.netconfig.bkup /root/.netconfig
+sudo rm /root/.nettoken
 sudo go run ./main.go remove
 
 sudo wg show