verify.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // Copyright 2021 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 main
  15. import (
  16. "fmt"
  17. "os"
  18. "github.com/spf13/cobra"
  19. "github.com/fatedier/frp/pkg/config"
  20. "github.com/fatedier/frp/pkg/config/v1/validation"
  21. "github.com/fatedier/frp/pkg/policy/security"
  22. )
  23. func init() {
  24. rootCmd.AddCommand(verifyCmd)
  25. }
  26. var verifyCmd = &cobra.Command{
  27. Use: "verify",
  28. Short: "Verify that the configures is valid",
  29. RunE: func(cmd *cobra.Command, args []string) error {
  30. if cfgFile == "" {
  31. fmt.Println("frps: the configuration file is not specified")
  32. return nil
  33. }
  34. svrCfg, _, err := config.LoadServerConfig(cfgFile, strictConfigMode)
  35. if err != nil {
  36. fmt.Println(err)
  37. os.Exit(1)
  38. }
  39. unsafeFeatures := security.NewUnsafeFeatures(allowUnsafe)
  40. validator := validation.NewConfigValidator(unsafeFeatures)
  41. warning, err := validator.ValidateServerConfig(svrCfg)
  42. if warning != nil {
  43. fmt.Printf("WARNING: %v\n", warning)
  44. }
  45. if err != nil {
  46. fmt.Println(err)
  47. os.Exit(1)
  48. }
  49. fmt.Printf("frps: the configuration file %s syntax is ok\n", cfgFile)
  50. return nil
  51. },
  52. }