This commit is contained in:
unknown
2019-10-16 18:28:36 +08:00
parent 6771816be7
commit f0a9f4e471
10 changed files with 136 additions and 44 deletions

View File

@@ -17,16 +17,16 @@ type CheckAccess struct {
}
func (check *CheckAccess) GetConfigName() *core.NpsConfigs {
c := core.NewNpsConfigs("socks5_simple_access_check", "need check the permission simply")
c.Add("socks5_simple_access_username", "simple auth username")
c.Add("socks5_simple_access_password", "simple auth password")
c := core.NewNpsConfigs("socks5_simple_access_check", "need check the permission simply", core.CONFIG_LEVEL_PLUGIN)
c.Add("socks5_simple_access_username", "simple auth username", core.CONFIG_LEVEL_PLUGIN)
c.Add("socks5_simple_access_password", "simple auth password", core.CONFIG_LEVEL_PLUGIN)
return c
}
func (check *CheckAccess) Run(ctx context.Context, config map[string]string) (context.Context, error) {
func (check *CheckAccess) Run(ctx context.Context) (context.Context, error) {
check.clientConn = check.GetClientConn(ctx)
check.configUsername = config["socks5_access_username"]
check.configPassword = config["socks5_access_password"]
check.configUsername = check.Configs["socks5_access_username"]
check.configPassword = check.Configs["socks5_access_password"]
return ctx, nil
}

View File

@@ -12,7 +12,7 @@ type Handshake struct {
core.NpsPlugin
}
func (handshake *Handshake) Run(ctx context.Context, config map[string]string) (context.Context, error) {
func (handshake *Handshake) Run(ctx context.Context) (context.Context, error) {
clientConn := handshake.GetClientConn(ctx)
buf := make([]byte, 2)
if _, err := io.ReadFull(clientConn, buf); err != nil {

View File

@@ -22,12 +22,12 @@ type Access struct {
}
func (access *Access) GetConfigName() *core.NpsConfigs {
return core.NewNpsConfigs("socks5_check_access_check", "need check the permission simply")
return core.NewNpsConfigs("socks5_check_access_check", "need check the permission simply",core.CONFIG_LEVEL_PLUGIN)
}
func (access *Access) Run(ctx context.Context, config map[string]string) (context.Context, error) {
func (access *Access) Run(ctx context.Context) (context.Context, error) {
access.clientConn = access.GetClientConn(ctx)
if config["socks5_check_access"] != "true" {
if access.Configs["socks5_check_access"] != "true" {
return ctx, access.sendAccessMsgToClient(UserNoAuth)
}
// need auth

View File

@@ -32,7 +32,7 @@ const (
addrTypeNotSupported = 8
)
func (request *Request) Run(ctx context.Context, config map[string]string) (context.Context, error) {
func (request *Request) Run(ctx context.Context) (context.Context, error) {
request.clientConn = request.GetClientConn(ctx)
request.ctx = ctx

View File

@@ -1,8 +1,9 @@
package socks5
import (
"context"
"fmt"
"github.com/cnlh/nps/core"
"github.com/cnlh/nps/lib/conn"
"github.com/cnlh/nps/server/common"
"net"
"strconv"
@@ -29,8 +30,28 @@ func NewS5Server(globalConfig, clientConfig, pluginConfig map[string]string) *S5
return s5
}
func (s5 *S5Server) Start() error {
return conn.NewTcpListenerAndProcess(s5.ServerIp+":"+strconv.Itoa(s5.ServerPort), func(c net.Conn) {
func (s5 *S5Server) Start(ctx context.Context) error {
// init config of plugin
for _, pg := range s5.plugins.AllPgs {
pg.InitConfig(s5.globalConfig, s5.clientConfig, s5.pluginConfig)
}
// run the plugin contains start
if core.RunPlugin(ctx, s5.plugins.StartPgs) != nil {
return nil
}
return core.NewTcpListenerAndProcess(s5.ServerIp+":"+strconv.Itoa(s5.ServerPort), func(c net.Conn) {
// init ctx value clientConn
ctx = context.WithValue(ctx, core.CLIENT_CONNECTION, c)
// start run the plugin run
if err := core.RunPlugin(ctx, s5.plugins.RunPgs); err != nil {
fmt.Println(err)
return
}
// start run the plugin end
if err := core.RunPlugin(ctx, s5.plugins.EndPgs); err != nil {
fmt.Println(err)
return
}
}, &s5.listener)
}