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

service.go 4.3 kB

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