客户端配置,端口白名单等

This commit is contained in:
刘河
2019-02-13 03:54:00 +08:00
parent 59d789d253
commit 44d314515b
34 changed files with 1096 additions and 472 deletions

View File

@@ -9,25 +9,17 @@ import (
"github.com/cnlh/nps/lib/install"
"github.com/cnlh/nps/lib/lg"
"github.com/cnlh/nps/server"
"github.com/cnlh/nps/server/test"
_ "github.com/cnlh/nps/web/routers"
"log"
"os"
"path/filepath"
)
const VERSION = "v0.0.13"
const VERSION = "v0.0.15"
var (
TcpPort = flag.Int("tcpport", 0, "客户端与服务端通信端口")
httpPort = flag.Int("httpport", 8024, "对外监听的端口")
rpMode = flag.String("mode", "webServer", "启动模式")
tunnelTarget = flag.String("target", "127.0.0.1:80", "远程目标")
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)")
logType = flag.String("log", "stdout", "日志输出方式stdout|file")
logType = flag.String("log", "stdout", "Log output modestdout|file")
)
func main() {
@@ -35,11 +27,11 @@ func main() {
if len(os.Args) > 1 {
switch os.Args[1] {
case "test":
server.TestServerConfig()
test.TestServerConfig()
log.Println("test ok, no error")
return
case "start", "restart", "stop", "status":
daemon.InitDaemon("nps", common.GetRunPath(), common.GetPidPath())
daemon.InitDaemon("nps", common.GetRunPath(), common.GetTmpPath())
case "install":
install.InstallNps()
return
@@ -51,46 +43,12 @@ func main() {
lg.InitLogFile("nps", false, common.GetLogPath())
}
task := &file.Tunnel{
TcpPort: *httpPort,
Mode: *rpMode,
Target: *tunnelTarget,
Config: &file.Config{
U: *u,
P: *p,
Compress: *compress,
Crypt: common.GetBoolByStr(*crypt),
},
Flow: &file.Flow{},
UseClientCnf: false,
Mode: "webServer",
}
if *VerifyKey != "" {
c := &file.Client{
Id: 0,
VerifyKey: *VerifyKey,
Addr: "",
Remark: "",
Status: true,
IsConnect: false,
Cnf: &file.Config{},
Flow: &file.Flow{},
}
c.Cnf.CompressDecode, c.Cnf.CompressEncode = common.GetCompressType(c.Cnf.Compress)
file.GetCsvDb().Clients[0] = c
task.Client = c
}
if *TcpPort == 0 {
p, err := beego.AppConfig.Int("bridgePort")
if err == nil && *rpMode == "webServer" {
*TcpPort = p
} else {
*TcpPort = 8284
}
}
lg.Printf("服务端启动,监听%s服务端口%d", beego.AppConfig.String("bridgeType"), *TcpPort)
task.Config.CompressDecode, task.Config.CompressEncode = common.GetCompressType(task.Config.Compress)
if *rpMode != "webServer" {
file.GetCsvDb().Tasks[0] = task
bridgePort, err := beego.AppConfig.Int("bridgePort")
if err != nil {
lg.Fatalln("Getting bridgePort error", err)
}
beego.LoadAppConfig("ini", filepath.Join(common.GetRunPath(), "conf", "app.conf"))
server.StartNewServer(*TcpPort, task, beego.AppConfig.String("bridgeType"))
server.StartNewServer(bridgePort, task, beego.AppConfig.String("bridgeType"))
}