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.

99 lines
4.7 KiB

  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. "code.gitea.io/gitea/modules/structs"
  8. )
  9. // Service settings
  10. var Service struct {
  11. DefaultOrgVisibility string
  12. DefaultOrgVisibilityMode structs.VisibleType
  13. ActiveCodeLives int
  14. ResetPwdCodeLives int
  15. RegisterEmailConfirm bool
  16. EmailDomainWhitelist []string
  17. DisableRegistration bool
  18. AllowOnlyExternalRegistration bool
  19. ShowRegistrationButton bool
  20. RequireSignInView bool
  21. EnableNotifyMail bool
  22. EnableReverseProxyAuth bool
  23. EnableReverseProxyAutoRegister bool
  24. EnableReverseProxyEmail bool
  25. EnableCaptcha bool
  26. CaptchaType string
  27. RecaptchaSecret string
  28. RecaptchaSitekey string
  29. RecaptchaURL string
  30. DefaultKeepEmailPrivate bool
  31. DefaultAllowCreateOrganization bool
  32. EnableTimetracking bool
  33. DefaultEnableTimetracking bool
  34. DefaultEnableDependencies bool
  35. DefaultAllowOnlyContributorsToTrackTime bool
  36. NoReplyAddress string
  37. EnableUserHeatmap bool
  38. AutoWatchNewRepos bool
  39. // OpenID settings
  40. EnableOpenIDSignIn bool
  41. EnableOpenIDSignUp bool
  42. OpenIDWhitelist []*regexp.Regexp
  43. OpenIDBlacklist []*regexp.Regexp
  44. }
  45. func newService() {
  46. sec := Cfg.Section("service")
  47. Service.ActiveCodeLives = sec.Key("ACTIVE_CODE_LIVE_MINUTES").MustInt(180)
  48. Service.ResetPwdCodeLives = sec.Key("RESET_PASSWD_CODE_LIVE_MINUTES").MustInt(180)
  49. Service.DisableRegistration = sec.Key("DISABLE_REGISTRATION").MustBool()
  50. Service.AllowOnlyExternalRegistration = sec.Key("ALLOW_ONLY_EXTERNAL_REGISTRATION").MustBool()
  51. Service.EmailDomainWhitelist = sec.Key("EMAIL_DOMAIN_WHITELIST").Strings(",")
  52. Service.ShowRegistrationButton = sec.Key("SHOW_REGISTRATION_BUTTON").MustBool(!(Service.DisableRegistration || Service.AllowOnlyExternalRegistration))
  53. Service.RequireSignInView = sec.Key("REQUIRE_SIGNIN_VIEW").MustBool()
  54. Service.EnableReverseProxyAuth = sec.Key("ENABLE_REVERSE_PROXY_AUTHENTICATION").MustBool()
  55. Service.EnableReverseProxyAutoRegister = sec.Key("ENABLE_REVERSE_PROXY_AUTO_REGISTRATION").MustBool()
  56. Service.EnableReverseProxyEmail = sec.Key("ENABLE_REVERSE_PROXY_EMAIL").MustBool()
  57. Service.EnableCaptcha = sec.Key("ENABLE_CAPTCHA").MustBool(false)
  58. Service.CaptchaType = sec.Key("CAPTCHA_TYPE").MustString(ImageCaptcha)
  59. Service.RecaptchaSecret = sec.Key("RECAPTCHA_SECRET").MustString("")
  60. Service.RecaptchaSitekey = sec.Key("RECAPTCHA_SITEKEY").MustString("")
  61. Service.RecaptchaURL = sec.Key("RECAPTCHA_URL").MustString("https://www.google.com/recaptcha/")
  62. Service.DefaultKeepEmailPrivate = sec.Key("DEFAULT_KEEP_EMAIL_PRIVATE").MustBool()
  63. Service.DefaultAllowCreateOrganization = sec.Key("DEFAULT_ALLOW_CREATE_ORGANIZATION").MustBool(true)
  64. Service.EnableTimetracking = sec.Key("ENABLE_TIMETRACKING").MustBool(true)
  65. if Service.EnableTimetracking {
  66. Service.DefaultEnableTimetracking = sec.Key("DEFAULT_ENABLE_TIMETRACKING").MustBool(true)
  67. }
  68. Service.DefaultEnableDependencies = sec.Key("DEFAULT_ENABLE_DEPENDENCIES").MustBool(true)
  69. Service.DefaultAllowOnlyContributorsToTrackTime = sec.Key("DEFAULT_ALLOW_ONLY_CONTRIBUTORS_TO_TRACK_TIME").MustBool(true)
  70. Service.NoReplyAddress = sec.Key("NO_REPLY_ADDRESS").MustString("noreply.example.org")
  71. Service.EnableUserHeatmap = sec.Key("ENABLE_USER_HEATMAP").MustBool(true)
  72. Service.AutoWatchNewRepos = sec.Key("AUTO_WATCH_NEW_REPOS").MustBool(true)
  73. Service.DefaultOrgVisibility = sec.Key("DEFAULT_ORG_VISIBILITY").In("public", structs.ExtractKeysFromMapString(structs.VisibilityModes))
  74. Service.DefaultOrgVisibilityMode = structs.VisibilityModes[Service.DefaultOrgVisibility]
  75. sec = Cfg.Section("openid")
  76. Service.EnableOpenIDSignIn = sec.Key("ENABLE_OPENID_SIGNIN").MustBool(!InstallLock)
  77. Service.EnableOpenIDSignUp = sec.Key("ENABLE_OPENID_SIGNUP").MustBool(!Service.DisableRegistration && Service.EnableOpenIDSignIn)
  78. pats := sec.Key("WHITELISTED_URIS").Strings(" ")
  79. if len(pats) != 0 {
  80. Service.OpenIDWhitelist = make([]*regexp.Regexp, len(pats))
  81. for i, p := range pats {
  82. Service.OpenIDWhitelist[i] = regexp.MustCompilePOSIX(p)
  83. }
  84. }
  85. pats = sec.Key("BLACKLISTED_URIS").Strings(" ")
  86. if len(pats) != 0 {
  87. Service.OpenIDBlacklist = make([]*regexp.Regexp, len(pats))
  88. for i, p := range pats {
  89. Service.OpenIDBlacklist[i] = regexp.MustCompilePOSIX(p)
  90. }
  91. }
  92. }