Files
natpass/code/client/app/connect.go
2021-11-18 23:17:44 +08:00

61 lines
1.7 KiB
Go

package app
import (
"natpass/code/client/global"
"natpass/code/client/pool"
"natpass/code/client/rule"
"natpass/code/client/rule/shell"
"natpass/code/client/rule/vnc"
"natpass/code/network"
"github.com/lwch/logging"
)
func (a *App) shellCreate(mgr *rule.Mgr, conn *pool.Conn, msg *network.Msg) {
create := msg.GetCreq()
tn := mgr.Get(create.GetName(), msg.GetFrom())
if tn == nil {
tn = shell.New(global.Rule{
Name: create.GetName(),
Target: msg.GetFrom(),
Type: "shell",
Exec: create.GetCshell().GetExec(),
Env: create.GetCshell().GetEnv(),
})
mgr.Add(tn)
}
lk := tn.NewLink(msg.GetLinkId(), msg.GetFrom(), msg.GetFromIdx(), nil, conn).(*shell.Link)
err := lk.Exec()
if err != nil {
logging.Error("create shell failed: %v", err)
conn.SendConnectError(msg.GetFrom(), msg.GetFromIdx(), msg.GetLinkId(), err.Error())
return
}
conn.SendConnectOK(msg.GetFrom(), msg.GetFromIdx(), msg.GetLinkId())
lk.Forward()
}
func (a *App) vncCreate(confDir string, mgr *rule.Mgr, conn *pool.Conn, msg *network.Msg) {
create := msg.GetCreq()
tn := mgr.Get(create.GetName(), msg.GetFrom())
if tn == nil {
tn = vnc.New(global.Rule{
Name: create.GetName(),
Target: msg.GetFrom(),
Type: "vnc",
Fps: create.GetCvnc().GetFps(),
})
mgr.Add(tn)
}
lk := tn.NewLink(msg.GetLinkId(), msg.GetFrom(), msg.GetFromIdx(), nil, conn).(*vnc.Link)
lk.SetQuality(create.GetCvnc().GetQuality())
err := lk.Fork(confDir)
if err != nil {
logging.Error("create vnc failed: %v", err)
conn.SendConnectError(msg.GetFrom(), msg.GetFromIdx(), msg.GetLinkId(), err.Error())
return
}
conn.SendConnectOK(msg.GetFrom(), msg.GetFromIdx(), msg.GetLinkId())
lk.Forward()
}