1
0

npc.go 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. "os"
  9. )
  10. const VERSION = "v0.0.13"
  11. var (
  12. TcpPort = flag.Int("tcpport", 0, "客户端与服务端通信端口")
  13. httpPort = flag.Int("httpport", 8024, "对外监听的端口")
  14. rpMode = flag.String("mode", "webServer", "启动模式")
  15. tunnelTarget = flag.String("target", "127.0.0.1:80", "远程目标")
  16. VerifyKey = flag.String("vkey", "", "验证密钥")
  17. u = flag.String("u", "", "验证用户名(socks5和web)")
  18. p = flag.String("p", "", "验证密码(socks5和web)")
  19. compress = flag.String("compress", "", "数据压缩方式(snappy)")
  20. crypt = flag.String("crypt", "false", "是否加密(true|false)")
  21. logType = flag.String("log", "stdout", "日志输出方式(stdout|file)")
  22. )
  23. func main() {
  24. flag.Parse()
  25. var test bool
  26. if len(os.Args) > 1 && os.Args[1] == "test" {
  27. test = true
  28. }
  29. utils.InitDaemon("server")
  30. if *logType == "stdout" || test {
  31. utils.InitLogFile("server", true)
  32. } else {
  33. utils.InitLogFile("server", false)
  34. }
  35. task := &utils.Tunnel{
  36. TcpPort: *httpPort,
  37. Mode: *rpMode,
  38. Target: *tunnelTarget,
  39. Config: &utils.Config{
  40. U: *u,
  41. P: *p,
  42. Compress: *compress,
  43. Crypt: utils.GetBoolByStr(*crypt),
  44. },
  45. Flow: &utils.Flow{},
  46. UseClientCnf: false,
  47. }
  48. if *VerifyKey != "" {
  49. c := &utils.Client{
  50. Id: 0,
  51. VerifyKey: *VerifyKey,
  52. Addr: "",
  53. Remark: "",
  54. Status: true,
  55. IsConnect: false,
  56. Cnf: &utils.Config{},
  57. Flow: &utils.Flow{},
  58. }
  59. c.Cnf.CompressDecode, c.Cnf.CompressEncode = utils.GetCompressType(c.Cnf.Compress)
  60. server.CsvDb.Clients[0] = c
  61. task.Client = c
  62. }
  63. if *TcpPort == 0 {
  64. p, err := beego.AppConfig.Int("tcpport")
  65. if err == nil && *rpMode == "webServer" {
  66. *TcpPort = p
  67. } else {
  68. *TcpPort = 8284
  69. }
  70. }
  71. utils.Println("服务端启动,监听tcp服务端端口:", *TcpPort)
  72. task.Config.CompressDecode, task.Config.CompressEncode = utils.GetCompressType(task.Config.Compress)
  73. if *rpMode != "webServer" {
  74. server.CsvDb.Tasks[0] = task
  75. }
  76. server.StartNewServer(*TcpPort, task, test)
  77. }