proxy_server.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. server.VerifyKey = *VerifyKey
  25. log.Println("服务端启动,监听tcp服务端端口:", *TcpPort)
  26. cnf := server.ServerConfig{
  27. TcpPort: *httpPort,
  28. Mode: *rpMode,
  29. Target: *tunnelTarget,
  30. VerifyKey: *VerifyKey,
  31. U: *u,
  32. P: *p,
  33. Compress: *compress,
  34. Start: 0,
  35. IsRun: 0,
  36. ClientStatus: 0,
  37. Crypt: utils.GetBoolByStr(*crypt),
  38. Mux: utils.GetBoolByStr(*mux),
  39. CompressEncode: 0,
  40. CompressDecode: 0,
  41. }
  42. if *TcpPort == 0 {
  43. p, err := beego.AppConfig.Int("tcpport")
  44. if err == nil && *rpMode == "webServer" {
  45. *TcpPort = p
  46. } else {
  47. *TcpPort = 8284
  48. }
  49. }
  50. log.SetFlags(log.Lshortfile)
  51. cnf.CompressDecode, cnf.CompressEncode = utils.GetCompressType(cnf.Compress)
  52. server.StartNewServer(*TcpPort, &cnf)
  53. }