initialize.go 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. //go:build ee
  2. // +build ee
  3. package pro
  4. import (
  5. "time"
  6. controller "github.com/gravitl/netmaker/controllers"
  7. "github.com/gravitl/netmaker/logger"
  8. "github.com/gravitl/netmaker/logic"
  9. "github.com/gravitl/netmaker/models"
  10. "github.com/gravitl/netmaker/mq"
  11. proControllers "github.com/gravitl/netmaker/pro/controllers"
  12. proLogic "github.com/gravitl/netmaker/pro/logic"
  13. "github.com/gravitl/netmaker/servercfg"
  14. "golang.org/x/exp/slog"
  15. )
  16. // InitPro - Initialize Pro Logic
  17. func InitPro() {
  18. servercfg.IsPro = true
  19. models.SetLogo(retrieveProLogo())
  20. controller.HttpMiddlewares = append(
  21. controller.HttpMiddlewares,
  22. proControllers.OnlyServerAPIWhenUnlicensedMiddleware,
  23. )
  24. controller.HttpHandlers = append(
  25. controller.HttpHandlers,
  26. proControllers.MetricHandlers,
  27. proControllers.RelayHandlers,
  28. proControllers.UserHandlers,
  29. proControllers.FailOverHandlers,
  30. )
  31. logic.EnterpriseCheckFuncs = append(logic.EnterpriseCheckFuncs, func() {
  32. // == License Handling ==
  33. enableLicenseHook := false
  34. licenseKeyValue := servercfg.GetLicenseKey()
  35. netmakerTenantID := servercfg.GetNetmakerTenantID()
  36. if licenseKeyValue != "" && netmakerTenantID != "" {
  37. enableLicenseHook = true
  38. }
  39. if !enableLicenseHook {
  40. err := initTrial()
  41. if err != nil {
  42. logger.FatalLog0("failed to init trail", err.Error())
  43. }
  44. trialEndDate, err := getTrialEndDate()
  45. if err != nil {
  46. slog.Error("failed to get trial end date", "error", err)
  47. enableLicenseHook = true
  48. } else {
  49. // check if trial ended
  50. if time.Now().After(trialEndDate) {
  51. // trial ended already
  52. enableLicenseHook = true
  53. }
  54. }
  55. }
  56. if enableLicenseHook {
  57. slog.Info("starting license checker")
  58. ClearLicenseCache()
  59. if err := ValidateLicense(); err != nil {
  60. slog.Error(err.Error())
  61. return
  62. }
  63. slog.Info("proceeding with Paid Tier license")
  64. logic.SetFreeTierForTelemetry(false)
  65. // == End License Handling ==
  66. AddLicenseHooks()
  67. } else {
  68. slog.Info("starting trial license hook")
  69. addTrialLicenseHook()
  70. }
  71. if servercfg.GetServerConfig().RacAutoDisable {
  72. AddRacHooks()
  73. }
  74. })
  75. logic.ResetFailOver = proLogic.ResetFailOver
  76. logic.ResetFailedOverPeer = proLogic.ResetFailedOverPeer
  77. logic.DenyClientNodeAccess = proLogic.DenyClientNode
  78. logic.IsClientNodeAllowed = proLogic.IsClientNodeAllowed
  79. logic.AllowClientNodeAccess = proLogic.RemoveDeniedNodeFromClient
  80. logic.SetClientDefaultACLs = proLogic.SetClientDefaultACLs
  81. logic.SetClientACLs = proLogic.SetClientACLs
  82. logic.UpdateProNodeACLs = proLogic.UpdateProNodeACLs
  83. logic.GetMetrics = proLogic.GetMetrics
  84. logic.UpdateMetrics = proLogic.UpdateMetrics
  85. logic.DeleteMetrics = proLogic.DeleteMetrics
  86. logic.GetRelays = proLogic.GetRelays
  87. logic.GetAllowedIpsForRelayed = proLogic.GetAllowedIpsForRelayed
  88. logic.RelayedAllowedIPs = proLogic.RelayedAllowedIPs
  89. logic.UpdateRelayed = proLogic.UpdateRelayed
  90. logic.SetRelayedNodes = proLogic.SetRelayedNodes
  91. logic.RelayUpdates = proLogic.RelayUpdates
  92. logic.IsInternetGw = proLogic.IsInternetGw
  93. logic.SetInternetGw = proLogic.SetInternetGw
  94. logic.GetTrialEndDate = getTrialEndDate
  95. mq.UpdateMetrics = proLogic.MQUpdateMetrics
  96. mq.UpdateMetricsFallBack = proLogic.MQUpdateMetricsFallBack
  97. }
  98. func retrieveProLogo() string {
  99. return `
  100. __ __ ______ ______ __ __ ______ __ __ ______ ______
  101. /\ "-.\ \ /\ ___\ /\__ _\ /\ "-./ \ /\ __ \ /\ \/ / /\ ___\ /\ == \
  102. \ \ \-. \ \ \ __\ \/_/\ \/ \ \ \-./\ \ \ \ __ \ \ \ _"-. \ \ __\ \ \ __<
  103. \ \_\\"\_\ \ \_____\ \ \_\ \ \_\ \ \_\ \ \_\ \_\ \ \_\ \_\ \ \_____\ \ \_\ \_\
  104. \/_/ \/_/ \/_____/ \/_/ \/_/ \/_/ \/_/\/_/ \/_/\/_/ \/_____/ \/_/ /_/
  105. ___ ___ ____
  106. ____ ____ ____ / _ \ / _ \ / __ \ ____ ____ ____
  107. /___/ /___/ /___/ / ___/ / , _// /_/ / /___/ /___/ /___/
  108. /___/ /___/ /___/ /_/ /_/|_| \____/ /___/ /___/ /___/
  109. `
  110. }