mirror of
https://github.com/ehang-io/nps.git
synced 2025-09-06 07:06:53 +00:00
core plugin
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
)
|
||||
|
||||
type CheckAccess struct {
|
||||
core.NpsPlugin
|
||||
clientConn net.Conn
|
||||
clientUsername string
|
||||
clientPassword string
|
||||
@@ -22,30 +23,14 @@ func (check *CheckAccess) GetConfigName() *core.NpsConfigs {
|
||||
return c
|
||||
}
|
||||
|
||||
func (check *CheckAccess) GetStage() core.Stage {
|
||||
return core.STAGE_RUN
|
||||
}
|
||||
|
||||
func (check *CheckAccess) Start(ctx context.Context, config map[string]string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (check *CheckAccess) Run(ctx context.Context, config map[string]string) error {
|
||||
clientCtxConn := ctx.Value(core.CLIENT_CONNECTION)
|
||||
if clientCtxConn == nil {
|
||||
return core.CLIENT_CONNECTION_NOT_EXIST
|
||||
}
|
||||
check.clientConn = clientCtxConn.(net.Conn)
|
||||
check.clientConn = check.GetClientConn(ctx)
|
||||
check.configUsername = config["socks5_access_username"]
|
||||
check.configPassword = config["socks5_access_password"]
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (check *CheckAccess) End(ctx context.Context, config map[string]string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (check *CheckAccess) checkAuth(configUserName, configPassword string) error {
|
||||
if check.clientUsername == configUserName && check.clientPassword == configPassword {
|
||||
_, err := check.clientConn.Write([]byte{userAuthVersion, authSuccess})
|
||||
|
Reference in New Issue
Block a user