Skip to content

Commit

Permalink
Merge pull request lwch#15 from lwch/dev
Browse files Browse the repository at this point in the history
v0.7.2
  • Loading branch information
lwch authored Dec 8, 2021
2 parents 9def197 + 2903992 commit fa557dc
Show file tree
Hide file tree
Showing 27 changed files with 272 additions and 538 deletions.
11 changes: 10 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,13 @@

# v0.7.1

1. vnc页面支持远程设置或读取剪贴板(仅支持文本内容)
1. vnc页面支持远程设置或读取剪贴板(仅支持文本内容)

# v0.7.2

1. 截屏库统一抽取到https://github.com/lwch/rdesktop
2. 修正windows下的错误日志显示格式问题
3. 修正windows下的配置文件include问题
4. 支持linux远程桌面

**注:linux受控端需使用np-cli.vnc程序进行启动,且目前无法以systemd等方式运行**
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,18 @@ windows11远程桌面

![win11-vnc](docs/imgs/vnc_win11.png)

ubuntu远程桌面

![ubuntu-vnc](docs/imgs/vnc_ubuntu.png)

fedora远程桌面

![fedora-vnc](docs/imgs/vnc_fedora.png)

deepin远程桌面

![deepin-vnc](docs/imgs/vnc_deepin.png)

windows读取剪贴板内容

![vnc-clipboard](docs/imgs/vnc_clipboard.png)
Expand Down
2 changes: 1 addition & 1 deletion build
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh

VERSION=0.7.1
VERSION=0.7.2

DOCKER_BUILDKIT=1 docker build -t natpass -f contrib/build/Dockerfile .
docker run --rm \
Expand Down
2 changes: 1 addition & 1 deletion build_all
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh

VERSION=0.7.1
VERSION=0.7.2

DOCKER_BUILDKIT=1 docker build -t natpass -f contrib/build/Dockerfile .
docker run --rm \
Expand Down
44 changes: 0 additions & 44 deletions code/client/rule/vnc/define/gdi32_windows.go

This file was deleted.

17 changes: 0 additions & 17 deletions code/client/rule/vnc/define/kernel32_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,7 @@ var (
libKernel32, _ = syscall.LoadLibrary("kernel32.dll")
// FuncWTSGetActiveConsoleSessionID https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-wtsgetactiveconsolesessionid
FuncWTSGetActiveConsoleSessionID, _ = syscall.GetProcAddress(syscall.Handle(libKernel32), "WTSGetActiveConsoleSessionId")
// FuncGlobalAlloc https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-globalalloc
FuncGlobalAlloc, _ = syscall.GetProcAddress(syscall.Handle(libKernel32), "GlobalAlloc")
// FuncGlobalFree https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-globalfree
FuncGlobalFree, _ = syscall.GetProcAddress(syscall.Handle(libKernel32), "GlobalFree")
)

// PROCESSALLACCESS https://docs.microsoft.com/en-us/windows/win32/procthread/process-security-and-access-rights
const PROCESSALLACCESS = 0x1F0FFF

const (
// GHND https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-globalalloc
GHND = 0x0042
// GMEMFIXED https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-globalalloc
GMEMFIXED = 0x0000
// GMEMMOVEABLE https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-globalalloc
GMEMMOVEABLE = 0x0002
// GMEMZEROINIT https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-globalalloc
GMEMZEROINIT = 0x0040
// GPTR https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-globalalloc
GPTR = 0x0040
)
59 changes: 2 additions & 57 deletions code/client/rule/vnc/define/user32_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,67 +4,12 @@ import "syscall"

