https.go 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. // Copyright 2018 fatedier, fatedier@gmail.com
  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 sub
  15. import (
  16. "fmt"
  17. "os"
  18. "strings"
  19. "github.com/spf13/cobra"
  20. "github.com/fatedier/frp/pkg/config/types"
  21. v1 "github.com/fatedier/frp/pkg/config/v1"
  22. "github.com/fatedier/frp/pkg/config/v1/validation"
  23. "github.com/fatedier/frp/pkg/consts"
  24. )
  25. func init() {
  26. RegisterCommonFlags(httpsCmd)
  27. httpsCmd.PersistentFlags().StringVarP(&proxyName, "proxy_name", "n", "", "proxy name")
  28. httpsCmd.PersistentFlags().StringVarP(&localIP, "local_ip", "i", "127.0.0.1", "local ip")
  29. httpsCmd.PersistentFlags().IntVarP(&localPort, "local_port", "l", 0, "local port")
  30. httpsCmd.PersistentFlags().StringVarP(&customDomains, "custom_domain", "d", "", "custom domain")
  31. httpsCmd.PersistentFlags().StringVarP(&subDomain, "sd", "", "", "sub domain")
  32. httpsCmd.PersistentFlags().BoolVarP(&useEncryption, "ue", "", false, "use encryption")
  33. httpsCmd.PersistentFlags().BoolVarP(&useCompression, "uc", "", false, "use compression")
  34. httpsCmd.PersistentFlags().StringVarP(&bandwidthLimit, "bandwidth_limit", "", "", "bandwidth limit")
  35. httpsCmd.PersistentFlags().StringVarP(&bandwidthLimitMode, "bandwidth_limit_mode", "", types.BandwidthLimitModeClient, "bandwidth limit mode")
  36. rootCmd.AddCommand(httpsCmd)
  37. }
  38. var httpsCmd = &cobra.Command{
  39. Use: "https",
  40. Short: "Run frpc with a single https proxy",
  41. RunE: func(cmd *cobra.Command, args []string) error {
  42. clientCfg, err := parseClientCommonCfgFromCmd()
  43. if err != nil {
  44. fmt.Println(err)
  45. os.Exit(1)
  46. }
  47. cfg := &v1.HTTPSProxyConfig{}
  48. var prefix string
  49. if user != "" {
  50. prefix = user + "."
  51. }
  52. cfg.Name = prefix + proxyName
  53. cfg.Type = consts.HTTPSProxy
  54. cfg.LocalIP = localIP
  55. cfg.LocalPort = localPort
  56. cfg.CustomDomains = strings.Split(customDomains, ",")
  57. cfg.SubDomain = subDomain
  58. cfg.Transport.UseEncryption = useEncryption
  59. cfg.Transport.UseCompression = useCompression
  60. cfg.Transport.BandwidthLimit, err = types.NewBandwidthQuantity(bandwidthLimit)
  61. if err != nil {
  62. fmt.Println(err)
  63. os.Exit(1)
  64. }
  65. cfg.Transport.BandwidthLimitMode = bandwidthLimitMode
  66. if err := validation.ValidateProxyConfigurerForClient(cfg); err != nil {
  67. fmt.Println(err)
  68. os.Exit(1)
  69. }
  70. err = startService(clientCfg, []v1.ProxyConfigurer{cfg}, nil, "")
  71. if err != nil {
  72. fmt.Println(err)
  73. os.Exit(1)
  74. }
  75. return nil
  76. },
  77. }