Browse Source

added version and fixed script and doc stuff

worker-9 4 years ago
parent
commit
9d2962a171

+ 3 - 0
.gitignore

@@ -1,4 +1,7 @@
 netmaker
 netclient/netclient
 netclient/files/netclient
+netclient/netclient-amd64
+netclient/netclient-arm
+netclient/netclient-arm64
 config/dnsconfig/

+ 1 - 0
compose/docker-compose.quickstart.yml

@@ -54,6 +54,7 @@ services:
       - "8082:80"
     environment:
       BACKEND_URL: "https://api.NETMAKER_BASE_DOMAIN"
+    restart: always
   coredns:
     depends_on:
       - netmaker 

+ 2 - 1
config/config.go

@@ -42,7 +42,6 @@ type ServerConfig struct {
 	GRPCHost             string `yaml:"grpchost"`
 	GRPCPort             string `yaml:"grpcport"`
 	GRPCSecure           string `yaml:"grpcsecure"`
-	DefaultNodeLimit     int32  `yaml:"defaultnodelimit"`
 	MasterKey            string `yaml:"masterkey"`
 	AllowedOrigin        string `yaml:"allowedorigin"`
 	RestBackend          string `yaml:"restbackend"`
@@ -52,6 +51,8 @@ type ServerConfig struct {
 	DisableRemoteIPCheck string `yaml:"disableremoteipcheck"`
 	DisableDefaultNet    string `yaml:"disabledefaultnet"`
 	GRPCSSL              string `yaml:"grpcssl"`
+	Version              string `yaml:"version"`
+	DefaultNodeLimit     int32  `yaml:"defaultnodelimit"`
 	Verbosity            int32  `yaml:"verbosity"`
 }
 

+ 2 - 1
config/environments/dev.yaml

@@ -9,4 +9,5 @@ server:
   agentbackend: "" # defaults to "on" or AGENT_BACKEND (if set)
   clientmode: "" # defaults to "on" or CLIENT_MODE (if set)
   dnsmode: "" # defaults to "on" or DNS_MODE (if set)
-  disableremoteipcheck: "" # defaults to "false" or DISABLE_REMOTE_IP_CHECK (if set)
+  disableremoteipcheck: "" # defaults to "false" or DISABLE_REMOTE_IP_CHECK (if set)
+  version: "0.7.1" # version of server

+ 58 - 56
controllers/serverHttpController.go

@@ -1,20 +1,21 @@
 package controller
 
 import (
-    "github.com/gravitl/netmaker/models"
-    "github.com/gravitl/netmaker/functions"
-    "github.com/gravitl/netmaker/serverctl"
-    "github.com/gravitl/netmaker/servercfg"
-    "encoding/json"
-    "strings"
-    "net/http"
-    "github.com/gorilla/mux"
+	"encoding/json"
+	"net/http"
+	"strings"
+
+	"github.com/gorilla/mux"
+	"github.com/gravitl/netmaker/functions"
+	"github.com/gravitl/netmaker/models"
+	"github.com/gravitl/netmaker/servercfg"
+	"github.com/gravitl/netmaker/serverctl"
 )
 
 func serverHandlers(r *mux.Router) {
-    r.HandleFunc("/api/server/addnetwork/{network}", securityCheckServer(true, http.HandlerFunc(addNetwork))).Methods("POST")
-    r.HandleFunc("/api/server/getconfig", securityCheckServer(false, http.HandlerFunc(getConfig))).Methods("GET")
-    r.HandleFunc("/api/server/removenetwork/{network}", securityCheckServer(true, http.HandlerFunc(removeNetwork))).Methods("DELETE")
+	r.HandleFunc("/api/server/addnetwork/{network}", securityCheckServer(true, http.HandlerFunc(addNetwork))).Methods("POST")
+	r.HandleFunc("/api/server/getconfig", securityCheckServer(false, http.HandlerFunc(getConfig))).Methods("GET")
+	r.HandleFunc("/api/server/removenetwork/{network}", securityCheckServer(true, http.HandlerFunc(removeNetwork))).Methods("DELETE")
 }
 
 //Security check is middleware for every function and just checks to make sure that its the master calling
@@ -29,65 +30,66 @@ func securityCheckServer(adminonly bool, next http.Handler) http.HandlerFunc {
 		bearerToken := r.Header.Get("Authorization")
 
 		var tokenSplit = strings.Split(bearerToken, " ")
-		var  authToken = ""
+		var authToken = ""
 		if len(tokenSplit) < 2 {
-                      errorResponse = models.ErrorResponse{
-                                Code: http.StatusUnauthorized, Message: "W1R3: You are unauthorized to access this endpoint.",
-                      }
-                      returnErrorResponse(w, r, errorResponse)
-			return 
-	        } else {
+			errorResponse = models.ErrorResponse{
+				Code: http.StatusUnauthorized, Message: "W1R3: You are unauthorized to access this endpoint.",
+			}
+			returnErrorResponse(w, r, errorResponse)
+			return
+		} else {
 			authToken = tokenSplit[1]
 		}
 		//all endpoints here require master so not as complicated
 		//still might not be a good  way of doing this
-                user, _, isadmin, err := functions.VerifyUserToken(authToken)
-                errorResponse = models.ErrorResponse{
-                        Code: http.StatusUnauthorized, Message: "W1R3: You are unauthorized to access this endpoint.",
-                }
-                if !adminonly && (err != nil || user == "") {
-                        returnErrorResponse(w, r, errorResponse)
-                }
+		user, _, isadmin, err := functions.VerifyUserToken(authToken)
+		errorResponse = models.ErrorResponse{
+			Code: http.StatusUnauthorized, Message: "W1R3: You are unauthorized to access this endpoint.",
+		}
+		if !adminonly && (err != nil || user == "") {
+			returnErrorResponse(w, r, errorResponse)
+		}
 		if !isadmin && !authenticateMasterServer(authToken) {
-                        returnErrorResponse(w, r, errorResponse)
-                }
+			returnErrorResponse(w, r, errorResponse)
+		}
 		next.ServeHTTP(w, r)
 	}
 }