var (
libUser32, _ = syscall.LoadLibrary("user32.dll")
// FuncGetThreadDesktop https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getthreaddesktop
FuncGetThreadDesktop, _ = syscall.GetProcAddress(syscall.Handle(libUser32), "GetThreadDesktop")
// FuncOpenInputDesktop https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-openinputdesktop
FuncOpenInputDesktop, _ = syscall.GetProcAddress(syscall.Handle(libUser32), "OpenInputDesktop")
// FuncSetThreadDesktop https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setthreaddesktop
FuncSetThreadDesktop, _ = syscall.GetProcAddress(syscall.Handle(libUser32), "SetThreadDesktop")
// FuncGetThreadDesktop https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getthreaddesktop
FuncGetThreadDesktop, _ = syscall.GetProcAddress(syscall.Handle(libUser32), "GetThreadDesktop")
// FuncCloseDesktop https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-closedesktop
FuncCloseDesktop, _ = syscall.GetProcAddress(syscall.Handle(libUser32), "CloseDesktop")
// FuncGetDesktopWindow https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getdesktopwindow
FuncGetDesktopWindow, _ = syscall.GetProcAddress(syscall.Handle(libUser32), "GetDesktopWindow")
// FuncGetDC https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getdc
FuncGetDC, _ = syscall.GetProcAddress(syscall.Handle(libUser32), "GetDC")
// FuncReleaseDC https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-releasedc
FuncReleaseDC, _ = syscall.GetProcAddress(syscall.Handle(libUser32), "ReleaseDC")
// FuncGetCursorInfo https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getcursorinfo
FuncGetCursorInfo, _ = syscall.GetProcAddress(syscall.Handle(libUser32), "GetCursorInfo")
// FuncGetIconInfo https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-geticoninfo
FuncGetIconInfo, _ = syscall.GetProcAddress(syscall.Handle(libUser32), "GetIconInfo")
// FuncDrawIcon https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-drawicon
FuncDrawIcon, _ = syscall.GetProcAddress(syscall.Handle(libUser32), "DrawIcon")
)

type (
// HANDLE handle object
HANDLE uintptr
// BOOL bool
BOOL int32
// DWORD double word
DWORD uint32
// LONG long
LONG int32
// HCURSOR cursor handle
HCURSOR HANDLE
// HBITMAP bitmap handle
HBITMAP HANDLE
)

// POINT pointer
type POINT struct {
X LONG
Y LONG
}

// CURSORINFO cursor info
type CURSORINFO struct {
CbSize DWORD
Flags DWORD
HCursor HCURSOR
PTScreenPos POINT
}

// ICONINFO icon info
type ICONINFO struct {
FIcon BOOL
XHotspot DWORD
YHotspot DWORD
HbmMask HBITMAP
HbmColor HBITMAP
}

const (
// CURSORSHOWING https://docs.microsoft.com/en-us/windows/win32/api/winuser/ns-winuser-cursorinfo
CURSORSHOWING = 0x00000001
)
61 changes: 61 additions & 0 deletions code/client/rule/vnc/process/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@ package process
import (
"errors"
"fmt"
"image"
"image/jpeg"
"natpass/code/client/rule/vnc/vncnetwork"
"natpass/code/utils"
"net"
"net/http"
"os"
"sync"
"time"

"github.com/gorilla/websocket"
"github.com/lwch/logging"
Expand Down Expand Up @@ -112,3 +115,61 @@ func (p *Process) kill() {
ps.Kill()
}
}

// Close close process
func (p *Process) Close() {
if p.srv != nil {
p.srv.Close()
}
if p.chImage != nil {
close(p.chImage)
p.chImage = nil
}
if p.chClipboard != nil {
close(p.chClipboard)
p.chClipboard = nil
}
if p.chWrite != nil {
close(p.chWrite)
p.chWrite = nil
}
p.kill()
}

// Capture capture desktop image
func (p *Process) Capture(timeout time.Duration) (*image.RGBA, error) {
var msg vncnetwork.VncMsg
msg.XType = vncnetwork.VncMsg_capture_req
p.chWrite <- &msg
trans := func(data *vncnetwork.ImageData) *image.RGBA {
img := image.NewRGBA(image.Rect(0, 0, int(data.GetWidth()), int(data.GetHeight())))
copy(img.Pix, data.GetData())
// dumpImage(img)
return img
}
if timeout > 0 {
select {
case data := <-p.chImage:
return trans(data), nil
case <-time.After(timeout):
return nil, errors.New("timeout")
}
} else {
data := <-p.chImage
return trans(data), nil
}
}

