|
@@ -12,6 +12,7 @@ import (
|
|
"github.com/gravitl/netmaker/config"
|
|
"github.com/gravitl/netmaker/config"
|
|
)
|
|
)
|
|
|
|
|
|
|
|
+// SetHost - sets the host ip
|
|
func SetHost() error {
|
|
func SetHost() error {
|
|
remoteip, err := GetPublicIP()
|
|
remoteip, err := GetPublicIP()
|
|
if err != nil {
|
|
if err != nil {
|
|
@@ -20,6 +21,8 @@ func SetHost() error {
|
|
os.Setenv("SERVER_HOST", remoteip)
|
|
os.Setenv("SERVER_HOST", remoteip)
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+// GetServerConfig - gets the server config into memory from file or env
|
|
func GetServerConfig() config.ServerConfig {
|
|
func GetServerConfig() config.ServerConfig {
|
|
var cfg config.ServerConfig
|
|
var cfg config.ServerConfig
|
|
cfg.APIConnString = GetAPIConnString()
|
|
cfg.APIConnString = GetAPIConnString()
|
|
@@ -76,6 +79,8 @@ func GetServerConfig() config.ServerConfig {
|
|
|
|
|
|
return cfg
|
|
return cfg
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+// GetFrontendURL - gets the frontend url
|
|
func GetFrontendURL() string {
|
|
func GetFrontendURL() string {
|
|
var frontend = ""
|
|
var frontend = ""
|
|
if os.Getenv("FRONTEND_URL") != "" {
|
|
if os.Getenv("FRONTEND_URL") != "" {
|
|
@@ -86,6 +91,7 @@ func GetFrontendURL() string {
|
|
return frontend
|
|
return frontend
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// GetAPIConnString - gets the api connections string
|
|
func GetAPIConnString() string {
|
|
func GetAPIConnString() string {
|
|
conn := ""
|
|
conn := ""
|
|
if os.Getenv("SERVER_API_CONN_STRING") != "" {
|
|
if os.Getenv("SERVER_API_CONN_STRING") != "" {
|
|
@@ -95,6 +101,8 @@ func GetAPIConnString() string {
|
|
}
|
|
}
|
|
return conn
|
|
return conn
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+// GetVersion - version of netmaker
|
|
func GetVersion() string {
|
|
func GetVersion() string {
|
|
version := "0.8.5"
|
|
version := "0.8.5"
|
|
if config.Config.Server.Version != "" {
|
|
if config.Config.Server.Version != "" {
|
|
@@ -102,6 +110,8 @@ func GetVersion() string {
|
|
}
|
|
}
|
|
return version
|
|
return version
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+// GetDB - gets the database type
|
|
func GetDB() string {
|
|
func GetDB() string {
|
|
database := "sqlite"
|
|
database := "sqlite"
|
|
if os.Getenv("DATABASE") != "" {
|
|
if os.Getenv("DATABASE") != "" {
|
|
@@ -111,6 +121,8 @@ func GetDB() string {
|
|
}
|
|
}
|
|
return database
|
|
return database
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+// GetAPIHost - gets the api host
|
|
func GetAPIHost() string {
|
|
func GetAPIHost() string {
|
|
serverhost := "127.0.0.1"
|
|
serverhost := "127.0.0.1"
|
|
remoteip, _ := GetPublicIP()
|
|
remoteip, _ := GetPublicIP()
|
|
@@ -127,6 +139,8 @@ func GetAPIHost() string {
|
|
}
|
|
}
|
|
return serverhost
|
|
return serverhost
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+// GetPodIP - get the pod's ip
|
|
func GetPodIP() string {
|
|
func GetPodIP() string {
|
|
podip := "127.0.0.1"
|
|
podip := "127.0.0.1"
|
|
if os.Getenv("POD_IP") != "" {
|
|
if os.Getenv("POD_IP") != "" {
|
|
@@ -135,6 +149,7 @@ func GetPodIP() string {
|
|
return podip
|
|
return podip
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// GetAPIPort - gets the api port
|
|
func GetAPIPort() string {
|
|
func GetAPIPort() string {
|
|
apiport := "8081"
|
|
apiport := "8081"
|
|
if os.Getenv("API_PORT") != "" {
|
|
if os.Getenv("API_PORT") != "" {
|
|
@@ -145,6 +160,7 @@ func GetAPIPort() string {
|
|
return apiport
|
|
return apiport
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// GetCheckinInterval - get check in interval for nodes
|
|
func GetCheckinInterval() string {
|
|
func GetCheckinInterval() string {
|
|
seconds := "15"
|
|
seconds := "15"
|
|
if os.Getenv("CHECKIN_INTERVAL") != "" {
|
|
if os.Getenv("CHECKIN_INTERVAL") != "" {
|
|
@@ -155,6 +171,7 @@ func GetCheckinInterval() string {
|
|
return seconds
|
|
return seconds
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// GetDefaultNodeLimit - get node limit if one is set
|
|
func GetDefaultNodeLimit() int32 {
|
|
func GetDefaultNodeLimit() int32 {
|
|
var limit int32
|
|
var limit int32
|
|
limit = 999999999
|
|
limit = 999999999
|
|
@@ -166,6 +183,8 @@ func GetDefaultNodeLimit() int32 {
|
|
}
|
|
}
|
|
return limit
|
|
return limit
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+// GetGRPCConnString - get grpc conn string
|
|
func GetGRPCConnString() string {
|
|
func GetGRPCConnString() string {
|
|
conn := ""
|
|
conn := ""
|
|
if os.Getenv("SERVER_GRPC_CONN_STRING") != "" {
|
|
if os.Getenv("SERVER_GRPC_CONN_STRING") != "" {
|
|
@@ -176,6 +195,7 @@ func GetGRPCConnString() string {
|
|
return conn
|
|
return conn
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// GetCoreDNSAddr - gets the core dns address
|
|
func GetCoreDNSAddr() string {
|
|
func GetCoreDNSAddr() string {
|
|
addr, _ := GetPublicIP()
|
|
addr, _ := GetPublicIP()
|
|
if os.Getenv("COREDNS_ADDR") != "" {
|
|
if os.Getenv("COREDNS_ADDR") != "" {
|
|
@@ -186,6 +206,7 @@ func GetCoreDNSAddr() string {
|
|
return addr
|
|
return addr
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// GetGRPCHost - get the grpc host url
|
|
func GetGRPCHost() string {
|
|
func GetGRPCHost() string {
|
|
serverhost := "127.0.0.1"
|
|
serverhost := "127.0.0.1"
|
|
remoteip, _ := GetPublicIP()
|
|
remoteip, _ := GetPublicIP()
|
|
@@ -202,6 +223,8 @@ func GetGRPCHost() string {
|
|
}
|
|
}
|
|
return serverhost
|
|
return serverhost
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+// GetGRPCPort - gets the grpc port
|
|
func GetGRPCPort() string {
|
|
func GetGRPCPort() string {
|
|
grpcport := "50051"
|
|
grpcport := "50051"
|
|
if os.Getenv("GRPC_PORT") != "" {
|
|
if os.Getenv("GRPC_PORT") != "" {
|
|
@@ -211,6 +234,8 @@ func GetGRPCPort() string {
|
|
}
|
|
}
|
|
return grpcport
|
|
return grpcport
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+// GetMasterKey - gets the configured master key of server
|
|
func GetMasterKey() string {
|
|
func GetMasterKey() string {
|
|
key := "secretkey"
|
|
key := "secretkey"
|
|
if os.Getenv("MASTER_KEY") != "" {
|
|
if os.Getenv("MASTER_KEY") != "" {
|
|
@@ -220,6 +245,8 @@ func GetMasterKey() string {
|
|
}
|
|
}
|
|
return key
|
|
return key
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+// GetAllowedOrigin - get the allowed origin
|
|
func GetAllowedOrigin() string {
|
|
func GetAllowedOrigin() string {
|
|
allowedorigin := "*"
|
|
allowedorigin := "*"
|
|
if os.Getenv("CORS_ALLOWED_ORIGIN") != "" {
|
|
if os.Getenv("CORS_ALLOWED_ORIGIN") != "" {
|
|
@@ -229,6 +256,8 @@ func GetAllowedOrigin() string {
|
|
}
|
|
}
|
|
return allowedorigin
|
|
return allowedorigin
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+// IsRestBackend - checks if rest is on or off
|
|
func IsRestBackend() bool {
|
|
func IsRestBackend() bool {
|
|
isrest := true
|
|
isrest := true
|
|
if os.Getenv("REST_BACKEND") != "" {
|
|
if os.Getenv("REST_BACKEND") != "" {
|
|
@@ -242,6 +271,8 @@ func IsRestBackend() bool {
|
|
}
|
|
}
|
|
return isrest
|
|
return isrest
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+// IsAgentBackend - checks if agent backed is on or off
|
|
func IsAgentBackend() bool {
|
|
func IsAgentBackend() bool {
|
|
isagent := true
|
|
isagent := true
|
|
if os.Getenv("AGENT_BACKEND") != "" {
|
|
if os.Getenv("AGENT_BACKEND") != "" {
|
|
@@ -255,6 +286,8 @@ func IsAgentBackend() bool {
|
|
}
|
|
}
|
|
return isagent
|
|
return isagent
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+// IsClientMode - checks if it should run in client mode
|
|
func IsClientMode() string {
|
|
func IsClientMode() string {
|
|
isclient := "on"
|
|
isclient := "on"
|
|
if os.Getenv("CLIENT_MODE") != "" {
|
|
if os.Getenv("CLIENT_MODE") != "" {
|
|
@@ -274,6 +307,8 @@ func IsClientMode() string {
|
|
}
|
|
}
|
|
return isclient
|
|
return isclient
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+// IsDNSMode - should it run with DNS
|
|
func IsDNSMode() bool {
|
|
func IsDNSMode() bool {
|
|
isdns := true
|
|
isdns := true
|
|
if os.Getenv("DNS_MODE") != "" {
|
|
if os.Getenv("DNS_MODE") != "" {
|
|
@@ -288,6 +323,7 @@ func IsDNSMode() bool {
|
|
return isdns
|
|
return isdns
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// IsGRPCSSL - ssl grpc on or off
|
|
func IsGRPCSSL() bool {
|
|
func IsGRPCSSL() bool {
|
|
isssl := false
|
|
isssl := false
|
|
if os.Getenv("GRPC_SSL") != "" {
|
|
if os.Getenv("GRPC_SSL") != "" {
|
|
@@ -302,6 +338,7 @@ func IsGRPCSSL() bool {
|
|
return isssl
|
|
return isssl
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// DisableRemoteIPCheck - disable the remote ip check
|
|
func DisableRemoteIPCheck() bool {
|
|
func DisableRemoteIPCheck() bool {
|
|
disabled := false
|
|
disabled := false
|
|
if os.Getenv("DISABLE_REMOTE_IP_CHECK") != "" {
|
|
if os.Getenv("DISABLE_REMOTE_IP_CHECK") != "" {
|
|
@@ -315,6 +352,8 @@ func DisableRemoteIPCheck() bool {
|
|
}
|
|
}
|
|
return disabled
|
|
return disabled
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+// DisableDefaultNet - disable default net
|
|
func DisableDefaultNet() bool {
|
|
func DisableDefaultNet() bool {
|
|
disabled := false
|
|
disabled := false
|
|
if os.Getenv("DISABLE_DEFAULT_NET") != "" {
|
|
if os.Getenv("DISABLE_DEFAULT_NET") != "" {
|
|
@@ -328,6 +367,8 @@ func DisableDefaultNet() bool {
|
|
}
|
|
}
|
|
return disabled
|
|
return disabled
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+// GetPublicIP - gets public ip
|
|
func GetPublicIP() (string, error) {
|
|
func GetPublicIP() (string, error) {
|
|
|
|
|
|
endpoint := ""
|
|
endpoint := ""
|
|
@@ -354,6 +395,8 @@ func GetPublicIP() (string, error) {
|
|
}
|
|
}
|
|
return endpoint, err
|
|
return endpoint, err
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+// GetVerbose - get the verbosity of server
|
|
func GetVerbose() int32 {
|
|
func GetVerbose() int32 {
|
|
level, err := strconv.Atoi(os.Getenv("VERBOSITY"))
|
|
level, err := strconv.Atoi(os.Getenv("VERBOSITY"))
|
|
if err != nil || level < 0 {
|
|
if err != nil || level < 0 {
|
|
@@ -365,6 +408,7 @@ func GetVerbose() int32 {
|
|
return int32(level)
|
|
return int32(level)
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// GetPlatform - get the system type of server
|
|
func GetPlatform() string {
|
|
func GetPlatform() string {
|
|
platform := "linux"
|
|
platform := "linux"
|
|
if os.Getenv("PLATFORM") != "" {
|
|
if os.Getenv("PLATFORM") != "" {
|
|
@@ -375,6 +419,7 @@ func GetPlatform() string {
|
|
return platform
|
|
return platform
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// GetSQLConn - get the sql connection string
|
|
func GetSQLConn() string {
|
|
func GetSQLConn() string {
|
|
sqlconn := "http://"
|
|
sqlconn := "http://"
|
|
if os.Getenv("SQL_CONN") != "" {
|
|
if os.Getenv("SQL_CONN") != "" {
|
|
@@ -385,6 +430,7 @@ func GetSQLConn() string {
|
|
return sqlconn
|
|
return sqlconn
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// IsSplitDNS - checks if split dns is on
|
|
func IsSplitDNS() bool {
|
|
func IsSplitDNS() bool {
|
|
issplit := false
|
|
issplit := false
|
|
if os.Getenv("IS_SPLIT_DNS") == "yes" {
|
|
if os.Getenv("IS_SPLIT_DNS") == "yes" {
|
|
@@ -395,6 +441,7 @@ func IsSplitDNS() bool {
|
|
return issplit
|
|
return issplit
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// GetNodeID - gets the node id
|
|
func GetNodeID() string {
|
|
func GetNodeID() string {
|
|
var id string
|
|
var id string
|
|
id = getMacAddr()
|
|
id = getMacAddr()
|
|
@@ -406,6 +453,7 @@ func GetNodeID() string {
|
|
return id
|
|
return id
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// GetServerCheckinInterval - gets the server check-in time
|
|
func GetServerCheckinInterval() int64 {
|
|
func GetServerCheckinInterval() int64 {
|
|
var t = int64(5)
|
|
var t = int64(5)
|
|
var envt, _ = strconv.Atoi(os.Getenv("SERVER_CHECKIN_INTERVAL"))
|
|
var envt, _ = strconv.Atoi(os.Getenv("SERVER_CHECKIN_INTERVAL"))
|