+
 //Consider a more secure way of setting master key
 func authenticateMasterServer(tokenString string) bool {
-    if tokenString == servercfg.GetMasterKey() {
-        return true
-    }
-    return false
+	if tokenString == servercfg.GetMasterKey() {
+		return true
+	}
+	return false
 }
 
 func removeNetwork(w http.ResponseWriter, r *http.Request) {
-        // Set header
-        w.Header().Set("Content-Type", "application/json")
+	// Set header
+	w.Header().Set("Content-Type", "application/json")
 
-        // get params
-        var params = mux.Vars(r)
+	// get params
+	var params = mux.Vars(r)
 
-        success, err := serverctl.RemoveNetwork(params["network"])
+	success, err := serverctl.RemoveNetwork(params["network"])
 
-        if err != nil || !success {
-                json.NewEncoder(w).Encode("Could not remove server from network " + params["network"])
-                return
-        }
+	if err != nil || !success {
+		json.NewEncoder(w).Encode("Could not remove server from network " + params["network"])
+		return
+	}
 
-        json.NewEncoder(w).Encode("Server removed from network " + params["network"])
+	json.NewEncoder(w).Encode("Server removed from network " + params["network"])
 }
 
 func getConfig(w http.ResponseWriter, r *http.Request) {
 	// Set header
-        w.Header().Set("Content-Type", "application/json")
+	w.Header().Set("Content-Type", "application/json")
 
-        // get params
+	// get params
 
-        scfg := servercfg.GetServerConfig()
-        w.WriteHeader(http.StatusOK)
-        json.NewEncoder(w).Encode(scfg)
+	scfg := servercfg.GetServerConfig()
+	w.WriteHeader(http.StatusOK)
+	json.NewEncoder(w).Encode(scfg)
 }
 
 /*
@@ -104,18 +106,18 @@ func getMongoConfig(w http.ResponseWriter, r *http.Request) {
 */
 
 func addNetwork(w http.ResponseWriter, r *http.Request) {
-        // Set header
-        w.Header().Set("Content-Type", "application/json")
+	// Set header
+	w.Header().Set("Content-Type", "application/json")
 
-        // get params
-        var params = mux.Vars(r)
+	// get params
+	var params = mux.Vars(r)
 
-        success, err := serverctl.AddNetwork(params["network"])
+	success, err := serverctl.AddNetwork(params["network"])
 
-        if err != nil || !success {
-                json.NewEncoder(w).Encode("Could not add server to network " + params["network"])
-                return
-        }
+	if err != nil || !success {
+		json.NewEncoder(w).Encode("Could not add server to network " + params["network"])
+		return
+	}
 
-        json.NewEncoder(w).Encode("Server added to network " + params["network"])
+	json.NewEncoder(w).Encode("Server added to network " + params["network"])
 }

