mirror of
https://github.com/amitbet/vncproxy.git
synced 2025-09-20 17:09:35 +00:00
some refactoring + better recorder
This commit is contained in:
148
proxy/proxy.go
148
proxy/proxy.go
@@ -9,8 +9,9 @@ import (
|
||||
"vncproxy/common"
|
||||
"vncproxy/encodings"
|
||||
"vncproxy/logger"
|
||||
"vncproxy/player"
|
||||
listeners "vncproxy/recorder"
|
||||
"vncproxy/server"
|
||||
listeners "vncproxy/tee-listeners"
|
||||
)
|
||||
|
||||
type VncProxy struct {
|
||||
@@ -34,14 +35,11 @@ func (vp *VncProxy) createClientConnection(targetServerUrl string, vncPass strin
|
||||
var noauth client.ClientAuthNone
|
||||
authArr := []client.ClientAuth{&client.PasswordAuth{Password: vncPass}, &noauth}
|
||||
|
||||
//vncSrvMessagesChan := make(chan common.ServerMessage)
|
||||
|
||||
clientConn, err := client.NewClientConn(nc,
|
||||
&client.ClientConfig{
|
||||
Auth: authArr,
|
||||
Exclusive: true,
|
||||
})
|
||||
//clientConn.Listener = split
|
||||
|
||||
if err != nil {
|
||||
logger.Errorf("error creating client: %s", err)
|
||||
@@ -52,7 +50,7 @@ func (vp *VncProxy) createClientConnection(targetServerUrl string, vncPass strin
|
||||
}
|
||||
|
||||
// if sessions not enabled, will always return the configured target server (only one)
|
||||
func (vp *VncProxy) getTargetServerFromSession(sessionId string) (*VncSession, error) {
|
||||
func (vp *VncProxy) getProxySession(sessionId string) (*VncSession, error) {
|
||||
|
||||
if !vp.UsingSessions {
|
||||
if vp.SingleSession == nil {
|
||||
@@ -65,83 +63,95 @@ func (vp *VncProxy) getTargetServerFromSession(sessionId string) (*VncSession, e
|
||||
|
||||
func (vp *VncProxy) newServerConnHandler(cfg *server.ServerConfig, sconn *server.ServerConn) error {
|
||||
|
||||
recFile := "recording" + strconv.FormatInt(time.Now().Unix(), 10) + ".rbs"
|
||||
recPath := path.Join(vp.RecordingDir, recFile)
|
||||
rec, err := listeners.NewRecorder(recPath)
|
||||
if err != nil {
|
||||
logger.Errorf("Proxy.newServerConnHandler can't open recorder save path: %s", recPath)
|
||||
return err
|
||||
}
|
||||
|
||||
session, err := vp.getTargetServerFromSession(sconn.SessionId)
|
||||
session, err := vp.getProxySession(sconn.SessionId)
|
||||
if err != nil {
|
||||
logger.Errorf("Proxy.newServerConnHandler can't get session: %d", sconn.SessionId)
|
||||
return err
|
||||
}
|
||||
|
||||
// for _, l := range rfbListeners {
|
||||
// sconn.Listeners.AddListener(l)
|
||||
// }
|
||||
sconn.Listeners.AddListener(rec)
|
||||
var rec *listeners.Recorder
|
||||
if session.Type == SessionTypeRecordingProxy {
|
||||
recFile := "recording" + strconv.FormatInt(time.Now().Unix(), 10) + ".rbs"
|
||||
recPath := path.Join(vp.RecordingDir, recFile)
|
||||
rec, err := listeners.NewRecorder(recPath)
|
||||
if err != nil {
|
||||
logger.Errorf("Proxy.newServerConnHandler can't open recorder save path: %s", recPath)
|
||||
return err
|
||||
}
|
||||
|
||||
//clientSplitter := &common.MultiListener{}
|
||||
|
||||
cconn, err := vp.createClientConnection(session.TargetHostname+":"+session.TargetPort, session.TargetPassword)
|
||||
if err != nil {
|
||||
logger.Errorf("Proxy.newServerConnHandler error creating connection: %s", err)
|
||||
return err
|
||||
}
|
||||
cconn.Listeners.AddListener(rec)
|
||||
//cconn.Listener = clientSplitter
|
||||
|
||||
//creating cross-listeners between server and client parts to pass messages through the proxy:
|
||||
|
||||
// gets the bytes from the actual vnc server on the env (client part of the proxy)
|
||||
// and writes them through the server socket to the vnc-client
|
||||
serverUpdater := &ServerUpdater{sconn}
|
||||
cconn.Listeners.AddListener(serverUpdater)
|
||||
|
||||
//serverMsgRepeater := &listeners.WriteTo{sconn, "vnc-client-bound"}
|
||||
//cconn.Listeners.AddListener(serverMsgRepeater)
|
||||
|
||||
// gets the messages from the server part (from vnc-client),
|
||||
// and write through the client to the actual vnc-server
|
||||
//clientMsgRepeater := &listeners.WriteTo{cconn, "vnc-server-bound"}
|
||||
clientUpdater := &ClientUpdater{cconn}
|
||||
sconn.Listeners.AddListener(clientUpdater)
|
||||
|
||||
err = cconn.Connect()
|
||||
if err != nil {
|
||||
logger.Errorf("Proxy.newServerConnHandler error connecting to client: %s", err)
|
||||
return err
|
||||
sconn.Listeners.AddListener(rec)
|
||||
}
|
||||
|
||||
encs := []common.IEncoding{
|
||||
&encodings.RawEncoding{},
|
||||
&encodings.TightEncoding{},
|
||||
&encodings.EncCursorPseudo{},
|
||||
//encodings.TightPngEncoding{},
|
||||
&encodings.RREEncoding{},
|
||||
&encodings.ZLibEncoding{},
|
||||
&encodings.ZRLEEncoding{},
|
||||
&encodings.CopyRectEncoding{},
|
||||
&encodings.CoRREEncoding{},
|
||||
&encodings.HextileEncoding{},
|
||||
session.Status = SessionStatusInit
|
||||
if session.Type == SessionTypeProxyPass || session.Type == SessionTypeRecordingProxy {
|
||||
cconn, err := vp.createClientConnection(session.TargetHostname+":"+session.TargetPort, session.TargetPassword)
|
||||
if err != nil {
|
||||
session.Status = SessionStatusError
|
||||
logger.Errorf("Proxy.newServerConnHandler error creating connection: %s", err)
|
||||
return err
|
||||
}
|
||||
if session.Type == SessionTypeRecordingProxy {
|
||||
cconn.Listeners.AddListener(rec)
|
||||
}
|
||||
|
||||
//creating cross-listeners between server and client parts to pass messages through the proxy:
|
||||
|
||||
// gets the bytes from the actual vnc server on the env (client part of the proxy)
|
||||
// and writes them through the server socket to the vnc-client
|
||||
serverUpdater := &ServerUpdater{sconn}
|
||||
cconn.Listeners.AddListener(serverUpdater)
|
||||
|
||||
// gets the messages from the server part (from vnc-client),
|
||||
// and write through the client to the actual vnc-server
|
||||
clientUpdater := &ClientUpdater{cconn}
|
||||
sconn.Listeners.AddListener(clientUpdater)
|
||||
|
||||
err = cconn.Connect()
|
||||
if err != nil {
|
||||
session.Status = SessionStatusError
|
||||
logger.Errorf("Proxy.newServerConnHandler error connecting to client: %s", err)
|
||||
return err
|
||||
}
|
||||
|
||||
encs := []common.IEncoding{
|
||||
&encodings.RawEncoding{},
|
||||
&encodings.TightEncoding{},
|
||||
&encodings.EncCursorPseudo{},
|
||||
&encodings.TightPngEncoding{},
|
||||
&encodings.RREEncoding{},
|
||||
&encodings.ZLibEncoding{},
|
||||
&encodings.ZRLEEncoding{},
|
||||
&encodings.CopyRectEncoding{},
|
||||
&encodings.CoRREEncoding{},
|
||||
&encodings.HextileEncoding{},
|
||||
}
|
||||
cconn.Encs = encs
|
||||
|
||||
if err != nil {
|
||||
session.Status = SessionStatusError
|
||||
logger.Errorf("Proxy.newServerConnHandler error connecting to client: %s", err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
cconn.Encs = encs
|
||||
//err = cconn.MsgSetEncodings(encs)
|
||||
if err != nil {
|
||||
logger.Errorf("Proxy.newServerConnHandler error connecting to client: %s", err)
|
||||
return err
|
||||
|
||||
if session.Type == SessionTypeReplayServer {
|
||||
fbs, err := player.ConnectFbsFile(session.ReplayFilePath, sconn)
|
||||
|
||||
if err != nil {
|
||||
logger.Error("TestServer.NewConnHandler: Error in loading FBS: ", err)
|
||||
return err
|
||||
}
|
||||
sconn.Listeners.AddListener(player.NewFBSPlayListener(sconn, fbs))
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
session.Status = SessionStatusActive
|
||||
return nil
|
||||
}
|
||||
|
||||
func (vp *VncProxy) StartListening() {
|
||||
|
||||
//chServer := make(chan common.ClientMessage)
|
||||
//chClient := make(chan common.ServerMessage)
|
||||
|
||||
secHandlers := []server.SecurityHandler{&server.ServerAuthNone{}}
|
||||
|
||||
if vp.ProxyVncPassword != "" {
|
||||
@@ -157,10 +167,6 @@ func (vp *VncProxy) StartListening() {
|
||||
Width: uint16(1024),
|
||||
NewConnHandler: vp.newServerConnHandler,
|
||||
UseDummySession: !vp.UsingSessions,
|
||||
// func(cfg *server.ServerConfig, conn *server.ServerConn) error {
|
||||
// vp.newServerConnHandler(cfg, conn)
|
||||
// return nil
|
||||
// },
|
||||
}
|
||||
|
||||
if vp.TcpListeningUrl != "" && vp.WsListeningUrl != "" {
|
||||
|
Reference in New Issue
Block a user