https.go 2.9 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/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")
  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().StringVarP(&proxyName, "proxy_name", "n", "", "proxy name")
  32. httpsCmd.PersistentFlags().StringVarP(&localIp, "local_ip", "i", "127.0.0.1", "local ip")
  33. httpsCmd.PersistentFlags().IntVarP(&localPort, "local_port", "l", 0, "local port")
  34. httpsCmd.PersistentFlags().StringVarP(&customDomains, "custom_domain", "d", "", "custom domain")
  35. httpsCmd.PersistentFlags().StringVarP(&subDomain, "sd", "", "", "sub domain")
  36. httpsCmd.PersistentFlags().BoolVarP(&useEncryption, "ue", "", false, "use encryption")
  37. httpsCmd.PersistentFlags().BoolVarP(&useCompression, "uc", "", false, "use compression")
  38. rootCmd.AddCommand(httpsCmd)
  39. }
  40. var httpsCmd = &cobra.Command{
  41. Use: "https",
  42. Short: "Run frpc with a single https proxy",
  43. RunE: func(cmd *cobra.Command, args []string) error {
  44. err := parseClientCommonCfg(CfgFileTypeCmd, "")
  45. if err != nil {
  46. fmt.Println(err)
  47. os.Exit(1)
  48. }
  49. cfg := &config.HttpsProxyConf{}
  50. var prefix string
  51. if user != "" {
  52. prefix = user + "."
  53. }
  54. cfg.ProxyName = prefix + proxyName
  55. cfg.ProxyType = consts.HttpsProxy
  56. cfg.LocalIp = localIp
  57. cfg.LocalPort = localPort
  58. cfg.CustomDomains = strings.Split(customDomains, ",")
  59. cfg.SubDomain = subDomain
  60. cfg.UseEncryption = useEncryption
  61. cfg.UseCompression = useCompression
  62. err = cfg.CheckForCli()
  63. if err != nil {
  64. fmt.Println(err)
  65. os.Exit(1)
  66. }
  67. proxyConfs := map[string]config.ProxyConf{
  68. cfg.ProxyName: cfg,
  69. }
  70. err = startService(proxyConfs, nil)
  71. if err != nil {
  72. fmt.Println(err)
  73. os.Exit(1)
  74. }
  75. return nil
  76. },
  77. }