static.go 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504
  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. // Repository editor settings
  95. Editor struct {
  96. LineWrapExtensions []string
  97. PreviewableFileModes []string
  98. } `ini:"repository.editor"`
  99. // Repository upload settings
  100. Upload struct {
  101. Enabled bool
  102. TempPath string
  103. AllowedTypes []string `delim:"|"`
  104. FileMaxSize int64
  105. MaxFiles int
  106. } `ini:"repository.upload"`
  107. }
  108. // Database settings
  109. Database struct {
  110. Type string
  111. Host string
  112. Name string
  113. User string
  114. Password string
  115. SSLMode string `ini:"SSL_MODE"`
  116. Path string
  117. // Deprecated: Use Type instead, will be removed in 0.13.
  118. DbType string
  119. // Deprecated: Use Password instead, will be removed in 0.13.
  120. Passwd string
  121. }
  122. // Security settings
  123. Security struct {
  124. InstallLock bool
  125. SecretKey string
  126. LoginRememberDays int
  127. CookieRememberName string
  128. CookieUsername string
  129. CookieSecure bool
  130. EnableLoginStatusCookie bool
  131. LoginStatusCookieName string
  132. // Deprecated: Use Auth.ReverseProxyAuthenticationHeader instead, will be removed in 0.13.
  133. ReverseProxyAuthenticationUser string
  134. }
  135. // Email settings
  136. Email struct {
  137. Enabled bool
  138. SubjectPrefix string
  139. Host string
  140. From string
  141. User string
  142. Password string
  143. DisableHELO bool `ini:"DISABLE_HELO"`
  144. HELOHostname string `ini:"HELO_HOSTNAME"`
  145. SkipVerify bool
  146. UseCertificate bool
  147. CertFile string
  148. KeyFile string
  149. UsePlainText bool
  150. AddPlainTextAlt bool
  151. // Derived from other static values
  152. FromEmail string `ini:"-"` // Parsed email address of From without person's name.
  153. // Deprecated: Use Password instead, will be removed in 0.13.
  154. Passwd string
  155. }
  156. // Authentication settings
  157. Auth struct {
  158. ActivateCodeLives int
  159. ResetPasswordCodeLives int
  160. RequireEmailConfirmation bool
  161. RequireSigninView bool
  162. DisableRegistration bool
  163. EnableRegistrationCaptcha bool
  164. EnableReverseProxyAuthentication bool
  165. EnableReverseProxyAutoRegistration bool
  166. ReverseProxyAuthenticationHeader string
  167. // Deprecated: Use ActivateCodeLives instead, will be removed in 0.13.
  168. ActiveCodeLiveMinutes int
  169. // Deprecated: Use ResetPasswordCodeLives instead, will be removed in 0.13.
  170. ResetPasswdCodeLiveMinutes int
  171. // Deprecated: Use RequireEmailConfirmation instead, will be removed in 0.13.
  172. RegisterEmailConfirm bool
  173. // Deprecated: Use EnableRegistrationCaptcha instead, will be removed in 0.13.
  174. EnableCaptcha bool
  175. // Deprecated: Use User.EnableEmailNotification instead, will be removed in 0.13.
  176. EnableNotifyMail bool
  177. }
  178. // User settings
  179. User struct {
  180. EnableEmailNotification bool
  181. }
  182. // Session settings
  183. Session struct {
  184. Provider string
  185. ProviderConfig string
  186. CookieName string
  187. CookieSecure bool
  188. GCInterval int64 `ini:"GC_INTERVAL"`
  189. MaxLifeTime int64
  190. CSRFCookieName string `ini:"CSRF_COOKIE_NAME"`
  191. // Deprecated: Use GCInterval instead, will be removed in 0.13.
  192. GCIntervalTime int64 `ini:"GC_INTERVAL_TIME"`
  193. // Deprecated: Use MaxLifeTime instead, will be removed in 0.13.
  194. SessionLifeTime int64
  195. }
  196. // Cache settings
  197. Cache struct {
  198. Adapter string
  199. Interval int
  200. Host string
  201. }
  202. // HTTP settings
  203. HTTP struct {
  204. AccessControlAllowOrigin string
  205. }
  206. // Attachment settings
  207. Attachment struct {
  208. Enabled bool
  209. Path string
  210. AllowedTypes []string `delim:"|"`
  211. MaxSize int64
  212. MaxFiles int
  213. }
  214. // Release settigns
  215. Release struct {
  216. Attachment struct {
  217. Enabled bool
  218. AllowedTypes []string `delim:"|"`
  219. MaxSize int64
  220. MaxFiles int
  221. } `ini:"release.attachment"`
  222. }
  223. // Time settings
  224. Time struct {
  225. Format string
  226. // Derived from other static values
  227. FormatLayout string `ini:"-"` // Actual layout of the Format.
  228. }
  229. // Picture settings
  230. Picture struct {
  231. AvatarUploadPath string
  232. RepositoryAvatarUploadPath string
  233. GravatarSource string
  234. DisableGravatar bool
  235. EnableFederatedAvatar bool
  236. // Derived from other static values
  237. LibravatarService *libravatar.Libravatar `ini:"-"` // Initialized client for federated avatar.
  238. }
  239. // Mirror settings
  240. Mirror struct {
  241. DefaultInterval int
  242. }
  243. // I18n settings
  244. I18n *i18nConf
  245. // Webhook settings
  246. Webhook struct {
  247. Types []string
  248. QueueLength int
  249. DeliverTimeout int
  250. SkipTLSVerify bool `ini:"SKIP_TLS_VERIFY"`
  251. PagingNum int
  252. }
  253. // Markdown sttings
  254. Markdown struct {
  255. EnableHardLineBreak bool
  256. CustomURLSchemes []string `ini:"CUSTOM_URL_SCHEMES"`
  257. FileExtensions []string
  258. }
  259. // Smartypants settings
  260. Smartypants struct {
  261. Enabled bool
  262. Fractions bool
  263. Dashes bool
  264. LatexDashes bool
  265. AngledQuotes bool
  266. }
  267. // Admin settings
  268. Admin struct {
  269. DisableRegularOrgCreation bool
  270. }
  271. // Cron tasks
  272. Cron struct {
  273. UpdateMirror struct {
  274. Enabled bool
  275. RunAtStart bool
  276. Schedule string
  277. } `ini:"cron.update_mirrors"`
  278. RepoHealthCheck struct {
  279. Enabled bool
  280. RunAtStart bool
  281. Schedule string
  282. Timeout time.Duration
  283. Args []string `delim:" "`
  284. } `ini:"cron.repo_health_check"`
  285. CheckRepoStats struct {
  286. Enabled bool
  287. RunAtStart bool
  288. Schedule string
  289. } `ini:"cron.check_repo_stats"`
  290. RepoArchiveCleanup struct {
  291. Enabled bool
  292. RunAtStart bool
  293. Schedule string
  294. OlderThan time.Duration
  295. } `ini:"cron.repo_archive_cleanup"`
  296. }
  297. // Git settings
  298. Git struct {
  299. // ⚠️ WARNING: Should only be set by "internal/db/repo.go".
  300. Version string `ini:"-"`
  301. DisableDiffHighlight bool
  302. MaxGitDiffLines int
  303. MaxGitDiffLineCharacters int
  304. MaxGitDiffFiles int
  305. GCArgs []string `ini:"GC_ARGS" delim:" "`
  306. Timeout struct {
  307. Migrate int
  308. Mirror int
  309. Clone int
  310. Pull int
  311. GC int `ini:"GC"`
  312. } `ini:"git.timeout"`
  313. }
  314. // API settings
  315. API struct {
  316. MaxResponseItems int
  317. }
  318. // UI settings
  319. UI 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 struct {
  332. RepoPagingNum int
  333. NewsFeedPagingNum int
  334. CommitsPagingNum int
  335. } `ini:"ui.user"`
  336. }
  337. // Prometheus settings
  338. Prometheus struct {
  339. Enabled bool
  340. EnableBasicAuth bool
  341. BasicAuthUsername string
  342. BasicAuthPassword string
  343. }
  344. // Other settings
  345. Other struct {
  346. ShowFooterBranding bool
  347. ShowFooterTemplateLoadTime bool
  348. }
  349. // Global setting
  350. HasRobotsTxt bool
  351. )
  352. type i18nConf struct {
  353. Langs []string `delim:","`
  354. Names []string `delim:","`
  355. dateLangs map[string]string `ini:"-"`
  356. }
  357. // DateLang transforms standard language locale name to corresponding value in datetime plugin.
  358. func (c *i18nConf) DateLang(lang string) string {
  359. name, ok := c.dateLangs[lang]
  360. if ok {
  361. return name
  362. }
  363. return "en"
  364. }
  365. // handleDeprecated transfers deprecated values to the new ones when set.
  366. func handleDeprecated() {
  367. if App.AppName != "" {
  368. App.BrandName = App.AppName
  369. App.AppName = ""
  370. }
  371. if Server.RootURL != "" {
  372. Server.ExternalURL = Server.RootURL
  373. Server.RootURL = ""
  374. }
  375. if Server.LangdingPage == "explore" {
  376. Server.LandingURL = "/explore"
  377. Server.LangdingPage = ""
  378. }
  379. if Database.DbType != "" {
  380. Database.Type = Database.DbType
  381. Database.DbType = ""
  382. }
  383. if Database.Passwd != "" {
  384. Database.Password = Database.Passwd
  385. Database.Passwd = ""
  386. }
  387. if Email.Passwd != "" {
  388. Email.Password = Email.Passwd
  389. Email.Passwd = ""
  390. }
  391. if Auth.ActiveCodeLiveMinutes > 0 {
  392. Auth.ActivateCodeLives = Auth.ActiveCodeLiveMinutes
  393. Auth.ActiveCodeLiveMinutes = 0
  394. }
  395. if Auth.ResetPasswdCodeLiveMinutes > 0 {
  396. Auth.ResetPasswordCodeLives = Auth.ResetPasswdCodeLiveMinutes
  397. Auth.ResetPasswdCodeLiveMinutes = 0
  398. }
  399. if Auth.RegisterEmailConfirm {
  400. Auth.RequireEmailConfirmation = true
  401. Auth.RegisterEmailConfirm = false
  402. }
  403. if Auth.EnableCaptcha {
  404. Auth.EnableRegistrationCaptcha = true
  405. Auth.EnableCaptcha = false
  406. }
  407. if Security.ReverseProxyAuthenticationUser != "" {
  408. Auth.ReverseProxyAuthenticationHeader = Security.ReverseProxyAuthenticationUser
  409. Security.ReverseProxyAuthenticationUser = ""
  410. }
  411. if Auth.EnableNotifyMail {
  412. User.EnableEmailNotification = true
  413. Auth.EnableNotifyMail = false
  414. }
  415. if Session.GCIntervalTime > 0 {
  416. Session.GCInterval = Session.GCIntervalTime
  417. Session.GCIntervalTime = 0
  418. }
  419. if Session.SessionLifeTime > 0 {
  420. Session.MaxLifeTime = Session.SessionLifeTime
  421. Session.SessionLifeTime = 0
  422. }
  423. }
  424. // HookMode indicates whether program starts as Git server-side hook callback.
  425. // All operations should be done synchronously to prevent program exits before finishing.
  426. var HookMode bool
  427. // Indicates which database backend is currently being used.
  428. var (
  429. UseSQLite3 bool
  430. UseMySQL bool
  431. UsePostgreSQL bool
  432. UseMSSQL bool
  433. )