Skip to content

Commit

Permalink
add: log system
Browse files Browse the repository at this point in the history
  • Loading branch information
XZB-1248 committed Oct 9, 2022
1 parent c8437aa commit 844a0ba
Show file tree
Hide file tree
Showing 39 changed files with 923 additions and 222 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/releases
/built
/tools
/logs
/.idea
/Config.json
dist/
Expand Down
31 changes: 28 additions & 3 deletions API.ZH.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,38 @@ Authorization: Basic WFpCOjEyNDg=

---

### 执行命令:`/device/exec`

参数:`cmd``args`以及`device`(设备ID)

示例:
```http request
POST http://localhost:8000/api/device/exec HTTP/1.1
Host: localhost:8000
Content-Length: 116
Content-Type: application/x-www-form-urlencoded
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.64 Safari/537.36 Edg/101.0.1210.47
Origin: http://localhost:8000
Referer: http://localhost:8000/
cmd=taskkill&args=%2Ff%20%2Fim%20regedit.exe&device=bc7e49f8f794f80ffb0032a4ba516c86d76041bf2023e1be6c5dda3b1ee0cf4c
```

```
{
"code": 0
}
```

---

### 获取截屏:`/device/screenshot/get`

参数:`device`(设备ID)

如果截屏获取成功,则会直接以图片的形式输出。
<br />
如果截屏失败,如下响应会被输出(错误信息不一定是这一个)。
如果截屏失败,如下响应会被输出(错误信息不唯一)。

```
{
Expand Down Expand Up @@ -199,7 +224,7 @@ Authorization: Basic WFpCOjEyNDg=
<br />
如果存在同名文件,则会被**覆盖**

Example:
示例:
```http request
POST http://localhost:8000/api/device/file/upload?path=D%3A%5C&file=Test.txt&device=bc7e49f8f794f80ffb0032a4ba516c86d76041bf2023e1be6c5dda3b1ee0cf4c HTTP/1.1
Host: localhost:8000
Expand All @@ -212,7 +237,7 @@ Referer: http://localhost:8000/
Hello World.
```

如果文件上传成功,则`code``1`
如果文件上传成功,则`code``0`
<br />
文件`D:\Test.txt`会写入:`Hello World.`

Expand Down
27 changes: 26 additions & 1 deletion API.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Example:
Authorization: Basic WFpCOjEyNDg=
```

After basic authentication, server will assign you a `Authorization` cookie.
After basic authentication, server will assign you an `Authorization` cookie.
<br />
You can use this token cookie to authenticate rest of your requests.

Expand Down Expand Up @@ -130,6 +130,31 @@ For example, when you call `/device/restart`, your device will restart.

---

### Execute command: `/device/exec`

Parameters: `cmd`, `args` and `device` (device ID)

Example:
```http request
POST http://localhost:8000/api/device/exec HTTP/1.1
Host: localhost:8000
Content-Length: 116
Content-Type: application/x-www-form-urlencoded
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.64 Safari/537.36 Edg/101.0.1210.47
Origin: http://localhost:8000
Referer: http://localhost:8000/
cmd=taskkill&args=%2Ff%20%2Fim%20regedit.exe&device=bc7e49f8f794f80ffb0032a4ba516c86d76041bf2023e1be6c5dda3b1ee0cf4c
```

```
{
"code": 0
}
```

---

### Take screenshot: `/device/screenshot/get`

Parameters: `device` (device ID)
Expand Down
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
## v0.1.6

* Optimize: potential crash problem of explorer.
* Add: set config through command line arguments.
* Add: log system.

* 优化:文件管理器可能导致服务崩溃。
* 添加:支持通过命令行设置相关配置。
* 新增:日志机制。



## v0.1.5

* Optimize: performance of desktop viewer on Windows.
Expand Down
15 changes: 11 additions & 4 deletions README.ZH.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@

**本项目及其源代码和发行版,旨在用于学习和交流。**
<br />
**禁止用于任何非法用途!**
<br />
**使用本项目所带来的风险由使用者本人承担。**
<br />
**作者和开发者不会对你的错误使用而造成的损害承担任何责任**
**作者和开发者不会对你错误使用而造成的损害承担任何责任**

