mirror of
https://github.com/fatedier/frp.git
synced 2025-07-14 01:42:21 +07:00
[Feature] Server Plugin - Ping and NewWorkConn RPC (#1702)
This commit is contained in:
@ -450,10 +450,23 @@ func (ctl *Control) manager() {
|
||||
ctl.CloseProxy(m)
|
||||
xl.Info("close proxy [%s] success", m.ProxyName)
|
||||
case *msg.Ping:
|
||||
if err := ctl.authVerifier.VerifyPing(m); err != nil {
|
||||
content := &plugin.PingContent{
|
||||
User: plugin.UserInfo{
|
||||
User: ctl.loginMsg.User,
|
||||
Metas: ctl.loginMsg.Metas,
|
||||
RunId: ctl.loginMsg.RunId,
|
||||
},
|
||||
Ping: *m,
|
||||
}
|
||||
retContent, err := ctl.pluginManager.Ping(content)
|
||||
if err == nil {
|
||||
m = &retContent.Ping
|
||||
err = ctl.authVerifier.VerifyPing(m)
|
||||
}
|
||||
if err != nil {
|
||||
xl.Warn("received invalid ping: %v", err)
|
||||
ctl.sendCh <- &msg.Pong{
|
||||
Error: "invalid authentication in ping",
|
||||
Error: util.GenerateResponseErrorString("invalid ping", err, ctl.serverCfg.DetailedErrorsToClient),
|
||||
}
|
||||
return
|
||||
}
|
||||
|
@ -457,13 +457,27 @@ func (svr *Service) RegisterWorkConn(workConn net.Conn, newMsg *msg.NewWorkConn)
|
||||
xl.Warn("No client control found for run id [%s]", newMsg.RunId)
|
||||
return fmt.Errorf("no client control found for run id [%s]", newMsg.RunId)
|
||||
}
|
||||
// Check auth.
|
||||
if err := svr.authVerifier.VerifyNewWorkConn(newMsg); err != nil {
|
||||
xl.Warn("Invalid authentication in NewWorkConn message on run id [%s]", newMsg.RunId)
|
||||
// server plugin hook
|
||||
content := &plugin.NewWorkConnContent{
|
||||
User: plugin.UserInfo{
|
||||
User: ctl.loginMsg.User,
|
||||
Metas: ctl.loginMsg.Metas,
|
||||
RunId: ctl.loginMsg.RunId,
|
||||
},
|
||||
NewWorkConn: *newMsg,
|
||||
}
|
||||
retContent, err := svr.pluginManager.NewWorkConn(content)
|
||||
if err == nil {
|
||||
newMsg = &retContent.NewWorkConn
|
||||
// Check auth.
|
||||
err = svr.authVerifier.VerifyNewWorkConn(newMsg)
|
||||
}
|
||||
if err != nil {
|
||||
xl.Warn("invalid NewWorkConn with run id [%s]", newMsg.RunId)
|
||||
msg.WriteMsg(workConn, &msg.StartWorkConn{
|
||||
Error: "invalid authentication in NewWorkConn",
|
||||
Error: util.GenerateResponseErrorString("invalid NewWorkConn", err, ctl.serverCfg.DetailedErrorsToClient),
|
||||
})
|
||||
return fmt.Errorf("invalid authentication in NewWorkConn message on run id [%s]", newMsg.RunId)
|
||||
return fmt.Errorf("invalid NewWorkConn with run id [%s]", newMsg.RunId)
|
||||
}
|
||||
return ctl.RegisterWorkConn(workConn)
|
||||
}
|
||||
|
Reference in New Issue
Block a user