static.go 11 KB

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