server.go 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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 validation
  15. import (
  16. "fmt"
  17. "slices"
  18. "github.com/samber/lo"
  19. v1 "github.com/fatedier/frp/pkg/config/v1"
  20. )
  21. func ValidateServerConfig(c *v1.ServerConfig) (Warning, error) {
  22. var (
  23. warnings Warning
  24. errs error
  25. )
  26. if !slices.Contains(SupportedAuthMethods, c.Auth.Method) {
  27. errs = AppendError(errs, fmt.Errorf("invalid auth method, optional values are %v", SupportedAuthMethods))
  28. }
  29. if !lo.Every(SupportedAuthAdditionalScopes, c.Auth.AdditionalScopes) {
  30. errs = AppendError(errs, fmt.Errorf("invalid auth additional scopes, optional values are %v", SupportedAuthAdditionalScopes))
  31. }
  32. if err := validateLogConfig(&c.Log); err != nil {
  33. errs = AppendError(errs, err)
  34. }
  35. if err := validateWebServerConfig(&c.WebServer); err != nil {
  36. errs = AppendError(errs, err)
  37. }
  38. errs = AppendError(errs, ValidatePort(c.BindPort, "bindPort"))
  39. errs = AppendError(errs, ValidatePort(c.KCPBindPort, "kcpBindPort"))
  40. errs = AppendError(errs, ValidatePort(c.QUICBindPort, "quicBindPort"))
  41. errs = AppendError(errs, ValidatePort(c.VhostHTTPPort, "vhostHTTPPort"))
  42. errs = AppendError(errs, ValidatePort(c.VhostHTTPSPort, "vhostHTTPSPort"))
  43. errs = AppendError(errs, ValidatePort(c.TCPMuxHTTPConnectPort, "tcpMuxHTTPConnectPort"))
  44. for _, p := range c.HTTPPlugins {
  45. if !lo.Every(SupportedHTTPPluginOps, p.Ops) {
  46. errs = AppendError(errs, fmt.Errorf("invalid http plugin ops, optional values are %v", SupportedHTTPPluginOps))
  47. }
  48. }
  49. return warnings, errs
  50. }