This commit is contained in:
刘河
2019-10-17 09:21:01 +08:00
parent 5e5df224b7
commit b6a9001d43
9 changed files with 371 additions and 86 deletions

View File

@@ -3,15 +3,13 @@ package socks5
import (
"context"
"errors"
"fmt"
"github.com/cnlh/nps/core"
"net"
)
type CheckAccess struct {
core.NpsPlugin
clientConn net.Conn
clientUsername string
clientPassword string
configUsername string
configPassword string
}
@@ -24,19 +22,23 @@ func (check *CheckAccess) GetConfigName() *core.NpsConfigs {
}
func (check *CheckAccess) Run(ctx context.Context) (context.Context, error) {
check.clientConn = check.GetClientConn(ctx)
check.configUsername = check.Configs["socks5_access_username"]
check.configPassword = check.Configs["socks5_access_password"]
clientConn := check.GetClientConn(ctx)
check.configUsername = check.Configs["socks5_simple_access_username"]
check.configPassword = check.Configs["socks5_simple_access_password"]
if check.Configs["socks5_simple_access_check"] == "true" {
connUsername := ctx.Value("socks_client_username").(string)
connPassword := ctx.Value("socks_client_password").(string)
return ctx, check.checkAuth(clientConn, connUsername, connPassword)
}
return ctx, nil
}
func (check *CheckAccess) checkAuth(configUserName, configPassword string) error {
if check.clientUsername == configUserName && check.clientPassword == configPassword {
_, err := check.clientConn.Write([]byte{userAuthVersion, authSuccess})
func (check *CheckAccess) checkAuth(clientConn net.Conn, connUserName, connPassword string) error {
if check.configUsername == connUserName && check.configPassword == connPassword {
_, err := clientConn.Write([]byte{userAuthVersion, authSuccess})
return err
} else {
_, err := check.clientConn.Write([]byte{userAuthVersion, authFailure})
_, err := clientConn.Write([]byte{userAuthVersion, authFailure})
if err != nil {
return err
}