static.go 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431
  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. "time"
  9. "github.com/gogs/go-libravatar"
  10. )
  11. // ℹ️ README: This file contains static values that should only be set at initialization time.
  12. // HasMinWinSvc is whether the application is built with Windows Service support.
  13. //
  14. // ⚠️ WARNING: should only be set by "internal/conf/static_minwinsvc.go".
  15. var HasMinWinSvc bool
  16. // Build time and commit information.
  17. //
  18. // ⚠️ WARNING: should only be set by "-ldflags".
  19. var (
  20. BuildTime string
  21. BuildCommit string
  22. )
  23. // CustomConf returns the absolute path of custom configuration file that is used.
  24. var CustomConf string
  25. // ⚠️ WARNING: After changing the following section, do not forget to update template of
  26. // "/admin/config" page as well.
  27. var (
  28. // Application settings
  29. App struct {
  30. // ⚠️ WARNING: Should only be set by the main package (i.e. "gogs.go").
  31. Version string `ini:"-"`
  32. BrandName string
  33. RunUser string
  34. RunMode string
  35. }
  36. // SSH settings
  37. SSH struct {
  38. Disabled bool `ini:"DISABLE_SSH"`
  39. Domain string `ini:"SSH_DOMAIN"`
  40. Port int `ini:"SSH_PORT"`
  41. RootPath string `ini:"SSH_ROOT_PATH"`
  42. KeygenPath string `ini:"SSH_KEYGEN_PATH"`
  43. KeyTestPath string `ini:"SSH_KEY_TEST_PATH"`
  44. MinimumKeySizeCheck bool
  45. MinimumKeySizes map[string]int `ini:"-"` // Load from [ssh.minimum_key_sizes]
  46. RewriteAuthorizedKeysAtStart bool
  47. StartBuiltinServer bool `ini:"START_SSH_SERVER"`
  48. ListenHost string `ini:"SSH_LISTEN_HOST"`
  49. ListenPort int `ini:"SSH_LISTEN_PORT"`
  50. ServerCiphers []string `ini:"SSH_SERVER_CIPHERS"`
  51. ServerMACs []string `ini:"SSH_SERVER_MACS"`
  52. }
  53. // Repository settings
  54. Repository struct {
  55. Root string
  56. ScriptType string
  57. ANSICharset string `ini:"ANSI_CHARSET"`
  58. ForcePrivate bool
  59. MaxCreationLimit int
  60. PreferredLicenses []string
  61. DisableHTTPGit bool `ini:"DISABLE_HTTP_GIT"`
  62. EnableLocalPathMigration bool
  63. EnableRawFileRenderMode bool
  64. CommitsFetchConcurrency int
  65. // Repository editor settings
  66. Editor struct {
  67. LineWrapExtensions []string
  68. PreviewableFileModes []string
  69. } `ini:"repository.editor"`
  70. // Repository upload settings
  71. Upload struct {
  72. Enabled bool
  73. TempPath string
  74. AllowedTypes []string `delim:"|"`
  75. FileMaxSize int64
  76. MaxFiles int
  77. } `ini:"repository.upload"`
  78. }
  79. // Security settings
  80. Security struct {
  81. InstallLock bool
  82. SecretKey string
  83. LoginRememberDays int
  84. CookieRememberName string
  85. CookieUsername string
  86. CookieSecure bool
  87. EnableLoginStatusCookie bool
  88. LoginStatusCookieName string
  89. LocalNetworkAllowlist []string `delim:","`
  90. }
  91. // Email settings
  92. Email struct {
  93. Enabled bool
  94. SubjectPrefix string
  95. Host string
  96. From string
  97. User string
  98. Password string
  99. DisableHELO bool `ini:"DISABLE_HELO"`
  100. HELOHostname string `ini:"HELO_HOSTNAME"`
  101. SkipVerify bool
  102. UseCertificate bool
  103. CertFile string
  104. KeyFile string
  105. UsePlainText bool
  106. AddPlainTextAlt bool
  107. // Derived from other static values
  108. FromEmail string `ini:"-"` // Parsed email address of From without person's name.
  109. }
  110. // Authentication settings
  111. Auth struct {
  112. ActivateCodeLives int
  113. ResetPasswordCodeLives int
  114. RequireEmailConfirmation bool
  115. RequireSigninView bool
  116. DisableRegistration bool
  117. EnableRegistrationCaptcha bool
  118. EnableReverseProxyAuthentication bool
  119. EnableReverseProxyAutoRegistration bool
  120. ReverseProxyAuthenticationHeader string
  121. }
  122. // User settings
  123. User struct {
  124. EnableEmailNotification bool
  125. }
  126. // Session settings
  127. Session struct {
  128. Provider string
  129. ProviderConfig string
  130. CookieName string
  131. CookieSecure bool
  132. GCInterval int64 `ini:"GC_INTERVAL"`
  133. MaxLifeTime int64
  134. CSRFCookieName string `ini:"CSRF_COOKIE_NAME"`
  135. }
  136. // Cache settings
  137. Cache struct {
  138. Adapter string
  139. Interval int
  140. Host string
  141. }
  142. // HTTP settings
  143. HTTP struct {
  144. AccessControlAllowOrigin string
  145. }
  146. // Attachment settings
  147. Attachment struct {
  148. Enabled bool
  149. Path string
  150. AllowedTypes []string `delim:"|"`
  151. MaxSize int64
  152. MaxFiles int
  153. }
  154. // Release settings
  155. Release struct {
  156. Attachment struct {
  157. Enabled bool
  158. AllowedTypes []string `delim:"|"`
  159. MaxSize int64
  160. MaxFiles int
  161. } `ini:"release.attachment"`
  162. }
  163. // Time settings
  164. Time struct {
  165. Format string
  166. // Derived from other static values
  167. FormatLayout string `ini:"-"` // Actual layout of the Format.
  168. }
  169. // Picture settings
  170. Picture struct {
  171. AvatarUploadPath string
  172. RepositoryAvatarUploadPath string
  173. GravatarSource string
  174. DisableGravatar bool
  175. EnableFederatedAvatar bool
  176. // Derived from other static values
  177. LibravatarService *libravatar.Libravatar `ini:"-"` // Initialized client for federated avatar.
  178. }
  179. // Mirror settings
  180. Mirror struct {
  181. DefaultInterval int
  182. }
  183. // Webhook settings
  184. Webhook struct {
  185. Types []string
  186. DeliverTimeout int
  187. SkipTLSVerify bool `ini:"SKIP_TLS_VERIFY"`
  188. PagingNum int
  189. }
  190. // Markdown settings
  191. Markdown struct {
  192. EnableHardLineBreak bool
  193. CustomURLSchemes []string `ini:"CUSTOM_URL_SCHEMES"`
  194. FileExtensions []string
  195. }
  196. // Smartypants settings
  197. Smartypants struct {
  198. Enabled bool
  199. Fractions bool
  200. Dashes bool
  201. LatexDashes bool
  202. AngledQuotes bool
  203. }
  204. // Admin settings
  205. Admin struct {
  206. DisableRegularOrgCreation bool
  207. }
  208. // Cron tasks
  209. Cron struct {
  210. UpdateMirror struct {
  211. Enabled bool
  212. RunAtStart bool
  213. Schedule string
  214. } `ini:"cron.update_mirrors"`
  215. RepoHealthCheck struct {
  216. Enabled bool
  217. RunAtStart bool
  218. Schedule string
  219. Timeout time.Duration
  220. Args []string `delim:" "`
  221. } `ini:"cron.repo_health_check"`
  222. CheckRepoStats struct {
  223. Enabled bool
  224. RunAtStart bool
  225. Schedule string
  226. } `ini:"cron.check_repo_stats"`
  227. RepoArchiveCleanup struct {
  228. Enabled bool
  229. RunAtStart bool
  230. Schedule string
  231. OlderThan time.Duration
  232. } `ini:"cron.repo_archive_cleanup"`
  233. }
  234. // Git settings
  235. Git struct {
  236. // ⚠️ WARNING: Should only be set by "internal/db/repo.go".
  237. Version string `ini:"-"`
  238. DisableDiffHighlight bool
  239. MaxDiffFiles int `ini:"MAX_GIT_DIFF_FILES"`
  240. MaxDiffLines int `ini:"MAX_GIT_DIFF_LINES"`
  241. MaxDiffLineChars int `ini:"MAX_GIT_DIFF_LINE_CHARACTERS"`
  242. GCArgs []string `ini:"GC_ARGS" delim:" "`
  243. Timeout struct {
  244. Migrate int
  245. Mirror int
  246. Clone int
  247. Pull int
  248. Diff int
  249. GC int `ini:"GC"`
  250. } `ini:"git.timeout"`
  251. }
  252. // API settings
  253. API struct {
  254. MaxResponseItems int
  255. }
  256. // UI settings
  257. UI struct {
  258. ExplorePagingNum int
  259. IssuePagingNum int
  260. FeedMaxCommitNum int
  261. ThemeColorMetaTag string
  262. MaxDisplayFileSize int64
  263. Admin struct {
  264. UserPagingNum int
  265. RepoPagingNum int
  266. NoticePagingNum int
  267. OrgPagingNum int
  268. } `ini:"ui.admin"`
  269. User struct {
  270. RepoPagingNum int
  271. NewsFeedPagingNum int
  272. CommitsPagingNum int
  273. } `ini:"ui.user"`
  274. }
  275. // Prometheus settings
  276. Prometheus struct {
  277. Enabled bool
  278. EnableBasicAuth bool
  279. BasicAuthUsername string
  280. BasicAuthPassword string
  281. }
  282. // Other settings
  283. Other struct {
  284. ShowFooterBranding bool
  285. ShowFooterTemplateLoadTime bool
  286. }
  287. // Global setting
  288. HasRobotsTxt bool
  289. )
  290. type ServerOpts struct {
  291. ExternalURL string `ini:"EXTERNAL_URL"`
  292. Domain string
  293. Protocol string
  294. HTTPAddr string `ini:"HTTP_ADDR"`
  295. HTTPPort string `ini:"HTTP_PORT"`
  296. CertFile string
  297. KeyFile string
  298. TLSMinVersion string `ini:"TLS_MIN_VERSION"`
  299. UnixSocketPermission string
  300. LocalRootURL string `ini:"LOCAL_ROOT_URL"`
  301. OfflineMode bool
  302. DisableRouterLog bool
  303. EnableGzip bool
  304. AppDataPath string
  305. LoadAssetsFromDisk bool
  306. LandingURL string `ini:"LANDING_URL"`
  307. // Derived from other static values
  308. URL *url.URL `ini:"-"` // Parsed URL object of ExternalURL.
  309. Subpath string `ini:"-"` // Subpath found the ExternalURL. Should be empty when not found.
  310. SubpathDepth int `ini:"-"` // The number of slashes found in the Subpath.
  311. UnixSocketMode os.FileMode `ini:"-"` // Parsed file mode of UnixSocketPermission.
  312. }
  313. // Server settings
  314. var Server ServerOpts
  315. type DatabaseOpts struct {
  316. Type string
  317. Host string
  318. Name string
  319. Schema string
  320. User string
  321. Password string
  322. SSLMode string `ini:"SSL_MODE"`
  323. Path string
  324. MaxOpenConns int
  325. MaxIdleConns int
  326. }
  327. // Database settings
  328. var Database DatabaseOpts
  329. type LFSOpts struct {
  330. Storage string
  331. ObjectsPath string
  332. }
  333. // LFS settings
  334. var LFS LFSOpts
  335. type i18nConf struct {
  336. Langs []string `delim:","`
  337. Names []string `delim:","`
  338. dateLangs map[string]string `ini:"-"`
  339. }
  340. // DateLang transforms standard language locale name to corresponding value in datetime plugin.
  341. func (c *i18nConf) DateLang(lang string) string {
  342. name, ok := c.dateLangs[lang]
  343. if ok {
  344. return name
  345. }
  346. return "en"
  347. }
  348. // I18n settings
  349. var I18n *i18nConf
  350. // handleDeprecated transfers deprecated values to the new ones when set.
  351. func handleDeprecated() {
  352. // Add fallback logic here, example:
  353. // if App.AppName != "" {
  354. // App.BrandName = App.AppName
  355. // App.AppName = ""
  356. // }
  357. }
  358. // HookMode indicates whether program starts as Git server-side hook callback.
  359. // All operations should be done synchronously to prevent program exits before finishing.
  360. //
  361. // ⚠️ WARNING: Should only be set by "internal/cmd/serv.go".
  362. var HookMode bool
  363. // Indicates which database backend is currently being used.
  364. var (
  365. UseSQLite3 bool
  366. UseMySQL bool
  367. UsePostgreSQL bool
  368. UseMSSQL bool
  369. )