static.go 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. // Copyright 2020 The Gogs 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 conf
  5. import (
  6. "net/url"
  7. "os"
  8. )
  9. // ℹ️ README: This file contains static values that should only be set at initialization time.
  10. // HasMinWinSvc is whether the application is built with Windows Service support.
  11. //
  12. // ⚠️ WARNING: should only be set by "static_minwinsvc.go".
  13. var HasMinWinSvc bool
  14. // Build time and commit information.
  15. //
  16. // ⚠️ WARNING: should only be set by -ldflags.
  17. var (
  18. BuildTime string
  19. BuildCommit string
  20. )
  21. // CustomConf returns the absolute path of custom configuration file that is used.
  22. var CustomConf string
  23. // ⚠️ WARNING: After changing the following section, do not forget to update template of
  24. // "/admin/config" page as well.
  25. var (
  26. // Application settings
  27. App struct {
  28. // ⚠️ WARNING: Should only be set by main package (i.e. "gogs.go").
  29. Version string `ini:"-"`
  30. BrandName string
  31. RunUser string
  32. RunMode string
  33. // Deprecated: Use BrandName instead, will be removed in 0.13.
  34. AppName string
  35. }
  36. // Server settings
  37. Server struct {
  38. ExternalURL string `ini:"EXTERNAL_URL"`
  39. Domain string
  40. Protocol string
  41. HTTPAddr string `ini:"HTTP_ADDR"`
  42. HTTPPort string `ini:"HTTP_PORT"`
  43. CertFile string
  44. KeyFile string
  45. TLSMinVersion string `ini:"TLS_MIN_VERSION"`
  46. UnixSocketPermission string
  47. LocalRootURL string `ini:"LOCAL_ROOT_URL"`
  48. OfflineMode bool
  49. DisableRouterLog bool
  50. EnableGzip bool
  51. AppDataPath string
  52. LoadAssetsFromDisk bool
  53. LandingURL string `ini:"LANDING_URL"`
  54. // Derived from other static values
  55. URL *url.URL `ini:"-"` // Parsed URL object of ExternalURL.
  56. Subpath string `ini:"-"` // Subpath found the ExternalURL. Should be empty when not found.
  57. SubpathDepth int `ini:"-"` // The number of slashes found in the Subpath.
  58. UnixSocketMode os.FileMode `ini:"-"` // Parsed file mode of UnixSocketPermission.
  59. // Deprecated: Use ExternalURL instead, will be removed in 0.13.
  60. RootURL string `ini:"ROOT_URL"`
  61. // Deprecated: Use LandingURL instead, will be removed in 0.13.
  62. LangdingPage string `ini:"LANDING_PAGE"`
  63. }
  64. // SSH settings
  65. SSH struct {
  66. Disabled bool `ini:"DISABLE_SSH"`
  67. Domain string `ini:"SSH_DOMAIN"`
  68. Port int `ini:"SSH_PORT"`
  69. RootPath string `ini:"SSH_ROOT_PATH"`
  70. KeygenPath string `ini:"SSH_KEYGEN_PATH"`
  71. KeyTestPath string `ini:"SSH_KEY_TEST_PATH"`
  72. MinimumKeySizeCheck bool
  73. MinimumKeySizes map[string]int `ini:"-"` // Load from [ssh.minimum_key_sizes]
  74. RewriteAuthorizedKeysAtStart bool
  75. StartBuiltinServer bool `ini:"START_SSH_SERVER"`
  76. ListenHost string `ini:"SSH_LISTEN_HOST"`
  77. ListenPort int `ini:"SSH_LISTEN_PORT"`
  78. ServerCiphers []string `ini:"SSH_SERVER_CIPHERS"`
  79. }
  80. // Repository settings
  81. Repository struct {
  82. Root string
  83. ScriptType string
  84. ANSICharset string `ini:"ANSI_CHARSET"`
  85. ForcePrivate bool
  86. MaxCreationLimit int
  87. PreferredLicenses []string
  88. DisableHTTPGit bool `ini:"DISABLE_HTTP_GIT"`
  89. EnableLocalPathMigration bool
  90. EnableRawFileRenderMode bool
  91. CommitsFetchConcurrency int
  92. // Repository editor settings
  93. Editor struct {
  94. LineWrapExtensions []string
  95. PreviewableFileModes []string
  96. } `ini:"repository.editor"`
  97. // Repository upload settings
  98. Upload struct {
  99. Enabled bool
  100. TempPath string
  101. AllowedTypes []string `delim:"|"`
  102. FileMaxSize int64
  103. MaxFiles int
  104. } `ini:"repository.upload"`
  105. }
  106. // Database settings
  107. Database struct {
  108. Type string
  109. Host string
  110. Name string
  111. User string
  112. Password string
  113. SSLMode string `ini:"SSL_MODE"`
  114. Path string
  115. // Deprecated: Use Type instead, will be removed in 0.13.
  116. DbType string
  117. // Deprecated: Use Password instead, will be removed in 0.13.
  118. Passwd string
  119. }
  120. // Security settings
  121. Security struct {
  122. InstallLock bool
  123. SecretKey string
  124. LoginRememberDays int
  125. CookieRememberName string
  126. CookieUsername string
  127. CookieSecure bool
  128. EnableLoginStatusCookie bool
  129. LoginStatusCookieName string
  130. // Deprecated: Use Auth.ReverseProxyAuthenticationHeader instead, will be removed in 0.13.
  131. ReverseProxyAuthenticationUser string
  132. }
  133. // Email settings
  134. Email struct {
  135. Enabled bool
  136. SubjectPrefix string
  137. Host string
  138. From string
  139. User string
  140. Password string
  141. DisableHELO bool `ini:"DISABLE_HELO"`
  142. HELOHostname string `ini:"HELO_HOSTNAME"`
  143. SkipVerify bool
  144. UseCertificate bool
  145. CertFile string
  146. KeyFile string
  147. UsePlainText bool
  148. AddPlainTextAlt bool
  149. // Derived from other static values
  150. FromEmail string `ini:"-"` // Parsed email address of From without person's name.
  151. // Deprecated: Use Password instead, will be removed in 0.13.
  152. Passwd string
  153. }
  154. // Authentication settings
  155. Auth struct {
  156. ActivateCodeLives int
  157. ResetPasswordCodeLives int
  158. RequireEmailConfirmation bool
  159. RequireSigninView bool
  160. DisableRegistration bool
  161. EnableRegistrationCaptcha bool
  162. EnableReverseProxyAuthentication bool
  163. EnableReverseProxyAutoRegistration bool
  164. ReverseProxyAuthenticationHeader string
  165. // Deprecated: Use ActivateCodeLives instead, will be removed in 0.13.
  166. ActiveCodeLiveMinutes int
  167. // Deprecated: Use ResetPasswordCodeLives instead, will be removed in 0.13.
  168. ResetPasswdCodeLiveMinutes int
  169. // Deprecated: Use RequireEmailConfirmation instead, will be removed in 0.13.
  170. RegisterEmailConfirm bool
  171. // Deprecated: Use EnableRegistrationCaptcha instead, will be removed in 0.13.
  172. EnableCaptcha bool
  173. // Deprecated: Use User.EnableEmailNotification instead, will be removed in 0.13.
  174. EnableNotifyMail bool
  175. }
  176. // User settings
  177. User struct {
  178. EnableEmailNotification bool
  179. }
  180. )
  181. // handleDeprecated transfers deprecated values to the new ones when set.
  182. func handleDeprecated() {
  183. if App.AppName != "" {
  184. App.BrandName = App.AppName
  185. App.AppName = ""
  186. }
  187. if Server.RootURL != "" {
  188. Server.ExternalURL = Server.RootURL
  189. Server.RootURL = ""
  190. }
  191. if Server.LangdingPage == "explore" {
  192. Server.LandingURL = "/explore"
  193. Server.LangdingPage = ""
  194. }
  195. if Database.DbType != "" {
  196. Database.Type = Database.DbType
  197. Database.DbType = ""
  198. }
  199. if Database.Passwd != "" {
  200. Database.Password = Database.Passwd
  201. Database.Passwd = ""
  202. }
  203. if Email.Passwd != "" {
  204. Email.Password = Email.Passwd
  205. Email.Passwd = ""
  206. }
  207. if Auth.ActiveCodeLiveMinutes > 0 {
  208. Auth.ActivateCodeLives = Auth.ActiveCodeLiveMinutes
  209. Auth.ActiveCodeLiveMinutes = 0
  210. }
  211. if Auth.ResetPasswdCodeLiveMinutes > 0 {
  212. Auth.ResetPasswordCodeLives = Auth.ResetPasswdCodeLiveMinutes
  213. Auth.ResetPasswdCodeLiveMinutes = 0
  214. }
  215. if Auth.RegisterEmailConfirm {
  216. Auth.RequireEmailConfirmation = true
  217. Auth.RegisterEmailConfirm = false
  218. }
  219. if Auth.EnableCaptcha {
  220. Auth.EnableRegistrationCaptcha = true
  221. Auth.EnableCaptcha = false
  222. }
  223. if Security.ReverseProxyAuthenticationUser != "" {
  224. Auth.ReverseProxyAuthenticationHeader = Security.ReverseProxyAuthenticationUser
  225. Security.ReverseProxyAuthenticationUser = ""
  226. }
  227. if Auth.EnableNotifyMail {
  228. User.EnableEmailNotification = true
  229. Auth.EnableNotifyMail = false
  230. }
  231. }