common.go 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. type AuthMethod string
  24. const (
  25. AuthMethodToken AuthMethod = "token"
  26. AuthMethodOIDC AuthMethod = "oidc"
  27. )
  28. // QUIC protocol options
  29. type QUICOptions struct {
  30. KeepalivePeriod int `json:"keepalivePeriod,omitempty"`
  31. MaxIdleTimeout int `json:"maxIdleTimeout,omitempty"`
  32. MaxIncomingStreams int `json:"maxIncomingStreams,omitempty"`
  33. }
  34. func (c *QUICOptions) Complete() {
  35. c.KeepalivePeriod = util.EmptyOr(c.KeepalivePeriod, 10)
  36. c.MaxIdleTimeout = util.EmptyOr(c.MaxIdleTimeout, 30)
  37. c.MaxIncomingStreams = util.EmptyOr(c.MaxIncomingStreams, 100000)
  38. }
  39. type WebServerConfig struct {
  40. // This is the network address to bind on for serving the web interface and API.
  41. // By default, this value is "127.0.0.1".
  42. Addr string `json:"addr,omitempty"`
  43. // Port specifies the port for the web server to listen on. If this
  44. // value is 0, the admin server will not be started.
  45. Port int `json:"port,omitempty"`
  46. // User specifies the username that the web server will use for login.
  47. User string `json:"user,omitempty"`
  48. // Password specifies the password that the admin server will use for login.
  49. Password string `json:"password,omitempty"`
  50. // AssetsDir specifies the local directory that the admin server will load
  51. // resources from. If this value is "", assets will be loaded from the
  52. // bundled executable using embed package.
  53. AssetsDir string `json:"assetsDir,omitempty"`
  54. // Enable golang pprof handlers.
  55. PprofEnable bool `json:"pprofEnable,omitempty"`
  56. // Enable TLS if TLSConfig is not nil.
  57. TLS *TLSConfig `json:"tls,omitempty"`
  58. }
  59. func (c *WebServerConfig) Complete() {
  60. c.Addr = util.EmptyOr(c.Addr, "127.0.0.1")
  61. }
  62. type TLSConfig struct {
  63. // CertPath specifies the path of the cert file that client will load.
  64. CertFile string `json:"certFile,omitempty"`
  65. // KeyPath specifies the path of the secret key file that client will load.
  66. KeyFile string `json:"keyFile,omitempty"`
  67. // TrustedCaFile specifies the path of the trusted ca file that will load.
  68. TrustedCaFile string `json:"trustedCaFile,omitempty"`
  69. // ServerName specifies the custom server name of tls certificate. By
  70. // default, server name if same to ServerAddr.
  71. ServerName string `json:"serverName,omitempty"`
  72. }
  73. type LogConfig struct {
  74. // This is destination where frp should wirte the logs.
  75. // If "console" is used, logs will be printed to stdout, otherwise,
  76. // logs will be written to the specified file.
  77. // By default, this value is "console".
  78. To string `json:"to,omitempty"`
  79. // Level specifies the minimum log level. Valid values are "trace",
  80. // "debug", "info", "warn", and "error". By default, this value is "info".
  81. Level string `json:"level,omitempty"`
  82. // MaxDays specifies the maximum number of days to store log information
  83. // before deletion.
  84. MaxDays int64 `json:"maxDays"`
  85. // DisablePrintColor disables log colors when log.to is "console".
  86. DisablePrintColor bool `json:"disablePrintColor,omitempty"`
  87. }
  88. func (c *LogConfig) Complete() {
  89. c.To = util.EmptyOr(c.To, "console")
  90. c.Level = util.EmptyOr(c.Level, "info")
  91. c.MaxDays = util.EmptyOr(c.MaxDays, 3)
  92. }
  93. type HTTPPluginOptions struct {
  94. Name string `json:"name"`
  95. Addr string `json:"addr"`
  96. Path string `json:"path"`
  97. Ops []string `json:"ops"`
  98. TLSVerify bool `json:"tlsVerify,omitempty"`
  99. }
  100. type HeaderOperations struct {
  101. Set map[string]string `json:"set,omitempty"`
  102. }