static.go 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516
  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. // LFS settings
  165. LFS struct {
  166. ObjectsPath string
  167. }
  168. // Attachment settings
  169. Attachment struct {
  170. Enabled bool
  171. Path string
  172. AllowedTypes []string `delim:"|"`
  173. MaxSize int64
  174. MaxFiles int
  175. }
  176. // Release settings
  177. Release struct {
  178. Attachment struct {
  179. Enabled bool
  180. AllowedTypes []string `delim:"|"`
  181. MaxSize int64
  182. MaxFiles int
  183. } `ini:"release.attachment"`
  184. }
  185. // Time settings
  186. Time struct {
  187. Format string
  188. // Derived from other static values
  189. FormatLayout string `ini:"-"` // Actual layout of the Format.
  190. }
  191. // Picture settings
  192. Picture struct {
  193. AvatarUploadPath string
  194. RepositoryAvatarUploadPath string
  195. GravatarSource string
  196. DisableGravatar bool
  197. EnableFederatedAvatar bool
  198. // Derived from other static values
  199. LibravatarService *libravatar.Libravatar `ini:"-"` // Initialized client for federated avatar.
  200. }
  201. // Mirror settings
  202. Mirror struct {
  203. DefaultInterval int
  204. }
  205. // Webhook settings
  206. Webhook struct {
  207. Types []string
  208. DeliverTimeout int
  209. SkipTLSVerify bool `ini:"SKIP_TLS_VERIFY"`
  210. PagingNum int
  211. }
  212. // Markdown settings
  213. Markdown struct {
  214. EnableHardLineBreak bool
  215. CustomURLSchemes []string `ini:"CUSTOM_URL_SCHEMES"`
  216. FileExtensions []string
  217. }
  218. // Smartypants settings
  219. Smartypants struct {
  220. Enabled bool
  221. Fractions bool
  222. Dashes bool
  223. LatexDashes bool
  224. AngledQuotes bool
  225. }
  226. // Admin settings
  227. Admin struct {
  228. DisableRegularOrgCreation bool
  229. }
  230. // Cron tasks
  231. Cron struct {
  232. UpdateMirror struct {
  233. Enabled bool
  234. RunAtStart bool
  235. Schedule string
  236. } `ini:"cron.update_mirrors"`
  237. RepoHealthCheck struct {
  238. Enabled bool
  239. RunAtStart bool
  240. Schedule string
  241. Timeout time.Duration
  242. Args []string `delim:" "`
  243. } `ini:"cron.repo_health_check"`
  244. CheckRepoStats struct {
  245. Enabled bool
  246. RunAtStart bool
  247. Schedule string
  248. } `ini:"cron.check_repo_stats"`
  249. RepoArchiveCleanup struct {
  250. Enabled bool
  251. RunAtStart bool
  252. Schedule string
  253. OlderThan time.Duration
  254. } `ini:"cron.repo_archive_cleanup"`
  255. }
  256. // Git settings
  257. Git struct {
  258. // ⚠️ WARNING: Should only be set by "internal/db/repo.go".
  259. Version string `ini:"-"`
  260. DisableDiffHighlight bool
  261. MaxDiffFiles int `ini:"MAX_GIT_DIFF_FILES"`
  262. MaxDiffLines int `ini:"MAX_GIT_DIFF_LINES"`
  263. MaxDiffLineChars int `ini:"MAX_GIT_DIFF_LINE_CHARACTERS"`
  264. GCArgs []string `ini:"GC_ARGS" delim:" "`
  265. Timeout struct {
  266. Migrate int
  267. Mirror int
  268. Clone int
  269. Pull int
  270. GC int `ini:"GC"`
  271. } `ini:"git.timeout"`
  272. }
  273. // API settings
  274. API struct {
  275. MaxResponseItems int
  276. }
  277. // UI settings
  278. UI struct {
  279. ExplorePagingNum int
  280. IssuePagingNum int
  281. FeedMaxCommitNum int
  282. ThemeColorMetaTag string
  283. MaxDisplayFileSize int64
  284. Admin struct {
  285. UserPagingNum int
  286. RepoPagingNum int
  287. NoticePagingNum int
  288. OrgPagingNum int
  289. } `ini:"ui.admin"`
  290. User struct {
  291. RepoPagingNum int
  292. NewsFeedPagingNum int
  293. CommitsPagingNum int
  294. } `ini:"ui.user"`
  295. }
  296. // Prometheus settings
  297. Prometheus struct {
  298. Enabled bool
  299. EnableBasicAuth bool
  300. BasicAuthUsername string
  301. BasicAuthPassword string
  302. }
  303. // Other settings
  304. Other struct {
  305. ShowFooterBranding bool
  306. ShowFooterTemplateLoadTime bool
  307. }
  308. // Global setting
  309. HasRobotsTxt bool
  310. )
  311. type ServerOpts struct {
  312. ExternalURL string `ini:"EXTERNAL_URL"`
  313. Domain string
  314. Protocol string
  315. HTTPAddr string `ini:"HTTP_ADDR"`
  316. HTTPPort string `ini:"HTTP_PORT"`
  317. CertFile string
  318. KeyFile string
  319. TLSMinVersion string `ini:"TLS_MIN_VERSION"`
  320. UnixSocketPermission string
  321. LocalRootURL string `ini:"LOCAL_ROOT_URL"`
  322. OfflineMode bool
  323. DisableRouterLog bool
  324. EnableGzip bool
  325. AppDataPath string
  326. LoadAssetsFromDisk bool
  327. LandingURL string `ini:"LANDING_URL"`
  328. // Derived from other static values
  329. URL *url.URL `ini:"-"` // Parsed URL object of ExternalURL.
  330. Subpath string `ini:"-"` // Subpath found the ExternalURL. Should be empty when not found.
  331. SubpathDepth int `ini:"-"` // The number of slashes found in the Subpath.
  332. UnixSocketMode os.FileMode `ini:"-"` // Parsed file mode of UnixSocketPermission.
  333. // Deprecated: Use ExternalURL instead, will be removed in 0.13.
  334. RootURL string `ini:"ROOT_URL"`
  335. // Deprecated: Use LandingURL instead, will be removed in 0.13.
  336. LangdingPage string `ini:"LANDING_PAGE"`
  337. }
  338. // Server settings
  339. var Server ServerOpts
  340. type DatabaseOpts struct {
  341. Type string
  342. Host string
  343. Name string
  344. User string
  345. Password string
  346. SSLMode string `ini:"SSL_MODE"`
  347. Path string
  348. MaxOpenConns int
  349. MaxIdleConns int
  350. // Deprecated: Use Type instead, will be removed in 0.13.
  351. DbType string
  352. // Deprecated: Use Password instead, will be removed in 0.13.
  353. Passwd string
  354. }
  355. // Database settings
  356. var Database DatabaseOpts
  357. type i18nConf struct {
  358. Langs []string `delim:","`
  359. Names []string `delim:","`
  360. dateLangs map[string]string `ini:"-"`
  361. }
  362. // DateLang transforms standard language locale name to corresponding value in datetime plugin.
  363. func (c *i18nConf) DateLang(lang string) string {
  364. name, ok := c.dateLangs[lang]
  365. if ok {
  366. return name
  367. }
  368. return "en"
  369. }
  370. // I18n settings
  371. var I18n *i18nConf
  372. // handleDeprecated transfers deprecated values to the new ones when set.
  373. func handleDeprecated() {
  374. if App.AppName != "" {
  375. App.BrandName = App.AppName
  376. App.AppName = ""
  377. }
  378. if Server.RootURL != "" {
  379. Server.ExternalURL = Server.RootURL
  380. Server.RootURL = ""
  381. }
  382. if Server.LangdingPage == "explore" {
  383. Server.LandingURL = "/explore"
  384. Server.LangdingPage = ""
  385. }
  386. if Database.DbType != "" {
  387. Database.Type = Database.DbType
  388. Database.DbType = ""
  389. }
  390. if Database.Passwd != "" {
  391. Database.Password = Database.Passwd
  392. Database.Passwd = ""
  393. }
  394. if Email.Passwd != "" {
  395. Email.Password = Email.Passwd
  396. Email.Passwd = ""
  397. }
  398. if Auth.ActiveCodeLiveMinutes > 0 {
  399. Auth.ActivateCodeLives = Auth.ActiveCodeLiveMinutes
  400. Auth.ActiveCodeLiveMinutes = 0
  401. }
  402. if Auth.ResetPasswdCodeLiveMinutes > 0 {
  403. Auth.ResetPasswordCodeLives = Auth.ResetPasswdCodeLiveMinutes
  404. Auth.ResetPasswdCodeLiveMinutes = 0
  405. }
  406. if Auth.RegisterEmailConfirm {
  407. Auth.RequireEmailConfirmation = true
  408. Auth.RegisterEmailConfirm = false
  409. }
  410. if Auth.EnableCaptcha {
  411. Auth.EnableRegistrationCaptcha = true
  412. Auth.EnableCaptcha = false
  413. }
  414. if Security.ReverseProxyAuthenticationUser != "" {
  415. Auth.ReverseProxyAuthenticationHeader = Security.ReverseProxyAuthenticationUser
  416. Security.ReverseProxyAuthenticationUser = ""
  417. }
  418. if Auth.EnableNotifyMail {
  419. User.EnableEmailNotification = true
  420. Auth.EnableNotifyMail = false
  421. }
  422. if Session.GCIntervalTime > 0 {
  423. Session.GCInterval = Session.GCIntervalTime
  424. Session.GCIntervalTime = 0
  425. }
  426. if Session.SessionLifeTime > 0 {
  427. Session.MaxLifeTime = Session.SessionLifeTime
  428. Session.SessionLifeTime = 0
  429. }
  430. }
  431. // HookMode indicates whether program starts as Git server-side hook callback.
  432. // All operations should be done synchronously to prevent program exits before finishing.
  433. //
  434. // ⚠️ WARNING: Should only be set by "internal/cmd/serv.go".
  435. var HookMode bool
  436. // Indicates which database backend is currently being used.
  437. var (
  438. UseSQLite3 bool
  439. UseMySQL bool
  440. UsePostgreSQL bool
  441. UseMSSQL bool
  442. )