From 06e555775fab571fa4edd3c3d5fffd11f57b89c7 Mon Sep 17 00:00:00 2001 From: Marc Falzon Date: Thu, 1 Nov 2018 10:02:35 +0100 Subject: [PATCH 1/2] Fix recording bug in proxy This change fixes a bug in the proxy session recording management, where the proxy would record sessions even if the user didn't provide a value for the `-recDir` CLI flag. --- proxy/cmd/main.go | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/proxy/cmd/main.go b/proxy/cmd/main.go index a0f2f64..1e1bbe8 100644 --- a/proxy/cmd/main.go +++ b/proxy/cmd/main.go @@ -1,9 +1,12 @@ package main -import "vncproxy/proxy" -import "flag" -import "vncproxy/logger" -import "os" +import ( + "flag" + "os" + + "vncproxy/logger" + vncproxy "vncproxy/proxy" +) func main() { //create default session if required @@ -34,30 +37,32 @@ func main() { if *vncPass == "" { logger.Warn("proxy will have no password") } - if *recordDir == "" { - logger.Warn("FBS recording is turned off") - } tcpUrl := "" if *tcpPort != "" { tcpUrl = ":" + string(*tcpPort) } - proxy := &proxy.VncProxy{ + proxy := &vncproxy.VncProxy{ WsListeningUrl: "http://0.0.0.0:" + string(*wsPort) + "/", // empty = not listening on ws - RecordingDir: *recordDir, //"/Users/amitbet/vncRec", // empty = no recording TcpListeningUrl: tcpUrl, ProxyVncPassword: *vncPass, //empty = no auth - SingleSession: &proxy.VncSession{ + SingleSession: &vncproxy.VncSession{ TargetHostname: *targetVncHost, TargetPort: *targetVncPort, TargetPassword: *targetVncPass, //"vncPass", ID: "dummySession", - Status: proxy.SessionStatusInit, - Type: proxy.SessionTypeRecordingProxy, + Status: vncproxy.SessionStatusInit, + Type: vncproxy.SessionTypeProxyPass, }, // to be used when not using sessions UsingSessions: false, //false = single session - defined in the var above } + if *recordDir != "" { + logger.Warn("FBS recording is turned on") + proxy.RecordingDir = *recordDir + proxy.SingleSession.Type = vncproxy.SessionTypeRecordingProxy + } + proxy.StartListening() } From 9a52a433ea5629f5a50ac1661f2671ca78151d4f Mon Sep 17 00:00:00 2001 From: Marc Falzon Date: Thu, 1 Nov 2018 10:14:15 +0100 Subject: [PATCH 2/2] Add support for UNIX socket VNC target This change add support for targeting a VNC server via a local UNIX socket. It introduces a new `-target` CLI flag able to handle both TCP "address:port" and "/path/to/unix.socket" formats, and deprecates the previous `-targHost` and `-targPort` flags for future removal. --- proxy/cmd/main.go | 10 ++++++---- proxy/proxy.go | 20 +++++++++++++++++--- proxy/vnc-session.go | 1 + 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/proxy/cmd/main.go b/proxy/cmd/main.go index 1e1bbe8..2d4b755 100644 --- a/proxy/cmd/main.go +++ b/proxy/cmd/main.go @@ -14,8 +14,9 @@ func main() { var wsPort = flag.String("wsPort", "", "websocket port") var vncPass = flag.String("vncPass", "", "password on incoming vnc connections to the proxy, defaults to no password") var recordDir = flag.String("recDir", "", "path to save FBS recordings WILL NOT RECORD if not defined.") - var targetVncPort = flag.String("targPort", "", "target vnc server port") - var targetVncHost = flag.String("targHost", "", "target vnc server host") + var targetVnc = flag.String("target", "", "target vnc server (host:port or /path/to/unix.socket)") + var targetVncPort = flag.String("targPort", "", "target vnc server port (deprecated, use -target)") + var targetVncHost = flag.String("targHost", "", "target vnc server host (deprecated, use -target)") var targetVncPass = flag.String("targPass", "", "target vnc password") var logLevel = flag.String("logLevel", "info", "change logging level") @@ -28,8 +29,8 @@ func main() { os.Exit(1) } - if *targetVncPort == "" { - logger.Error("no target vnc server port defined") + if *targetVnc == "" && *targetVncPort == "" { + logger.Error("no target vnc server host/port or socket defined") flag.Usage() os.Exit(1) } @@ -48,6 +49,7 @@ func main() { TcpListeningUrl: tcpUrl, ProxyVncPassword: *vncPass, //empty = no auth SingleSession: &vncproxy.VncSession{ + Target: *targetVnc, TargetHostname: *targetVncHost, TargetPort: *targetVncPort, TargetPassword: *targetVncPass, //"vncPass", diff --git a/proxy/proxy.go b/proxy/proxy.go index ed14ab2..8198ef5 100644 --- a/proxy/proxy.go +++ b/proxy/proxy.go @@ -24,8 +24,17 @@ type VncProxy struct { sessionManager *SessionManager } -func (vp *VncProxy) createClientConnection(targetServerUrl string, vncPass string) (*client.ClientConn, error) { - nc, err := net.Dial("tcp", targetServerUrl) +func (vp *VncProxy) createClientConnection(target string, vncPass string) (*client.ClientConn, error) { + var ( + nc net.Conn + err error + ) + + if target[0] == '/' { + nc, err = net.Dial("unix", target) + } else { + nc, err = net.Dial("tcp", target) + } if err != nil { logger.Errorf("error connecting to vnc server: %s", err) @@ -85,7 +94,12 @@ func (vp *VncProxy) newServerConnHandler(cfg *server.ServerConfig, sconn *server session.Status = SessionStatusInit if session.Type == SessionTypeProxyPass || session.Type == SessionTypeRecordingProxy { - cconn, err := vp.createClientConnection(session.TargetHostname+":"+session.TargetPort, session.TargetPassword) + target := session.Target + if session.TargetHostname != "" && session.TargetPort != "" { + target = session.TargetHostname + ":" + session.TargetPort + } + + cconn, err := vp.createClientConnection(target, session.TargetPassword) if err != nil { session.Status = SessionStatusError logger.Errorf("Proxy.newServerConnHandler error creating connection: %s", err) diff --git a/proxy/vnc-session.go b/proxy/vnc-session.go index eae8a73..dd8ac64 100644 --- a/proxy/vnc-session.go +++ b/proxy/vnc-session.go @@ -16,6 +16,7 @@ const ( ) type VncSession struct { + Target string TargetHostname string TargetPort string TargetPassword string