You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

service.go 6.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. // Copyright 2019 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package setting
  5. import (
  6. "regexp"
  7. "time"
  8. "code.gitea.io/gitea/modules/log"
  9. "code.gitea.io/gitea/modules/structs"
  10. )
  11. // Service settings
  12. var Service struct {
  13. DefaultOrgVisibility string
  14. DefaultOrgVisibilityMode structs.VisibleType
  15. ActiveCodeLives int
  16. ResetPwdCodeLives int
  17. RegisterEmailConfirm bool
  18. RegisterManualConfirm bool
  19. EmailDomainWhitelist []string
  20. EmailDomainBlocklist []string
  21. DisableRegistration bool
  22. AllowOnlyExternalRegistration bool
  23. ShowRegistrationButton bool
  24. ShowMilestonesDashboardPage bool
  25. RequireSignInView bool
  26. EnableNotifyMail bool
  27. EnableBasicAuth bool
  28. EnableReverseProxyAuth bool
  29. EnableReverseProxyAutoRegister bool
  30. EnableReverseProxyEmail bool
  31. EnableCaptcha bool
  32. RequireExternalRegistrationCaptcha bool
  33. RequireExternalRegistrationPassword bool
  34. CaptchaType string
  35. RecaptchaSecret string
  36. RecaptchaSitekey string
  37. RecaptchaURL string
  38. HcaptchaSecret string
  39. HcaptchaSitekey string
  40. DefaultKeepEmailPrivate bool
  41. DefaultAllowCreateOrganization bool
  42. EnableTimetracking bool
  43. DefaultEnableTimetracking bool
  44. DefaultEnableDependencies bool
  45. AllowCrossRepositoryDependencies bool
  46. DefaultAllowOnlyContributorsToTrackTime bool
  47. NoReplyAddress string
  48. EnableUserHeatmap bool
  49. AutoWatchNewRepos bool
  50. AutoWatchOnChanges bool
  51. DefaultOrgMemberVisible bool
  52. UserDeleteWithCommentsMaxTime time.Duration
  53. // OpenID settings
  54. EnableOpenIDSignIn bool
  55. EnableOpenIDSignUp bool
  56. OpenIDWhitelist []*regexp.Regexp
  57. OpenIDBlacklist []*regexp.Regexp
  58. // Explore page settings
  59. Explore struct {
  60. RequireSigninView bool `ini:"REQUIRE_SIGNIN_VIEW"`
  61. DisableUsersPage bool `ini:"DISABLE_USERS_PAGE"`
  62. } `ini:"service.explore"`
  63. }
  64. func newService() {
  65. sec := Cfg.Section("service")
  66. Service.ActiveCodeLives = sec.Key("ACTIVE_CODE_LIVE_MINUTES").MustInt(180)
  67. Service.ResetPwdCodeLives = sec.Key("RESET_PASSWD_CODE_LIVE_MINUTES").MustInt(180)
  68. Service.DisableRegistration = sec.Key("DISABLE_REGISTRATION").MustBool()
  69. Service.AllowOnlyExternalRegistration = sec.Key("ALLOW_ONLY_EXTERNAL_REGISTRATION").MustBool()
  70. if !sec.Key("REGISTER_EMAIL_CONFIRM").MustBool() {
  71. Service.RegisterManualConfirm = sec.Key("REGISTER_MANUAL_CONFIRM").MustBool(false)
  72. } else {
  73. Service.RegisterManualConfirm = false
  74. }
  75. Service.EmailDomainWhitelist = sec.Key("EMAIL_DOMAIN_WHITELIST").Strings(",")
  76. Service.EmailDomainBlocklist = sec.Key("EMAIL_DOMAIN_BLOCKLIST").Strings(",")
  77. Service.ShowRegistrationButton = sec.Key("SHOW_REGISTRATION_BUTTON").MustBool(!(Service.DisableRegistration || Service.AllowOnlyExternalRegistration))
  78. Service.ShowMilestonesDashboardPage = sec.Key("SHOW_MILESTONES_DASHBOARD_PAGE").MustBool(true)
  79. Service.RequireSignInView = sec.Key("REQUIRE_SIGNIN_VIEW").MustBool()
  80. Service.EnableBasicAuth = sec.Key("ENABLE_BASIC_AUTHENTICATION").MustBool(true)
  81. Service.EnableReverseProxyAuth = sec.Key("ENABLE_REVERSE_PROXY_AUTHENTICATION").MustBool()
  82. Service.EnableReverseProxyAutoRegister = sec.Key("ENABLE_REVERSE_PROXY_AUTO_REGISTRATION").MustBool()
  83. Service.EnableReverseProxyEmail = sec.Key("ENABLE_REVERSE_PROXY_EMAIL").MustBool()
  84. Service.EnableCaptcha = sec.Key("ENABLE_CAPTCHA").MustBool(false)
  85. Service.RequireExternalRegistrationCaptcha = sec.Key("REQUIRE_EXTERNAL_REGISTRATION_CAPTCHA").MustBool(Service.EnableCaptcha)
  86. Service.RequireExternalRegistrationPassword = sec.Key("REQUIRE_EXTERNAL_REGISTRATION_PASSWORD").MustBool()
  87. Service.CaptchaType = sec.Key("CAPTCHA_TYPE").MustString(ImageCaptcha)
  88. Service.RecaptchaSecret = sec.Key("RECAPTCHA_SECRET").MustString("")
  89. Service.RecaptchaSitekey = sec.Key("RECAPTCHA_SITEKEY").MustString("")
  90. Service.RecaptchaURL = sec.Key("RECAPTCHA_URL").MustString("https://www.google.com/recaptcha/")
  91. Service.HcaptchaSecret = sec.Key("HCAPTCHA_SECRET").MustString("")
  92. Service.HcaptchaSitekey = sec.Key("HCAPTCHA_SITEKEY").MustString("")
  93. Service.DefaultKeepEmailPrivate = sec.Key("DEFAULT_KEEP_EMAIL_PRIVATE").MustBool()
  94. Service.DefaultAllowCreateOrganization = sec.Key("DEFAULT_ALLOW_CREATE_ORGANIZATION").MustBool(true)
  95. Service.EnableTimetracking = sec.Key("ENABLE_TIMETRACKING").MustBool(true)
  96. if Service.EnableTimetracking {
  97. Service.DefaultEnableTimetracking = sec.Key("DEFAULT_ENABLE_TIMETRACKING").MustBool(true)
  98. }
  99. Service.DefaultEnableDependencies = sec.Key("DEFAULT_ENABLE_DEPENDENCIES").MustBool(true)
  100. Service.AllowCrossRepositoryDependencies = sec.Key("ALLOW_CROSS_REPOSITORY_DEPENDENCIES").MustBool(true)
  101. Service.DefaultAllowOnlyContributorsToTrackTime = sec.Key("DEFAULT_ALLOW_ONLY_CONTRIBUTORS_TO_TRACK_TIME").MustBool(true)
  102. Service.NoReplyAddress = sec.Key("NO_REPLY_ADDRESS").MustString("noreply." + Domain)
  103. Service.EnableUserHeatmap = sec.Key("ENABLE_USER_HEATMAP").MustBool(true)
  104. Service.AutoWatchNewRepos = sec.Key("AUTO_WATCH_NEW_REPOS").MustBool(true)
  105. Service.AutoWatchOnChanges = sec.Key("AUTO_WATCH_ON_CHANGES").MustBool(false)
  106. Service.DefaultOrgVisibility = sec.Key("DEFAULT_ORG_VISIBILITY").In("public", structs.ExtractKeysFromMapString(structs.VisibilityModes))
  107. Service.DefaultOrgVisibilityMode = structs.VisibilityModes[Service.DefaultOrgVisibility]
  108. Service.DefaultOrgMemberVisible = sec.Key("DEFAULT_ORG_MEMBER_VISIBLE").MustBool()
  109. Service.UserDeleteWithCommentsMaxTime = sec.Key("USER_DELETE_WITH_COMMENTS_MAX_TIME").MustDuration(0)
  110. if err := Cfg.Section("service.explore").MapTo(&Service.Explore); err != nil {
  111. log.Fatal("Failed to map service.explore settings: %v", err)
  112. }
  113. sec = Cfg.Section("openid")
  114. Service.EnableOpenIDSignIn = sec.Key("ENABLE_OPENID_SIGNIN").MustBool(!InstallLock)
  115. Service.EnableOpenIDSignUp = sec.Key("ENABLE_OPENID_SIGNUP").MustBool(!Service.DisableRegistration && Service.EnableOpenIDSignIn)
  116. pats := sec.Key("WHITELISTED_URIS").Strings(" ")
  117. if len(pats) != 0 {
  118. Service.OpenIDWhitelist = make([]*regexp.Regexp, len(pats))
  119. for i, p := range pats {
  120. Service.OpenIDWhitelist[i] = regexp.MustCompilePOSIX(p)
  121. }
  122. }
  123. pats = sec.Key("BLACKLISTED_URIS").Strings(" ")
  124. if len(pats) != 0 {
  125. Service.OpenIDBlacklist = make([]*regexp.Regexp, len(pats))
  126. for i, p := range pats {
  127. Service.OpenIDBlacklist[i] = regexp.MustCompilePOSIX(p)
  128. }
  129. }
  130. }