common.go 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. // Copyright 2023 The frp Authors
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package v1
  15. import (
  16. "github.com/fatedier/frp/pkg/util/util"
  17. )
  18. type AuthScope string
  19. const (
  20. AuthScopeHeartBeats AuthScope = "HeartBeats"
  21. AuthScopeNewWorkConns AuthScope = "NewWorkConns"
  22. )
  23. // QUIC protocol options
  24. type QUICOptions struct {
  25. KeepalivePeriod int `json:"quicKeepalivePeriod,omitempty" validate:"gte=0"`
  26. MaxIdleTimeout int `json:"quicMaxIdleTimeout,omitempty" validate:"gte=0"`
  27. MaxIncomingStreams int `json:"quicMaxIncomingStreams,omitempty" validate:"gte=0"`
  28. }
  29. func (c *QUICOptions) Complete() {
  30. c.KeepalivePeriod = util.EmptyOr(c.KeepalivePeriod, 10)
  31. c.MaxIdleTimeout = util.EmptyOr(c.MaxIdleTimeout, 30)
  32. c.MaxIncomingStreams = util.EmptyOr(c.MaxIncomingStreams, 100000)
  33. }
  34. type WebServerConfig struct {
  35. // This is the network address to bind on for serving the web interface and API.
  36. // By default, this value is "127.0.0.1".
  37. Addr string `json:"addr,omitempty"`
  38. // Port specifies the port for the web server to listen on. If this
  39. // value is 0, the admin server will not be started.
  40. Port int `json:"port,omitempty"`
  41. // User specifies the username that the web server will use for login.
  42. User string `json:"user,omitempty"`
  43. // Password specifies the password that the admin server will use for login.
  44. Password string `json:"password,omitempty"`
  45. // AssetsDir specifies the local directory that the admin server will load
  46. // resources from. If this value is "", assets will be loaded from the
  47. // bundled executable using embed package.
  48. AssetsDir string `json:"assetsDir,omitempty"`
  49. // Enable golang pprof handlers.
  50. PprofEnable bool `json:"pprofEnable,omitempty"`
  51. // Enable TLS if TLSConfig is not nil.
  52. TLS *TLSConfig `json:"tls,omitempty"`
  53. }
  54. func (c *WebServerConfig) Complete() {
  55. c.Addr = util.EmptyOr(c.Addr, "127.0.0.1")
  56. }
  57. type TLSConfig struct {
  58. // CertPath specifies the path of the cert file that client will load.
  59. CertFile string `json:"certFile,omitempty"`
  60. // KeyPath specifies the path of the secret key file that client will load.
  61. KeyFile string `json:"keyFile,omitempty"`
  62. // TrustedCaFile specifies the path of the trusted ca file that will load.
  63. TrustedCaFile string `json:"trustedCaFile,omitempty"`
  64. // ServerName specifies the custom server name of tls certificate. By
  65. // default, server name if same to ServerAddr.
  66. ServerName string `json:"serverName,omitempty"`
  67. }
  68. type LogConfig struct {
  69. // This is destination where frp should wirte the logs.
  70. // If "console" is used, logs will be printed to stdout, otherwise,
  71. // logs will be written to the specified file.
  72. // By default, this value is "console".
  73. To string `json:"to,omitempty"`
  74. // Level specifies the minimum log level. Valid values are "trace",
  75. // "debug", "info", "warn", and "error". By default, this value is "info".
  76. Level string `json:"level,omitempty"`
  77. // MaxDays specifies the maximum number of days to store log information
  78. // before deletion.
  79. MaxDays int64 `json:"maxDays"`
  80. // DisablePrintColor disables log colors when log.to is "console".
  81. DisablePrintColor bool `json:"disablePrintColor,omitempty"`
  82. }
  83. func (c *LogConfig) Complete() {
  84. c.To = util.EmptyOr(c.To, "console")
  85. c.Level = util.EmptyOr(c.Level, "info")
  86. c.MaxDays = util.EmptyOr(c.MaxDays, 3)
  87. }
  88. type HTTPPluginOptions struct {
  89. Name string `json:"name"`
  90. Addr string `json:"addr"`
  91. Path string `json:"path"`
  92. Ops []string `json:"ops"`
  93. TLSVerify bool `json:"tls_verify,omitempty"`
  94. }
  95. type HeaderOperations struct {
  96. Set map[string]string `json:"set,omitempty"`
  97. }