static.go 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505
  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. DeliverTimeout int
  249. SkipTLSVerify bool `ini:"SKIP_TLS_VERIFY"`
  250. PagingNum int
  251. }
  252. // Markdown sttings
  253. Markdown struct {
  254. EnableHardLineBreak bool
  255. CustomURLSchemes []string `ini:"CUSTOM_URL_SCHEMES"`
  256. FileExtensions []string
  257. }
  258. // Smartypants settings
  259. Smartypants struct {
  260. Enabled bool
  261. Fractions bool
  262. Dashes bool
  263. LatexDashes bool
  264. AngledQuotes bool
  265. }
  266. // Admin settings
  267. Admin struct {
  268. DisableRegularOrgCreation bool
  269. }
  270. // Cron tasks
  271. Cron struct {
  272. UpdateMirror struct {
  273. Enabled bool
  274. RunAtStart bool
  275. Schedule string
  276. } `ini:"cron.update_mirrors"`
  277. RepoHealthCheck struct {
  278. Enabled bool
  279. RunAtStart bool
  280. Schedule string
  281. Timeout time.Duration
  282. Args []string `delim:" "`
  283. } `ini:"cron.repo_health_check"`
  284. CheckRepoStats struct {
  285. Enabled bool
  286. RunAtStart bool
  287. Schedule string
  288. } `ini:"cron.check_repo_stats"`
  289. RepoArchiveCleanup struct {
  290. Enabled bool
  291. RunAtStart bool
  292. Schedule string
  293. OlderThan time.Duration
  294. } `ini:"cron.repo_archive_cleanup"`
  295. }
  296. // Git settings
  297. Git struct {
  298. // ⚠️ WARNING: Should only be set by "internal/db/repo.go".
  299. Version string `ini:"-"`
  300. DisableDiffHighlight bool
  301. MaxDiffFiles int `ini:"MAX_GIT_DIFF_FILES"`
  302. MaxDiffLines int `ini:"MAX_GIT_DIFF_LINES"`
  303. MaxDiffLineChars int `ini:"MAX_GIT_DIFF_LINE_CHARACTERS"`
  304. GCArgs []string `ini:"GC_ARGS" delim:" "`
  305. Timeout struct {
  306. Migrate int
  307. Mirror int
  308. Clone int
  309. Pull int
  310. GC int `ini:"GC"`
  311. } `ini:"git.timeout"`
  312. }
  313. // API settings
  314. API struct {
  315. MaxResponseItems int
  316. }
  317. // UI settings
  318. UI struct {
  319. ExplorePagingNum int
  320. IssuePagingNum int
  321. FeedMaxCommitNum int
  322. ThemeColorMetaTag string
  323. MaxDisplayFileSize int64
  324. Admin struct {
  325. UserPagingNum int
  326. RepoPagingNum int
  327. NoticePagingNum int
  328. OrgPagingNum int
  329. } `ini:"ui.admin"`
  330. User struct {
  331. RepoPagingNum int
  332. NewsFeedPagingNum int
  333. CommitsPagingNum int
  334. } `ini:"ui.user"`
  335. }
  336. // Prometheus settings
  337. Prometheus struct {
  338. Enabled bool
  339. EnableBasicAuth bool
  340. BasicAuthUsername string
  341. BasicAuthPassword string
  342. }
  343. // Other settings
  344. Other struct {
  345. ShowFooterBranding bool
  346. ShowFooterTemplateLoadTime bool
  347. }
  348. // Global setting
  349. HasRobotsTxt bool
  350. )
  351. type i18nConf struct {
  352. Langs []string `delim:","`
  353. Names []string `delim:","`
  354. dateLangs map[string]string `ini:"-"`
  355. }
  356. // DateLang transforms standard language locale name to corresponding value in datetime plugin.
  357. func (c *i18nConf) DateLang(lang string) string {
  358. name, ok := c.dateLangs[lang]
  359. if ok {
  360. return name
  361. }
  362. return "en"
  363. }
  364. // handleDeprecated transfers deprecated values to the new ones when set.
  365. func handleDeprecated() {
  366. if App.AppName != "" {
  367. App.BrandName = App.AppName
  368. App.AppName = ""
  369. }
  370. if Server.RootURL != "" {
  371. Server.ExternalURL = Server.RootURL
  372. Server.RootURL = ""
  373. }
  374. if Server.LangdingPage == "explore" {
  375. Server.LandingURL = "/explore"
  376. Server.LangdingPage = ""
  377. }
  378. if Database.DbType != "" {
  379. Database.Type = Database.DbType
  380. Database.DbType = ""
  381. }
  382. if Database.Passwd != "" {
  383. Database.Password = Database.Passwd
  384. Database.Passwd = ""
  385. }
  386. if Email.Passwd != "" {
  387. Email.Password = Email.Passwd
  388. Email.Passwd = ""
  389. }
  390. if Auth.ActiveCodeLiveMinutes > 0 {
  391. Auth.ActivateCodeLives = Auth.ActiveCodeLiveMinutes
  392. Auth.ActiveCodeLiveMinutes = 0
  393. }
  394. if Auth.ResetPasswdCodeLiveMinutes > 0 {
  395. Auth.ResetPasswordCodeLives = Auth.ResetPasswdCodeLiveMinutes
  396. Auth.ResetPasswdCodeLiveMinutes = 0
  397. }
  398. if Auth.RegisterEmailConfirm {
  399. Auth.RequireEmailConfirmation = true
  400. Auth.RegisterEmailConfirm = false
  401. }
  402. if Auth.EnableCaptcha {
  403. Auth.EnableRegistrationCaptcha = true
  404. Auth.EnableCaptcha = false
  405. }
  406. if Security.ReverseProxyAuthenticationUser != "" {
  407. Auth.ReverseProxyAuthenticationHeader = Security.ReverseProxyAuthenticationUser
  408. Security.ReverseProxyAuthenticationUser = ""
  409. }
  410. if Auth.EnableNotifyMail {
  411. User.EnableEmailNotification = true
  412. Auth.EnableNotifyMail = false
  413. }
  414. if Session.GCIntervalTime > 0 {
  415. Session.GCInterval = Session.GCIntervalTime
  416. Session.GCIntervalTime = 0
  417. }
  418. if Session.SessionLifeTime > 0 {
  419. Session.MaxLifeTime = Session.SessionLifeTime
  420. Session.SessionLifeTime = 0
  421. }
  422. }
  423. // HookMode indicates whether program starts as Git server-side hook callback.
  424. // All operations should be done synchronously to prevent program exits before finishing.
  425. //
  426. // ⚠️ WARNING: Should only be set by "internal/cmd/serv.go".
  427. var HookMode bool
  428. // Indicates which database backend is currently being used.
  429. var (
  430. UseSQLite3 bool
  431. UseMySQL bool
  432. UsePostgreSQL bool
  433. UseMSSQL bool
  434. )