static.go 13 KB

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