added cmdline binaries for proxy and player

This commit is contained in:
amit bezalel
2017-07-28 17:48:22 +03:00
parent 28c664f5cd
commit eed10643b3
8 changed files with 463 additions and 295 deletions

57
proxy/cmd/main.go Normal file
View File

@@ -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()
}

View File

@@ -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)
}
}

View File

@@ -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,