proxy_server.go 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package main
  2. import (
  3. "flag"
  4. "github.com/astaxie/beego"
  5. "github.com/cnlh/easyProxy/server"
  6. "github.com/cnlh/easyProxy/utils"
  7. _ "github.com/cnlh/easyProxy/web/routers"
  8. "log"
  9. )
  10. var (
  11. TcpPort = flag.Int("tcpport", 0, "客户端与服务端通信端口")
  12. httpPort = flag.Int("httpport", 8024, "对外监听的端口")
  13. rpMode = flag.String("mode", "webServer", "启动模式")
  14. tunnelTarget = flag.String("target", "10.1.50.203:80", "远程目标")
  15. VerifyKey = flag.String("vkey", "", "验证密钥")
  16. u = flag.String("u", "", "验证用户名(socks5和web)")
  17. p = flag.String("p", "", "验证密码(socks5和web)")
  18. compress = flag.String("compress", "", "数据压缩方式(snappy)")
  19. crypt = flag.String("crypt", "false", "是否加密(true|false)")
  20. mux = flag.String("mux", "false", "是否TCP多路复用(true|false)")
  21. )
  22. func main() {
  23. flag.Parse()
  24. task := &utils.Tunnel{
  25. TcpPort: *httpPort,
  26. Mode: *rpMode,
  27. Target: *tunnelTarget,
  28. Config: &utils.Config{
  29. U: *u,
  30. P: *p,
  31. Compress: *compress,
  32. Crypt: utils.GetBoolByStr(*crypt),
  33. Mux: utils.GetBoolByStr(*mux),
  34. },
  35. Flow: &utils.Flow{},
  36. UseClientCnf: false,
  37. }
  38. if *VerifyKey != "" {
  39. c := &utils.Client{
  40. Id: 0,
  41. VerifyKey: *VerifyKey,
  42. Addr: "",
  43. Remark: "",
  44. Status: true,
  45. IsConnect: false,
  46. }
  47. c.Cnf.CompressDecode, c.Cnf.CompressEncode = utils.GetCompressType(c.Cnf.Compress)
  48. server.CsvDb.Clients[0] = c
  49. task.Client = c
  50. }
  51. if *TcpPort == 0 {
  52. p, err := beego.AppConfig.Int("tcpport")
  53. if err == nil && *rpMode == "webServer" {
  54. *TcpPort = p
  55. } else {
  56. *TcpPort = 8284
  57. }
  58. }
  59. log.Println("服务端启动,监听tcp服务端端口:", *TcpPort)
  60. task.Config.CompressDecode, task.Config.CompressEncode = utils.GetCompressType(task.Config.Compress)
  61. server.StartNewServer(*TcpPort, task)
  62. }