static.go 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456
  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. ServerAlgorithms []string `ini:"SSH_SERVER_ALGORITHMS"`
  262. }
  263. // SSH settings
  264. var SSH SSHOpts
  265. type RepositoryOpts struct {
  266. Root string
  267. ScriptType string
  268. ANSICharset string `ini:"ANSI_CHARSET"`
  269. ForcePrivate bool
  270. MaxCreationLimit int
  271. PreferredLicenses []string
  272. DisableHTTPGit bool `ini:"DISABLE_HTTP_GIT"`
  273. EnableLocalPathMigration bool
  274. EnableRawFileRenderMode bool
  275. CommitsFetchConcurrency int
  276. DefaultBranch string
  277. // Repository editor settings
  278. Editor struct {
  279. LineWrapExtensions []string
  280. PreviewableFileModes []string
  281. } `ini:"repository.editor"`
  282. // Repository upload settings
  283. Upload struct {
  284. Enabled bool
  285. TempPath string
  286. AllowedTypes []string `delim:"|"`
  287. FileMaxSize int64
  288. MaxFiles int
  289. } `ini:"repository.upload"`
  290. }
  291. // Repository settings
  292. var Repository RepositoryOpts
  293. type DatabaseOpts struct {
  294. Type string
  295. Host string
  296. Name string
  297. Schema string
  298. User string
  299. Password string
  300. SSLMode string `ini:"SSL_MODE"`
  301. Path string
  302. MaxOpenConns int
  303. MaxIdleConns int
  304. }
  305. // Database settings
  306. var Database DatabaseOpts
  307. type LFSOpts struct {
  308. Storage string
  309. ObjectsPath string
  310. }
  311. // LFS settings
  312. var LFS LFSOpts
  313. type UIUserOpts struct {
  314. RepoPagingNum int
  315. NewsFeedPagingNum int
  316. CommitsPagingNum int
  317. }
  318. type UIOpts struct {
  319. ExplorePagingNum int
  320. IssuePagingNum int
  321. FeedMaxCommitNum int
  322. ThemeColorMetaTag string
  323. MaxDisplayFileSize int64
  324. Admin struct {
  325. UserPagingNum int
  326. RepoPagingNum int
  327. NoticePagingNum int
  328. OrgPagingNum int
  329. } `ini:"ui.admin"`
  330. User UIUserOpts `ini:"ui.user"`
  331. }
  332. // UI settings
  333. var UI UIOpts
  334. type PictureOpts struct {
  335. AvatarUploadPath string
  336. RepositoryAvatarUploadPath string
  337. GravatarSource string
  338. DisableGravatar bool
  339. EnableFederatedAvatar bool
  340. // Derived from other static values
  341. LibravatarService *libravatar.Libravatar `ini:"-"` // Initialized client for federated avatar.
  342. }
  343. // Picture settings
  344. var Picture PictureOpts
  345. type i18nConf struct {
  346. Langs []string `delim:","`
  347. Names []string `delim:","`
  348. dateLangs map[string]string `ini:"-"`
  349. }
  350. // DateLang transforms standard language locale name to corresponding value in datetime plugin.
  351. func (c *i18nConf) DateLang(lang string) string {
  352. name, ok := c.dateLangs[lang]
  353. if ok {
  354. return name
  355. }
  356. return "en"
  357. }
  358. // I18n settings
  359. var I18n *i18nConf
  360. // handleDeprecated transfers deprecated values to the new ones when set.
  361. func handleDeprecated() {
  362. // Add fallback logic here, example:
  363. // if App.AppName != "" {
  364. // App.BrandName = App.AppName
  365. // App.AppName = ""
  366. // }
  367. }
  368. // HookMode indicates whether program starts as Git server-side hook callback.
  369. // All operations should be done synchronously to prevent program exits before finishing.
  370. //
  371. // ⚠️ WARNING: Should only be set by "internal/cmd/serv.go".
  372. var HookMode bool
  373. // Indicates which database backend is currently being used.
  374. var (
  375. UseSQLite3 bool
  376. UseMySQL bool
  377. UsePostgreSQL bool
  378. UseMSSQL bool
  379. )
  380. // UsersAvatarPathPrefix is the path prefix to user avatars.
  381. const UsersAvatarPathPrefix = "avatars"
  382. // UserDefaultAvatarURLPath returns the URL path of the default user avatar.
  383. func UserDefaultAvatarURLPath() string {
  384. return Server.Subpath + "/img/avatar_default.png"
  385. }