diff --git a/code/client/pool/send_vnc.go b/code/client/pool/send_vnc.go index 8c676f2..0083f27 100644 --- a/code/client/pool/send_vnc.go +++ b/code/client/pool/send_vnc.go @@ -122,3 +122,16 @@ func (conn *Conn) SendVNCKeyboard(to string, toIdx uint32, id string, case <-time.After(conn.parent.cfg.WriteTimeout): } } + +// SendVNC send vnc keyboard event +func (conn *Conn) SendVNCCADEvent(to string, toIdx uint32, id string) { + var msg network.Msg + msg.To = to + msg.ToIdx = toIdx + msg.XType = network.Msg_vnc_cad + msg.LinkId = id + select { + case conn.write <- &msg: + case <-time.After(conn.parent.cfg.WriteTimeout): + } +} diff --git a/code/client/tunnel/vnc/define/sas_windows.go b/code/client/tunnel/vnc/define/sas_windows.go new file mode 100644 index 0000000..beb5a5f --- /dev/null +++ b/code/client/tunnel/vnc/define/sas_windows.go @@ -0,0 +1,8 @@ +package define + +import "syscall" + +var ( + libSas, _ = syscall.LoadLibrary("Sas.dll") + FuncSendSAS, _ = syscall.GetProcAddress(syscall.Handle(libSas), "SendSAS") +) diff --git a/code/client/tunnel/vnc/events.go b/code/client/tunnel/vnc/events.go index f9cf029..d1898db 100644 --- a/code/client/tunnel/vnc/events.go +++ b/code/client/tunnel/vnc/events.go @@ -40,3 +40,7 @@ func (v *VNC) keyboardEvent(remote *pool.Conn, data []byte) { remote.SendVNCKeyboard(v.link.target, v.link.targetIdx, v.link.id, payload.Payload.Status, payload.Payload.Key) } + +func (v *VNC) cadEvent(remote *pool.Conn) { + remote.SendVNCCADEvent(v.link.target, v.link.targetIdx, v.link.id) +} diff --git a/code/client/tunnel/vnc/h_ws.go b/code/client/tunnel/vnc/h_ws.go index 0476b13..05bf76f 100644 --- a/code/client/tunnel/vnc/h_ws.go +++ b/code/client/tunnel/vnc/h_ws.go @@ -103,6 +103,7 @@ func (v *VNC) localRead(ctx context.Context, local *websocket.Conn, remote *pool case "keyboard": v.keyboardEvent(remote, data) case "cad": + v.cadEvent(remote) } } } diff --git a/code/client/tunnel/vnc/link.go b/code/client/tunnel/vnc/link.go index 80cf937..11af5c5 100644 --- a/code/client/tunnel/vnc/link.go +++ b/code/client/tunnel/vnc/link.go @@ -101,6 +101,8 @@ func (link *Link) remoteRead() { link.ps.MouseEvent(msg.GetVmouse()) case network.Msg_vnc_keyboard: link.ps.KeyboardEvent(msg.GetVkbd()) + case network.Msg_vnc_cad: + link.ps.CADEvent() case network.Msg_disconnect: logging.Info("link %s disconnected", link.id) return diff --git a/code/client/tunnel/vnc/process/event_windows.go b/code/client/tunnel/vnc/process/event_windows.go new file mode 100644 index 0000000..960bd45 --- /dev/null +++ b/code/client/tunnel/vnc/process/event_windows.go @@ -0,0 +1,15 @@ +package process + +import ( + "natpass/code/client/tunnel/vnc/define" + "syscall" + + "github.com/lwch/logging" +) + +func (p *Process) CADEvent() { + ok, _, err := syscall.Syscall(define.FuncSendSAS, 1, 0, 0, 0) + if ok == 0 { + logging.Error("send sas failed: %v", err) + } +} diff --git a/html/vnc/index.js b/html/vnc/index.js index f957783..696efed 100644 --- a/html/vnc/index.js +++ b/html/vnc/index.js @@ -64,7 +64,10 @@ var page = { }); }, cad: function() { - // TODO + if (!page.ws) { + return; + } + page.ws.send(JSON.stringify({action: 'cad'})); }, mousemove: function(e) { if (!page.ws) {