diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 318f991..371dedb 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -24,6 +24,7 @@
+
@@ -32,7 +33,7 @@
-
+
@@ -42,7 +43,7 @@
-
+
@@ -52,7 +53,7 @@
-
+
@@ -62,7 +63,7 @@
-
+
@@ -72,7 +73,7 @@
-
+
@@ -92,7 +93,7 @@
-
+
@@ -102,7 +103,7 @@
-
+
@@ -114,8 +115,8 @@
-
-
+
+
@@ -224,11 +225,11 @@
-
-
-
-
-
+
+
+
+
+
@@ -283,24 +284,9 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
@@ -325,176 +311,13 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- project
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
@@ -551,6 +374,29 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -632,11 +478,69 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -646,6 +550,17 @@
+
+
+
+
+
+
+
+
+
+
+
@@ -662,6 +577,36 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -724,12 +669,57 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ project
+
+
+
+
+
+
+
@@ -743,14 +733,24 @@
-
+
+
+
+
+
+
+
+
+
+
+
-
+
@@ -759,8 +759,9 @@
+
-
+
@@ -769,8 +770,9 @@
+
-
+
@@ -779,6 +781,7 @@
+
@@ -817,6 +820,8 @@
+
+
@@ -853,7 +858,7 @@
-
+
@@ -865,22 +870,24 @@
-
+
+
-
+
+
-
+
@@ -890,21 +897,39 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
+
@@ -1194,18 +1211,10 @@
-
-
-
-
-
-
-
-
-
+
@@ -1213,7 +1222,7 @@
-
+
@@ -1221,7 +1230,7 @@
-
+
@@ -1231,7 +1240,7 @@
-
+
@@ -1239,8 +1248,24 @@
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/main.go b/main.go
index c377bc4..734ca6d 100644
--- a/main.go
+++ b/main.go
@@ -56,13 +56,9 @@ func main() {
//&encodings.CopyRectEncoding{},
//coRRE := encodings.CoRREEncoding{},
//hextile := encodings.HextileEncoding{},
- &encodings.PseudoEncoding{int32(common.EncJPEGQualityLevelPseudo9)},
+ &encodings.PseudoEncoding{int32(common.EncJPEGQualityLevelPseudo8)},
}
- // file, _ := os.OpenFile("stam.bin", os.O_CREATE|os.O_RDWR, 0755)
- // defer file.Close()
-
- //tight.SetOutput(file)
clientConn.SetEncodings(encs)
clientConn.FramebufferUpdateRequest(false, 0, 0, 1280, 800)
@@ -94,16 +90,9 @@ func main() {
clientConn.Close()
}()
- //go func() {
- // for msg := range vncSrvMessagesChan {
- // logger.Debugf("message type: %d, content: %v\n", msg.Type(), msg)
- // }
for {
time.Sleep(time.Minute)
}
- //}()
-
- //clientConn.Close()
}
func getNowMillisec() int {
return int(time.Now().UnixNano() / int64(time.Millisecond))
diff --git a/player/cmd/main.go b/player/cmd/main.go
new file mode 100644
index 0000000..f4ab3f3
--- /dev/null
+++ b/player/cmd/main.go
@@ -0,0 +1,98 @@
+package main
+
+import (
+ "flag"
+ "fmt"
+ "os"
+ "vncproxy/common"
+ "vncproxy/encodings"
+ "vncproxy/logger"
+ "vncproxy/player"
+ "vncproxy/server"
+)
+
+func main() {
+ wsPort := flag.String("wsPort", "", "websocket port for player to listen to client connections")
+ tcpPort := flag.String("tcpPort", "", "tcp port for player to listen to client connections")
+ fbsFile := flag.String("fbsFile", "", "fbs file to serve to all connecting clients")
+
+ flag.Parse()
+
+ fmt.Println("**************************************************************************")
+ fmt.Println("*** This is a toy server that replays a single FBS file to all clients ***")
+ fmt.Println("**************************************************************************")
+
+ if *fbsFile == "" {
+ logger.Error("there is no FBS file to replay to incoming clients")
+ flag.Usage()
+ os.Exit(1)
+ }
+
+ if *tcpPort == "" && *wsPort == "" {
+ logger.Error("no listening port defined")
+ flag.Usage()
+ os.Exit(1)
+ }
+
+ //chServer := make(chan common.ClientMessage)
+ //chClient := make(chan common.ServerMessage)
+
+ encs := []common.IEncoding{
+ &encodings.RawEncoding{},
+ &encodings.TightEncoding{},
+ &encodings.EncCursorPseudo{},
+ &encodings.TightPngEncoding{},
+ &encodings.RREEncoding{},
+ &encodings.ZLibEncoding{},
+ &encodings.ZRLEEncoding{},
+ &encodings.CopyRectEncoding{},
+ &encodings.CoRREEncoding{},
+ &encodings.HextileEncoding{},
+ }
+
+ cfg := &server.ServerConfig{
+ //SecurityHandlers: []SecurityHandler{&ServerAuthNone{}, &ServerAuthVNC{}},
+ SecurityHandlers: []server.SecurityHandler{&server.ServerAuthNone{}},
+ Encodings: encs,
+ PixelFormat: common.NewPixelFormat(32),
+ ClientMessages: server.DefaultClientMessages,
+ DesktopName: []byte("workDesk"),
+ Height: uint16(768),
+ Width: uint16(1024),
+ }
+
+ cfg.NewConnHandler = func(cfg *server.ServerConfig, conn *server.ServerConn) error {
+ //fbs, err := loadFbsFile("/Users/amitbet/Dropbox/recording.rbs", conn)
+ //fbs, err := loadFbsFile("/Users/amitbet/vncRec/recording.rbs", conn)
+ fbs, err := player.ConnectFbsFile(*fbsFile, conn)
+
+ if err != nil {
+ logger.Error("TestServer.NewConnHandler: Error in loading FBS: ", err)
+ return err
+ }
+ conn.Listeners.AddListener(player.NewFBSPlayListener(conn, fbs))
+ return nil
+ }
+
+ if *tcpPort == "" && *wsPort == "" {
+ logger.Error("no listening port defined")
+ flag.Usage()
+ os.Exit(1)
+ }
+
+ url := "http://localhost:" + *wsPort + "/"
+
+ if *tcpPort != "" && *wsPort != "" {
+ logger.Infof("running two listeners: tcp port: %s, ws url: %s", *tcpPort, url)
+
+ go server.WsServe(url, cfg)
+ server.TcpServe(":"+*tcpPort, cfg)
+ }
+ if *tcpPort == "" && *wsPort != "" {
+ logger.Infof("running ws listener url: %s", url)
+ server.WsServe(url, cfg)
+ }
+ logger.Infof("running tcp listener on port: %s", *tcpPort)
+ server.TcpServe(":"+*tcpPort, cfg)
+
+}
diff --git a/player/fbs-play-listener.go b/player/fbs-play-listener.go
index 6aff804..29e2c8f 100644
--- a/player/fbs-play-listener.go
+++ b/player/fbs-play-listener.go
@@ -19,6 +19,26 @@ type FBSPlayListener struct {
startTime int
}
+func ConnectFbsFile(filename string, conn *server.ServerConn) (*FbsReader, error) {
+ fbs, err := NewFbsReader(filename)
+ if err != nil {
+ logger.Error("failed to open fbs reader:", err)
+ return nil, err
+ }
+ //NewFbsReader("/Users/amitbet/vncRec/recording.rbs")
+ initMsg, err := fbs.ReadStartSession()
+ if err != nil {
+ logger.Error("failed to open read fbs start session:", err)
+ return nil, err
+ }
+ conn.SetPixelFormat(&initMsg.PixelFormat)
+ conn.SetHeight(initMsg.FBHeight)
+ conn.SetWidth(initMsg.FBWidth)
+ conn.SetDesktopName(string(initMsg.NameText))
+
+ return fbs, nil
+}
+
func NewFBSPlayListener(conn *server.ServerConn, r *FbsReader) *FBSPlayListener {
h := &FBSPlayListener{Conn: conn, Fbs: r}
cm := client.MsgBell(0)
diff --git a/player/player_test.go b/player/player_test.go
index 9a1026e..30e2c40 100644
--- a/player/player_test.go
+++ b/player/player_test.go
@@ -9,26 +9,6 @@ import (
"vncproxy/server"
)
-func connectFbsFile(filename string, conn *server.ServerConn) (*FbsReader, error) {
- fbs, err := NewFbsReader(filename)
- if err != nil {
- logger.Error("failed to open fbs reader:", err)
- return nil, err
- }
- //NewFbsReader("/Users/amitbet/vncRec/recording.rbs")
- initMsg, err := fbs.ReadStartSession()
- if err != nil {
- logger.Error("failed to open read fbs start session:", err)
- return nil, err
- }
- conn.SetPixelFormat(&initMsg.PixelFormat)
- conn.SetHeight(initMsg.FBHeight)
- conn.SetWidth(initMsg.FBWidth)
- conn.SetDesktopName(string(initMsg.NameText))
-
- return fbs, nil
-}
-
func TestServer(t *testing.T) {
//chServer := make(chan common.ClientMessage)
@@ -61,7 +41,7 @@ func TestServer(t *testing.T) {
cfg.NewConnHandler = func(cfg *server.ServerConfig, conn *server.ServerConn) error {
//fbs, err := loadFbsFile("/Users/amitbet/Dropbox/recording.rbs", conn)
//fbs, err := loadFbsFile("/Users/amitbet/vncRec/recording.rbs", conn)
- fbs, err := connectFbsFile("/Users/amitbet/vncRec/recording1500554806.rbs", conn)
+ fbs, err := ConnectFbsFile("/Users/amitbet/vncRec/recording1500554806.rbs", conn)
if err != nil {
logger.Error("TestServer.NewConnHandler: Error in loading FBS: ", err)
diff --git a/proxy/cmd/main.go b/proxy/cmd/main.go
new file mode 100644
index 0000000..1c943a3
--- /dev/null
+++ b/proxy/cmd/main.go
@@ -0,0 +1,57 @@
+package main
+
+import "vncproxy/proxy"
+import "flag"
+import "fmt"
+import "vncproxy/logger"
+import "os"
+
+func main() {
+ fmt.Println("running!")
+ //create default session if required
+ var tcpPort = flag.String("tcpPort", "", "tcp port")
+ 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 targetVncPass = flag.String("targPass", "", "target vnc password")
+
+ flag.Parse()
+
+ if *tcpPort == "" && *wsPort == "" {
+ logger.Error("no listening port defined")
+ flag.Usage()
+ os.Exit(1)
+ }
+
+ if *targetVncPort == "" {
+ logger.Error("no target vnc server port defined")
+ flag.Usage()
+ os.Exit(1)
+ }
+
+ if *vncPass == "" {
+ logger.Warn("proxy will have no password")
+ }
+ if *recordDir == "" {
+ logger.Warn("FBS recording is turned off")
+ }
+
+ proxy := &proxy.VncProxy{
+ WsListeningUrl: "http://localhost:" + string(*wsPort) + "/", // empty = not listening on ws
+ RecordingDir: *recordDir, //"/Users/amitbet/vncRec", // empty = no recording
+ TcpListeningUrl: ":" + string(*tcpPort),
+ ProxyVncPassword: *vncPass, //empty = no auth
+ SingleSession: &proxy.VncSession{
+ TargetHostname: "localhost",
+ TargetPort: *targetVncPort,
+ TargetPassword: *targetVncPass, //"vncPass",
+ ID: "dummySession",
+ //Status: SessionStatusActive,
+ //Type: SessionTypeRecordingProxy,
+ }, // to be used when not using sessions
+ UsingSessions: false, //false = single session - defined in the var above
+ }
+
+ proxy.StartListening()
+}
diff --git a/proxy/proxy.go b/proxy/proxy.go
index 7c847fc..cc2a272 100644
--- a/proxy/proxy.go
+++ b/proxy/proxy.go
@@ -1,7 +1,6 @@
package proxy
import (
- "log"
"net"
"path"
"strconv"
@@ -15,17 +14,16 @@ import (
)
type VncProxy struct {
- tcpListeningUrl string // empty = not listening on tcp
- wsListeningUrl string // empty = not listening on ws
- recordingDir string // empty = no recording
- proxyPassword string // empty = no auth
- targetServersPassword string //empty = no auth
- SingleSession *VncSession // to be used when not using sessions
- UsingSessions bool //false = single session - defined in the var above
- sessionManager *SessionManager
+ TcpListeningUrl string // empty = not listening on tcp
+ WsListeningUrl string // empty = not listening on ws
+ RecordingDir string // empty = no recording
+ ProxyVncPassword string //empty = no auth
+ SingleSession *VncSession // to be used when not using sessions
+ UsingSessions bool //false = single session - defined in the var above
+ sessionManager *SessionManager
}
-func (vp *VncProxy) createClientConnection(targetServerUrl string) (*client.ClientConn, error) {
+func (vp *VncProxy) createClientConnection(targetServerUrl string, vncPass string) (*client.ClientConn, error) {
nc, err := net.Dial("tcp", targetServerUrl)
if err != nil {
@@ -34,7 +32,7 @@ func (vp *VncProxy) createClientConnection(targetServerUrl string) (*client.Clie
}
var noauth client.ClientAuthNone
- authArr := []client.ClientAuth{&client.PasswordAuth{Password: vp.targetServersPassword}, &noauth}
+ authArr := []client.ClientAuth{&client.PasswordAuth{Password: vncPass}, &noauth}
//vncSrvMessagesChan := make(chan common.ServerMessage)
@@ -68,7 +66,7 @@ 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)
+ 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)
@@ -88,7 +86,7 @@ func (vp *VncProxy) newServerConnHandler(cfg *server.ServerConfig, sconn *server
//clientSplitter := &common.MultiListener{}
- cconn, err := vp.createClientConnection(session.TargetHostname + ":" + session.TargetPort)
+ cconn, err := vp.createClientConnection(session.TargetHostname+":"+session.TargetPort, session.TargetPassword)
if err != nil {
logger.Errorf("Proxy.newServerConnHandler error creating connection: %s", err)
return err
@@ -142,12 +140,12 @@ func (vp *VncProxy) newServerConnHandler(cfg *server.ServerConfig, sconn *server
func (vp *VncProxy) StartListening() {
//chServer := make(chan common.ClientMessage)
- chClient := make(chan common.ServerMessage)
+ //chClient := make(chan common.ServerMessage)
secHandlers := []server.SecurityHandler{&server.ServerAuthNone{}}
- if vp.proxyPassword != "" {
- secHandlers = []server.SecurityHandler{&server.ServerAuthVNC{vp.proxyPassword}}
+ if vp.ProxyVncPassword != "" {
+ secHandlers = []server.SecurityHandler{&server.ServerAuthVNC{vp.ProxyVncPassword}}
}
cfg := &server.ServerConfig{
SecurityHandlers: secHandlers,
@@ -165,18 +163,19 @@ func (vp *VncProxy) StartListening() {
// },
}
- if vp.tcpListeningUrl != "" {
- go server.TcpServe(vp.tcpListeningUrl, cfg)
+ if vp.TcpListeningUrl != "" && vp.WsListeningUrl != "" {
+ logger.Infof("running two listeners: tcp port: %s, ws url: %s", vp.TcpListeningUrl, vp.WsListeningUrl)
+
+ go server.WsServe(vp.WsListeningUrl, cfg)
+ server.TcpServe(":"+vp.TcpListeningUrl, cfg)
}
- if vp.wsListeningUrl != "" {
- go server.WsServe(vp.wsListeningUrl, cfg)
+
+ if vp.WsListeningUrl != "" {
+ logger.Infof("running ws listener url: %s", vp.WsListeningUrl)
+ server.WsServe(vp.WsListeningUrl, cfg)
}
- // Process messages coming in on the ClientMessage channel.
- for {
- msg := <-chClient
- switch msg.Type() {
- default:
- log.Printf("Received message type:%v msg:%v\n", msg.Type(), msg)
- }
+ if vp.TcpListeningUrl != "" {
+ logger.Infof("running tcp listener on port: %s", vp.TcpListeningUrl)
+ server.TcpServe(":"+vp.TcpListeningUrl, cfg)
}
}
diff --git a/proxy/proxy_test.go b/proxy/proxy_test.go
index 2eb166a..2db96be 100644
--- a/proxy/proxy_test.go
+++ b/proxy/proxy_test.go
@@ -6,15 +6,15 @@ func TestProxy(t *testing.T) {
//create default session if required
proxy := &VncProxy{
- wsListeningUrl: "http://localhost:7777/", // empty = not listening on ws
- recordingDir: "/Users/amitbet/vncRec", // empty = no recording
- tcpListeningUrl: ":5904",
+ WsListeningUrl: "http://localhost:7777/", // empty = not listening on ws
+ RecordingDir: "/Users/amitbet/vncRec", // empty = no recording
+ TcpListeningUrl: ":5904",
//recordingDir: "C:\\vncRec", // empty = no recording
- targetServersPassword: "Ch_#!T@8", //empty = no auth
+ ProxyVncPassword: "1234", //empty = no auth
SingleSession: &VncSession{
TargetHostname: "localhost",
TargetPort: "5903",
- TargetPassword: "vncPass",
+ TargetPassword: "Ch_#!T@8",
ID: "dummySession",
Status: SessionStatusActive,
Type: SessionTypeRecordingProxy,