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 5.1KB

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