static.go 11 KB

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