static.go 10.0 KB

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