static.go 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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. // GIN settings
  93. ShowHTTPGit bool `ini:"SHOW_HTTP_GIT"`
  94. RawCaptchaMinFileSize int64
  95. CaptchaMinFileSize int64
  96. AutoInit bool
  97. // Repository editor settings
  98. Editor struct {
  99. LineWrapExtensions []string
  100. PreviewableFileModes []string
  101. } `ini:"repository.editor"`
  102. // Repository upload settings
  103. Upload struct {
  104. Enabled bool
  105. TempPath string
  106. AllowedTypes []string `delim:"|"`
  107. FileMaxSize int64
  108. MaxFiles int
  109. AnnexFileMinSize int64
  110. } `ini:"repository.upload"`
  111. }
  112. // Database settings
  113. Database struct {
  114. Type string
  115. Host string
  116. Name string
  117. User string
  118. Password string
  119. SSLMode string `ini:"SSL_MODE"`
  120. Path string
  121. // Deprecated: Use Type instead, will be removed in 0.13.
  122. DbType string
  123. // Deprecated: Use Password instead, will be removed in 0.13.
  124. Passwd string
  125. }
  126. )
  127. // handleDeprecated transfers deprecated values to the new ones when set.
  128. func handleDeprecated() {
  129. if App.AppName != "" {
  130. App.BrandName = App.AppName
  131. App.AppName = ""
  132. }
  133. if Server.RootURL != "" {
  134. Server.ExternalURL = Server.RootURL
  135. Server.RootURL = ""
  136. }
  137. if Server.LangdingPage == "explore" {
  138. Server.LandingURL = "/explore"
  139. Server.LangdingPage = ""
  140. }
  141. if Database.DbType != "" {
  142. Database.Type = Database.DbType
  143. Database.DbType = ""
  144. }
  145. if Database.Passwd != "" {
  146. Database.Password = Database.Passwd
  147. Database.Passwd = ""
  148. }
  149. }