**数据无价,在点击任何按钮、输入任何命令之前,请三思。**

Expand All @@ -40,14 +42,19 @@

*[Releases](https://github.com/XZB-1248/Spark/releases) 页面下载对应系统的可执行文件。
* 解压文件,**不要删除**`built`文件夹。
* 在目录下创建一个名为`Config.json`的配置文件,修改其中的信息
* 在目录下创建一个名为`config.json`的配置文件,设置好相关的配置信息

```json
{
"listen": ":8000",
"salt": "some random string",
"salt": "随机字符串(英文数字符号,小于24位)",
"auth": {
"username": "password"
"用户名": "密码(英文数字符号)"
},
"log": {
"level": "info",
"path": "./logs",
"days": 7
}
}
```
Expand Down
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ server forever.

**THIS PROJECT, ITS SOURCE CODE, AND ITS RELEASES SHOULD ONLY BE USED FOR EDUCATIONAL PURPOSES.**
<br />
**ALL ILLEGAL USAGE IS PROHIBITED!**
<br />
**YOU SHALL USE THIS PROJECT AT YOUR OWN RISK.**
<br />
**THE AUTHORS AND DEVELOPERS ARE NOT RESPONSIBLE FOR ANY DAMAGE CAUSED BY YOUR MISUSE OF THIS PROJECT.**
Expand All @@ -41,14 +43,19 @@ Only local installation are available yet.
### Local installation
* Get prebuilt executable file from [Releases](https://github.com/XZB-1248/Spark/releases) page.
* Extract all files and **do not** delete `built` directory.
* Create a configuration file named `Config.json` and set your own salt.
* Create a configuration file named `config.json` and set your own salt.

```json
{
"listen": ":8000",
"salt": "some random string",
"salt": "some random string length <= 24",
"auth": {
"username": "password"
},
"log": {
"level": "info",
"path": "./logs",
"days": 7
}
}
```
Expand Down
11 changes: 4 additions & 7 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import (
"crypto/aes"
"crypto/cipher"
"math/big"
"net/http"
_ "net/http/pprof"
"os"
"os/exec"
"strings"
Expand All @@ -21,18 +19,18 @@ import (
func init() {
golog.SetTimeFormat(`2006/01/02 15:04:05`)

if len(strings.Trim(config.CfgBuffer, "\x19")) == 0 {
if len(strings.Trim(config.ConfigBuffer, "\x19")) == 0 {
os.Exit(0)
return
}

// Convert first 2 bytes to int, which is the length of the encrypted config.
dataLen := int(big.NewInt(0).SetBytes([]byte(config.CfgBuffer[:2])).Uint64())
if dataLen > len(config.CfgBuffer)-2 {
dataLen := int(big.NewInt(0).SetBytes([]byte(config.ConfigBuffer[:2])).Uint64())
if dataLen > len(config.ConfigBuffer)-2 {
os.Exit(0)
return
}
cfgBytes := []byte(config.CfgBuffer[2 : 2+dataLen])
cfgBytes := utils.StringToBytes(config.ConfigBuffer, 2, 2+dataLen)
cfgBytes, err := decrypt(cfgBytes[16:], cfgBytes[:16])
if err != nil {
os.Exit(0)
Expand All @@ -49,7 +47,6 @@ func init() {
}

func main() {
go http.ListenAndServe(`:6060`, nil)
update()
core.Start()
}
Expand Down
8 changes: 4 additions & 4 deletions client/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ type Conn struct {
secretHex string
}

const MaxMessageSize = (2 << 15) + 1024

var WSConn *Conn
var Mutex = &sync.Mutex{}
var HTTP = CreateClient()

const MaxMessageSize = 32768 + 1024

func CreateConn(wsConn *ws.Conn, secret []byte) *Conn {
return &Conn{
Conn: wsConn,
Expand All @@ -42,7 +42,7 @@ func (wsConn *Conn) SendData(data []byte) error {
if WSConn == nil {
return errors.New(`${i18n|wsClosed}`)
}
wsConn.SetWriteDeadline(Now.Add(5 * time.Second))
wsConn.SetWriteDeadline(utils.Now.Add(5 * time.Second))
defer wsConn.SetWriteDeadline(time.Time{})
return wsConn.WriteMessage(ws.BinaryMessage, data)
}
Expand All @@ -68,7 +68,7 @@ func (wsConn *Conn) SendPack(pack any) error {
if WSConn == nil {
return errors.New(`${i18n|wsClosed}`)
}
wsConn.SetWriteDeadline(Now.Add(5 * time.Second))
wsConn.SetWriteDeadline(utils.Now.Add(5 * time.Second))
defer wsConn.SetWriteDeadline(time.Time{})
return wsConn.WriteMessage(ws.BinaryMessage, data)
}
Expand Down
4 changes: 2 additions & 2 deletions client/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ type Cfg struct {

// Localhost for my development only.
// Shall be commented out when development is done.
//var CfgBuffer = "\x00\xcd\xc6\x68\x5d\xf5\x83\x53\x1c\x49\xa2\x35\x7b\x5b\xaf\xf2\x9e\x6d\x74\x00\x95\x23\x73\x00\x77\xa0\xe1\x46\x64\xd2\x33\x2b\x04\xb2\xca\x70\xda\x4b\xed\xec\x43\x6b\xeb\x6e\x10\x53\x6e\x62\x13\x3c\xb1\x0a\xdd\xc0\x48\x2d\x77\xfa\x4a\x9b\x26\xb5\x1b\x50\x62\x05\xcc\xc9\x3b\x22\xf5\x19\x5b\xac\x41\x74\xc9\x9e\x02\x9f\xe8\x75\xce\x3a\xe0\x50\x67\x0f\x81\x01\xca\x47\x0d\xb2\x09\x8b\x74\x6c\xfd\xc5\x73\xf9\x2a\xf0\x13\x52\xb7\x79\xff\xeb\xab\xcd\x9f\xe8\xb7\xae\xff\xa9\x50\xb2\x90\x11\x35\x4d\x94\x6e\x67\x55\x37\x66\x58\x21\xc0\x0d\xab\x3b\x6f\xc4\x00\x56\xd6\x06\xa0\x7e\x73\xdf\x46\x76\xe0\xb3\x89\x0d\xa2\x33\x07\x39\x81\x2b\x59\x30\x24\xc7\x4f\xe9\xb9\xf6\x3c\xb6\x24\xc5\x44\xde\xe6\x66\x66\x92\x49\xe1\x38\x50\xff\xb5\xf3\x20\xb9\x15\x60\x4a\xdf\xba\xd5\xae\x85\x7e\x3f\x8a\xf0\xb8\xf5\x23\x39\xf0\x46\x11\x64\x42\x04\x8c\xf0\x8a\x5e\xc7\x43\xd2\x0c\x89\xd1\xc4\x14\x26\xb1\x67\x64\x28\x77\xf4\xc8\xf3\x51\x69\xba\xf2\xca\xfa\x2f\x11\xe0\x8d\x6c\x4e\x8c\xb7\x28\xf5\x2a\x67\xe3\x8f\xf0\x7f\x79\xc5\xa5\x1a\xb5\xa1\x22\xe9\x55\x61\xdd\xce\x39\x13\x4b\xdd\x19\xf1\x5c\x86\x9b\x16\x89\x45\xba\x16\x68\xfc\x88\x4b\xd5\x13\xa4\x7e\x26\xce\x35\x2d\x42\x4d\x21\xf1\xc3\x6d\xf5\x64\x16\xc9\x05\xed\x9b\x6c\xbf\x26\xe3\xad\x40\x1d\xc6\x64\x03\xb9\xcb\xca\x3c\x62\x5d\x07\x6b\x07\x8b\xa9\x86\x60\x27\x28\xe7\xa3\xc2\x8d\x6f\xc0\x3d\x8e\x14\xa6\xcc\xe0\x50\x51\x22\x20\x6b\x16\x10\xe9\xe0\x4a\xd2\x4e\x77\xc8\xd1\xf7\x60\x4c\xed\xca\x3f\x1e\x13\x0a\x2e\x84\x15\xd3\xf6\x3e\x13\x4e\x68\xaf\xfd\x7a\xd7\x5b\xaa\x5b\x28\x7c\x3f\xb3\xd0\xd0"
//var ConfigBuffer = "\x00\xcd\xc6\x68\x5d\xf5\x83\x53\x1c\x49\xa2\x35\x7b\x5b\xaf\xf2\x9e\x6d\x74\x00\x95\x23\x73\x00\x77\xa0\xe1\x46\x64\xd2\x33\x2b\x04\xb2\xca\x70\xda\x4b\xed\xec\x43\x6b\xeb\x6e\x10\x53\x6e\x62\x13\x3c\xb1\x0a\xdd\xc0\x48\x2d\x77\xfa\x4a\x9b\x26\xb5\x1b\x50\x62\x05\xcc\xc9\x3b\x22\xf5\x19\x5b\xac\x41\x74\xc9\x9e\x02\x9f\xe8\x75\xce\x3a\xe0\x50\x67\x0f\x81\x01\xca\x47\x0d\xb2\x09\x8b\x74\x6c\xfd\xc5\x73\xf9\x2a\xf0\x13\x52\xb7\x79\xff\xeb\xab\xcd\x9f\xe8\xb7\xae\xff\xa9\x50\xb2\x90\x11\x35\x4d\x94\x6e\x67\x55\x37\x66\x58\x21\xc0\x0d\xab\x3b\x6f\xc4\x00\x56\xd6\x06\xa0\x7e\x73\xdf\x46\x76\xe0\xb3\x89\x0d\xa2\x33\x07\x39\x81\x2b\x59\x30\x24\xc7\x4f\xe9\xb9\xf6\x3c\xb6\x24\xc5\x44\xde\xe6\x66\x66\x92\x49\xe1\x38\x50\xff\xb5\xf3\x20\xb9\x15\x60\x4a\xdf\xba\xd5\xae\x85\x7e\x3f\x8a\xf0\xb8\xf5\x23\x39\xf0\x46\x11\x64\x42\x04\x8c\xf0\x8a\x5e\xc7\x43\xd2\x0c\x89\xd1\xc4\x14\x26\xb1\x67\x64\x28\x77\xf4\xc8\xf3\x51\x69\xba\xf2\xca\xfa\x2f\x11\xe0\x8d\x6c\x4e\x8c\xb7\x28\xf5\x2a\x67\xe3\x8f\xf0\x7f\x79\xc5\xa5\x1a\xb5\xa1\x22\xe9\x55\x61\xdd\xce\x39\x13\x4b\xdd\x19\xf1\x5c\x86\x9b\x16\x89\x45\xba\x16\x68\xfc\x88\x4b\xd5\x13\xa4\x7e\x26\xce\x35\x2d\x42\x4d\x21\xf1\xc3\x6d\xf5\x64\x16\xc9\x05\xed\x9b\x6c\xbf\x26\xe3\xad\x40\x1d\xc6\x64\x03\xb9\xcb\xca\x3c\x62\x5d\x07\x6b\x07\x8b\xa9\x86\x60\x27\x28\xe7\xa3\xc2\x8d\x6f\xc0\x3d\x8e\x14\xa6\xcc\xe0\x50\x51\x22\x20\x6b\x16\x10\xe9\xe0\x4a\xd2\x4e\x77\xc8\xd1\xf7\x60\x4c\xed\xca\x3f\x1e\x13\x0a\x2e\x84\x15\xd3\xf6\x3e\x13\x4e\x68\xaf\xfd\x7a\xd7\x5b\xaa\x5b\x28\x7c\x3f\xb3\xd0\xd0"

// None
var CfgBuffer = "\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19"
var ConfigBuffer = "\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19\x19"

// COMMIT means this commit hash, help to identify version and self upgrade.
var COMMIT = ``
Expand Down
4 changes: 2 additions & 2 deletions client/core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func reportWS(wsConn *common.Conn) error {
if err != nil {
return err
}
common.WSConn.SetReadDeadline(common.Now.Add(5 * time.Second))
common.WSConn.SetReadDeadline(utils.Now.Add(5 * time.Second))
_, data, err := common.WSConn.ReadMessage()
common.WSConn.SetReadDeadline(time.Time{})
if err != nil {
Expand All @@ -116,7 +116,7 @@ func checkUpdate(wsConn *common.Conn) error {
return nil
}
resp, err := common.HTTP.R().
SetBody(config.CfgBuffer).
SetBody(config.ConfigBuffer).
SetQueryParam(`os`, runtime.GOOS).
SetQueryParam(`arch`, runtime.GOARCH).
SetQueryParam(`commit`, config.COMMIT).
Expand Down
38 changes: 38 additions & 0 deletions client/core/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ import (
"Spark/modules"
"github.com/kataras/golog"
"os"
"os/exec"
"reflect"
"strings"
)

var handlers = map[string]func(pack modules.Packet, wsConn *common.Conn){
Expand Down Expand Up @@ -40,6 +42,7 @@ var handlers = map[string]func(pack modules.Packet, wsConn *common.Conn){
`pingDesktop`: pingDesktop,
`killDesktop`: killDesktop,
`getDesktop`: getDesktop,
`execCommand`: execCommand,
}

func ping(pack modules.Packet, wsConn *common.Conn) {
Expand Down Expand Up @@ -131,6 +134,8 @@ func initTerminal(pack modules.Packet, wsConn *common.Conn) {
err := terminal.InitTerminal(pack)
if err != nil {
wsConn.SendCallback(modules.Packet{Act: `initTerminal`, Code: 1, Msg: err.Error()}, pack)
} else {
wsConn.SendCallback(modules.Packet{Act: `initTerminal`, Code: 0}, pack)
}
}

Expand Down Expand Up @@ -318,6 +323,8 @@ func initDesktop(pack modules.Packet, wsConn *common.Conn) {
err := desktop.InitDesktop(pack)
if err != nil {
wsConn.SendCallback(modules.Packet{Act: `initDesktop`, Code: 1, Msg: err.Error()}, pack)
} else {
wsConn.SendCallback(modules.Packet{Act: `initDesktop`, Code: 0}, pack)
}
}

Expand All @@ -332,3 +339,34 @@ func killDesktop(pack modules.Packet, wsConn *common.Conn) {
func getDesktop(pack modules.Packet, wsConn *common.Conn) {
desktop.GetDesktop(pack)
}

func execCommand(pack modules.Packet, wsConn *common.Conn) {
var proc *exec.Cmd
var cmd, args string
if val, ok := pack.Data[`cmd`]; !ok {
wsConn.SendCallback(modules.Packet{Code: 1, Msg: `${i18n|invalidParameter}`}, pack)
return
} else {
cmd = val.(string)
}
if val, ok := pack.Data[`args`]; !ok {
wsConn.SendCallback(modules.Packet{Code: 1, Msg: `${i18n|invalidParameter}`}, pack)
return
} else {
args = val.(string)
}
if len(args) == 0 {
proc = exec.Command(cmd)
} else {
proc = exec.Command(cmd, strings.Split(args, ` `)...)
}
err := proc.Start()
if err != nil {
wsConn.SendCallback(modules.Packet{Code: 1, Msg: err.Error()}, pack)
} else {
wsConn.SendCallback(modules.Packet{Code: 0, Data: map[string]any{
`pid`: proc.Process.Pid,
}}, pack)
proc.Process.Release()
}
}
4 changes: 2 additions & 2 deletions client/service/desktop/desktop.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ func InitDesktop(pack modules.Packet) error {
desktop := &session{
event: pack.Event,
rawEvent: rawEvent,
lastPack: common.Unix,
lastPack: utils.Unix,
escape: false,
channel: make(chan message, 4),
lock: &sync.Mutex{},
Expand Down Expand Up @@ -345,7 +345,7 @@ func PingDesktop(pack modules.Packet) {
return
} else {
desktop = val.(*session)
desktop.lastPack = common.Unix
desktop.lastPack = utils.Unix
}
}

Expand Down
Loading

0 comments on commit 844a0ba

Please sign in to comment.