static.go 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428
  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. }
  36. // SSH settings
  37. SSH struct {
  38. Disabled bool `ini:"DISABLE_SSH"`
  39. Domain string `ini:"SSH_DOMAIN"`
  40. Port int `ini:"SSH_PORT"`
  41. RootPath string `ini:"SSH_ROOT_PATH"`
  42. KeygenPath string `ini:"SSH_KEYGEN_PATH"`
  43. KeyTestPath string `ini:"SSH_KEY_TEST_PATH"`
  44. MinimumKeySizeCheck bool
  45. MinimumKeySizes map[string]int `ini:"-"` // Load from [ssh.minimum_key_sizes]
  46. RewriteAuthorizedKeysAtStart bool
  47. StartBuiltinServer bool `ini:"START_SSH_SERVER"`
  48. ListenHost string `ini:"SSH_LISTEN_HOST"`
  49. ListenPort int `ini:"SSH_LISTEN_PORT"`
  50. ServerCiphers []string `ini:"SSH_SERVER_CIPHERS"`
  51. }
  52. // Repository settings
  53. Repository struct {
  54. Root string
  55. ScriptType string
  56. ANSICharset string `ini:"ANSI_CHARSET"`
  57. ForcePrivate bool
  58. MaxCreationLimit int
  59. PreferredLicenses []string
  60. DisableHTTPGit bool `ini:"DISABLE_HTTP_GIT"`
  61. EnableLocalPathMigration bool
  62. EnableRawFileRenderMode bool
  63. CommitsFetchConcurrency int
  64. // Repository editor settings
  65. Editor struct {
  66. LineWrapExtensions []string
  67. PreviewableFileModes []string
  68. } `ini:"repository.editor"`
  69. // Repository upload settings
  70. Upload struct {
  71. Enabled bool
  72. TempPath string
  73. AllowedTypes []string `delim:"|"`
  74. FileMaxSize int64
  75. MaxFiles int
  76. } `ini:"repository.upload"`
  77. }
  78. // Security settings
  79. Security struct {
  80. InstallLock bool
  81. SecretKey string
  82. LoginRememberDays int
  83. CookieRememberName string
  84. CookieUsername string
  85. CookieSecure bool
  86. EnableLoginStatusCookie bool
  87. LoginStatusCookieName string
  88. }
  89. // Email settings
  90. Email struct {
  91. Enabled bool
  92. SubjectPrefix string
  93. Host string
  94. From string
  95. User string
  96. Password string
  97. DisableHELO bool `ini:"DISABLE_HELO"`
  98. HELOHostname string `ini:"HELO_HOSTNAME"`
  99. SkipVerify bool
  100. UseCertificate bool
  101. CertFile string
  102. KeyFile string
  103. UsePlainText bool
  104. AddPlainTextAlt bool
  105. // Derived from other static values
  106. FromEmail string `ini:"-"` // Parsed email address of From without person's name.
  107. }
  108. // Authentication settings
  109. Auth struct {
  110. ActivateCodeLives int
  111. ResetPasswordCodeLives int
  112. RequireEmailConfirmation bool
  113. RequireSigninView bool
  114. DisableRegistration bool
  115. EnableRegistrationCaptcha bool
  116. EnableReverseProxyAuthentication bool
  117. EnableReverseProxyAutoRegistration bool
  118. ReverseProxyAuthenticationHeader string
  119. }
  120. // User settings
  121. User struct {
  122. EnableEmailNotification bool
  123. }
  124. // Session settings
  125. Session struct {
  126. Provider string
  127. ProviderConfig string
  128. CookieName string
  129. CookieSecure bool
  130. GCInterval int64 `ini:"GC_INTERVAL"`
  131. MaxLifeTime int64
  132. CSRFCookieName string `ini:"CSRF_COOKIE_NAME"`
  133. }
  134. // Cache settings
  135. Cache struct {
  136. Adapter string
  137. Interval int
  138. Host string
  139. }
  140. // HTTP settings
  141. HTTP struct {
  142. AccessControlAllowOrigin string
  143. }
  144. // Attachment settings
  145. Attachment struct {
  146. Enabled bool
  147. Path string
  148. AllowedTypes []string `delim:"|"`
  149. MaxSize int64
  150. MaxFiles int
  151. }
  152. // Release settings
  153. Release struct {
  154. Attachment struct {
  155. Enabled bool
  156. AllowedTypes []string `delim:"|"`
  157. MaxSize int64
  158. MaxFiles int
  159. } `ini:"release.attachment"`
  160. }
  161. // Time settings
  162. Time struct {
  163. Format string
  164. // Derived from other static values
  165. FormatLayout string `ini:"-"` // Actual layout of the Format.
  166. }
  167. // Picture settings
  168. Picture struct {
  169. AvatarUploadPath string
  170. RepositoryAvatarUploadPath string
  171. GravatarSource string
  172. DisableGravatar bool
  173. EnableFederatedAvatar bool
  174. // Derived from other static values
  175. LibravatarService *libravatar.Libravatar `ini:"-"` // Initialized client for federated avatar.
  176. }
  177. // Mirror settings
  178. Mirror struct {
  179. DefaultInterval int
  180. }
  181. // Webhook settings
  182. Webhook struct {
  183. Types []string
  184. DeliverTimeout int
  185. SkipTLSVerify bool `ini:"SKIP_TLS_VERIFY"`
  186. PagingNum int
  187. }
  188. // Markdown settings
  189. Markdown struct {
  190. EnableHardLineBreak bool
  191. CustomURLSchemes []string `ini:"CUSTOM_URL_SCHEMES"`
  192. FileExtensions []string
  193. }
  194. // Smartypants settings
  195. Smartypants struct {
  196. Enabled bool
  197. Fractions bool
  198. Dashes bool
  199. LatexDashes bool
  200. AngledQuotes bool
  201. }
  202. // Admin settings
  203. Admin struct {
  204. DisableRegularOrgCreation bool
  205. }
  206. // Cron tasks
  207. Cron struct {
  208. UpdateMirror struct {
  209. Enabled bool
  210. RunAtStart bool
  211. Schedule string
  212. } `ini:"cron.update_mirrors"`
  213. RepoHealthCheck struct {
  214. Enabled bool
  215. RunAtStart bool
  216. Schedule string
  217. Timeout time.Duration
  218. Args []string `delim:" "`
  219. } `ini:"cron.repo_health_check"`
  220. CheckRepoStats struct {
  221. Enabled bool
  222. RunAtStart bool
  223. Schedule string
  224. } `ini:"cron.check_repo_stats"`
  225. RepoArchiveCleanup struct {
  226. Enabled bool
  227. RunAtStart bool
  228. Schedule string
  229. OlderThan time.Duration
  230. } `ini:"cron.repo_archive_cleanup"`
  231. }
  232. // Git settings
  233. Git struct {
  234. // ⚠️ WARNING: Should only be set by "internal/db/repo.go".
  235. Version string `ini:"-"`
  236. DisableDiffHighlight bool
  237. MaxDiffFiles int `ini:"MAX_GIT_DIFF_FILES"`
  238. MaxDiffLines int `ini:"MAX_GIT_DIFF_LINES"`
  239. MaxDiffLineChars int `ini:"MAX_GIT_DIFF_LINE_CHARACTERS"`
  240. GCArgs []string `ini:"GC_ARGS" delim:" "`
  241. Timeout struct {
  242. Migrate int
  243. Mirror int
  244. Clone int
  245. Pull int
  246. Diff int
  247. GC int `ini:"GC"`
  248. } `ini:"git.timeout"`
  249. }
  250. // API settings
  251. API struct {
  252. MaxResponseItems int
  253. }
  254. // UI settings
  255. UI struct {
  256. ExplorePagingNum int
  257. IssuePagingNum int
  258. FeedMaxCommitNum int
  259. ThemeColorMetaTag string
  260. MaxDisplayFileSize int64
  261. Admin struct {
  262. UserPagingNum int
  263. RepoPagingNum int
  264. NoticePagingNum int
  265. OrgPagingNum int
  266. } `ini:"ui.admin"`
  267. User struct {
  268. RepoPagingNum int
  269. NewsFeedPagingNum int
  270. CommitsPagingNum int
  271. } `ini:"ui.user"`
  272. }
  273. // Prometheus settings
  274. Prometheus struct {
  275. Enabled bool
  276. EnableBasicAuth bool
  277. BasicAuthUsername string
  278. BasicAuthPassword string
  279. }
  280. // Other settings
  281. Other struct {
  282. ShowFooterBranding bool
  283. ShowFooterTemplateLoadTime bool
  284. }
  285. // Global setting
  286. HasRobotsTxt bool
  287. )
  288. type ServerOpts struct {
  289. ExternalURL string `ini:"EXTERNAL_URL"`
  290. Domain string
  291. Protocol string
  292. HTTPAddr string `ini:"HTTP_ADDR"`
  293. HTTPPort string `ini:"HTTP_PORT"`
  294. CertFile string
  295. KeyFile string
  296. TLSMinVersion string `ini:"TLS_MIN_VERSION"`
  297. UnixSocketPermission string
  298. LocalRootURL string `ini:"LOCAL_ROOT_URL"`
  299. OfflineMode bool
  300. DisableRouterLog bool
  301. EnableGzip bool
  302. AppDataPath string
  303. LoadAssetsFromDisk bool
  304. LandingURL string `ini:"LANDING_URL"`
  305. // Derived from other static values
  306. URL *url.URL `ini:"-"` // Parsed URL object of ExternalURL.
  307. Subpath string `ini:"-"` // Subpath found the ExternalURL. Should be empty when not found.
  308. SubpathDepth int `ini:"-"` // The number of slashes found in the Subpath.
  309. UnixSocketMode os.FileMode `ini:"-"` // Parsed file mode of UnixSocketPermission.
  310. }
  311. // Server settings
  312. var Server ServerOpts
  313. type DatabaseOpts struct {
  314. Type string
  315. Host string
  316. Name string
  317. User string
  318. Password string
  319. SSLMode string `ini:"SSL_MODE"`
  320. Path string
  321. MaxOpenConns int
  322. MaxIdleConns int
  323. }
  324. // Database settings
  325. var Database DatabaseOpts
  326. type LFSOpts struct {
  327. Storage string
  328. ObjectsPath string
  329. }
  330. // LFS settings
  331. var LFS LFSOpts
  332. type i18nConf struct {
  333. Langs []string `delim:","`
  334. Names []string `delim:","`
  335. dateLangs map[string]string `ini:"-"`
  336. }
  337. // DateLang transforms standard language locale name to corresponding value in datetime plugin.
  338. func (c *i18nConf) DateLang(lang string) string {
  339. name, ok := c.dateLangs[lang]
  340. if ok {
  341. return name
  342. }
  343. return "en"
  344. }
  345. // I18n settings
  346. var I18n *i18nConf
  347. // handleDeprecated transfers deprecated values to the new ones when set.
  348. func handleDeprecated() {
  349. // Add fallback logic here, example:
  350. // if App.AppName != "" {
  351. // App.BrandName = App.AppName
  352. // App.AppName = ""
  353. // }
  354. }
  355. // HookMode indicates whether program starts as Git server-side hook callback.
  356. // All operations should be done synchronously to prevent program exits before finishing.
  357. //
  358. // ⚠️ WARNING: Should only be set by "internal/cmd/serv.go".
  359. var HookMode bool
  360. // Indicates which database backend is currently being used.
  361. var (
  362. UseSQLite3 bool
  363. UseMySQL bool
  364. UsePostgreSQL bool
  365. UseMSSQL bool
  366. )