serverconf.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710
  1. package servercfg
  2. import (
  3. "errors"
  4. "io"
  5. "net/http"
  6. "os"
  7. "strconv"
  8. "strings"
  9. "time"
  10. "github.com/gravitl/netmaker/config"
  11. "github.com/gravitl/netmaker/models"
  12. )
  13. // EmqxBrokerType denotes the broker type for EMQX MQTT
  14. const EmqxBrokerType = "emqx"
  15. var (
  16. Version = "dev"
  17. Is_EE = false
  18. )
  19. // SetHost - sets the host ip
  20. func SetHost() error {
  21. remoteip, err := GetPublicIP()
  22. if err != nil {
  23. return err
  24. }
  25. os.Setenv("SERVER_HOST", remoteip)
  26. return nil
  27. }
  28. // GetServerConfig - gets the server config into memory from file or env
  29. func GetServerConfig() config.ServerConfig {
  30. var cfg config.ServerConfig
  31. cfg.APIConnString = GetAPIConnString()
  32. cfg.CoreDNSAddr = GetCoreDNSAddr()
  33. cfg.APIHost = GetAPIHost()
  34. cfg.APIPort = GetAPIPort()
  35. cfg.MasterKey = "(hidden)"
  36. cfg.DNSKey = "(hidden)"
  37. cfg.AllowedOrigin = GetAllowedOrigin()
  38. cfg.RestBackend = "off"
  39. cfg.NodeID = GetNodeID()
  40. cfg.BrokerType = GetBrokerType()
  41. cfg.EmqxRestEndpoint = GetEmqxRestEndpoint()
  42. if AutoUpdateEnabled() {
  43. cfg.NetclientAutoUpdate = "enabled"
  44. } else {
  45. cfg.NetclientAutoUpdate = "disabled"
  46. }
  47. if EndpointDetectionEnabled() {
  48. cfg.NetclientEndpointDetection = "enabled"
  49. } else {
  50. cfg.NetclientEndpointDetection = "disabled"
  51. }
  52. if IsRestBackend() {
  53. cfg.RestBackend = "on"
  54. }
  55. cfg.DNSMode = "off"
  56. if IsDNSMode() {
  57. cfg.DNSMode = "on"
  58. }
  59. cfg.DisplayKeys = "off"
  60. if IsDisplayKeys() {
  61. cfg.DisplayKeys = "on"
  62. }
  63. cfg.DisableRemoteIPCheck = "off"
  64. if DisableRemoteIPCheck() {
  65. cfg.DisableRemoteIPCheck = "on"
  66. }
  67. cfg.Database = GetDB()
  68. cfg.Platform = GetPlatform()
  69. cfg.Version = GetVersion()
  70. // == auth config ==
  71. var authInfo = GetAuthProviderInfo()
  72. cfg.AuthProvider = authInfo[0]
  73. cfg.ClientID = authInfo[1]
  74. cfg.ClientSecret = authInfo[2]
  75. cfg.FrontendURL = GetFrontendURL()
  76. cfg.Telemetry = Telemetry()
  77. cfg.Server = GetServer()
  78. cfg.Verbosity = GetVerbosity()
  79. cfg.IsEE = "no"
  80. if Is_EE {
  81. cfg.IsEE = "yes"
  82. }
  83. return cfg
  84. }
  85. // GetServerConfig - gets the server config into memory from file or env
  86. func GetServerInfo() models.ServerConfig {
  87. var cfg models.ServerConfig
  88. cfg.Server = GetServer()
  89. cfg.MQUserName = GetMqUserName()
  90. cfg.MQPassword = GetMqPassword()
  91. cfg.API = GetAPIConnString()
  92. cfg.CoreDNSAddr = GetCoreDNSAddr()
  93. cfg.APIPort = GetAPIPort()
  94. cfg.DNSMode = "off"
  95. cfg.Broker = GetPublicBrokerEndpoint()
  96. if IsDNSMode() {
  97. cfg.DNSMode = "on"
  98. }
  99. cfg.Version = GetVersion()
  100. cfg.Is_EE = Is_EE
  101. cfg.TurnDomain = GetTurnHost()
  102. cfg.TurnPort = GetTurnPort()
  103. cfg.UseTurn = IsUsingTurn()
  104. cfg.EndpointDetection = EndpointDetectionEnabled()
  105. return cfg
  106. }
  107. // GetTurnHost - fetches the turn host domain
  108. func GetTurnHost() string {
  109. turnServer := ""
  110. if os.Getenv("TURN_SERVER_HOST") != "" {
  111. turnServer = os.Getenv("TURN_SERVER_HOST")
  112. } else if config.Config.Server.TurnServer != "" {
  113. turnServer = config.Config.Server.TurnServer
  114. }
  115. return turnServer
  116. }
  117. // IsUsingTurn - check if server has turn configured
  118. func IsUsingTurn() (b bool) {
  119. if os.Getenv("USE_TURN") != "" {
  120. b = os.Getenv("USE_TURN") == "true"
  121. } else {
  122. b = config.Config.Server.UseTurn
  123. }
  124. return
  125. }
  126. // GetTurnApiHost - fetches the turn api host domain
  127. func GetTurnApiHost() string {
  128. turnApiServer := ""
  129. if os.Getenv("TURN_SERVER_API_HOST") != "" {
  130. turnApiServer = os.Getenv("TURN_SERVER_API_HOST")
  131. } else if config.Config.Server.TurnApiServer != "" {
  132. turnApiServer = config.Config.Server.TurnApiServer
  133. }
  134. return turnApiServer
  135. }
  136. // GetFrontendURL - gets the frontend url
  137. func GetFrontendURL() string {
  138. var frontend = ""
  139. if os.Getenv("FRONTEND_URL") != "" {
  140. frontend = os.Getenv("FRONTEND_URL")
  141. } else if config.Config.Server.FrontendURL != "" {
  142. frontend = config.Config.Server.FrontendURL
  143. }
  144. return frontend
  145. }
  146. // GetAPIConnString - gets the api connections string
  147. func GetAPIConnString() string {
  148. conn := ""
  149. if os.Getenv("SERVER_API_CONN_STRING") != "" {
  150. conn = os.Getenv("SERVER_API_CONN_STRING")
  151. } else if config.Config.Server.APIConnString != "" {
  152. conn = config.Config.Server.APIConnString
  153. }
  154. return conn
  155. }
  156. // SetVersion - set version of netmaker
  157. func SetVersion(v string) {
  158. Version = v
  159. }
  160. // GetVersion - version of netmaker
  161. func GetVersion() string {
  162. return Version
  163. }
  164. // GetDB - gets the database type
  165. func GetDB() string {
  166. database := "sqlite"
  167. if os.Getenv("DATABASE") != "" {
  168. database = os.Getenv("DATABASE")
  169. } else if config.Config.Server.Database != "" {
  170. database = config.Config.Server.Database
  171. }
  172. return database
  173. }
  174. // GetAPIHost - gets the api host
  175. func GetAPIHost() string {
  176. serverhost := "127.0.0.1"
  177. remoteip, _ := GetPublicIP()
  178. if os.Getenv("SERVER_HTTP_HOST") != "" {
  179. serverhost = os.Getenv("SERVER_HTTP_HOST")
  180. } else if config.Config.Server.APIHost != "" {
  181. serverhost = config.Config.Server.APIHost
  182. } else if os.Getenv("SERVER_HOST") != "" {
  183. serverhost = os.Getenv("SERVER_HOST")
  184. } else {
  185. if remoteip != "" {
  186. serverhost = remoteip
  187. }
  188. }
  189. return serverhost
  190. }
  191. // GetAPIPort - gets the api port
  192. func GetAPIPort() string {
  193. apiport := "8081"
  194. if os.Getenv("API_PORT") != "" {
  195. apiport = os.Getenv("API_PORT")
  196. } else if config.Config.Server.APIPort != "" {
  197. apiport = config.Config.Server.APIPort
  198. }
  199. return apiport
  200. }
  201. // GetCoreDNSAddr - gets the core dns address
  202. func GetCoreDNSAddr() string {
  203. addr, _ := GetPublicIP()
  204. if os.Getenv("COREDNS_ADDR") != "" {
  205. addr = os.Getenv("COREDNS_ADDR")
  206. } else if config.Config.Server.CoreDNSAddr != "" {
  207. addr = config.Config.Server.CoreDNSAddr
  208. }
  209. return addr
  210. }
  211. // GetPublicBrokerEndpoint - returns the public broker endpoint which shall be used by netclient
  212. func GetPublicBrokerEndpoint() string {
  213. if os.Getenv("BROKER_ENDPOINT") != "" {
  214. return os.Getenv("BROKER_ENDPOINT")
  215. } else {
  216. return config.Config.Server.Broker
  217. }
  218. }
  219. // GetMessageQueueEndpoint - gets the message queue endpoint
  220. func GetMessageQueueEndpoint() (string, bool) {
  221. host, _ := GetPublicIP()
  222. if os.Getenv("SERVER_BROKER_ENDPOINT") != "" {
  223. host = os.Getenv("SERVER_BROKER_ENDPOINT")
  224. } else if config.Config.Server.ServerBrokerEndpoint != "" {
  225. host = config.Config.Server.ServerBrokerEndpoint
  226. } else if os.Getenv("BROKER_ENDPOINT") != "" {
  227. host = os.Getenv("BROKER_ENDPOINT")
  228. } else if config.Config.Server.Broker != "" {
  229. host = config.Config.Server.Broker
  230. } else {
  231. host += ":1883" // default
  232. }
  233. return host, strings.Contains(host, "wss") || strings.Contains(host, "ssl") || strings.Contains(host, "mqtts")
  234. }
  235. // GetBrokerType - returns the type of MQ broker
  236. func GetBrokerType() string {
  237. if os.Getenv("BROKER_TYPE") != "" {
  238. return os.Getenv("BROKER_TYPE")
  239. } else {
  240. return "mosquitto"
  241. }
  242. }
  243. // GetMasterKey - gets the configured master key of server
  244. func GetMasterKey() string {
  245. key := ""
  246. if os.Getenv("MASTER_KEY") != "" {
  247. key = os.Getenv("MASTER_KEY")
  248. } else if config.Config.Server.MasterKey != "" {
  249. key = config.Config.Server.MasterKey
  250. }
  251. return key
  252. }
  253. // GetDNSKey - gets the configured dns key of server
  254. func GetDNSKey() string {
  255. key := ""
  256. if os.Getenv("DNS_KEY") != "" {
  257. key = os.Getenv("DNS_KEY")
  258. } else if config.Config.Server.DNSKey != "" {
  259. key = config.Config.Server.DNSKey
  260. }
  261. return key
  262. }
  263. // GetAllowedOrigin - get the allowed origin
  264. func GetAllowedOrigin() string {
  265. allowedorigin := "*"
  266. if os.Getenv("CORS_ALLOWED_ORIGIN") != "" {
  267. allowedorigin = os.Getenv("CORS_ALLOWED_ORIGIN")
  268. } else if config.Config.Server.AllowedOrigin != "" {
  269. allowedorigin = config.Config.Server.AllowedOrigin
  270. }
  271. return allowedorigin
  272. }
  273. // IsRestBackend - checks if rest is on or off
  274. func IsRestBackend() bool {
  275. isrest := true
  276. if os.Getenv("REST_BACKEND") != "" {
  277. if os.Getenv("REST_BACKEND") == "off" {
  278. isrest = false
  279. }
  280. } else if config.Config.Server.RestBackend != "" {
  281. if config.Config.Server.RestBackend == "off" {
  282. isrest = false
  283. }
  284. }
  285. return isrest
  286. }
  287. // IsMetricsExporter - checks if metrics exporter is on or off
  288. func IsMetricsExporter() bool {
  289. export := false
  290. if os.Getenv("METRICS_EXPORTER") != "" {
  291. if os.Getenv("METRICS_EXPORTER") == "on" {
  292. export = true
  293. }
  294. } else if config.Config.Server.MetricsExporter != "" {
  295. if config.Config.Server.MetricsExporter == "on" {
  296. export = true
  297. }
  298. }
  299. return export
  300. }
  301. // Telemetry - checks if telemetry data should be sent
  302. func Telemetry() string {
  303. telemetry := "on"
  304. if os.Getenv("TELEMETRY") == "off" {
  305. telemetry = "off"
  306. }
  307. if config.Config.Server.Telemetry == "off" {
  308. telemetry = "off"
  309. }
  310. return telemetry
  311. }
  312. // GetServer - gets the server name
  313. func GetServer() string {
  314. server := ""
  315. if os.Getenv("SERVER_NAME") != "" {
  316. server = os.Getenv("SERVER_NAME")
  317. } else if config.Config.Server.Server != "" {
  318. server = config.Config.Server.Server
  319. }
  320. return server
  321. }
  322. func GetVerbosity() int32 {
  323. var verbosity = 0
  324. var err error
  325. if os.Getenv("VERBOSITY") != "" {
  326. verbosity, err = strconv.Atoi(os.Getenv("VERBOSITY"))
  327. if err != nil {
  328. verbosity = 0
  329. }
  330. } else if config.Config.Server.Verbosity != 0 {
  331. verbosity = int(config.Config.Server.Verbosity)
  332. }
  333. if verbosity < 0 || verbosity > 4 {
  334. verbosity = 0
  335. }
  336. return int32(verbosity)
  337. }
  338. // AutoUpdateEnabled returns a boolean indicating whether netclient auto update is enabled or disabled
  339. // default is enabled
  340. func AutoUpdateEnabled() bool {
  341. if os.Getenv("NETCLIENT_AUTO_UPDATE") == "disabled" {
  342. return false
  343. } else if config.Config.Server.NetclientAutoUpdate == "disabled" {
  344. return false
  345. }
  346. return true
  347. }
  348. // EndpointDetectionEnabled returns a boolean indicating whether netclient endpoint detection is enabled or disabled
  349. // default is enabled
  350. func EndpointDetectionEnabled() bool {
  351. if os.Getenv("NETCLIENT_ENDPOINT_DETECTION") == "disabled" {
  352. return false
  353. } else if config.Config.Server.NetclientEndpointDetection == "disabled" {
  354. return false
  355. }
  356. return true
  357. }
  358. // IsDNSMode - should it run with DNS
  359. func IsDNSMode() bool {
  360. isdns := true
  361. if os.Getenv("DNS_MODE") != "" {
  362. if os.Getenv("DNS_MODE") == "off" {
  363. isdns = false
  364. }
  365. } else if config.Config.Server.DNSMode != "" {
  366. if config.Config.Server.DNSMode == "off" {
  367. isdns = false
  368. }
  369. }
  370. return isdns
  371. }
  372. // IsDisplayKeys - should server be able to display keys?
  373. func IsDisplayKeys() bool {
  374. isdisplay := true
  375. if os.Getenv("DISPLAY_KEYS") != "" {
  376. if os.Getenv("DISPLAY_KEYS") == "off" {
  377. isdisplay = false
  378. }
  379. } else if config.Config.Server.DisplayKeys != "" {
  380. if config.Config.Server.DisplayKeys == "off" {
  381. isdisplay = false
  382. }
  383. }
  384. return isdisplay
  385. }
  386. // DisableRemoteIPCheck - disable the remote ip check
  387. func DisableRemoteIPCheck() bool {
  388. disabled := false
  389. if os.Getenv("DISABLE_REMOTE_IP_CHECK") != "" {
  390. if os.Getenv("DISABLE_REMOTE_IP_CHECK") == "on" {
  391. disabled = true
  392. }
  393. } else if config.Config.Server.DisableRemoteIPCheck != "" {
  394. if config.Config.Server.DisableRemoteIPCheck == "on" {
  395. disabled = true
  396. }
  397. }
  398. return disabled
  399. }
  400. // GetPublicIP - gets public ip
  401. func GetPublicIP() (string, error) {
  402. endpoint := ""
  403. var err error
  404. iplist := []string{"https://ip.server.gravitl.com", "https://ifconfig.me", "https://api.ipify.org", "https://ipinfo.io/ip"}
  405. publicIpService := os.Getenv("PUBLIC_IP_SERVICE")
  406. if publicIpService != "" {
  407. // prepend the user-specified service so it's checked first
  408. iplist = append([]string{publicIpService}, iplist...)
  409. } else if config.Config.Server.PublicIPService != "" {
  410. publicIpService = config.Config.Server.PublicIPService
  411. // prepend the user-specified service so it's checked first
  412. iplist = append([]string{publicIpService}, iplist...)
  413. }
  414. for _, ipserver := range iplist {
  415. client := &http.Client{
  416. Timeout: time.Second * 10,
  417. }
  418. resp, err := client.Get(ipserver)
  419. if err != nil {
  420. continue
  421. }
  422. defer resp.Body.Close()
  423. if resp.StatusCode == http.StatusOK {
  424. bodyBytes, err := io.ReadAll(resp.Body)
  425. if err != nil {
  426. continue
  427. }
  428. endpoint = string(bodyBytes)
  429. break
  430. }
  431. }
  432. if err == nil && endpoint == "" {
  433. err = errors.New("public address not found")
  434. }
  435. return endpoint, err
  436. }
  437. // GetPlatform - get the system type of server
  438. func GetPlatform() string {
  439. platform := "linux"
  440. if os.Getenv("PLATFORM") != "" {
  441. platform = os.Getenv("PLATFORM")
  442. } else if config.Config.Server.Platform != "" {
  443. platform = config.Config.Server.Platform
  444. }
  445. return platform
  446. }
  447. // GetSQLConn - get the sql connection string
  448. func GetSQLConn() string {
  449. sqlconn := "http://"
  450. if os.Getenv("SQL_CONN") != "" {
  451. sqlconn = os.Getenv("SQL_CONN")
  452. } else if config.Config.Server.SQLConn != "" {
  453. sqlconn = config.Config.Server.SQLConn
  454. }
  455. return sqlconn
  456. }
  457. // GetNodeID - gets the node id
  458. func GetNodeID() string {
  459. var id string
  460. var err error
  461. // id = getMacAddr()
  462. if os.Getenv("NODE_ID") != "" {
  463. id = os.Getenv("NODE_ID")
  464. } else if config.Config.Server.NodeID != "" {
  465. id = config.Config.Server.NodeID
  466. } else {
  467. id, err = os.Hostname()
  468. if err != nil {
  469. return ""
  470. }
  471. }
  472. return id
  473. }
  474. func SetNodeID(id string) {
  475. config.Config.Server.NodeID = id
  476. }
  477. // GetAuthProviderInfo = gets the oauth provider info
  478. func GetAuthProviderInfo() (pi []string) {
  479. var authProvider = ""
  480. defer func() {
  481. if authProvider == "oidc" {
  482. if os.Getenv("OIDC_ISSUER") != "" {
  483. pi = append(pi, os.Getenv("OIDC_ISSUER"))
  484. } else if config.Config.Server.OIDCIssuer != "" {
  485. pi = append(pi, config.Config.Server.OIDCIssuer)
  486. } else {
  487. pi = []string{"", "", ""}
  488. }
  489. }
  490. }()
  491. if os.Getenv("AUTH_PROVIDER") != "" && os.Getenv("CLIENT_ID") != "" && os.Getenv("CLIENT_SECRET") != "" {
  492. authProvider = strings.ToLower(os.Getenv("AUTH_PROVIDER"))
  493. if authProvider == "google" || authProvider == "azure-ad" || authProvider == "github" || authProvider == "oidc" {
  494. return []string{authProvider, os.Getenv("CLIENT_ID"), os.Getenv("CLIENT_SECRET")}
  495. } else {
  496. authProvider = ""
  497. }
  498. } else if config.Config.Server.AuthProvider != "" && config.Config.Server.ClientID != "" && config.Config.Server.ClientSecret != "" {
  499. authProvider = strings.ToLower(config.Config.Server.AuthProvider)
  500. if authProvider == "google" || authProvider == "azure-ad" || authProvider == "github" || authProvider == "oidc" {
  501. return []string{authProvider, config.Config.Server.ClientID, config.Config.Server.ClientSecret}
  502. }
  503. }
  504. return []string{"", "", ""}
  505. }
  506. // GetAzureTenant - retrieve the azure tenant ID from env variable or config file
  507. func GetAzureTenant() string {
  508. var azureTenant = ""
  509. if os.Getenv("AZURE_TENANT") != "" {
  510. azureTenant = os.Getenv("AZURE_TENANT")
  511. } else if config.Config.Server.AzureTenant != "" {
  512. azureTenant = config.Config.Server.AzureTenant
  513. }
  514. return azureTenant
  515. }
  516. // GetMqPassword - fetches the MQ password
  517. func GetMqPassword() string {
  518. password := ""
  519. if os.Getenv("MQ_PASSWORD") != "" {
  520. password = os.Getenv("MQ_PASSWORD")
  521. } else if config.Config.Server.MQPassword != "" {
  522. password = config.Config.Server.MQPassword
  523. }
  524. return password
  525. }
  526. // GetMqUserName - fetches the MQ username
  527. func GetMqUserName() string {
  528. password := ""
  529. if os.Getenv("MQ_USERNAME") != "" {
  530. password = os.Getenv("MQ_USERNAME")
  531. } else if config.Config.Server.MQUserName != "" {
  532. password = config.Config.Server.MQUserName
  533. }
  534. return password
  535. }
  536. // GetEmqxRestEndpoint - returns the REST API Endpoint of EMQX
  537. func GetEmqxRestEndpoint() string {
  538. return os.Getenv("EMQX_REST_ENDPOINT")
  539. }
  540. // IsBasicAuthEnabled - checks if basic auth has been configured to be turned off
  541. func IsBasicAuthEnabled() bool {
  542. var enabled = true //default
  543. if os.Getenv("BASIC_AUTH") != "" {
  544. enabled = os.Getenv("BASIC_AUTH") == "yes"
  545. } else if config.Config.Server.BasicAuth != "" {
  546. enabled = config.Config.Server.BasicAuth == "yes"
  547. }
  548. return enabled
  549. }
  550. // GetLicenseKey - retrieves pro license value from env or conf files
  551. func GetLicenseKey() string {
  552. licenseKeyValue := os.Getenv("LICENSE_KEY")
  553. if licenseKeyValue == "" {
  554. licenseKeyValue = config.Config.Server.LicenseValue
  555. }
  556. return licenseKeyValue
  557. }
  558. // GetNetmakerTenantID - get's the associated, Netmaker, tenant ID to verify ownership
  559. func GetNetmakerTenantID() string {
  560. netmakerTenantID := os.Getenv("NETMAKER_TENANT_ID")
  561. if netmakerTenantID == "" {
  562. netmakerTenantID = config.Config.Server.NetmakerTenantID
  563. }
  564. return netmakerTenantID
  565. }
  566. // GetTurnPort - Get the port to run the turn server on
  567. func GetTurnPort() int {
  568. port := 3479 //default
  569. if os.Getenv("TURN_PORT") != "" {
  570. portInt, err := strconv.Atoi(os.Getenv("TURN_PORT"))
  571. if err == nil {
  572. port = portInt
  573. }
  574. } else if config.Config.Server.TurnPort != 0 {
  575. port = config.Config.Server.TurnPort
  576. }
  577. return port
  578. }
  579. // GetTurnUserName - fetches the turn server username
  580. func GetTurnUserName() string {
  581. userName := ""
  582. if os.Getenv("TURN_USERNAME") != "" {
  583. userName = os.Getenv("TURN_USERNAME")
  584. } else {
  585. userName = config.Config.Server.TurnUserName
  586. }
  587. return userName
  588. }
  589. // GetTurnPassword - fetches the turn server password
  590. func GetTurnPassword() string {
  591. pass := ""
  592. if os.Getenv("TURN_PASSWORD") != "" {
  593. pass = os.Getenv("TURN_PASSWORD")
  594. } else {
  595. pass = config.Config.Server.TurnPassword
  596. }
  597. return pass
  598. }
  599. // GetNetworkLimit - fetches free tier limits on users
  600. func GetUserLimit() int {
  601. var userslimit int
  602. if os.Getenv("USERS_LIMIT") != "" {
  603. userslimit, _ = strconv.Atoi(os.Getenv("USERS_LIMIT"))
  604. } else {
  605. userslimit = config.Config.Server.UsersLimit
  606. }
  607. return userslimit
  608. }
  609. // GetNetworkLimit - fetches free tier limits on networks
  610. func GetNetworkLimit() int {
  611. var networkslimit int
  612. if os.Getenv("NETWORKS_LIMIT") != "" {
  613. networkslimit, _ = strconv.Atoi(os.Getenv("NETWORKS_LIMIT"))
  614. } else {
  615. networkslimit = config.Config.Server.NetworksLimit
  616. }
  617. return networkslimit
  618. }
  619. // GetClientLimit - fetches free tier limits on ext. clients
  620. func GetClientLimit() int {
  621. var clientsLimit int
  622. if os.Getenv("CLIENTS_LIMIT") != "" {
  623. clientsLimit, _ = strconv.Atoi(os.Getenv("CLIENTS_LIMIT"))
  624. } else {
  625. clientsLimit = config.Config.Server.ClientsLimit
  626. }
  627. return clientsLimit
  628. }
  629. // GetHostLimit - fetches free tier limits on hosts
  630. func GetHostLimit() int {
  631. var hostsLimit int
  632. if os.Getenv("HOSTS_LIMIT") != "" {
  633. hostsLimit, _ = strconv.Atoi(os.Getenv("HOSTS_LIMIT"))
  634. } else {
  635. hostsLimit = config.Config.Server.HostsLimit
  636. }
  637. return hostsLimit
  638. }
  639. // DeployedByOperator - returns true if the instance is deployed by netmaker operator
  640. func DeployedByOperator() bool {
  641. if os.Getenv("DEPLOYED_BY_OPERATOR") != "" {
  642. return os.Getenv("DEPLOYED_BY_OPERATOR") == "true"
  643. }
  644. return config.Config.Server.DeployedByOperator
  645. }