static.go 10 KB

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