| // |
| 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 |
| 15 | package v1 |
| 16 |
| 17 | import ( |
| 18 | "maps" |
| 19 |
| 20 | "github.com/fatedier/frp/pkg/util/util" |
| 21 | ) |
| 22 |
| 23 | type AuthScope string |
| 24 |
| 25 | const ( |
| 26 | AuthScopeHeartBeats AuthScope = "HeartBeats" |
| 27 | AuthScopeNewWorkConns AuthScope = "NewWorkConns" |
| 28 | ) |
| 29 |
| 30 | type AuthMethod string |
| 31 |
| 32 | const ( |
| 33 | AuthMethodToken AuthMethod = "token" |
| 34 | AuthMethodOIDC AuthMethod = "oidc" |
| 35 | ) |
| 36 |
| 37 | // QUIC protocol options |
| 38 | type QUICOptions struct { |
| 39 | KeepalivePeriod int `json:"keepalivePeriod,omitempty"` |
| 40 | MaxIdleTimeout int `json:"maxIdleTimeout,omitempty"` |
| 41 | MaxIncomingStreams int `json:"maxIncomingStreams,omitempty"` |
| 42 | } |
| 43 |
| 44 | func (c *QUICOptions) Complete() { |
| 45 | c.KeepalivePeriod = util.EmptyOr(c.KeepalivePeriod, 10) |
| 46 | c.MaxIdleTimeout = util.EmptyOr(c.MaxIdleTimeout, 30) |
| 47 | c.MaxIncomingStreams = util.EmptyOr(c.MaxIncomingStreams, 100000) |
| 48 | } |
| 49 |
| 50 | type WebServerConfig struct { |
| 51 | // This is the network address to bind on for serving the web interface and API. |
| 52 | // By default, this value is "127.0.0.1". |
| 53 | Addr string `json:"addr,omitempty"` |
| 54 | // Port specifies the port for the web server to listen on. If this |
| 55 | // value is 0, the admin server will not be started. |
| 56 | Port int `json:"port,omitempty"` |
| 57 | // User specifies the username that the web server will use for login. |
| 58 | User string `json:"user,omitempty"` |
| 59 | // Password specifies the password that the admin server will use for login. |
| 60 | Password string `json:"password,omitempty"` |
| 61 | // AssetsDir specifies the local directory that the admin server will load |
| 62 | // resources from. If this value is "", assets will be loaded from the |
| 63 | // bundled executable using embed package. |
| 64 | AssetsDir string `json:"assetsDir,omitempty"` |
| 65 | // Enable golang pprof handlers. |
| 66 | PprofEnable bool `json:"pprofEnable,omitempty"` |
| 67 | // Enable TLS if TLSConfig is not nil. |
| 68 | TLS *TLSConfig `json:"tls,omitempty"` |
| 69 | } |
| 70 |
| 71 | func (c *WebServerConfig) Complete() { |
| 72 | c.Addr = util.EmptyOr(c.Addr, "127.0.0.1") |
| 73 | } |
| 74 |
| 75 | type TLSConfig struct { |
| 76 | // CertFile specifies the path of the cert file that client will load. |
| 77 | CertFile string `json:"certFile,omitempty"` |
| 78 | // KeyFile specifies the path of the secret key file that client will load. |
| 79 | KeyFile string `json:"keyFile,omitempty"` |
| 80 | // TrustedCaFile specifies the path of the trusted ca file that will load. |
| 81 | TrustedCaFile string `json:"trustedCaFile,omitempty"` |
| 82 | // ServerName specifies the custom server name of tls certificate. By |
| 83 | // default, server name if same to ServerAddr. |
| 84 | ServerName string `json:"serverName,omitempty"` |
| 85 | } |
| 86 |
| 87 | // NatTraversalConfig defines configuration options for NAT traversal |
| 88 | type NatTraversalConfig struct { |
| 89 | // DisableAssistedAddrs disables the use of local network interfaces |
| 90 | // for assisted connections during NAT traversal. When enabled, |
| 91 | // only STUN-discovered public addresses will be used. |
| 92 | DisableAssistedAddrs bool `json:"disableAssistedAddrs,omitempty"` |
| 93 | } |
| 94 |
| 95 | func (c *NatTraversalConfig) Clone() *NatTraversalConfig { |
| 96 | if c == nil { |
| 97 | return nil |
| 98 | } |
| 99 | out := *c |
| 100 | return &out |
| 101 | } |
| 102 |
| 103 | type LogConfig struct { |
| 104 | // This is destination where frp should write the logs. |
| 105 | // If "console" is used, logs will be printed to stdout, otherwise, |
| 106 | // logs will be written to the specified file. |
| 107 | // By default, this value is "console". |
| 108 | To string `json:"to,omitempty"` |
| 109 | // Level specifies the minimum log level. Valid values are "trace", |
| 110 | // "debug", "info", "warn", and "error". By default, this value is "info". |
| 111 | Level string `json:"level,omitempty"` |
| 112 | // MaxDays specifies the maximum number of days to store log information |
| 113 | // before deletion. |
| 114 | MaxDays int64 `json:"maxDays"` |
| 115 | // DisablePrintColor disables log colors when log.to is "console". |
| 116 | DisablePrintColor bool `json:"disablePrintColor,omitempty"` |
| 117 | } |
| 118 |
| 119 | func (c *LogConfig) Complete() { |
| 120 | c.To = util.EmptyOr(c.To, "console") |
| 121 | c.Level = util.EmptyOr(c.Level, "info") |
| 122 | c.MaxDays = util.EmptyOr(c.MaxDays, 3) |
| 123 | } |
| 124 |
| 125 | type HTTPPluginOptions struct { |
| 126 | Name string `json:"name"` |
| 127 | Addr string `json:"addr"` |
| 128 | Path string `json:"path"` |
| 129 | Ops []string `json:"ops"` |
| 130 | TLSVerify bool `json:"tlsVerify,omitempty"` |
| 131 | } |
| 132 |
| 133 | type HeaderOperations struct { |
| 134 | Set map[string]string `json:"set,omitempty"` |
| 135 | } |
| 136 |
| 137 | func (o HeaderOperations) Clone() HeaderOperations { |
| 138 | return HeaderOperations{ |
| 139 | Set: maps.Clone(o.Set), |
| 140 | } |
| 141 | } |
| 142 |
| 143 | type HTTPHeader struct { |
| 144 | Name string `json:"name"` |
| 145 | Value string `json:"value"` |
| 146 | } |