wireguardconf.go 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. package servercfg
  2. import (
  3. "github.com/gravitl/netmaker/config"
  4. "os"
  5. )
  6. func IsRegisterKeyRequired() bool {
  7. isrequired := false
  8. if os.Getenv("SERVER_GRPC_WG_KEYREQUIRED") != "" {
  9. if os.Getenv("SERVER_GRPC_WG_KEYREQUIRED") == "yes" {
  10. isrequired = true
  11. }
  12. } else if config.Config.WG.RegisterKeyRequired != "" {
  13. if config.Config.WG.RegisterKeyRequired == "yes" {
  14. isrequired = true
  15. }
  16. }
  17. return isrequired
  18. }
  19. func IsGRPCWireGuard() bool {
  20. iswg := true
  21. if os.Getenv("SERVER_GRPC_WIREGUARD") != "" {
  22. if os.Getenv("SERVER_GRPC_WIREGUARD") == "off" {
  23. iswg = false
  24. }
  25. } else if config.Config.WG.GRPCWireGuard != "" {
  26. if config.Config.WG.GRPCWireGuard == "off" {
  27. iswg = false
  28. }
  29. }
  30. return iswg
  31. }
  32. func GetGRPCWGInterface() string {
  33. iface := "nm-grpc-wg"
  34. if os.Getenv("SERVER_GRPC_WG_INTERFACE") != "" {
  35. iface = os.Getenv("SERVER_GRPC_WG_INTERFACE")
  36. } else if config.Config.WG.GRPCWGInterface != "" {
  37. iface = config.Config.WG.GRPCWGInterface
  38. }
  39. return iface
  40. }
  41. func GetGRPCWGAddress() string {
  42. address := "10.101.0.1"
  43. if os.Getenv("SERVER_GRPC_WG_ADDRESS") != "" {
  44. address = os.Getenv("SERVER_GRPC_WG_ADDRESS")
  45. } else if config.Config.WG.GRPCWGAddress != "" {
  46. address = config.Config.WG.GRPCWGAddress
  47. }
  48. return address
  49. }
  50. func GetGRPCWGAddressRange() string {
  51. address := "10.101.0.0/16"
  52. if os.Getenv("SERVER_GRPC_WG_ADDRESS_RANGE") != "" {
  53. address = os.Getenv("SERVER_GRPC_WG_ADDRESS_RANGE")
  54. } else if config.Config.WG.GRPCWGAddressRange != "" {
  55. address = config.Config.WG.GRPCWGAddressRange
  56. }
  57. return address
  58. }
  59. func GetGRPCWGPort() string {
  60. port := "50555"
  61. if os.Getenv("SERVER_GRPC_WG_PORT") != "" {
  62. port = os.Getenv("SERVER_GRPC_WG_PORT")
  63. } else if config.Config.WG.GRPCWGPort != "" {
  64. port = config.Config.WG.GRPCWGPort
  65. }
  66. return port
  67. }
  68. func GetGRPCWGPubKey() string {
  69. key := os.Getenv("SERVER_GRPC_WG_PUBKEY")
  70. if config.Config.WG.GRPCWGPubKey != "" {
  71. key = config.Config.WG.GRPCWGPubKey
  72. }
  73. return key
  74. }
  75. func GetGRPCWGPrivKey() string {
  76. key := os.Getenv("SERVER_GRPC_WG_PRIVKEY")
  77. if config.Config.WG.GRPCWGPrivKey != "" {
  78. key = config.Config.WG.GRPCWGPrivKey
  79. }
  80. return key
  81. }