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

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