mirror of
https://github.com/amitbet/vncproxy.git
synced 2025-10-26 14:42:16 +00:00
Compare commits
18 Commits
keyframes_
...
1.11
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
82e1549c4f | ||
|
|
33be77dedc | ||
|
|
11b1d45ce9 | ||
|
|
42873297d2 | ||
|
|
f00e2c33e7 | ||
|
|
9a52a433ea | ||
|
|
06e555775f | ||
|
|
3e882d6140 | ||
|
|
5a488bcd0f | ||
|
|
1596f0daee | ||
|
|
7cecffecf2 | ||
|
|
f57b698430 | ||
|
|
e03c85f7ab | ||
|
|
931b08376b | ||
|
|
2ccc4009f4 | ||
|
|
6e1a343b5f | ||
|
|
446bc0e537 | ||
|
|
a870f3cbb9 |
@@ -3,7 +3,7 @@ An RFB proxy, written in go that can save and replay FBS files
|
||||
* Supports all modern encodings & most useful pseudo-encodings
|
||||
* Supports multiple VNC client connections & multi servers (chosen by sessionId)
|
||||
* Supports being a "websockify" proxy (for web clients like NoVnc)
|
||||
* Produces FBS files compatible with tightvnc player (while using tight's default 3Byte color format)
|
||||
* Produces FBS files compatible with [tightvnc's rfb player](https://www.tightvnc.com/rfbplayer.php) (while using tight's default 3Byte color format)
|
||||
* Can also be used as:
|
||||
* A screen recorder vnc-client
|
||||
* A replay server to show fbs recordings to connecting clients
|
||||
@@ -11,7 +11,7 @@ An RFB proxy, written in go that can save and replay FBS files
|
||||
- Tested on tight encoding with:
|
||||
- Tightvnc (client + java client + server)
|
||||
- FBS player (tightVnc Java player)
|
||||
- NoVnc(web client)
|
||||
- NoVnc(web client) => use -wsPort to open a websocket
|
||||
- ChickenOfTheVnc(client)
|
||||
- VineVnc(server)
|
||||
- TigerVnc(client)
|
||||
@@ -23,9 +23,9 @@ An RFB proxy, written in go that can save and replay FBS files
|
||||
* player - a toy player that will replay a given fbs file to all incoming connections
|
||||
|
||||
## Usage:
|
||||
recorder -recDir=./recording.rbs -targHost=192.168.0.100 -targPort=5903 -targPass=@@@@@
|
||||
recorder -recFile=./recording.rbs -targHost=192.168.0.100 -targPort=5903 -targPass=@@@@@
|
||||
player -fbsFile=./myrec.fbs -tcpPort=5905
|
||||
proxy -recDir=./recordings/ -targHost=192.168.0.100 -targPort=5903 -targPass=@@@@@ -tcpPort=5903 -vncPass=@!@!@!
|
||||
proxy -recDir=./recordings/ -targHost=192.168.0.100 -targPort=5903 -targPass=@@@@@ -tcpPort=5903 -wsPort=5905 -vncPass=@!@!@!
|
||||
|
||||
### Code usage examples
|
||||
* player/main.go (fbs recording vnc client)
|
||||
|
||||
2
build.sh
2
build.sh
@@ -2,7 +2,7 @@
|
||||
sum="sha1sum"
|
||||
|
||||
# VERSION=`date -u +%Y%m%d`
|
||||
VERSION="v1.02"
|
||||
VERSION="v1.11"
|
||||
LDFLAGS="-X main.VERSION=$VERSION -s -w"
|
||||
GCFLAGS=""
|
||||
|
||||
|
||||
@@ -7,8 +7,8 @@ import (
|
||||
"io"
|
||||
"net"
|
||||
"unicode"
|
||||
"vncproxy/common"
|
||||
"vncproxy/logger"
|
||||
"github.com/amitbet/vncproxy/common"
|
||||
"github.com/amitbet/vncproxy/logger"
|
||||
)
|
||||
|
||||
// A ServerMessage implements a message sent from the server to the client.
|
||||
@@ -506,7 +506,7 @@ func (c *ClientConn) mainLoop() {
|
||||
// Unsupported message type! Bad!
|
||||
break
|
||||
}
|
||||
logger.Infof("ClientConn.MainLoop: got ServerMessage:%s", common.ServerMessageType(messageType))
|
||||
logger.Debugf("ClientConn.MainLoop: got ServerMessage:%s", common.ServerMessageType(messageType))
|
||||
reader.SendMessageStart(common.ServerMessageType(messageType))
|
||||
reader.PublishBytes([]byte{byte(messageType)})
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
"io"
|
||||
"vncproxy/common"
|
||||
"github.com/amitbet/vncproxy/common"
|
||||
)
|
||||
|
||||
func readPixelFormat(r io.Reader, result *common.PixelFormat) error {
|
||||
|
||||
@@ -6,9 +6,9 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"strings"
|
||||
"vncproxy/common"
|
||||
"vncproxy/encodings"
|
||||
"vncproxy/logger"
|
||||
"github.com/amitbet/vncproxy/common"
|
||||
"github.com/amitbet/vncproxy/encodings"
|
||||
"github.com/amitbet/vncproxy/logger"
|
||||
)
|
||||
|
||||
// MsgFramebufferUpdate consists of a sequence of rectangles of
|
||||
@@ -63,7 +63,7 @@ func (fbm *MsgFramebufferUpdate) Read(c common.IClientConn, r *common.RfbReadHel
|
||||
// We must always support the raw encoding
|
||||
rawEnc := new(encodings.RawEncoding)
|
||||
encMap[rawEnc.Type()] = rawEnc
|
||||
logger.Infof("MsgFramebufferUpdate.Read: numrects= %d", numRects)
|
||||
logger.Debugf("MsgFramebufferUpdate.Read: numrects= %d", numRects)
|
||||
|
||||
rects := make([]common.Rectangle, numRects)
|
||||
for i := uint16(0); i < numRects; i++ {
|
||||
@@ -90,7 +90,7 @@ func (fbm *MsgFramebufferUpdate) Read(c common.IClientConn, r *common.RfbReadHel
|
||||
|
||||
encType := common.EncodingType(encodingTypeInt)
|
||||
|
||||
logger.Infof("MsgFramebufferUpdate.Read: rect# %d, rect hdr data: enctype=%s, data: %s", i, encType, string(jBytes))
|
||||
logger.Debugf("MsgFramebufferUpdate.Read: rect# %d, rect hdr data: enctype=%s, data: %s", i, encType, string(jBytes))
|
||||
enc, supported := encMap[encodingTypeInt]
|
||||
if supported {
|
||||
var err error
|
||||
|
||||
@@ -2,8 +2,8 @@ package client
|
||||
|
||||
import (
|
||||
"io"
|
||||
"vncproxy/common"
|
||||
"vncproxy/logger"
|
||||
"github.com/amitbet/vncproxy/common"
|
||||
"github.com/amitbet/vncproxy/logger"
|
||||
)
|
||||
|
||||
type WriteTo struct {
|
||||
|
||||
@@ -73,6 +73,8 @@ func (enct EncodingType) String() string {
|
||||
return "EncJPEGQualityLevelPseudo1"
|
||||
case EncCursorPseudo:
|
||||
return "EncCursorPseudo"
|
||||
case EncLedStatePseudo:
|
||||
return "EncLedStatePseudo"
|
||||
case EncDesktopSizePseudo:
|
||||
return "EncDesktopSizePseudo"
|
||||
case EncLastRectPseudo:
|
||||
@@ -183,6 +185,7 @@ const (
|
||||
EncQEMUPointerMotionChangePseudo EncodingType = -257
|
||||
EncQEMUExtendedKeyEventPseudo EncodingType = -258
|
||||
EncTightPng EncodingType = -260
|
||||
EncLedStatePseudo EncodingType = -261
|
||||
EncExtendedDesktopSizePseudo EncodingType = -308
|
||||
EncXvpPseudo EncodingType = -309
|
||||
EncFencePseudo EncodingType = -312
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
"io"
|
||||
"vncproxy/logger"
|
||||
"github.com/amitbet/vncproxy/logger"
|
||||
)
|
||||
|
||||
var TightMinToCompress = 12
|
||||
|
||||
@@ -3,7 +3,7 @@ package encodings
|
||||
import (
|
||||
"encoding/binary"
|
||||
"io"
|
||||
"vncproxy/common"
|
||||
"github.com/amitbet/vncproxy/common"
|
||||
)
|
||||
|
||||
type CopyRectEncoding struct {
|
||||
|
||||
@@ -3,7 +3,7 @@ package encodings
|
||||
import (
|
||||
"encoding/binary"
|
||||
"io"
|
||||
"vncproxy/common"
|
||||
"github.com/amitbet/vncproxy/common"
|
||||
)
|
||||
|
||||
type CoRREEncoding struct {
|
||||
|
||||
@@ -3,7 +3,7 @@ package encodings
|
||||
import (
|
||||
"io"
|
||||
"math"
|
||||
"vncproxy/common"
|
||||
"github.com/amitbet/vncproxy/common"
|
||||
)
|
||||
|
||||
type EncCursorPseudo struct {
|
||||
|
||||
@@ -2,8 +2,8 @@ package encodings
|
||||
|
||||
import (
|
||||
"io"
|
||||
"vncproxy/common"
|
||||
"vncproxy/logger"
|
||||
"github.com/amitbet/vncproxy/common"
|
||||
"github.com/amitbet/vncproxy/logger"
|
||||
)
|
||||
|
||||
const (
|
||||
|
||||
31
encodings/enc-led-state.go
Normal file
31
encodings/enc-led-state.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package encodings
|
||||
|
||||
import (
|
||||
"io"
|
||||
"github.com/amitbet/vncproxy/common"
|
||||
"github.com/amitbet/vncproxy/logger"
|
||||
)
|
||||
|
||||
type EncLedStatePseudo struct {
|
||||
LedState uint8
|
||||
}
|
||||
|
||||
func (pe *EncLedStatePseudo) Type() int32 {
|
||||
return int32(common.EncLedStatePseudo)
|
||||
}
|
||||
func (pe *EncLedStatePseudo) WriteTo(w io.Writer) (n int, err error) {
|
||||
w.Write([]byte{pe.LedState})
|
||||
return 1, nil
|
||||
}
|
||||
func (pe *EncLedStatePseudo) Read(pf *common.PixelFormat, rect *common.Rectangle, r *common.RfbReadHelper) (common.IEncoding, error) {
|
||||
if rect.Width*rect.Height == 0 {
|
||||
return pe, nil
|
||||
}
|
||||
u8, err := r.ReadUint8()
|
||||
pe.LedState = u8
|
||||
if err != nil {
|
||||
logger.Error("error while reading led state: ", err)
|
||||
return pe, err
|
||||
}
|
||||
return pe, nil
|
||||
}
|
||||
@@ -2,7 +2,7 @@ package encodings
|
||||
|
||||
import (
|
||||
"io"
|
||||
"vncproxy/common"
|
||||
"github.com/amitbet/vncproxy/common"
|
||||
)
|
||||
|
||||
type PseudoEncoding struct {
|
||||
|
||||
@@ -3,7 +3,7 @@ package encodings
|
||||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
"vncproxy/common"
|
||||
"github.com/amitbet/vncproxy/common"
|
||||
)
|
||||
|
||||
// RawEncoding is raw pixel data sent by the server.
|
||||
|
||||
@@ -3,7 +3,7 @@ package encodings
|
||||
import (
|
||||
"encoding/binary"
|
||||
"io"
|
||||
"vncproxy/common"
|
||||
"github.com/amitbet/vncproxy/common"
|
||||
)
|
||||
|
||||
type RREEncoding struct {
|
||||
|
||||
@@ -4,8 +4,8 @@ import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"io"
|
||||
"vncproxy/common"
|
||||
"vncproxy/logger"
|
||||
"github.com/amitbet/vncproxy/common"
|
||||
"github.com/amitbet/vncproxy/logger"
|
||||
)
|
||||
|
||||
var TightMinToCompress int = 12
|
||||
@@ -142,7 +142,7 @@ func handleTightFilters(subencoding uint8, pixelFmt *common.PixelFormat, rect *c
|
||||
return
|
||||
}
|
||||
|
||||
paletteSize := colorCount + 1 // add one more
|
||||
paletteSize := int(colorCount) + 1 // add one more
|
||||
logger.Debugf("handleTightFilters: ----PALETTE_FILTER: paletteSize=%d bytesPixel=%d\n", paletteSize, bytesPixel)
|
||||
//complete palette
|
||||
_, err = r.ReadBytes(int(paletteSize) * bytesPixel)
|
||||
|
||||
@@ -3,8 +3,8 @@ package encodings
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"vncproxy/common"
|
||||
"vncproxy/logger"
|
||||
"github.com/amitbet/vncproxy/common"
|
||||
"github.com/amitbet/vncproxy/logger"
|
||||
)
|
||||
|
||||
type TightPngEncoding struct {
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
"io"
|
||||
"vncproxy/common"
|
||||
"github.com/amitbet/vncproxy/common"
|
||||
)
|
||||
|
||||
type ZLibEncoding struct {
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
"io"
|
||||
"vncproxy/common"
|
||||
"github.com/amitbet/vncproxy/common"
|
||||
)
|
||||
|
||||
type ZRLEEncoding struct {
|
||||
|
||||
3
go.mod
Normal file
3
go.mod
Normal file
@@ -0,0 +1,3 @@
|
||||
module github.com/amitbet/vncproxy
|
||||
|
||||
require golang.org/x/net v0.0.0-20181129055619-fae4c4e3ad76
|
||||
2
go.sum
Normal file
2
go.sum
Normal file
@@ -0,0 +1,2 @@
|
||||
golang.org/x/net v0.0.0-20181129055619-fae4c4e3ad76 h1:xx5MUFyRQRbPk6VjWjIE1epE/K5AoDD8QUN116NCy8k=
|
||||
golang.org/x/net v0.0.0-20181129055619-fae4c4e3ad76/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
@@ -2,7 +2,31 @@ package logger
|
||||
|
||||
import "fmt"
|
||||
|
||||
var simpleLogger = SimpleLogger{LogLevelWarn}
|
||||
var simpleLogger = SimpleLogger{LogLevelInfo}
|
||||
|
||||
func SetLogLevel(logLevel string) {
|
||||
level := GetLogLevel(logLevel)
|
||||
fmt.Println("Log level set to: ", logLevel)
|
||||
simpleLogger = SimpleLogger{level}
|
||||
}
|
||||
|
||||
func GetLogLevel(logLevel string) LogLevel {
|
||||
switch logLevel {
|
||||
case "trace":
|
||||
return LogLevelTrace
|
||||
case "debug":
|
||||
return LogLevelDebug
|
||||
case "info":
|
||||
return LogLevelInfo
|
||||
case "warn":
|
||||
return LogLevelWarn
|
||||
case "error":
|
||||
return LogLevelError
|
||||
case "fatal":
|
||||
return LogLevelFatal
|
||||
}
|
||||
return LogLevelInfo
|
||||
}
|
||||
|
||||
type Logger interface {
|
||||
Debug(v ...interface{})
|
||||
@@ -127,6 +151,13 @@ func Debugf(format string, v ...interface{}) {
|
||||
simpleLogger.Debugf(format, v...)
|
||||
}
|
||||
|
||||
func Trace(v ...interface{}) {
|
||||
simpleLogger.Trace(v...)
|
||||
}
|
||||
func Tracef(format string, v ...interface{}) {
|
||||
simpleLogger.Tracef(format, v...)
|
||||
}
|
||||
|
||||
func Info(v ...interface{}) {
|
||||
simpleLogger.Info(v...)
|
||||
}
|
||||
|
||||
@@ -4,19 +4,21 @@ import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
"vncproxy/common"
|
||||
"vncproxy/encodings"
|
||||
"vncproxy/logger"
|
||||
"vncproxy/player"
|
||||
"vncproxy/server"
|
||||
"github.com/amitbet/vncproxy/common"
|
||||
"github.com/amitbet/vncproxy/encodings"
|
||||
"github.com/amitbet/vncproxy/logger"
|
||||
"github.com/amitbet/vncproxy/player"
|
||||
"github.com/amitbet/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")
|
||||
logLevel := flag.String("logLevel", "info", "change logging level")
|
||||
|
||||
flag.Parse()
|
||||
logger.SetLogLevel(*logLevel)
|
||||
|
||||
fmt.Println("**************************************************************************")
|
||||
fmt.Println("*** This is a toy server that replays a single FBS file to all clients ***")
|
||||
|
||||
@@ -5,10 +5,10 @@ import (
|
||||
|
||||
"io"
|
||||
"time"
|
||||
"vncproxy/client"
|
||||
"vncproxy/common"
|
||||
"vncproxy/logger"
|
||||
"vncproxy/server"
|
||||
"github.com/amitbet/vncproxy/client"
|
||||
"github.com/amitbet/vncproxy/common"
|
||||
"github.com/amitbet/vncproxy/logger"
|
||||
"github.com/amitbet/vncproxy/server"
|
||||
)
|
||||
|
||||
type VncStreamFileReader interface {
|
||||
|
||||
@@ -5,9 +5,9 @@ import (
|
||||
"encoding/binary"
|
||||
"io"
|
||||
"os"
|
||||
"vncproxy/common"
|
||||
"vncproxy/encodings"
|
||||
"vncproxy/logger"
|
||||
"github.com/amitbet/vncproxy/common"
|
||||
"github.com/amitbet/vncproxy/encodings"
|
||||
"github.com/amitbet/vncproxy/logger"
|
||||
)
|
||||
|
||||
type FbsReader struct {
|
||||
@@ -58,6 +58,7 @@ func NewFbsReader(fbsFile string) (*FbsReader, error) {
|
||||
&encodings.TightEncoding{},
|
||||
&encodings.TightPngEncoding{},
|
||||
&encodings.EncCursorPseudo{},
|
||||
&encodings.EncLedStatePseudo{},
|
||||
&encodings.RawEncoding{},
|
||||
&encodings.RREEncoding{},
|
||||
},
|
||||
|
||||
@@ -3,10 +3,10 @@ package player
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
"vncproxy/common"
|
||||
"vncproxy/encodings"
|
||||
"vncproxy/logger"
|
||||
"vncproxy/server"
|
||||
"github.com/amitbet/vncproxy/common"
|
||||
"github.com/amitbet/vncproxy/encodings"
|
||||
"github.com/amitbet/vncproxy/logger"
|
||||
"github.com/amitbet/vncproxy/server"
|
||||
)
|
||||
|
||||
func TestServer(t *testing.T) {
|
||||
@@ -18,6 +18,7 @@ func TestServer(t *testing.T) {
|
||||
&encodings.RawEncoding{},
|
||||
&encodings.TightEncoding{},
|
||||
&encodings.EncCursorPseudo{},
|
||||
&encodings.EncLedStatePseudo{},
|
||||
//encodings.TightPngEncoding{},
|
||||
&encodings.RREEncoding{},
|
||||
&encodings.ZLibEncoding{},
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
package main
|
||||
|
||||
import "vncproxy/proxy"
|
||||
import "flag"
|
||||
import "vncproxy/logger"
|
||||
import "os"
|
||||
import (
|
||||
"flag"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/amitbet/vncproxy/logger"
|
||||
vncproxy "github.com/amitbet/vncproxy/proxy"
|
||||
)
|
||||
|
||||
func main() {
|
||||
//create default session if required
|
||||
@@ -11,11 +15,14 @@ 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")
|
||||
|
||||
flag.Parse()
|
||||
logger.SetLogLevel(*logLevel)
|
||||
|
||||
if *tcpPort == "" && *wsPort == "" {
|
||||
logger.Error("no listening port defined")
|
||||
@@ -23,8 +30,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)
|
||||
}
|
||||
@@ -32,30 +39,42 @@ func main() {
|
||||
if *vncPass == "" {
|
||||
logger.Warn("proxy will have no password")
|
||||
}
|
||||
if *recordDir == "" {
|
||||
logger.Warn("FBS recording is turned off")
|
||||
}
|
||||
|
||||
tcpUrl := ""
|
||||
tcpURL := ""
|
||||
if *tcpPort != "" {
|
||||
tcpUrl = ":" + string(*tcpPort)
|
||||
tcpURL = ":" + string(*tcpPort)
|
||||
}
|
||||
|
||||
proxy := &proxy.VncProxy{
|
||||
WsListeningUrl: "http://0.0.0.0:" + string(*wsPort) + "/", // empty = not listening on ws
|
||||
RecordingDir: *recordDir, //"/Users/amitbet/vncRec", // empty = no recording
|
||||
TcpListeningUrl: tcpUrl,
|
||||
wsURL := ""
|
||||
if *wsPort != "" {
|
||||
wsURL = "http://0.0.0.0:" + string(*wsPort) + "/"
|
||||
}
|
||||
proxy := &vncproxy.VncProxy{
|
||||
WsListeningURL: wsURL, // empty = not listening on ws
|
||||
TCPListeningURL: tcpURL,
|
||||
ProxyVncPassword: *vncPass, //empty = no auth
|
||||
SingleSession: &proxy.VncSession{
|
||||
SingleSession: &vncproxy.VncSession{
|
||||
Target: *targetVnc,
|
||||
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 != "" {
|
||||
fullPath, err := filepath.Abs(*recordDir)
|
||||
if err != nil {
|
||||
logger.Error("bad recording path: ", err)
|
||||
}
|
||||
logger.Info("FBS recording is turned on, writing to dir: ", fullPath)
|
||||
proxy.RecordingDir = fullPath
|
||||
proxy.SingleSession.Type = vncproxy.SessionTypeRecordingProxy
|
||||
} else {
|
||||
logger.Info("FBS recording is turned off")
|
||||
}
|
||||
|
||||
proxy.StartListening()
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package proxy
|
||||
|
||||
import (
|
||||
"vncproxy/client"
|
||||
"vncproxy/common"
|
||||
"vncproxy/logger"
|
||||
"vncproxy/server"
|
||||
"github.com/amitbet/vncproxy/client"
|
||||
"github.com/amitbet/vncproxy/common"
|
||||
"github.com/amitbet/vncproxy/logger"
|
||||
"github.com/amitbet/vncproxy/server"
|
||||
)
|
||||
|
||||
type ClientUpdater struct {
|
||||
@@ -13,7 +13,7 @@ type ClientUpdater struct {
|
||||
|
||||
// Consume recieves vnc-server-bound messages (Client messages) and updates the server part of the proxy
|
||||
func (cc *ClientUpdater) Consume(seg *common.RfbSegment) error {
|
||||
//logger.Debugf("ClientUpdater.Consume (vnc-server-bound): got segment type=%s bytes: %v", seg.SegmentType, seg.Bytes)
|
||||
logger.Tracef("ClientUpdater.Consume (vnc-server-bound): got segment type=%s bytes: %v", seg.SegmentType, seg.Bytes)
|
||||
switch seg.SegmentType {
|
||||
|
||||
case common.SegmentFullyParsedClientMessage:
|
||||
|
||||
@@ -5,18 +5,19 @@ import (
|
||||
"path"
|
||||
"strconv"
|
||||
"time"
|
||||
"vncproxy/client"
|
||||
"vncproxy/common"
|
||||
"vncproxy/encodings"
|
||||
"vncproxy/logger"
|
||||
"vncproxy/player"
|
||||
listeners "vncproxy/recorder"
|
||||
"vncproxy/server"
|
||||
|
||||
"github.com/amitbet/vncproxy/client"
|
||||
"github.com/amitbet/vncproxy/common"
|
||||
"github.com/amitbet/vncproxy/encodings"
|
||||
"github.com/amitbet/vncproxy/logger"
|
||||
"github.com/amitbet/vncproxy/player"
|
||||
listeners "github.com/amitbet/vncproxy/recorder"
|
||||
"github.com/amitbet/vncproxy/server"
|
||||
)
|
||||
|
||||
type VncProxy struct {
|
||||
TcpListeningUrl string // empty = not listening on tcp
|
||||
WsListeningUrl string // empty = not listening on ws
|
||||
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
|
||||
@@ -24,8 +25,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 +95,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)
|
||||
@@ -118,6 +133,7 @@ func (vp *VncProxy) newServerConnHandler(cfg *server.ServerConfig, sconn *server
|
||||
&encodings.RawEncoding{},
|
||||
&encodings.TightEncoding{},
|
||||
&encodings.EncCursorPseudo{},
|
||||
&encodings.EncLedStatePseudo{},
|
||||
&encodings.TightPngEncoding{},
|
||||
&encodings.RREEncoding{},
|
||||
&encodings.ZLibEncoding{},
|
||||
@@ -170,19 +186,19 @@ func (vp *VncProxy) StartListening() {
|
||||
UseDummySession: !vp.UsingSessions,
|
||||
}
|
||||
|
||||
if vp.TcpListeningUrl != "" && vp.WsListeningUrl != "" {
|
||||
logger.Infof("running two listeners: tcp port: %s, ws url: %s", vp.TcpListeningUrl, vp.WsListeningUrl)
|
||||
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)
|
||||
go server.WsServe(vp.WsListeningURL, cfg)
|
||||
server.TcpServe(vp.TCPListeningURL, cfg)
|
||||
}
|
||||
|
||||
if vp.WsListeningUrl != "" {
|
||||
logger.Infof("running ws listener url: %s", vp.WsListeningUrl)
|
||||
server.WsServe(vp.WsListeningUrl, cfg)
|
||||
if vp.WsListeningURL != "" {
|
||||
logger.Infof("running ws listener url: %s", vp.WsListeningURL)
|
||||
server.WsServe(vp.WsListeningURL, cfg)
|
||||
}
|
||||
if vp.TcpListeningUrl != "" {
|
||||
logger.Infof("running tcp listener on port: %s", vp.TcpListeningUrl)
|
||||
server.TcpServe(":"+vp.TcpListeningUrl, cfg)
|
||||
if vp.TCPListeningURL != "" {
|
||||
logger.Infof("running tcp listener on port: %s", vp.TCPListeningURL)
|
||||
server.TcpServe(vp.TCPListeningURL, cfg)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ const (
|
||||
)
|
||||
|
||||
type VncSession struct {
|
||||
Target string
|
||||
TargetHostname string
|
||||
TargetPort string
|
||||
TargetPassword string
|
||||
|
||||
@@ -5,23 +5,25 @@ import (
|
||||
"net"
|
||||
"os"
|
||||
"time"
|
||||
"vncproxy/client"
|
||||
"vncproxy/common"
|
||||
"vncproxy/encodings"
|
||||
"vncproxy/logger"
|
||||
"vncproxy/recorder"
|
||||
"github.com/amitbet/vncproxy/client"
|
||||
"github.com/amitbet/vncproxy/common"
|
||||
"github.com/amitbet/vncproxy/encodings"
|
||||
"github.com/amitbet/vncproxy/logger"
|
||||
"github.com/amitbet/vncproxy/recorder"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// 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 EMPTY.")
|
||||
var recordDir = flag.String("recFile", "", "FBS file to create, recordings WILL NOT RECORD IF EMPTY.")
|
||||
var targetVncPort = flag.String("targPort", "", "target vnc server port")
|
||||
var targetVncPass = flag.String("targPass", "", "target vnc password")
|
||||
var targetVncHost = flag.String("targHost", "localhost", "target vnc hostname")
|
||||
var logLevel = flag.String("logLevel", "info", "change logging level")
|
||||
|
||||
flag.Parse()
|
||||
logger.SetLogLevel(*logLevel)
|
||||
|
||||
if *targetVncHost == "" {
|
||||
logger.Error("no target vnc server host defined")
|
||||
@@ -40,6 +42,8 @@ func main() {
|
||||
}
|
||||
if *recordDir == "" {
|
||||
logger.Warn("FBS recording is turned off")
|
||||
} else {
|
||||
logger.Infof("Recording rfb stream into file: '%s'", *recordDir)
|
||||
}
|
||||
|
||||
//nc, err := net.Dial("tcp", "192.168.1.101:5903")
|
||||
|
||||
@@ -5,9 +5,9 @@ import (
|
||||
"encoding/binary"
|
||||
"os"
|
||||
"time"
|
||||
"vncproxy/common"
|
||||
"vncproxy/logger"
|
||||
"vncproxy/server"
|
||||
"github.com/amitbet/vncproxy/common"
|
||||
"github.com/amitbet/vncproxy/logger"
|
||||
"github.com/amitbet/vncproxy/server"
|
||||
)
|
||||
|
||||
type Recorder struct {
|
||||
|
||||
@@ -2,9 +2,9 @@ package recorder
|
||||
|
||||
import (
|
||||
"time"
|
||||
"vncproxy/client"
|
||||
"vncproxy/common"
|
||||
"vncproxy/logger"
|
||||
"github.com/amitbet/vncproxy/client"
|
||||
"github.com/amitbet/vncproxy/common"
|
||||
"github.com/amitbet/vncproxy/logger"
|
||||
)
|
||||
|
||||
type RfbRequester struct {
|
||||
|
||||
@@ -3,7 +3,7 @@ package server
|
||||
import (
|
||||
"encoding/binary"
|
||||
"io"
|
||||
"vncproxy/common"
|
||||
"github.com/amitbet/vncproxy/common"
|
||||
)
|
||||
|
||||
// Key represents a VNC key press.
|
||||
@@ -310,3 +310,34 @@ func (msg *MsgClientCutText) Write(c io.Writer) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// MsgClientQemuExtendedKey holds the wire format message, for qemu keys
|
||||
type MsgClientQemuExtendedKey struct {
|
||||
SubType uint8 // sub type
|
||||
IsDown uint16 // button down indicator
|
||||
KeySym uint32 // key symbol
|
||||
KeyCode uint32 // key code
|
||||
}
|
||||
|
||||
func (*MsgClientQemuExtendedKey) Type() common.ClientMessageType {
|
||||
return common.QEMUExtendedKeyEventMsgType
|
||||
}
|
||||
|
||||
func (*MsgClientQemuExtendedKey) Read(c io.Reader) (common.ClientMessage, error) {
|
||||
msg := MsgClientQemuExtendedKey{}
|
||||
|
||||
if err := binary.Read(c, binary.BigEndian, &msg); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &msg, nil
|
||||
}
|
||||
|
||||
func (msg *MsgClientQemuExtendedKey) Write(c io.Writer) error {
|
||||
if err := binary.Write(c, binary.BigEndian, msg.Type()); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := binary.Write(c, binary.BigEndian, msg); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -3,10 +3,10 @@ package server
|
||||
import (
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"vncproxy/common"
|
||||
"github.com/amitbet/vncproxy/common"
|
||||
|
||||
"io"
|
||||
"vncproxy/logger"
|
||||
"github.com/amitbet/vncproxy/logger"
|
||||
)
|
||||
|
||||
const ProtoVersionLength = 12
|
||||
@@ -95,7 +95,7 @@ func ServerSecurityHandler(cfg *ServerConfig, c *ServerConn) error {
|
||||
|
||||
sType, ok := secTypes[secType]
|
||||
if !ok {
|
||||
return fmt.Errorf("server type %d not implemented")
|
||||
return fmt.Errorf("server type %d not implemented", secType)
|
||||
}
|
||||
|
||||
var authCode uint32
|
||||
@@ -135,7 +135,7 @@ func ServerServerInitHandler(cfg *ServerConfig, c *ServerConn) error {
|
||||
NameLength: uint32(len(cfg.DesktopName)),
|
||||
NameText: []byte(cfg.DesktopName),
|
||||
}
|
||||
logger.Infof("Server.ServerServerInitHandler initMessage: %v", srvInit)
|
||||
logger.Debugf("Server.ServerServerInitHandler initMessage: %v", srvInit)
|
||||
if err := binary.Write(c, binary.BigEndian, srvInit.FBWidth); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"crypto/rand"
|
||||
"errors"
|
||||
"log"
|
||||
"vncproxy/common"
|
||||
"github.com/amitbet/vncproxy/common"
|
||||
)
|
||||
|
||||
type SecurityType uint8
|
||||
|
||||
@@ -5,8 +5,8 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"sync"
|
||||
"vncproxy/common"
|
||||
"vncproxy/logger"
|
||||
"github.com/amitbet/vncproxy/common"
|
||||
"github.com/amitbet/vncproxy/logger"
|
||||
)
|
||||
|
||||
type ServerConn struct {
|
||||
@@ -168,16 +168,17 @@ func (c *ServerConn) handle() error {
|
||||
default:
|
||||
var messageType common.ClientMessageType
|
||||
if err := binary.Read(c, binary.BigEndian, &messageType); err != nil {
|
||||
logger.Errorf("IServerConn.handle error: %v", err)
|
||||
logger.Errorf("ServerConn.handle error: %v", err)
|
||||
return err
|
||||
}
|
||||
logger.Debugf("ServerConn.handle: got messagetype, %d", messageType)
|
||||
msg, ok := clientMessages[messageType]
|
||||
logger.Debugf("ServerConn.handle: found message type, %v", ok)
|
||||
if !ok {
|
||||
return fmt.Errorf("IServerConn.Handle: unsupported message-type: %v", messageType)
|
||||
logger.Errorf("ServerConn.handle: unsupported message-type: %v", messageType)
|
||||
}
|
||||
|
||||
parsedMsg, err := msg.Read(c)
|
||||
|
||||
logger.Debugf("ServerConn.handle: got parsed messagetype, %v", parsedMsg)
|
||||
//update connection for pixel format / color map changes
|
||||
switch parsedMsg.Type() {
|
||||
case common.SetPixelFormatMsgType:
|
||||
@@ -196,7 +197,7 @@ func (c *ServerConn) handle() error {
|
||||
return err
|
||||
}
|
||||
|
||||
logger.Infof("IServerConn.Handle got ClientMessage: %s, %v", parsedMsg.Type(), parsedMsg)
|
||||
logger.Debugf("IServerConn.Handle got ClientMessage: %s, %v", parsedMsg.Type(), parsedMsg)
|
||||
//TODO: treat set encodings by allowing only supported encoding in proxy configurations
|
||||
//// if parsedMsg.Type() == common.SetEncodingsMsgType{
|
||||
//// c.cfg.Encodings
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"io"
|
||||
"log"
|
||||
"net"
|
||||
"vncproxy/common"
|
||||
"github.com/amitbet/vncproxy/common"
|
||||
)
|
||||
|
||||
var DefaultClientMessages = []common.ClientMessage{
|
||||
@@ -15,6 +15,7 @@ var DefaultClientMessages = []common.ClientMessage{
|
||||
&MsgKeyEvent{},
|
||||
&MsgPointerEvent{},
|
||||
&MsgClientCutText{},
|
||||
&MsgClientQemuExtendedKey{},
|
||||
}
|
||||
|
||||
// FramebufferUpdate holds a FramebufferUpdate wire format message.
|
||||
|
||||
@@ -3,8 +3,8 @@ package server
|
||||
import (
|
||||
"log"
|
||||
"testing"
|
||||
"vncproxy/common"
|
||||
"vncproxy/encodings"
|
||||
"github.com/amitbet/vncproxy/common"
|
||||
"github.com/amitbet/vncproxy/encodings"
|
||||
)
|
||||
|
||||
func newServerConnHandler(cfg *ServerConfig, conn *ServerConn) error {
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"vncproxy/logger"
|
||||
"github.com/amitbet/vncproxy/logger"
|
||||
|
||||
"golang.org/x/net/websocket"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user