mirror of
https://github.com/ehang-io/nps.git
synced 2025-09-06 07:06:53 +00:00
module
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user