+ 1 - 1
docs/server-installation.rst

@@ -175,7 +175,7 @@ This template is equivalent but omits CoreDNS.
 Linux Install without Docker
 =============================
 
-Most systems support Docker, but some, such as LXC, do not. In such environments, there are many options for installing Netmaker. Netmaker is available as a binary file, and there is a zip file of the Netmaker UI static HTML on GitHub. Beyond the UI and Server, you need to install MongoDB and CoreDNS (optional). 
+Most systems support Docker, but some do not. In such environments, there are many options for installing Netmaker. Netmaker is available as a binary file, and there is a zip file of the Netmaker UI static HTML on GitHub. Beyond the UI and Server, you need to install MongoDB and CoreDNS (optional). 
 
 To start, we recommend following the Nginx instructions in the :doc:`Quick Install <./quick-start>` guide to enable SSL for your environment.
 

+ 8 - 1
docs/troubleshoot.rst

@@ -62,7 +62,7 @@ UI
 **Can I have multiple nodes with the same name?**
   Yes, nodes can share names without issue. It may just be harder on you to know which is which.
 
-Agent
+Netclient
 -------
 **How do I connect a node to my Netmaker network with Netclient?**
   First get your access token (not just access key), then run ``sudo netclient join -t <access token>``.
@@ -83,6 +83,13 @@ Agent
 **I am done with the agent on my machine, can I uninstall it?**
   Yes, on the node simply run ``sudo /etc/netclient/netclient uninstall``. 
 
+**I am running SELinux and when I reboot my node I get a permission denied in my netclient logs and it doesn't connect anymore, why?**
+  If you're running SELinux, it will interfere with systemd's ability to restart the client properly. Therefore, please run the following:
+  .. code-block::
+  
+    sudo semanage fcontext -a -t bin_t '/etc/netclient/netclient' 
+    sudo chcon -Rv -u system_u -t bin_t '/etc/netclient/netclient' 
+    sudo restorecon -R -v /etc/netclient/netclient
 
 CoreDNS
 --------

BIN
netclient/netclient-amd64


BIN
netclient/netclient-arm


BIN
netclient/netclient-arm64


+ 1 - 1
scripts/netclient-install.sh

@@ -8,7 +8,7 @@ fi
 
 [ -z "$KEY" ] && KEY=nokey;
 
-wget -O netclient https://github.com/gravitl/netmaker/releases/download/v0.7/netclient
+wget -O netclient https://github.com/gravitl/netmaker/releases/download/v0.7.1/netclient
 chmod +x netclient
 sudo ./netclient join -t $KEY
 rm -f netclient

+ 15 - 7
servercfg/serverconf.go

@@ -58,6 +58,7 @@ func GetServerConfig() config.ServerConfig {
 	if DisableDefaultNet() {
 		cfg.DisableRemoteIPCheck = "on"
 	}
+	cfg.Version = GetVersion()
 	return cfg
 }
 func GetAPIConnString() string {
@@ -69,6 +70,13 @@ func GetAPIConnString() string {
 	}
 	return conn
 }
+func GetVersion() string {
+	version := "0.7.1"
+	if config.Config.Server.Version != "" {
+		version = config.Config.Server.Version
+	}
+	return version
+}
 func GetAPIHost() string {
 	serverhost := "127.0.0.1"
 	remoteip, _ := GetPublicIP()
@@ -117,13 +125,13 @@ func GetGRPCConnString() string {
 }
 
 func GetCoreDNSAddr() string {
-        addr, _ := GetPublicIP()
-        if os.Getenv("COREDNS_ADDR") != ""  {
-                addr = os.Getenv("COREDNS_ADDR")
-        } else if config.Config.Server.CoreDNSAddr != "" {
-                addr = config.Config.Server.GRPCConnString
-        }
-        return addr
+	addr, _ := GetPublicIP()
+	if os.Getenv("COREDNS_ADDR") != "" {
+		addr = os.Getenv("COREDNS_ADDR")
+	} else if config.Config.Server.CoreDNSAddr != "" {
+		addr = config.Config.Server.GRPCConnString
+	}
+	return addr
 }
 
 func GetGRPCHost() string {