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

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