static.go 10 KB

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