Files
nps/cmd/proxy_server/proxy_server.go
T

82 lines
2.2 KiB
Go
Raw Normal View History

2019-01-09 20:33:00 +08:00
package main
import (
"flag"
2019-01-13 00:09:12 +08:00
"github.com/astaxie/beego"
2019-01-09 20:33:00 +08:00
"github.com/cnlh/easyProxy/server"
"github.com/cnlh/easyProxy/utils"
_ "github.com/cnlh/easyProxy/web/routers"
2019-02-03 00:54:43 +08:00
"os"
2019-01-09 20:33:00 +08:00
)
2019-02-03 00:54:43 +08:00
const VERSION = "v0.0.13"
2019-01-09 20:33:00 +08:00
var (
2019-01-13 00:09:12 +08:00
TcpPort = flag.Int("tcpport", 0, "客户端与服务端通信端口")
2019-01-09 20:33:00 +08:00
httpPort = flag.Int("httpport", 8024, "对外监听的端口")
2019-01-13 00:09:12 +08:00
rpMode = flag.String("mode", "webServer", "启动模式")
2019-02-03 00:54:43 +08:00
tunnelTarget = flag.String("target", "127.0.0.1:80", "远程目标")
2019-01-09 20:33:00 +08:00
VerifyKey = flag.String("vkey", "", "验证密钥")
u = flag.String("u", "", "验证用户名(socks5和web)")
p = flag.String("p", "", "验证密码(socks5和web)")
compress = flag.String("compress", "", "数据压缩方式(snappy)")
crypt = flag.String("crypt", "false", "是否加密(true|false)")
2019-02-03 00:54:43 +08:00
logType = flag.String("log", "stdout", "日志输出方式(stdout|file)")
2019-01-09 20:33:00 +08:00
)
func main() {
flag.Parse()
2019-02-03 00:54:43 +08:00
var test bool
if len(os.Args) > 1 && os.Args[1] == "test" {
test = true
}
utils.InitDaemon("server")
if *logType == "stdout" || test {
utils.InitLogFile("server", true)
} else {
utils.InitLogFile("server", false)
}
2019-01-26 17:27:28 +08:00
task := &utils.Tunnel{
TcpPort: *httpPort,
Mode: *rpMode,
Target: *tunnelTarget,
Config: &utils.Config{
U: *u,
P: *p,
Compress: *compress,
Crypt: utils.GetBoolByStr(*crypt),
},
Flow: &utils.Flow{},
UseClientCnf: false,
}
if *VerifyKey != "" {
c := &utils.Client{
Id: 0,
VerifyKey: *VerifyKey,
Addr: "",
Remark: "",
Status: true,
IsConnect: false,
2019-02-01 02:39:28 +08:00
Cnf: &utils.Config{},
Flow: &utils.Flow{},
2019-01-26 17:27:28 +08:00
}
c.Cnf.CompressDecode, c.Cnf.CompressEncode = utils.GetCompressType(c.Cnf.Compress)
server.CsvDb.Clients[0] = c
task.Client = c
2019-01-09 20:33:00 +08:00
}
2019-01-13 00:09:12 +08:00
if *TcpPort == 0 {
p, err := beego.AppConfig.Int("tcpport")
if err == nil && *rpMode == "webServer" {
*TcpPort = p
} else {
*TcpPort = 8284
}
}
2019-02-03 00:54:43 +08:00
utils.Println("服务端启动,监听tcp服务端端口:", *TcpPort)
2019-01-26 17:27:28 +08:00
task.Config.CompressDecode, task.Config.CompressEncode = utils.GetCompressType(task.Config.Compress)
2019-02-03 00:54:43 +08:00
if *rpMode != "webServer" {
2019-02-01 02:39:28 +08:00
server.CsvDb.Tasks[0] = task
}
2019-02-03 00:54:43 +08:00
server.StartNewServer(*TcpPort, task, test)
2019-01-09 20:33:00 +08:00
}