Skip to content

Commit

Permalink
release: v0.2.0
Browse files Browse the repository at this point in the history
add: zmodem(lrzsz) support for terminal
add: update notification (won't auto update)
optimize: protocol of terminal and desktop
optimize: experience of explorer
optimize: github workflow
remove: CryptoJS
  • Loading branch information
XZB-1248 committed Nov 1, 2022
1 parent 451bff4 commit 6920f72
Show file tree
Hide file tree
Showing 49 changed files with 7,762 additions and 1,060 deletions.
29 changes: 20 additions & 9 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ jobs:

- name: Build and pack static resources
run: |
export COMMIT=`git rev-parse HEAD`
export VERSION=`git describe --tags | sed 's/^v//'`
sed -i "s/\$COMMIT/$COMMIT/g" ./web/src/config/version.json
sed -i "s/\$VERSION/$VERSION/g" ./web/src/config/version.json
cd ./web
npm install
npm run build-prod
Expand All @@ -115,20 +120,20 @@ jobs:
- name: Prepare release note
run: |
wget -q https://1248.ink/Tools/release.js
node release.js ${{ github.ref_name }}
export REF_NAME=`git describe --tags`
node ./scripts/release.js $REF_NAME
- name: Pack releases
run: |
mv ./built ./releases/built
cd ./releases
sudo apt install zip tar -y
tar -zcf server_darwin_arm64.tar.gz server_darwin_arm64 ./built
tar -zcf server_darwin_amd64.tar.gz server_darwin_amd64 ./built
tar -zcf server_linux_arm.tar.gz server_linux_arm ./built
tar -zcf server_linux_i386.tar.gz server_linux_i386 ./built
tar -zcf server_linux_arm64.tar.gz server_linux_arm64 ./built
tar -zcf server_linux_amd64.tar.gz server_linux_amd64 ./built
sudo apt install zip tar pigz -y
tar -cpf server_darwin_arm64.tar.gz server_darwin_arm64 ./built
tar -cpf server_darwin_amd64.tar.gz server_darwin_amd64 ./built
tar -cpf server_linux_arm.tar.gz server_linux_arm ./built
tar -cpf server_linux_i386.tar.gz server_linux_i386 ./built
tar -cpf server_linux_arm64.tar.gz server_linux_arm64 ./built
tar -cpf server_linux_amd64.tar.gz server_linux_amd64 ./built
zip -r -9 -q server_windows_arm.zip server_windows_arm.exe ./built
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
Expand Down Expand Up @@ -158,3 +163,9 @@ jobs:
name: |
darwin_arm64
darwin_amd64
- name: Update version info
env:
RELEASE_TOKEN: ${{ secrets.RELEASE_TOKEN }}
run: |
curl -X POST -H "Authorization: $RELEASE_TOKEN" --retry 10 -m 60 -o /dev/null https://1248.ink/spark/release > /dev/null 2>&1
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
## v0.2.0

* Add: zmodem(lrzsz) support for terminal.
* Add: update notification (won't auto update).
* Optimize: protocol of terminal and desktop.
* Optimize: experience of explorer.
* Remove: CryptoJS.

* 新增:终端支持zmodem协议(lrzsz)。
* 新增:版本更新通知(不会自动更新)。
* 优化:终端和桌面端的通信协议。
* 优化:文件管理器的使用体验。
* 移除:CryptoJS。



## v0.1.9

* Add: special keys for terminal.
Expand Down
53 changes: 0 additions & 53 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -23,56 +23,3 @@ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

-------

utils/melody are copied and modified from olahol/melody.

Copyright (c) 2015 Ola Holmström. All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

-------

utils/cmap are copied and modified from orcaman/concurrent-map.

The MIT License (MIT)

Copyright (c) 2014 streamrail

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
20 changes: 20 additions & 0 deletions client/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"Spark/client/config"
"Spark/modules"
"Spark/utils"
"encoding/binary"
"encoding/hex"
"errors"
ws "github.com/gorilla/websocket"
Expand Down Expand Up @@ -73,6 +74,25 @@ func (wsConn *Conn) SendPack(pack any) error {
return wsConn.WriteMessage(ws.BinaryMessage, data)
}

func (wsConn *Conn) SendRawData(event, data []byte, service byte, op byte) error {
Mutex.Lock()
defer Mutex.Unlock()
if WSConn == nil {
return errors.New(`${i18n|COMMON.DISCONNECTED}`)
}
buffer := make([]byte, 24)
copy(buffer[6:22], event)
copy(buffer[:4], []byte{34, 22, 19, 17})
buffer[4] = service
buffer[5] = op
binary.BigEndian.PutUint16(buffer[22:24], uint16(len(data)))
buffer = append(buffer, data...)

wsConn.SetWriteDeadline(utils.Now.Add(5 * time.Second))
defer wsConn.SetWriteDeadline(time.Time{})
return wsConn.WriteMessage(ws.BinaryMessage, buffer)
}

func (wsConn *Conn) SendCallback(pack, prev modules.Packet) error {
if len(prev.Event) > 0 {
pack.Event = prev.Event
Expand Down
12 changes: 12 additions & 0 deletions client/core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,18 @@ func handleWS(wsConn *common.Conn) error {
golog.Error(err)
return nil
}
if service, op, isBinary := utils.CheckBinaryPack(data); isBinary && len(data) > 24 {
event := hex.EncodeToString(data[6:22])
switch service {
case 20:
case 21:
switch op {
case 0:
inputRawTerminal(data[24:], event)
}
}
continue
}
data, err = utils.Decrypt(data, wsConn.GetSecret())
if err != nil {
golog.Error(err)
Expand Down
12 changes: 6 additions & 6 deletions client/core/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,16 +179,16 @@ func GetDevice() (*modules.Device, error) {
}
localIP, err := GetLocalIP()
if err != nil {
localIP = `unknown`
localIP = `<unknown>`
}
macAddr, err := GetMacAddress()
if err != nil {
macAddr = `unknown`
macAddr = `<unknown>`
}
cpuInfo, err := GetCPUInfo()
if err != nil {
cpuInfo = modules.CPU{
Model: `unknown`,
Model: `<unknown>`,
Usage: 0,
}
}
Expand Down Expand Up @@ -221,11 +221,11 @@ func GetDevice() (*modules.Device, error) {
}
hostname, err := os.Hostname()
if err != nil {
hostname = `unknown`
hostname = `<unknown>`
}
username, err := user.Current()
if err != nil {
username = &user.User{Username: `unknown`}
username = &user.User{Username: `<unknown>`}
} else {
slashIndex := strings.Index(username.Username, `\`)
if slashIndex > -1 && slashIndex+1 < len(username.Username) {
Expand All @@ -252,7 +252,7 @@ func GetPartialInfo() (*modules.Device, error) {
cpuInfo, err := GetCPUInfo()
if err != nil {
cpuInfo = modules.CPU{
Model: `unknown`,
Model: `<unknown>`,
Usage: 0,
}
}
Expand Down
4 changes: 4 additions & 0 deletions client/core/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,3 +370,7 @@ func execCommand(pack modules.Packet, wsConn *common.Conn) {
proc.Process.Release()
}
}

func inputRawTerminal(pack []byte, event string) {
terminal.InputRawTerminal(pack, event)
}
53 changes: 31 additions & 22 deletions client/service/desktop/desktop.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,22 @@ type message struct {
frame *[]*[]byte
}

// +---------+---------+----------+----------+------------+---------+---------+---------+---------+-------+
// | magic | OP code | event id | img type | img length | x | y | width | height | image |
// +---------+---------+----------+----------+------------+---------+---------+---------+---------+-------+
// | 5 bytes | 1 byte | 16 bytes | 2 bytes | 2 bytes | 2 bytes | 2 bytes | 2 bytes | 2 bytes | - |
// +---------+---------+----------+----------+------------+---------+---------+---------+---------+-------+
// packet explanation:

// +---------+---------+----------+-------------+----------+---------+---------+---------+---------+-------+
// | magic | op code | event id | body length | img type | x | y | width | height | image |
// +---------+---------+----------+-------------+----------+---------+---------+---------+---------+-------+
// | 5 bytes | 1 byte | 16 bytes | 2 bytes | 2 bytes | 2 bytes | 2 bytes | 2 bytes | 2 bytes | - |
// +---------+---------+----------+-------------+----------+---------+---------+---------+---------+-------+

// magic:
// []byte{34, 22, 19, 17, 20}

// OP code:
// 00: first part of a frame
// 01: rest parts of a frame
// 02: set resolution of every frame
// 03: JSON string (only for server)
// op code:
// 00: first part of a frame, device -> browser
// 01: rest parts of a frame, device -> browser
// 02: set resolution of every frame, device -> browser
// 03: JSON string, server -> browser

// img type:
// 0: raw image
Expand Down Expand Up @@ -167,12 +169,12 @@ func imageCompare(img, prev *image.RGBA, compress bool) []*[]byte {
for _, rect := range diff {
block := getImageBlock(img, rect, compress)
buf := make([]byte, 12)
binary.BigEndian.PutUint16(buf[0:2], uint16(len(block)+10))
if compress {
binary.BigEndian.PutUint16(buf[0:2], uint16(1))
binary.BigEndian.PutUint16(buf[2:4], uint16(1))
} else {
binary.BigEndian.PutUint16(buf[0:2], uint16(0))
binary.BigEndian.PutUint16(buf[2:4], uint16(0))
}
binary.BigEndian.PutUint16(buf[2:4], uint16(len(block)))
binary.BigEndian.PutUint16(buf[4:6], uint16(rect.Min.X))
binary.BigEndian.PutUint16(buf[6:8], uint16(rect.Min.Y))
binary.BigEndian.PutUint16(buf[8:10], uint16(rect.Size().X))
Expand All @@ -197,12 +199,12 @@ func splitFullImage(img *image.RGBA, compress bool) []*[]byte {
width := utils.If(x+blockSize > imgWidth, imgWidth-x, blockSize)
block := getImageBlock(img, image.Rect(x, y, x+width, y+height), compress)
buf := make([]byte, 12)
binary.BigEndian.PutUint16(buf[0:2], uint16(len(block)+10))
if compress {
binary.BigEndian.PutUint16(buf[0:2], uint16(1))
binary.BigEndian.PutUint16(buf[2:4], uint16(1))
} else {
binary.BigEndian.PutUint16(buf[0:2], uint16(0))
binary.BigEndian.PutUint16(buf[2:4], uint16(0))
}
binary.BigEndian.PutUint16(buf[2:4], uint16(len(block)))
binary.BigEndian.PutUint16(buf[4:6], uint16(x))
binary.BigEndian.PutUint16(buf[6:8], uint16(y))
binary.BigEndian.PutUint16(buf[8:10], uint16(width))
Expand Down Expand Up @@ -318,7 +320,9 @@ func InitDesktop(pack modules.Packet) error {
if screenshot.NumActiveDisplays() == 0 {
if displayBounds.Dx() == 0 || displayBounds.Dy() == 0 {
close(desktop.channel)
common.WSConn.SendCallback(modules.Packet{Act: `DESKTOP_QUIT`, Msg: `${i18n|DESKTOP.NO_DISPLAY_FOUND}`}, pack)
data, _ := utils.JSON.Marshal(modules.Packet{Act: `DESKTOP_QUIT`, Msg: `${i18n|DESKTOP.NO_DISPLAY_FOUND}`})
data = utils.XOR(data, common.WSConn.GetSecret())
common.WSConn.SendRawData(desktop.rawEvent, data, 20, 03)
return errors.New(`${i18n|DESKTOP.NO_DISPLAY_FOUND}`)
}
}
Expand Down Expand Up @@ -368,11 +372,13 @@ func KillDesktop(pack modules.Packet) {
desktop = val.(*session)
}
sessions.Remove(uuid)
data, _ := utils.JSON.Marshal(modules.Packet{Act: `DESKTOP_QUIT`, Msg: `${i18n|DESKTOP.SESSION_CLOSED}`})
data = utils.XOR(data, common.WSConn.GetSecret())
common.WSConn.SendRawData(desktop.rawEvent, data, 20, 03)
desktop.lock.Lock()
desktop.escape = true
desktop.rawEvent = nil
desktop.lock.Unlock()
common.WSConn.SendCallback(modules.Packet{Act: `DESKTOP_QUIT`, Msg: `${i18n|DESKTOP.SESSION_CLOSED}`}, pack)
}

func GetDesktop(pack modules.Packet) {
Expand Down Expand Up @@ -404,7 +410,9 @@ func handleDesktop(pack modules.Packet, uuid string, desktop *session) {
case msg, ok := <-desktop.channel:
// send error info
if msg.t == 1 || !ok {
common.WSConn.SendCallback(modules.Packet{Act: `DESKTOP_QUIT`, Msg: msg.info}, pack)
data, _ := utils.JSON.Marshal(modules.Packet{Act: `DESKTOP_QUIT`, Msg: msg.info})
data = utils.XOR(data, common.WSConn.GetSecret())
common.WSConn.SendRawData(desktop.rawEvent, data, 20, 03)
desktop.escape = true
sessions.Remove(uuid)
break
Expand All @@ -428,9 +436,10 @@ func handleDesktop(pack modules.Packet, uuid string, desktop *session) {
// set resolution
if msg.t == 2 {
buf := append([]byte{34, 22, 19, 17, 20, 02}, desktop.rawEvent...)
data := make([]byte, 4)
binary.BigEndian.PutUint16(data[:2], uint16(displayBounds.Dx()))
binary.BigEndian.PutUint16(data[2:], uint16(displayBounds.Dy()))
data := make([]byte, 6)
binary.BigEndian.PutUint16(data[:2], 4)
binary.BigEndian.PutUint16(data[2:4], uint16(displayBounds.Dx()))
binary.BigEndian.PutUint16(data[4:6], uint16(displayBounds.Dy()))
buf = append(buf, data...)
common.WSConn.SendData(buf)
break
Expand Down
17 changes: 16 additions & 1 deletion client/service/terminal/terminal.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,19 @@ var (
errDataNotFound = errors.New(`no input found in packet`)
errDataInvalid = errors.New(`can not parse data in packet`)
errUUIDNotFound = errors.New(`can not find terminal identifier`)
)
)

// packet explanation:

// +---------+---------+----------+-------------+------+
// | magic | op code | event id | data length | data |
// +---------+---------+----------+-------------+------+
// | 5 bytes | 1 byte | 16 bytes | 2 bytes | - |
// +---------+---------+----------+-------------+------+

// magic:
// []byte{34, 22, 19, 17, 21}

// op code:
// 00: binary packet
// 01: JSON packet
Loading

0 comments on commit 6920f72

Please sign in to comment.