1
0

static.go 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452
  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. }
  216. // Authentication settings
  217. var Auth AuthOpts
  218. type ServerOpts struct {
  219. ExternalURL string `ini:"EXTERNAL_URL"`
  220. Domain string
  221. Protocol string
  222. HTTPAddr string `ini:"HTTP_ADDR"`
  223. HTTPPort string `ini:"HTTP_PORT"`
  224. CertFile string
  225. KeyFile string
  226. TLSMinVersion string `ini:"TLS_MIN_VERSION"`
  227. UnixSocketPermission string
  228. LocalRootURL string `ini:"LOCAL_ROOT_URL"`
  229. OfflineMode bool
  230. DisableRouterLog bool
  231. EnableGzip bool
  232. AppDataPath string
  233. LoadAssetsFromDisk bool
  234. LandingURL string `ini:"LANDING_URL"`
  235. // Derived from other static values
  236. URL *url.URL `ini:"-"` // Parsed URL object of ExternalURL.
  237. Subpath string `ini:"-"` // Subpath found the ExternalURL. Should be empty when not found.
  238. SubpathDepth int `ini:"-"` // The number of slashes found in the Subpath.
  239. UnixSocketMode os.FileMode `ini:"-"` // Parsed file mode of UnixSocketPermission.
  240. }
  241. // Server settings
  242. var Server ServerOpts
  243. type SSHOpts struct {
  244. Disabled bool `ini:"DISABLE_SSH"`
  245. Domain string `ini:"SSH_DOMAIN"`
  246. Port int `ini:"SSH_PORT"`
  247. RootPath string `ini:"SSH_ROOT_PATH"`
  248. KeygenPath string `ini:"SSH_KEYGEN_PATH"`
  249. KeyTestPath string `ini:"SSH_KEY_TEST_PATH"`
  250. MinimumKeySizeCheck bool
  251. MinimumKeySizes map[string]int `ini:"-"` // Load from [ssh.minimum_key_sizes]
  252. RewriteAuthorizedKeysAtStart bool
  253. StartBuiltinServer bool `ini:"START_SSH_SERVER"`
  254. ListenHost string `ini:"SSH_LISTEN_HOST"`
  255. ListenPort int `ini:"SSH_LISTEN_PORT"`
  256. ServerCiphers []string `ini:"SSH_SERVER_CIPHERS"`
  257. ServerMACs []string `ini:"SSH_SERVER_MACS"`
  258. ServerAlgorithms []string `ini:"SSH_SERVER_ALGORITHMS"`
  259. }
  260. // SSH settings
  261. var SSH SSHOpts
  262. type RepositoryOpts struct {
  263. Root string
  264. ScriptType string
  265. ANSICharset string `ini:"ANSI_CHARSET"`
  266. ForcePrivate bool
  267. MaxCreationLimit int
  268. PreferredLicenses []string
  269. DisableHTTPGit bool `ini:"DISABLE_HTTP_GIT"`
  270. EnableLocalPathMigration bool
  271. EnableRawFileRenderMode bool
  272. CommitsFetchConcurrency int
  273. DefaultBranch string
  274. // Repository editor settings
  275. Editor struct {
  276. LineWrapExtensions []string
  277. PreviewableFileModes []string
  278. } `ini:"repository.editor"`
  279. // Repository upload settings
  280. Upload struct {
  281. Enabled bool
  282. TempPath string
  283. AllowedTypes []string `delim:"|"`
  284. FileMaxSize int64
  285. MaxFiles int
  286. } `ini:"repository.upload"`
  287. }
  288. // Repository settings
  289. var Repository RepositoryOpts
  290. type DatabaseOpts struct {
  291. Type string
  292. Host string
  293. Name string
  294. Schema string
  295. User string
  296. Password string
  297. SSLMode string `ini:"SSL_MODE"`
  298. Path string
  299. MaxOpenConns int
  300. MaxIdleConns int
  301. }
  302. // Database settings
  303. var Database DatabaseOpts
  304. type LFSOpts struct {
  305. Storage string
  306. ObjectsPath string
  307. }
  308. // LFS settings
  309. var LFS LFSOpts
  310. type UIUserOpts struct {
  311. RepoPagingNum int
  312. NewsFeedPagingNum int
  313. CommitsPagingNum int
  314. }
  315. type UIOpts struct {
  316. ExplorePagingNum int
  317. IssuePagingNum int
  318. FeedMaxCommitNum int
  319. ThemeColorMetaTag string
  320. MaxDisplayFileSize int64
  321. Admin struct {
  322. UserPagingNum int
  323. RepoPagingNum int
  324. NoticePagingNum int
  325. OrgPagingNum int
  326. } `ini:"ui.admin"`
  327. User UIUserOpts `ini:"ui.user"`
  328. }
  329. // UI settings
  330. var UI UIOpts
  331. type PictureOpts struct {
  332. AvatarUploadPath string
  333. RepositoryAvatarUploadPath string
  334. GravatarSource string
  335. DisableGravatar bool
  336. EnableFederatedAvatar bool
  337. // Derived from other static values
  338. LibravatarService *libravatar.Libravatar `ini:"-"` // Initialized client for federated avatar.
  339. }
  340. // Picture settings
  341. var Picture PictureOpts
  342. type i18nConf struct {
  343. Langs []string `delim:","`
  344. Names []string `delim:","`
  345. dateLangs map[string]string `ini:"-"`
  346. }
  347. // DateLang transforms standard language locale name to corresponding value in datetime plugin.
  348. func (c *i18nConf) DateLang(lang string) string {
  349. name, ok := c.dateLangs[lang]
  350. if ok {
  351. return name
  352. }
  353. return "en"
  354. }
  355. // I18n settings
  356. var I18n *i18nConf
  357. // handleDeprecated transfers deprecated values to the new ones when set.
  358. func handleDeprecated() {
  359. // Add fallback logic here, example:
  360. // if App.AppName != "" {
  361. // App.BrandName = App.AppName
  362. // App.AppName = ""
  363. // }
  364. }
  365. // HookMode indicates whether program starts as Git server-side hook callback.
  366. // All operations should be done synchronously to prevent program exits before finishing.
  367. //
  368. // ⚠️ WARNING: Should only be set by "internal/cmd/serv.go".
  369. var HookMode bool
  370. // Indicates which database backend is currently being used.
  371. var (
  372. UseSQLite3 bool
  373. UseMySQL bool
  374. UsePostgreSQL bool
  375. UseMSSQL bool
  376. )
  377. // UsersAvatarPathPrefix is the path prefix to user avatars.
  378. const UsersAvatarPathPrefix = "avatars"
  379. // UserDefaultAvatarURLPath returns the URL path of the default user avatar.
  380. func UserDefaultAvatarURLPath() string {
  381. return Server.Subpath + "/img/avatar_default.png"
  382. }