static.go 13 KB

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