static.go 10 KB

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