static.go 13 KB

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