https.go 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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/models/config"
  21. "github.com/fatedier/frp/models/consts"
  22. )
  23. func init() {
  24. httpsCmd.PersistentFlags().StringVarP(&serverAddr, "server_addr", "s", "127.0.0.1:7000", "frp server's address")
  25. httpsCmd.PersistentFlags().StringVarP(&user, "user", "u", "", "user")
  26. httpsCmd.PersistentFlags().StringVarP(&protocol, "protocol", "p", "tcp", "tcp or kcp or websocket")
  27. httpsCmd.PersistentFlags().StringVarP(&token, "token", "t", "", "auth token")
  28. httpsCmd.PersistentFlags().StringVarP(&logLevel, "log_level", "", "info", "log level")
  29. httpsCmd.PersistentFlags().StringVarP(&logFile, "log_file", "", "console", "console or file path")
  30. httpsCmd.PersistentFlags().IntVarP(&logMaxDays, "log_max_days", "", 3, "log file reversed days")
  31. httpsCmd.PersistentFlags().BoolVarP(&disableLogColor, "disable_log_color", "", false, "disable log color in console")
  32. httpsCmd.PersistentFlags().StringVarP(&proxyName, "proxy_name", "n", "", "proxy name")
  33. httpsCmd.PersistentFlags().StringVarP(&localIp, "local_ip", "i", "127.0.0.1", "local ip")
  34. httpsCmd.PersistentFlags().IntVarP(&localPort, "local_port", "l", 0, "local port")
  35. httpsCmd.PersistentFlags().StringVarP(&customDomains, "custom_domain", "d", "", "custom domain")
  36. httpsCmd.PersistentFlags().StringVarP(&subDomain, "sd", "", "", "sub domain")
  37. httpsCmd.PersistentFlags().BoolVarP(&useEncryption, "ue", "", false, "use encryption")
  38. httpsCmd.PersistentFlags().BoolVarP(&useCompression, "uc", "", false, "use compression")
  39. httpsCmd.PersistentFlags().BoolVarP(&tlsEnable, "tls_enable", "", false, "enable frpc tls")
  40. rootCmd.AddCommand(httpsCmd)
  41. }
  42. var httpsCmd = &cobra.Command{
  43. Use: "https",
  44. Short: "Run frpc with a single https proxy",
  45. RunE: func(cmd *cobra.Command, args []string) error {
  46. clientCfg, err := parseClientCommonCfg(CfgFileTypeCmd, "")
  47. if err != nil {
  48. fmt.Println(err)
  49. os.Exit(1)
  50. }
  51. cfg := &config.HttpsProxyConf{}
  52. var prefix string
  53. if user != "" {
  54. prefix = user + "."
  55. }
  56. cfg.ProxyName = prefix + proxyName
  57. cfg.ProxyType = consts.HttpsProxy
  58. cfg.LocalIp = localIp
  59. cfg.LocalPort = localPort
  60. cfg.CustomDomains = strings.Split(customDomains, ",")
  61. cfg.SubDomain = subDomain
  62. cfg.UseEncryption = useEncryption
  63. cfg.UseCompression = useCompression
  64. err = cfg.CheckForCli()
  65. if err != nil {
  66. fmt.Println(err)
  67. os.Exit(1)
  68. }
  69. proxyConfs := map[string]config.ProxyConf{
  70. cfg.ProxyName: cfg,
  71. }
  72. err = startService(clientCfg, proxyConfs, nil, "")
  73. if err != nil {
  74. fmt.Println(err)
  75. os.Exit(1)
  76. }
  77. return nil
  78. },
  79. }