Skip to content

Commit 40f66d9

Browse files
committed
删除无用依赖, 添加客户端提交到服务端数据aes加密
1 parent 197820c commit 40f66d9

File tree

12 files changed

+179
-449
lines changed

12 files changed

+179
-449
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ test/unit/coverage
99
test/e2e/reports
1010
selenium-debug.log
1111
rdm-connections.json
12-
server/rdm-log.log
1312
server/data.db
1413
server/resources/app/
1514
server/resources/dist/
1615
bind_*.go
1716
windows.syso
17+
/server/error.log

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ redis管理客户端, 基于[go-astilectron](https://github.com/asticode/go-ast
44
## BUG ##
55
1. http模式pubsub接口兼容, 调整订阅与发布顺序, 消除第一次发送消息失败的情况
66
2. 选中tree节点时无法高亮
7+
3. 刷新value概率锁定按钮loading
78

89
## 伪redis-cli功能 ##
910
可以使用`help`查看可用的命令. 部分还原redis-cli的响应值.
@@ -14,7 +15,7 @@ redis管理客户端, 基于[go-astilectron](https://github.com/asticode/go-ast
1415
- [ ] Electron Cpu占用率太高, windows 不关闭Electron进程
1516
- [ ] redis-cli功能新增切换连接情况功能.(保持select 数据库的状态)
1617
- [ ] 替换类库为(https://github.com/zserge/lorca), 精简文件大小与依赖
17-
18+
- [ ] 切换db清空cli的输入内容(暴露全局命令行对象)
1819
## 原理图 ##
1920
```
2021
+-------------------------+

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@
1414
"lint": "eslint --ext .js,.vue src test/unit/specs test/e2e/specs"
1515
},
1616
"dependencies": {
17-
"axios": "^0.19.2",
1817
"browser-update": "^2.1.4",
19-
"html2canvas": "^1.0.0-alpha.12",
18+
"crypto-js": "^3.1.9-1",
2019
"iview": "^3.5.1",
2120
"jquery": "^3.4.1",
2221
"md5": "^2.2.1",

server/go.mod

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,17 @@ module github.com/xiusin/redis_manager/server
33
go 1.13
44

55
require (
6-
github.com/apex/log v1.1.1
7-
github.com/astaxie/beego v1.12.0
6+
github.com/Luzifer/go-openssl v2.0.0+incompatible
87
github.com/asticode/go-astilectron v0.11.0
98
github.com/asticode/go-astilectron-bootstrap v0.3.0
10-
github.com/asticode/go-astilectron-bundler v0.3.0
119
github.com/asticode/go-astilog v1.4.0
1210
github.com/gomodule/redigo v2.0.0+incompatible
1311
github.com/gorilla/websocket v1.4.1
12+
github.com/kr/pretty v0.1.0 // indirect
13+
github.com/mattn/go-isatty v0.0.11 // indirect
1414
github.com/pkg/errors v0.8.1
15-
github.com/rs/cors v1.7.0 // indirect
16-
github.com/shiena/ansicolor v0.0.0-20151119151921-a422bbe96644 // indirect
17-
github.com/xiusin/iriscms v0.0.0-20200108141855-2cc75e14d21a
15+
github.com/rs/cors v1.7.0
16+
golang.org/x/crypto v0.0.0-20191206172530-e9b2fee46413 // indirect
17+
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
18+
gopkg.in/yaml.v2 v2.2.7 // indirect
1819
)

server/go.sum

Lines changed: 6 additions & 346 deletions
Large diffs are not rendered by default.

server/main.go

Lines changed: 43 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,19 @@ package main
33
import (
44
"encoding/json"
55
"fmt"
6+
"github.com/Luzifer/go-openssl"
67
"github.com/asticode/go-astilectron"
78
bootstrap "github.com/asticode/go-astilectron-bootstrap"
89
"github.com/asticode/go-astilog"
910
"github.com/pkg/errors"
1011
"github.com/xiusin/redis_manager/server/src"
1112
"log"
13+
"math/rand"
1214
"os"
1315
"path/filepath"
1416
"strings"
1517
"sync"
18+
"time"
1619
)
1720

1821
const DEBUG = true
@@ -23,13 +26,23 @@ var cacheDir string
2326

2427
var handler = src.NewHandler()
2528

29+
const SecretLen = 32
30+
31+
var secretKey []byte
32+
2633
func init() {
2734
cacheDir = GetCacheDir()
28-
35+
salt := "ABCEDFGHIJKLMNOPQRSTUVWXYZ0123456789"
36+
l := len(salt)
37+
rand.Seed(time.Now().UnixNano())
38+
for i := 0; i < SecretLen; i++ {
39+
secretKey = append(secretKey, salt[rand.Int63n(int64(l))])
40+
}
41+
src.SecretKey = string(secretKey)
2942
astilog.SetLogger(astilog.New(astilog.Configuration{
3043
AppName: "RedisManager",
31-
Filename: fmt.Sprintf("%s/rdm-log.log", cacheDir),
32-
Verbose: DEBUG,
44+
Filename: fmt.Sprintf("%s/error.log", cacheDir),
45+
Verbose: false,
3346
}))
3447
astilog.FlagConfig()
3548

@@ -47,10 +60,10 @@ func init() {
4760
"/redis/connection/command": src.RedisManagerCommand,
4861
"/redis/connection/pubsub": src.RedisPubSub,
4962
"/redis/connection/info": src.RedisManagerGetInfo,
63+
"/gek": gek,
5064
"/redis/connection/get-command": src.RedisManagerGetCommandList,
5165
}
5266

53-
5467
for route, handle := range routes {
5568
handler.Add(route, handle)
5669
}
@@ -72,9 +85,6 @@ func main() {
7285
} else {
7386
url = "index.html"
7487
}
75-
//else {
76-
// url = cacheDir + "/resources/dist/index.html"
77-
//}
7888
center, HasShadow, Fullscreenable, Closable, skipTaskBar := true, true, true, true, true
7989
height, width := 800, 1280
8090

@@ -91,38 +101,50 @@ func main() {
91101
return
92102
})
93103
a.On(astilectron.EventNameAppClose, func(e astilectron.Event) (deleteListener bool) {
94-
a.Close()
95104
fmt.Println("astilectron.EventNameAppClose")
96105
return
97106
})
98107
a.On(astilectron.EventNameAppCmdQuit, func(e astilectron.Event) (deleteListener bool) {
99-
a.Close()
100108
fmt.Println("astilectron.EventNameAppCmdQuit")
101109
return
102110
})
103-
104111
src.Window = ws[0]
112+
if DEBUG {
113+
src.Window.OpenDevTools()
114+
}
105115
ws[0].OnMessage(func(m *astilectron.EventMessage) (v interface{}) {
116+
opensslHandler := openssl.New()
106117
var s string
107118
err := m.Unmarshal(&s)
108119
if err != nil {
109120
return "{}"
110121
}
111-
112122
info := strings.Split(s, "___::___")
113123
data := make(map[string]interface{})
114124
if len(info) == 1 {
115125
data = nil
116126
} else {
117-
err := json.Unmarshal([]byte(info[1]), &data)
127+
s, err := opensslHandler.DecryptString(src.SecretKey, info[1])
118128
if err != nil {
129+
astilog.Errorf("Decrypt Error", err.Error())
130+
return err.Error()
131+
}
132+
if err := json.Unmarshal(s, &data); err != nil {
119133
astilog.Errorf("UnmarshalData Error", err.Error())
120134
return err.Error()
121135
}
122136
}
123137
return handler.Handle(info[0], data)
138+
//if info[0] != "/gek" {
139+
// sb, err := opensslHandler.EncryptString(src.SecretKey, rest)
140+
// if err != nil {
141+
// astilog.Errorf("Encrypt Error", err.Error())
142+
// return err.Error()
143+
// }
144+
// return string(sb)
145+
//}
146+
//return rest
124147
})
125-
126148
return nil
127149
},
128150
Windows: []*bootstrap.Window{{
@@ -158,3 +180,11 @@ func GetCacheDir() string {
158180
})
159181
return cacheDir
160182
}
183+
184+
func gek(_ map[string]interface{}) string {
185+
return src.JSON(src.ResponseData{
186+
Status: 200,
187+
Msg: "success",
188+
Data: src.SecretKey,
189+
})
190+
}

server/src/actions.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,18 @@ func RedisManagerConnectionList(_ map[string]interface{}) string {
114114
if err != nil {
115115
return JSON(ResponseData{5000, "获取列表失败:" + err.Error(), nil})
116116
}
117-
return JSON(ResponseData{200, "获取列表成功", connectionList})
117+
var conns []struct {
118+
ID int64 `json:"id"`
119+
Title string `json:"title"`
120+
}
121+
for _, conn := range connectionList {
122+
conns = append(conns, struct {
123+
ID int64 `json:"id"`
124+
Title string `json:"title"`
125+
}{ID: conn.ID, Title: conn.Title})
126+
}
127+
128+
return JSON(ResponseData{200, "获取列表成功", conns})
118129
}
119130

120131
func getFromInterfaceOrFloat64ToInt(id interface{}) int {

server/src/helper.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@ var (
1818
totalConnection = 0
1919
connectionList []connection
2020
ConnectionFile string
21+
SecretKey string
2122
)

server/src/openssl_test.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package src
2+
3+
import (
4+
"fmt"
5+
"github.com/Luzifer/go-openssl"
6+
"testing"
7+
)
8+
9+
func Test_ExampleOpenSSL_EncryptBytes(t *testing.T) {
10+
plaintext := "Hello World!"
11+
passphrase := "z4yH36a6zerhfE5427ZV"
12+
13+
o := openssl.New()
14+
15+
enc, err := o.EncryptBytes(passphrase, []byte(plaintext))
16+
if err != nil {
17+
fmt.Printf("An error occurred: %s\n", err)
18+
}
19+
20+
fmt.Printf("Encrypted text: %s\n", string(enc))
21+
}
22+
23+
func Test_ExampleOpenSSL_DecryptBytes(t *testing.T) {
24+
opensslEncrypted := "U2FsdGVkX1+5JiqOUtaMCsVQcqSUIaVR1spb7PBZQGE="
25+
passphrase := "z4yH36a6zerhfE5427ZV"
26+
27+
o := openssl.New()
28+
29+
dec, err := o.DecryptBytes(passphrase, []byte(opensslEncrypted))
30+
if err != nil {
31+
fmt.Printf("An error occurred: %s\n", err)
32+
}
33+
34+
fmt.Printf("Decrypted text: %s\n", string(dec))
35+
36+
// Output:
37+
// Decrypted text: hallowelt
38+
}

0 commit comments

Comments
 (0)