serverconf.go 17 KB

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