-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrdpproxy.go
74 lines (61 loc) · 1.68 KB
/
rdpproxy.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package main
import (
"encoding/json"
"net/http"
"github.com/GoFeGroup/gordp"
"github.com/GoFeGroup/gordp/core"
"github.com/GoFeGroup/gordp/glog"
"github.com/GoFeGroup/gordp/proto/bitmap"
"github.com/gin-gonic/gin"
"github.com/gorilla/websocket"
)
var upgrade = websocket.Upgrader{CheckOrigin: func(r *http.Request) bool { return true }}
type Processor struct {
ws *websocket.Conn
}
func (p *Processor) ProcessBitmap(option *bitmap.Option, bitmap *bitmap.BitMap) {
message := &Message{Bitmap: &Bitmap{
X: option.Left,
Y: option.Top,
W: option.Width,
H: option.Height,
Data: bitmap.ToPng(),
}}
core.ThrowError(p.ws.WriteJSON(message))
}
func rdpProxy(ctx *gin.Context) {
proto := ctx.Request.Header.Get("Sec-Websocket-Protocol")
ws, err := upgrade.Upgrade(ctx.Writer, ctx.Request, http.Header{
"Sec-Websocket-Protocol": {proto},
})
core.ThrowError(err)
client := gordp.NewClient(&gordp.Option{
Addr: "192.168.1.129:3389",
UserName: "anhk",
Password: "[your-password-here]",
})
core.ThrowError(client.Connect())
go func() {
core.ThrowError(client.Run(&Processor{ws: ws}))
}()
for {
_, msgBytes, err := ws.ReadMessage()
core.ThrowError(err)
msg := Message{}
core.ThrowError(json.Unmarshal(msgBytes, &msg))
glog.Debugf("msg: %+v", msg.Mouse)
if msg.Keyboard != nil {
}
if msg.Mouse != nil {
switch msg.Mouse.Type {
case "mousemove":
client.SendMouseMoveEvent(uint16(msg.Mouse.X), uint16(msg.Mouse.Y))
case "mousedown":
client.SendMouseLeftDownEvent(uint16(msg.Mouse.X), uint16(msg.Mouse.Y))
case "mouseup":
client.SendMouseLeftUpEvent(uint16(msg.Mouse.X), uint16(msg.Mouse.Y))
case "mouseright":
}
}
}
}