func dumpImage(img image.Image) {
f, err := os.Create(`C:\Users\lwch\Pictures\debug.jpeg`)
if err != nil {
logging.Error("debug: %v", err)
return
}
defer f.Close()
err = jpeg.Encode(f, img, nil)
if err != nil {
logging.Error("encode: %v", err)
return
}
}
6 changes: 6 additions & 0 deletions code/client/rule/vnc/process/process_darwin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package process

// CreateWorker create worker process
func CreateWorker(name, confDir string, showCursor bool) (*Process, error) {
return nil, ErrNotSupported
}
34 changes: 34 additions & 0 deletions code/client/rule/vnc/process/process_linux.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package process

import (
"fmt"
"natpass/code/client/rule/vnc/vncnetwork"
"os"
"os/exec"
)

// CreateWorker create worker process
func CreateWorker(name, confDir string, showCursor bool) (*Process, error) {
dir, err := os.Executable()
if err != nil {
return nil, err
}
var p Process
p.chWrite = make(chan *vncnetwork.VncMsg)
p.chImage = make(chan *vncnetwork.ImageData)
p.chClipboard = make(chan *vncnetwork.ClipboardData)
port, err := p.listenAndServe()
if err != nil {
return nil, err
}
cmd := exec.Command(dir, "-conf", confDir,
"-action", "vnc.worker",
"-name", name,
"-vport", fmt.Sprintf("%d", port))
err = cmd.Start()
if err != nil {
p.Close()
return nil, err
}
return &p, nil
}
63 changes: 0 additions & 63 deletions code/client/rule/vnc/process/process_windows.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
package process

import (
"errors"
"fmt"
"image"
"image/jpeg"
"natpass/code/client/rule/vnc/define"
"natpass/code/client/rule/vnc/vncnetwork"
"os"
"strings"
"syscall"
"time"
"unicode/utf16"
"unsafe"

"github.com/lwch/logging"
"golang.org/x/sys/windows"
)

Expand Down Expand Up @@ -123,61 +118,3 @@ func createWorker(name, confDir string, tk windows.Token, showCursor bool) (*Pro
p.pid = int(process.ProcessId)
return &p, nil
}

// Close close process
func (p *Process) Close() {
if p.srv != nil {
p.srv.Close()
}
if p.chImage != nil {
close(p.chImage)
p.chImage = nil
}
if p.chClipboard != nil {
close(p.chClipboard)
p.chClipboard = nil
}
if p.chWrite != nil {
close(p.chWrite)
p.chWrite = nil
}
p.kill()
}

// Capture capture desktop image
func (p *Process) Capture(timeout time.Duration) (*image.RGBA, error) {
var msg vncnetwork.VncMsg
msg.XType = vncnetwork.VncMsg_capture_req
p.chWrite <- &msg
trans := func(data *vncnetwork.ImageData) *image.RGBA {
img := image.NewRGBA(image.Rect(0, 0, int(data.GetWidth()), int(data.GetHeight())))
copy(img.Pix, data.GetData())
// dumpImage(img)
return img
}
if timeout > 0 {
select {
case data := <-p.chImage:
return trans(data), nil
case <-time.After(timeout):
return nil, errors.New("timeout")
}
} else {
data := <-p.chImage
return trans(data), nil
}
}

func dumpImage(img image.Image) {
f, err := os.Create(`C:\Users\lwch\Pictures\debug.jpeg`)
if err != nil {
logging.Error("debug: %v", err)
return
}
defer f.Close()
err = jpeg.Encode(f, img, nil)
if err != nil {
logging.Error("encode: %v", err)
return
}
}
Loading

0 comments on commit fa557dc

Please sign in to comment.