Added OpExit
This commit is contained in:
parent
3e721d122b
commit
3c8e61bc90
@ -94,6 +94,29 @@ Client login operation
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### Exit
|
||||||
|
|
||||||
|
Client exit operation. When client cannot connect to server that will notify to admin.
|
||||||
|
Can use a new version (OpExit supported at: https://github.com/lowk3v/frp-notify/releases/tag/OpExitSupported)
|
||||||
|
|
||||||
|
```
|
||||||
|
{
|
||||||
|
"content": {
|
||||||
|
"version": <string>,
|
||||||
|
"hostname": <string>,
|
||||||
|
"os": <string>,
|
||||||
|
"arch": <string>,
|
||||||
|
"user": <string>,
|
||||||
|
"timestamp": <int64>,
|
||||||
|
"privilege_key": <string>,
|
||||||
|
"run_id": <string>,
|
||||||
|
"pool_count": <int>,
|
||||||
|
"metas": map<string>string,
|
||||||
|
"client_address": <string>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
#### NewProxy
|
#### NewProxy
|
||||||
|
|
||||||
Create new proxy
|
Create new proxy
|
||||||
|
@ -83,6 +83,19 @@ type LoginResp struct {
|
|||||||
Error string `json:"error,omitempty"`
|
Error string `json:"error,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// When frpc exit success, send this message to exit plugin server
|
||||||
|
type Exit struct {
|
||||||
|
Version string `json:"version,omitempty"`
|
||||||
|
Hostname string `json:"hostname,omitempty"`
|
||||||
|
Os string `json:"os,omitempty"`
|
||||||
|
Arch string `json:"arch,omitempty"`
|
||||||
|
User string `json:"user,omitempty"`
|
||||||
|
PrivilegeKey string `json:"privilege_key,omitempty"`
|
||||||
|
Timestamp int64 `json:"timestamp,omitempty"`
|
||||||
|
RunID string `json:"run_id,omitempty"`
|
||||||
|
Metas map[string]string `json:"metas,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
// When frpc login success, send this message to frps for running a new proxy.
|
// When frpc login success, send this message to frps for running a new proxy.
|
||||||
type NewProxy struct {
|
type NewProxy struct {
|
||||||
ProxyName string `json:"proxy_name,omitempty"`
|
ProxyName string `json:"proxy_name,omitempty"`
|
||||||
|
@ -26,6 +26,7 @@ import (
|
|||||||
|
|
||||||
type Manager struct {
|
type Manager struct {
|
||||||
loginPlugins []Plugin
|
loginPlugins []Plugin
|
||||||
|
exitPlugins []Plugin
|
||||||
newProxyPlugins []Plugin
|
newProxyPlugins []Plugin
|
||||||
closeProxyPlugins []Plugin
|
closeProxyPlugins []Plugin
|
||||||
pingPlugins []Plugin
|
pingPlugins []Plugin
|
||||||
@ -36,6 +37,7 @@ type Manager struct {
|
|||||||
func NewManager() *Manager {
|
func NewManager() *Manager {
|
||||||
return &Manager{
|
return &Manager{
|
||||||
loginPlugins: make([]Plugin, 0),
|
loginPlugins: make([]Plugin, 0),
|
||||||
|
exitPlugins: make([]Plugin, 0),
|
||||||
newProxyPlugins: make([]Plugin, 0),
|
newProxyPlugins: make([]Plugin, 0),
|
||||||
closeProxyPlugins: make([]Plugin, 0),
|
closeProxyPlugins: make([]Plugin, 0),
|
||||||
pingPlugins: make([]Plugin, 0),
|
pingPlugins: make([]Plugin, 0),
|
||||||
@ -48,6 +50,9 @@ func (m *Manager) Register(p Plugin) {
|
|||||||
if p.IsSupport(OpLogin) {
|
if p.IsSupport(OpLogin) {
|
||||||
m.loginPlugins = append(m.loginPlugins, p)
|
m.loginPlugins = append(m.loginPlugins, p)
|
||||||
}
|
}
|
||||||
|
if p.IsSupport(OpExit) {
|
||||||
|
m.exitPlugins = append(m.exitPlugins, p)
|
||||||
|
}
|
||||||
if p.IsSupport(OpNewProxy) {
|
if p.IsSupport(OpNewProxy) {
|
||||||
m.newProxyPlugins = append(m.newProxyPlugins, p)
|
m.newProxyPlugins = append(m.newProxyPlugins, p)
|
||||||
}
|
}
|
||||||
@ -99,6 +104,32 @@ func (m *Manager) Login(content *LoginContent) (*LoginContent, error) {
|
|||||||
return content, nil
|
return content, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *Manager) Exit(content *ExitContent) error {
|
||||||
|
if len(m.exitPlugins) == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
errs := make([]string, 0)
|
||||||
|
reqid, _ := util.RandID()
|
||||||
|
xl := xlog.New().AppendPrefix("reqid: " + reqid)
|
||||||
|
ctx := xlog.NewContext(context.Background(), xl)
|
||||||
|
ctx = NewReqidContext(ctx, reqid)
|
||||||
|
|
||||||
|
for _, p := range m.exitPlugins {
|
||||||
|
_, _, err := p.Handle(ctx, OpExit, *content)
|
||||||
|
if err != nil {
|
||||||
|
xl.Warn("send Exit request to plugin [%s] error: %v", p.Name(), err)
|
||||||
|
errs = append(errs, fmt.Sprintf("[%s]: %v", p.Name(), err))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(errs) > 0 {
|
||||||
|
return fmt.Errorf("send Exit request to plugin errors: %s", strings.Join(errs, "; "))
|
||||||
|
} else {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (m *Manager) NewProxy(content *NewProxyContent) (*NewProxyContent, error) {
|
func (m *Manager) NewProxy(content *NewProxyContent) (*NewProxyContent, error) {
|
||||||
if len(m.newProxyPlugins) == 0 {
|
if len(m.newProxyPlugins) == 0 {
|
||||||
return content, nil
|
return content, nil
|
||||||
|
@ -19,9 +19,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
APIVersion = "0.1.0"
|
APIVersion = "0.1.1"
|
||||||
|
|
||||||
OpLogin = "Login"
|
OpLogin = "Login"
|
||||||
|
OpExit = "Exit"
|
||||||
OpNewProxy = "NewProxy"
|
OpNewProxy = "NewProxy"
|
||||||
OpCloseProxy = "CloseProxy"
|
OpCloseProxy = "CloseProxy"
|
||||||
OpPing = "Ping"
|
OpPing = "Ping"
|
||||||
|
@ -37,6 +37,11 @@ type LoginContent struct {
|
|||||||
ClientAddress string `json:"client_address,omitempty"`
|
ClientAddress string `json:"client_address,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ExitContent struct {
|
||||||
|
ClientAddress string `json:"client_address,omitempty"`
|
||||||
|
msg.Exit
|
||||||
|
}
|
||||||
|
|
||||||
type UserInfo struct {
|
type UserInfo struct {
|
||||||
User string `json:"user"`
|
User string `json:"user"`
|
||||||
Metas map[string]string `json:"metas"`
|
Metas map[string]string `json:"metas"`
|
||||||
|
@ -394,6 +394,25 @@ func (ctl *Control) stoper() {
|
|||||||
|
|
||||||
ctl.allShutdown.Done()
|
ctl.allShutdown.Done()
|
||||||
xl.Info("client exit success")
|
xl.Info("client exit success")
|
||||||
|
|
||||||
|
notifyContent := &plugin.ExitContent{
|
||||||
|
ClientAddress: ctl.conn.RemoteAddr().String(),
|
||||||
|
Exit: msg.Exit{
|
||||||
|
Version: ctl.loginMsg.Version,
|
||||||
|
Hostname: ctl.loginMsg.Hostname,
|
||||||
|
Os: ctl.loginMsg.Os,
|
||||||
|
Arch: ctl.loginMsg.Arch,
|
||||||
|
User: ctl.loginMsg.User,
|
||||||
|
PrivilegeKey: ctl.loginMsg.PrivilegeKey,
|
||||||
|
Timestamp: ctl.loginMsg.Timestamp,
|
||||||
|
RunID: ctl.loginMsg.RunID,
|
||||||
|
Metas: ctl.loginMsg.Metas,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
go func() {
|
||||||
|
_ = ctl.pluginManager.Exit(notifyContent)
|
||||||
|
}()
|
||||||
|
|
||||||
metrics.Server.CloseClient()
|
metrics.Server.CloseClient()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user