https.go 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. // Copyright 2018 fatedier, [email protected]
  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"
  21. "github.com/fatedier/frp/pkg/consts"
  22. )
  23. func init() {
  24. RegisterCommonFlags(httpsCmd)
  25. httpsCmd.PersistentFlags().StringVarP(&proxyName, "proxy_name", "n", "", "proxy name")
  26. httpsCmd.PersistentFlags().StringVarP(&localIP, "local_ip", "i", "127.0.0.1", "local ip")
  27. httpsCmd.PersistentFlags().IntVarP(&localPort, "local_port", "l", 0, "local port")
  28. httpsCmd.PersistentFlags().StringVarP(&customDomains, "custom_domain", "d", "", "custom domain")
  29. httpsCmd.PersistentFlags().StringVarP(&subDomain, "sd", "", "", "sub domain")
  30. httpsCmd.PersistentFlags().BoolVarP(&useEncryption, "ue", "", false, "use encryption")
  31. httpsCmd.PersistentFlags().BoolVarP(&useCompression, "uc", "", false, "use compression")
  32. rootCmd.AddCommand(httpsCmd)
  33. }
  34. var httpsCmd = &cobra.Command{
  35. Use: "https",
  36. Short: "Run frpc with a single https proxy",
  37. RunE: func(cmd *cobra.Command, args []string) error {
  38. clientCfg, err := parseClientCommonCfgFromCmd()
  39. if err != nil {
  40. fmt.Println(err)
  41. os.Exit(1)
  42. }
  43. cfg := &config.HTTPSProxyConf{}
  44. var prefix string
  45. if user != "" {
  46. prefix = user + "."
  47. }
  48. cfg.ProxyName = prefix + proxyName
  49. cfg.ProxyType = consts.HTTPSProxy
  50. cfg.LocalIP = localIP
  51. cfg.LocalPort = localPort
  52. cfg.CustomDomains = strings.Split(customDomains, ",")
  53. cfg.SubDomain = subDomain
  54. cfg.UseEncryption = useEncryption
  55. cfg.UseCompression = useCompression
  56. err = cfg.CheckForCli()
  57. if err != nil {
  58. fmt.Println(err)
  59. os.Exit(1)
  60. }
  61. proxyConfs := map[string]config.ProxyConf{
  62. cfg.ProxyName: cfg,
  63. }
  64. err, _ = startService(clientCfg, proxyConfs, nil, "")
  65. if err != nil {
  66. fmt.Println(err)
  67. os.Exit(1)
  68. }
  69. return nil
  70. },
  71. }