2017-06-12 14:11:23 +03:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"log"
|
|
|
|
"net"
|
2017-06-18 21:01:01 +03:00
|
|
|
"net/http"
|
|
|
|
_ "net/http/pprof"
|
2017-06-12 14:11:23 +03:00
|
|
|
|
2017-06-13 01:52:07 +03:00
|
|
|
vnc "github.com/vtolstov/go-vnc"
|
2017-06-12 14:11:23 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2017-06-18 21:01:01 +03:00
|
|
|
go func() {
|
|
|
|
log.Println(http.ListenAndServe(":6060", nil))
|
|
|
|
}()
|
|
|
|
|
2017-06-13 01:52:07 +03:00
|
|
|
ln, err := net.Listen("tcp", ":5900")
|
2017-06-12 14:11:23 +03:00
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("Error listen. %v", err)
|
|
|
|
}
|
|
|
|
|
2017-06-13 16:20:35 +03:00
|
|
|
schClient := make(chan vnc.ClientMessage)
|
|
|
|
schServer := make(chan vnc.ServerMessage)
|
2017-06-12 14:11:23 +03:00
|
|
|
|
2017-06-13 01:52:07 +03:00
|
|
|
scfg := &vnc.ServerConfig{
|
2017-06-18 19:42:41 +03:00
|
|
|
Width: 800,
|
|
|
|
Height: 600,
|
|
|
|
VersionHandler: vnc.ServerVersionHandler,
|
|
|
|
SecurityHandler: vnc.ServerSecurityHandler,
|
|
|
|
SecurityHandlers: []vnc.SecurityHandler{
|
|
|
|
&vnc.ClientAuthVeNCrypt02Plain{Username: []byte("test"), Password: []byte("test")},
|
|
|
|
&vnc.ClientAuthNone{},
|
|
|
|
},
|
2017-06-13 01:52:07 +03:00
|
|
|
ClientInitHandler: vnc.ServerClientInitHandler,
|
|
|
|
ServerInitHandler: vnc.ServerServerInitHandler,
|
2017-06-18 19:42:41 +03:00
|
|
|
Encodings: []vnc.Encoding{
|
|
|
|
&vnc.TightPngEncoding{},
|
|
|
|
&vnc.CopyRectEncoding{},
|
|
|
|
&vnc.RawEncoding{},
|
|
|
|
},
|
|
|
|
PixelFormat: vnc.PixelFormat32bit,
|
|
|
|
ClientMessageCh: schClient,
|
|
|
|
ServerMessageCh: schServer,
|
|
|
|
ClientMessages: vnc.DefaultClientMessages,
|
|
|
|
DesktopName: []byte("vnc proxy"),
|
2017-06-13 01:52:07 +03:00
|
|
|
}
|
2017-06-13 16:20:35 +03:00
|
|
|
c, err := net.Dial("tcp", "127.0.0.1:5995")
|
2017-06-12 14:11:23 +03:00
|
|
|
if err != nil {
|
2017-06-13 01:52:07 +03:00
|
|
|
log.Fatalf("Error dial. %v", err)
|
2017-06-12 14:11:23 +03:00
|
|
|
}
|
2017-06-13 01:52:07 +03:00
|
|
|
cchServer := make(chan vnc.ServerMessage)
|
|
|
|
cchClient := make(chan vnc.ClientMessage)
|
2017-06-12 14:11:23 +03:00
|
|
|
|
2017-06-13 01:52:07 +03:00
|
|
|
ccfg := &vnc.ClientConfig{
|
|
|
|
VersionHandler: vnc.ClientVersionHandler,
|
|
|
|
SecurityHandler: vnc.ClientSecurityHandler,
|
|
|
|
SecurityHandlers: []vnc.SecurityHandler{&vnc.ClientAuthNone{}},
|
|
|
|
ClientInitHandler: vnc.ClientClientInitHandler,
|
|
|
|
ServerInitHandler: vnc.ClientServerInitHandler,
|
2017-06-13 16:20:35 +03:00
|
|
|
PixelFormat: vnc.PixelFormat32bit,
|
2017-06-13 01:52:07 +03:00
|
|
|
ClientMessageCh: cchClient,
|
|
|
|
ServerMessageCh: cchServer,
|
|
|
|
ServerMessages: vnc.DefaultServerMessages,
|
|
|
|
Encodings: []vnc.Encoding{&vnc.RawEncoding{}},
|
|
|
|
}
|
2017-06-12 14:11:23 +03:00
|
|
|
|
2017-06-13 01:52:07 +03:00
|
|
|
cc, err := vnc.Connect(context.Background(), c, ccfg)
|
2017-06-12 14:11:23 +03:00
|
|
|
if err != nil {
|
2017-06-13 01:52:07 +03:00
|
|
|
log.Fatalf("Error dial. %v", err)
|
2017-06-12 14:11:23 +03:00
|
|
|
}
|
2017-06-13 16:20:35 +03:00
|
|
|
|
|
|
|
go vnc.Serve(context.Background(), ln, scfg)
|
|
|
|
|
2017-06-13 01:52:07 +03:00
|
|
|
defer cc.Close()
|
|
|
|
go cc.Handle()
|
2017-06-12 14:11:23 +03:00
|
|
|
|
|
|
|
for {
|
2017-06-13 01:52:07 +03:00
|
|
|
select {
|
|
|
|
case msg := <-cchServer:
|
2017-06-20 00:56:17 +03:00
|
|
|
schServer <- msg
|
2017-06-13 01:52:07 +03:00
|
|
|
case msg := <-schClient:
|
|
|
|
switch msg.Type() {
|
|
|
|
case vnc.SetEncodingsMsgType:
|
2017-06-18 19:42:41 +03:00
|
|
|
var encTypes []vnc.EncodingType
|
2017-06-20 00:56:17 +03:00
|
|
|
for _, senc := range scfg.Encodings {
|
|
|
|
for _, cenc := range msg.(*vnc.SetEncodings).Encodings {
|
|
|
|
if cenc == senc.Type() {
|
|
|
|
encTypes = append(encTypes, senc.Type())
|
2017-06-18 19:42:41 +03:00
|
|
|
}
|
2017-06-13 16:20:35 +03:00
|
|
|
}
|
2017-06-20 00:56:17 +03:00
|
|
|
}
|
|
|
|
cchClient <- &vnc.SetEncodings{Encodings: encTypes}
|
2017-06-13 01:52:07 +03:00
|
|
|
default:
|
2017-06-13 16:20:35 +03:00
|
|
|
cchClient <- msg
|
2017-06-13 01:52:07 +03:00
|
|
|
}
|
2017-06-12 14:11:23 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|