static.go 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453
  1. package conf
  2. import (
  3. "net/url"
  4. "os"
  5. "time"
  6. "github.com/gogs/go-libravatar"
  7. )
  8. // ℹ️ README: This file contains static values that should only be set at initialization time.
  9. //
  10. // ⚠️ WARNING: After changing any options, do not forget to update template of
  11. // "/admin/config" page as well.
  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. var (
  26. // Security settings
  27. Security struct {
  28. InstallLock bool
  29. SecretKey string
  30. LoginRememberDays int
  31. CookieRememberName string
  32. CookieUsername string
  33. CookieSecure bool
  34. EnableLoginStatusCookie bool
  35. LoginStatusCookieName string
  36. LocalNetworkAllowlist []string `delim:","`
  37. }
  38. // Email settings
  39. Email struct {
  40. Enabled bool
  41. SubjectPrefix string
  42. Host string
  43. From string
  44. User string
  45. Password string
  46. DisableHELO bool `ini:"DISABLE_HELO"`
  47. HELOHostname string `ini:"HELO_HOSTNAME"`
  48. SkipVerify bool
  49. UseCertificate bool
  50. CertFile string
  51. KeyFile string
  52. UsePlainText bool
  53. AddPlainTextAlt bool
  54. // Derived from other static values
  55. FromEmail string `ini:"-"` // Parsed email address of From without person's name.
  56. }
  57. // User settings
  58. User struct {
  59. EnableEmailNotification bool
  60. }
  61. // Session settings
  62. Session struct {
  63. Provider string
  64. ProviderConfig string
  65. CookieName string
  66. CookieSecure bool
  67. GCInterval int64 `ini:"GC_INTERVAL"`
  68. MaxLifeTime int64
  69. CSRFCookieName string `ini:"CSRF_COOKIE_NAME"`
  70. }
  71. // Cache settings
  72. Cache struct {
  73. Adapter string
  74. Interval int
  75. Host string
  76. }
  77. // HTTP settings
  78. HTTP struct {
  79. AccessControlAllowOrigin string
  80. }
  81. // Attachment settings
  82. Attachment struct {
  83. Enabled bool
  84. Path string
  85. AllowedTypes []string `delim:"|"`
  86. MaxSize int64
  87. MaxFiles int
  88. }
  89. // Release settings
  90. Release struct {
  91. Attachment struct {
  92. Enabled bool
  93. AllowedTypes []string `delim:"|"`
  94. MaxSize int64
  95. MaxFiles int
  96. } `ini:"release.attachment"`
  97. }
  98. // Time settings
  99. Time struct {
  100. Format string
  101. // Derived from other static values
  102. FormatLayout string `ini:"-"` // Actual layout of the Format.
  103. }
  104. // Mirror settings
  105. Mirror struct {
  106. DefaultInterval int
  107. }
  108. // Webhook settings
  109. Webhook struct {
  110. Types []string
  111. DeliverTimeout int
  112. SkipTLSVerify bool `ini:"SKIP_TLS_VERIFY"`
  113. PagingNum int
  114. }
  115. // Markdown settings
  116. Markdown struct {
  117. EnableHardLineBreak bool
  118. CustomURLSchemes []string `ini:"CUSTOM_URL_SCHEMES"`
  119. FileExtensions []string
  120. }
  121. // Smartypants settings
  122. Smartypants struct {
  123. Enabled bool
  124. Fractions bool
  125. Dashes bool
  126. LatexDashes bool
  127. AngledQuotes bool
  128. }
  129. // Admin settings
  130. Admin struct {
  131. DisableRegularOrgCreation bool
  132. }
  133. // Cron tasks
  134. Cron struct {
  135. UpdateMirror struct {
  136. Enabled bool
  137. RunAtStart bool
  138. Schedule string
  139. } `ini:"cron.update_mirrors"`
  140. RepoHealthCheck struct {
  141. Enabled bool
  142. RunAtStart bool
  143. Schedule string
  144. Timeout time.Duration
  145. Args []string `delim:" "`
  146. } `ini:"cron.repo_health_check"`
  147. CheckRepoStats struct {
  148. Enabled bool
  149. RunAtStart bool
  150. Schedule string
  151. } `ini:"cron.check_repo_stats"`
  152. RepoArchiveCleanup struct {
  153. Enabled bool
  154. RunAtStart bool
  155. Schedule string
  156. OlderThan time.Duration
  157. } `ini:"cron.repo_archive_cleanup"`
  158. }
  159. // Git settings
  160. Git struct {
  161. // ⚠️ WARNING: Should only be set by "internal/db/repo.go".
  162. Version string `ini:"-"`
  163. DisableDiffHighlight bool
  164. MaxDiffFiles int `ini:"MAX_GIT_DIFF_FILES"`
  165. MaxDiffLines int `ini:"MAX_GIT_DIFF_LINES"`
  166. MaxDiffLineChars int `ini:"MAX_GIT_DIFF_LINE_CHARACTERS"`
  167. GCArgs []string `ini:"GC_ARGS" delim:" "`
  168. Timeout struct {
  169. Migrate int
  170. Mirror int
  171. Clone int
  172. Pull int
  173. Diff int
  174. GC int `ini:"GC"`
  175. } `ini:"git.timeout"`
  176. }
  177. // API settings
  178. API struct {
  179. MaxResponseItems int
  180. }
  181. // Prometheus settings
  182. Prometheus struct {
  183. Enabled bool
  184. EnableBasicAuth bool
  185. BasicAuthUsername string
  186. BasicAuthPassword string
  187. }
  188. // Other settings
  189. Other struct {
  190. ShowFooterBranding bool
  191. ShowFooterTemplateLoadTime bool
  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. CustomLogoutURL string `ini:"CUSTOM_LOGOUT_URL"`
  216. }
  217. // Authentication settings
  218. var Auth AuthOpts
  219. type ServerOpts struct {
  220. ExternalURL string `ini:"EXTERNAL_URL"`
  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. MaxCreationLimit int
  269. PreferredLicenses []string
  270. DisableHTTPGit bool `ini:"DISABLE_HTTP_GIT"`
  271. EnableLocalPathMigration bool
  272. EnableRawFileRenderMode bool
  273. CommitsFetchConcurrency int
  274. DefaultBranch string
  275. // Repository editor settings
  276. Editor struct {
  277. LineWrapExtensions []string
  278. PreviewableFileModes []string
  279. } `ini:"repository.editor"`
  280. // Repository upload settings
  281. Upload struct {
  282. Enabled bool
  283. TempPath string
  284. AllowedTypes []string `delim:"|"`
  285. FileMaxSize int64
  286. MaxFiles int
  287. } `ini:"repository.upload"`
  288. }
  289. // Repository settings
  290. var Repository RepositoryOpts
  291. type DatabaseOpts struct {
  292. Type string
  293. Host string
  294. Name string
  295. Schema string
  296. User string
  297. Password string
  298. SSLMode string `ini:"SSL_MODE"`
  299. Path string
  300. MaxOpenConns int
  301. MaxIdleConns int
  302. }
  303. // Database settings
  304. var Database DatabaseOpts
  305. type LFSOpts struct {
  306. Storage string
  307. ObjectsPath string
  308. }
  309. // LFS settings
  310. var LFS LFSOpts
  311. type UIUserOpts struct {
  312. RepoPagingNum int
  313. NewsFeedPagingNum int
  314. CommitsPagingNum int
  315. }
  316. type UIOpts struct {
  317. ExplorePagingNum int
  318. IssuePagingNum int
  319. FeedMaxCommitNum int
  320. ThemeColorMetaTag string
  321. MaxDisplayFileSize int64
  322. Admin struct {
  323. UserPagingNum int
  324. RepoPagingNum int
  325. NoticePagingNum int
  326. OrgPagingNum int
  327. } `ini:"ui.admin"`
  328. User UIUserOpts `ini:"ui.user"`
  329. }
  330. // UI settings
  331. var UI UIOpts
  332. type PictureOpts struct {
  333. AvatarUploadPath string
  334. RepositoryAvatarUploadPath string
  335. GravatarSource string
  336. DisableGravatar bool
  337. EnableFederatedAvatar bool
  338. // Derived from other static values
  339. LibravatarService *libravatar.Libravatar `ini:"-"` // Initialized client for federated avatar.
  340. }
  341. // Picture settings
  342. var Picture PictureOpts
  343. type i18nConf struct {
  344. Langs []string `delim:","`
  345. Names []string `delim:","`
  346. dateLangs map[string]string `ini:"-"`
  347. }
  348. // DateLang transforms standard language locale name to corresponding value in datetime plugin.
  349. func (c *i18nConf) DateLang(lang string) string {
  350. name, ok := c.dateLangs[lang]
  351. if ok {
  352. return name
  353. }
  354. return "en"
  355. }
  356. // I18n settings
  357. var I18n *i18nConf
  358. // handleDeprecated transfers deprecated values to the new ones when set.
  359. func handleDeprecated() {
  360. // Add fallback logic here, example:
  361. // if App.AppName != "" {
  362. // App.BrandName = App.AppName
  363. // App.AppName = ""
  364. // }
  365. }
  366. // HookMode indicates whether program starts as Git server-side hook callback.
  367. // All operations should be done synchronously to prevent program exits before finishing.
  368. //
  369. // ⚠️ WARNING: Should only be set by "internal/cmd/serv.go".
  370. var HookMode bool
  371. // Indicates which database backend is currently being used.
  372. var (
  373. UseSQLite3 bool
  374. UseMySQL bool
  375. UsePostgreSQL bool
  376. UseMSSQL bool
  377. )
  378. // UsersAvatarPathPrefix is the path prefix to user avatars.
  379. const UsersAvatarPathPrefix = "avatars"
  380. // UserDefaultAvatarURLPath returns the URL path of the default user avatar.
  381. func UserDefaultAvatarURLPath() string {
  382. return Server.Subpath + "/img/avatar_default.png"
  383. }