mirror of
https://github.com/amitbet/vncproxy.git
synced 2025-06-21 03:52:39 +00:00
commit
42873297d2
@ -1,9 +1,12 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import "vncproxy/proxy"
|
import (
|
||||||
import "flag"
|
"flag"
|
||||||
import "vncproxy/logger"
|
"os"
|
||||||
import "os"
|
|
||||||
|
"vncproxy/logger"
|
||||||
|
vncproxy "vncproxy/proxy"
|
||||||
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
//create default session if required
|
//create default session if required
|
||||||
@ -11,8 +14,9 @@ func main() {
|
|||||||
var wsPort = flag.String("wsPort", "", "websocket 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 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 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 targetVnc = flag.String("target", "", "target vnc server (host:port or /path/to/unix.socket)")
|
||||||
var targetVncHost = flag.String("targHost", "", "target vnc server host")
|
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 targetVncPass = flag.String("targPass", "", "target vnc password")
|
||||||
var logLevel = flag.String("logLevel", "info", "change logging level")
|
var logLevel = flag.String("logLevel", "info", "change logging level")
|
||||||
|
|
||||||
@ -25,8 +29,8 @@ func main() {
|
|||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
if *targetVncPort == "" {
|
if *targetVnc == "" && *targetVncPort == "" {
|
||||||
logger.Error("no target vnc server port defined")
|
logger.Error("no target vnc server host/port or socket defined")
|
||||||
flag.Usage()
|
flag.Usage()
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
@ -34,30 +38,33 @@ func main() {
|
|||||||
if *vncPass == "" {
|
if *vncPass == "" {
|
||||||
logger.Warn("proxy will have no password")
|
logger.Warn("proxy will have no password")
|
||||||
}
|
}
|
||||||
if *recordDir == "" {
|
|
||||||
logger.Warn("FBS recording is turned off")
|
|
||||||
}
|
|
||||||
|
|
||||||
tcpUrl := ""
|
tcpUrl := ""
|
||||||
if *tcpPort != "" {
|
if *tcpPort != "" {
|
||||||
tcpUrl = ":" + string(*tcpPort)
|
tcpUrl = ":" + string(*tcpPort)
|
||||||
}
|
}
|
||||||
|
|
||||||
proxy := &proxy.VncProxy{
|
proxy := &vncproxy.VncProxy{
|
||||||
WsListeningUrl: "http://0.0.0.0:" + string(*wsPort) + "/", // empty = not listening on ws
|
WsListeningUrl: "http://0.0.0.0:" + string(*wsPort) + "/", // empty = not listening on ws
|
||||||
RecordingDir: *recordDir, //"/Users/amitbet/vncRec", // empty = no recording
|
|
||||||
TcpListeningUrl: tcpUrl,
|
TcpListeningUrl: tcpUrl,
|
||||||
ProxyVncPassword: *vncPass, //empty = no auth
|
ProxyVncPassword: *vncPass, //empty = no auth
|
||||||
SingleSession: &proxy.VncSession{
|
SingleSession: &vncproxy.VncSession{
|
||||||
|
Target: *targetVnc,
|
||||||
TargetHostname: *targetVncHost,
|
TargetHostname: *targetVncHost,
|
||||||
TargetPort: *targetVncPort,
|
TargetPort: *targetVncPort,
|
||||||
TargetPassword: *targetVncPass, //"vncPass",
|
TargetPassword: *targetVncPass, //"vncPass",
|
||||||
ID: "dummySession",
|
ID: "dummySession",
|
||||||
Status: proxy.SessionStatusInit,
|
Status: vncproxy.SessionStatusInit,
|
||||||
Type: proxy.SessionTypeRecordingProxy,
|
Type: vncproxy.SessionTypeProxyPass,
|
||||||
}, // to be used when not using sessions
|
}, // to be used when not using sessions
|
||||||
UsingSessions: false, //false = single session - defined in the var above
|
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()
|
proxy.StartListening()
|
||||||
}
|
}
|
||||||
|
@ -24,8 +24,17 @@ type VncProxy struct {
|
|||||||
sessionManager *SessionManager
|
sessionManager *SessionManager
|
||||||
}
|
}
|
||||||
|
|
||||||
func (vp *VncProxy) createClientConnection(targetServerUrl string, vncPass string) (*client.ClientConn, error) {
|
func (vp *VncProxy) createClientConnection(target string, vncPass string) (*client.ClientConn, error) {
|
||||||
nc, err := net.Dial("tcp", targetServerUrl)
|
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 {
|
if err != nil {
|
||||||
logger.Errorf("error connecting to vnc server: %s", err)
|
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
|
session.Status = SessionStatusInit
|
||||||
if session.Type == SessionTypeProxyPass || session.Type == SessionTypeRecordingProxy {
|
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 {
|
if err != nil {
|
||||||
session.Status = SessionStatusError
|
session.Status = SessionStatusError
|
||||||
logger.Errorf("Proxy.newServerConnHandler error creating connection: %s", err)
|
logger.Errorf("Proxy.newServerConnHandler error creating connection: %s", err)
|
||||||
|
@ -16,6 +16,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type VncSession struct {
|
type VncSession struct {
|
||||||
|
Target string
|
||||||
TargetHostname string
|
TargetHostname string
|
||||||
TargetPort string
|
TargetPort string
|
||||||
TargetPassword string
|
TargetPassword string
|
||||||
|
Loading…
Reference in New Issue
Block a user