Skip to content
This repository has been archived by the owner on Jun 11, 2023. It is now read-only.

Commit

Permalink
add: desktop viewer
Browse files Browse the repository at this point in the history
  • Loading branch information
XZB-1248 committed Sep 10, 2022
1 parent aadf368 commit 98b1beb
Show file tree
Hide file tree
Showing 38 changed files with 1,605 additions and 448 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ jobs:
zip -r -9 -q server_windows_i386.zip server_windows_i386.exe ./built
zip -r -9 -q server_windows_arm64.zip server_windows_arm64.exe ./built
zip -r -9 -q server_windows_amd64.zip server_windows_amd64.exe ./built
zip -r -9 -q frontend_assets.zip ../web/dist/*
- name: Release
uses: softprops/action-gh-release@v1
Expand All @@ -149,6 +150,7 @@ jobs:
releases/server_windows_i386.zip
releases/server_windows_arm64.zip
releases/server_windows_amd64.zip
releases/frontend_assets.zip
- name: Clean up
uses: geekyeggo/delete-artifact@v1
Expand Down
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
## v0.1.4

* Add: desktop viewer (experimental).
* Optimize: project structure.

* 新增:桌面监控(试验版)。
* 优化:项目结构。



## v0.1.3

* Optimize: basic operations for macOS.
Expand Down
12 changes: 10 additions & 2 deletions README.ZH.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,12 @@
| 文件浏览 ||||
| 文件传输 ||||
| 文件编辑 ||||
| 代码高亮 ||||
| 删除文件 ||||
| 代码高亮 ||||
| 屏幕监控 ||||
| 屏幕快照 ||||
| 系统信息 ||||
| 远程终端 ||||
| 屏幕快照 ||||
| * 关机 ||||
| * 重启 ||||
| * 注销 ||||
Expand All @@ -91,6 +92,8 @@

![terminal](./screenshots/terminal.ZH.png)

![desktop](./screenshots/desktop.ZH.png)

![procmgr](./screenshots/procmgr.ZH.png)

![explorer](./screenshots/explorer.ZH.png)
Expand Down Expand Up @@ -197,6 +200,11 @@ Spark使用了许多第三方的开源项目。

* [crypto-js](https://github.com/brix/crypto-js) (MIT License)

### 感谢

* [natpass](https://github.com/lwch/natpass) (MIT License)
* 图像差异算法部分参考了natpass项目的有关部分。

---

### Star趋势
Expand Down
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,12 @@ Only local installation are available yet.
| File explorer ||||
| File transfer ||||
| File editor ||||
| Code highlight ||||
| Delete file ||||
| Code highlight ||||
| Desktop monitor ||||
| Screenshot ||||
| OS info ||||
| Terminal ||||
| Screenshot ||||
| * Shutdown ||||
| * Reboot ||||
| * Log off ||||
Expand All @@ -92,6 +93,8 @@ Only local installation are available yet.

![terminal](./screenshots/terminal.png)

![desktop](./screenshots/desktop.png)

![procmgr](./screenshots/procmgr.png)

![explorer](./screenshots/explorer.png)
Expand Down Expand Up @@ -200,6 +203,11 @@ Some major dependencies are listed below.

* [crypto-js](https://github.com/brix/crypto-js) (MIT License)

### Acknowledgements

* [natpass](https://github.com/lwch/natpass) (MIT License)
* Image difference algorithm inspired by natpass.

---

### Stargazers over time
Expand Down
15 changes: 9 additions & 6 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,16 @@ func main() {
}

func update() {
selfPath, err := os.Executable()
if err != nil {
selfPath = os.Args[0]
}
if len(os.Args) > 1 && os.Args[1] == `--update` {
thisPath := os.Args[0]
destPath := thisPath[:len(thisPath)-4]
if len(thisPath) <= 4 {
if len(selfPath) <= 4 {
return
}
thisFile, err := ioutil.ReadFile(thisPath)
destPath := selfPath[:len(selfPath)-4]
thisFile, err := ioutil.ReadFile(selfPath)
if err != nil {
return
}
Expand All @@ -71,8 +74,8 @@ func update() {
}
}
if len(os.Args) > 1 && os.Args[1] == `--clean` {
<-time.After(time.Second)
os.Remove(os.Args[0] + `.tmp`)
<-time.After(3 * time.Second)
os.Remove(selfPath + `.tmp`)
}
}

Expand Down
28 changes: 23 additions & 5 deletions client/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"Spark/modules"
"Spark/utils"
"encoding/hex"
"errors"
ws "github.com/gorilla/websocket"
"github.com/imroc/req/v3"
"sync"
Expand All @@ -17,11 +18,25 @@ type Conn struct {
}

var WSConn *Conn
var lock = sync.Mutex{}
var WSLock = sync.Mutex{}
var HTTP = req.C().SetUserAgent(`SPARK COMMIT: ` + config.COMMIT)

const MaxMessageSize = 32768 + 1024

func SendData(data []byte, wsConn *Conn) error {
WSLock.Lock()
defer WSLock.Unlock()
if WSConn == nil {
return errors.New(`${i18n|wsClosed}`)
}
wsConn.SetWriteDeadline(time.Now().Add(5 * time.Second))
defer wsConn.SetWriteDeadline(time.Time{})
return wsConn.WriteMessage(ws.BinaryMessage, data)
}

func SendPack(pack interface{}, wsConn *Conn) error {
lock.Lock()
defer lock.Unlock()
WSLock.Lock()
defer WSLock.Unlock()
data, err := utils.JSON.Marshal(pack)
if err != nil {
return err
Expand All @@ -30,13 +45,16 @@ func SendPack(pack interface{}, wsConn *Conn) error {
if err != nil {
return err
}
if len(data) > 1024 {
_, err = req.R().
if len(data) > MaxMessageSize {
_, err = HTTP.R().
SetBody(data).
SetHeader(`Secret`, hex.EncodeToString(wsConn.Secret)).
Send(`POST`, config.GetBaseURL(false)+`/ws`)
return err
}
if WSConn == nil {
return errors.New(`${i18n|wsClosed}`)
}
wsConn.SetWriteDeadline(time.Now().Add(5 * time.Second))
defer wsConn.SetWriteDeadline(time.Time{})
return wsConn.WriteMessage(ws.BinaryMessage, data)
Expand Down
24 changes: 18 additions & 6 deletions client/core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ import (
"os"
"os/exec"
"runtime"
"strings"
"time"

ws "github.com/gorilla/websocket"
"github.com/imroc/req/v3"
"github.com/kataras/golog"
)

Expand All @@ -39,6 +39,7 @@ var handlers = map[string]func(pack modules.Packet, wsConn *common.Conn){
`initTerminal`: initTerminal,
`inputTerminal`: inputTerminal,
`resizeTerminal`: resizeTerminal,
`pingTerminal`: pingTerminal,
`killTerminal`: killTerminal,
`listFiles`: listFiles,
`fetchFile`: fetchFile,
Expand All @@ -47,16 +48,23 @@ var handlers = map[string]func(pack modules.Packet, wsConn *common.Conn){
`uploadTextFile`: uploadTextFile,
`listProcesses`: listProcesses,
`killProcess`: killProcess,
`initDesktop`: initDesktop,
`pingDesktop`: pingDesktop,
`killDesktop`: killDesktop,
`getDesktop`: getDesktop,
}

func Start() {
for !stop {
var err error
if common.WSConn != nil {
common.WSLock.Lock()
common.WSConn.Close()
common.WSConn = nil
common.WSLock.Unlock()
}
common.WSLock.Lock()
common.WSConn, err = connectWS()
common.WSLock.Unlock()
if err != nil && !stop {
golog.Error(`Connection error: `, err)
<-time.After(3 * time.Second)
Expand Down Expand Up @@ -135,7 +143,7 @@ func checkUpdate(wsConn *common.Conn) error {
if len(config.COMMIT) == 0 {
return nil
}
resp, err := req.R().
resp, err := common.HTTP.R().
SetBody(config.CfgBuffer).
SetQueryParam(`os`, runtime.GOOS).
SetQueryParam(`arch`, runtime.GOARCH).
Expand All @@ -148,14 +156,18 @@ func checkUpdate(wsConn *common.Conn) error {
if resp == nil {
return errors.New(`${i18n|unknownError}`)
}
if resp.GetContentType() == `application/octet-stream` {
if strings.HasPrefix(resp.GetContentType(), `application/octet-stream`) {
body := resp.Bytes()
if len(body) > 0 {
err = ioutil.WriteFile(os.Args[0]+`.tmp`, body, 0755)
selfPath, err := os.Executable()
if err != nil {
selfPath = os.Args[0]
}
err = ioutil.WriteFile(selfPath+`.tmp`, body, 0755)
if err != nil {
return err
}
cmd := exec.Command(os.Args[0]+`.tmp`, `--update`)
cmd := exec.Command(selfPath+`.tmp`, `--update`)
err = cmd.Start()
if err != nil {
return err
Expand Down
26 changes: 25 additions & 1 deletion client/core/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package core
import (
"Spark/client/common"
"Spark/client/service/basic"
"Spark/client/service/desktop"
"Spark/client/service/file"
"Spark/client/service/process"
Screenshot "Spark/client/service/screenshot"
Expand Down Expand Up @@ -114,6 +115,10 @@ func resizeTerminal(pack modules.Packet, wsConn *common.Conn) {
terminal.ResizeTerminal(pack)
}

func pingTerminal(pack modules.Packet, wsConn *common.Conn) {
terminal.PingTerminal(pack)
}

func killTerminal(pack modules.Packet, wsConn *common.Conn) {
terminal.KillTerminal(pack)
}
Expand Down Expand Up @@ -234,7 +239,7 @@ func uploadFiles(pack modules.Packet, wsConn *common.Conn) {
func uploadTextFile(pack modules.Packet, wsConn *common.Conn) {
var path string
var bridge string
if val, ok := pack.Data[`file`]; !ok {
if val, ok := pack.GetData(`file`, reflect.String); !ok {
common.SendCb(modules.Packet{Code: 1, Msg: `${i18n|fileOrDirNotExist}`}, pack, wsConn)
return
} else {
Expand Down Expand Up @@ -279,3 +284,22 @@ func killProcess(pack modules.Packet, wsConn *common.Conn) {
common.SendCb(modules.Packet{Code: 0}, pack, wsConn)
}
}

func initDesktop(pack modules.Packet, wsConn *common.Conn) {
err := desktop.InitDesktop(pack)
if err != nil {
common.SendCb(modules.Packet{Act: `initDesktop`, Code: 1, Msg: err.Error()}, pack, wsConn)
}
}

func pingDesktop(pack modules.Packet, wsConn *common.Conn) {
desktop.PingDesktop(pack)
}

func killDesktop(pack modules.Packet, wsConn *common.Conn) {
desktop.KillDesktop(pack)
}

func getDesktop(pack modules.Packet, wsConn *common.Conn) {
desktop.GetDesktop(pack)
}
Loading

0 comments on commit 98b1beb

Please sign in to comment.