mirror of
https://github.com/ehang-io/nps.git
synced 2025-09-03 04:26:53 +00:00
module
This commit is contained in:
@@ -13,10 +13,10 @@ type Proxy struct {
|
||||
}
|
||||
|
||||
func (proxy *Proxy) GetConfigName() *core.NpsConfigs {
|
||||
return core.NewNpsConfigs("socks5_proxy", "proxy to inet")
|
||||
return core.NewNpsConfigs("socks5_proxy", "proxy to inet", core.CONFIG_LEVEL_PLUGIN)
|
||||
}
|
||||
|
||||
func (proxy *Proxy) Run(ctx context.Context, config map[string]string) (context.Context, error) {
|
||||
func (proxy *Proxy) Run(ctx context.Context) (context.Context, error) {
|
||||
proxy.ctx = ctx
|
||||
proxy.clientConn = proxy.GetClientConn(ctx)
|
||||
clientId := proxy.GetClientId(ctx)
|
||||
@@ -27,7 +27,13 @@ func (proxy *Proxy) Run(ctx context.Context, config map[string]string) (context.
|
||||
return ctx, err
|
||||
}
|
||||
|
||||
// send connection information to the npc
|
||||
if _, err := core.SendInfo(severConn, nil); err != nil {
|
||||
return ctx, err
|
||||
}
|
||||
|
||||
// data exchange
|
||||
go core.CopyBuffer(severConn, proxy.clientConn)
|
||||
core.CopyBuffer(proxy.clientConn, severConn)
|
||||
return ctx, nil
|
||||
return ctx, core.REQUEST_EOF
|
||||
}
|
||||
|
@@ -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
|
||||
}
|
||||
|
@@ -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 {
|
||||
|
@@ -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
|
||||
|
@@ -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
|
||||
|
||||
|
@@ -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)
|
||||
}
|
||||
|
Reference in New Issue
Block a user