Skip to content

Commit

Permalink
删除无用依赖, 添加客户端提交到服务端数据aes加密
Browse files Browse the repository at this point in the history
  • Loading branch information
xiusin committed Feb 8, 2020
1 parent 197820c commit 40f66d9
Show file tree
Hide file tree
Showing 12 changed files with 179 additions and 449 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ test/unit/coverage
test/e2e/reports
selenium-debug.log
rdm-connections.json
server/rdm-log.log
server/data.db
server/resources/app/
server/resources/dist/
bind_*.go
windows.syso
/server/error.log
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ redis管理客户端, 基于[go-astilectron](https://github.com/asticode/go-ast
## BUG ##
1. http模式pubsub接口兼容, 调整订阅与发布顺序, 消除第一次发送消息失败的情况
2. 选中tree节点时无法高亮
3. 刷新value概率锁定按钮loading

## 伪redis-cli功能 ##
可以使用`help`查看可用的命令. 部分还原redis-cli的响应值.
Expand All @@ -14,7 +15,7 @@ redis管理客户端, 基于[go-astilectron](https://github.com/asticode/go-ast
- [ ] Electron Cpu占用率太高, windows 不关闭Electron进程
- [ ] redis-cli功能新增切换连接情况功能.(保持select 数据库的状态)
- [ ] 替换类库为(https://github.com/zserge/lorca), 精简文件大小与依赖

- [ ] 切换db清空cli的输入内容(暴露全局命令行对象)
## 原理图 ##
```
+-------------------------+
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@
"lint": "eslint --ext .js,.vue src test/unit/specs test/e2e/specs"
},
"dependencies": {
"axios": "^0.19.2",
"browser-update": "^2.1.4",
"html2canvas": "^1.0.0-alpha.12",
"crypto-js": "^3.1.9-1",
"iview": "^3.5.1",
"jquery": "^3.4.1",
"md5": "^2.2.1",
Expand Down
13 changes: 7 additions & 6 deletions server/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@ module github.com/xiusin/redis_manager/server
go 1.13

require (
github.com/apex/log v1.1.1
github.com/astaxie/beego v1.12.0
github.com/Luzifer/go-openssl v2.0.0+incompatible
github.com/asticode/go-astilectron v0.11.0
github.com/asticode/go-astilectron-bootstrap v0.3.0
github.com/asticode/go-astilectron-bundler v0.3.0
github.com/asticode/go-astilog v1.4.0
github.com/gomodule/redigo v2.0.0+incompatible
github.com/gorilla/websocket v1.4.1
github.com/kr/pretty v0.1.0 // indirect
github.com/mattn/go-isatty v0.0.11 // indirect
github.com/pkg/errors v0.8.1
github.com/rs/cors v1.7.0 // indirect
github.com/shiena/ansicolor v0.0.0-20151119151921-a422bbe96644 // indirect
github.com/xiusin/iriscms v0.0.0-20200108141855-2cc75e14d21a
github.com/rs/cors v1.7.0
golang.org/x/crypto v0.0.0-20191206172530-e9b2fee46413 // indirect
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
gopkg.in/yaml.v2 v2.2.7 // indirect
)
352 changes: 6 additions & 346 deletions server/go.sum

Large diffs are not rendered by default.

56 changes: 43 additions & 13 deletions server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,19 @@ package main
import (
"encoding/json"
"fmt"
"github.com/Luzifer/go-openssl"
"github.com/asticode/go-astilectron"
bootstrap "github.com/asticode/go-astilectron-bootstrap"
"github.com/asticode/go-astilog"
"github.com/pkg/errors"
"github.com/xiusin/redis_manager/server/src"
"log"
"math/rand"
"os"
"path/filepath"
"strings"
"sync"
"time"
)

const DEBUG = true
Expand All @@ -23,13 +26,23 @@ var cacheDir string

var handler = src.NewHandler()

const SecretLen = 32

var secretKey []byte

func init() {
cacheDir = GetCacheDir()

salt := "ABCEDFGHIJKLMNOPQRSTUVWXYZ0123456789"
l := len(salt)
rand.Seed(time.Now().UnixNano())
for i := 0; i < SecretLen; i++ {
secretKey = append(secretKey, salt[rand.Int63n(int64(l))])
}
src.SecretKey = string(secretKey)
astilog.SetLogger(astilog.New(astilog.Configuration{
AppName: "RedisManager",
Filename: fmt.Sprintf("%s/rdm-log.log", cacheDir),
Verbose: DEBUG,
Filename: fmt.Sprintf("%s/error.log", cacheDir),
Verbose: false,
}))
astilog.FlagConfig()

Expand All @@ -47,10 +60,10 @@ func init() {
"/redis/connection/command": src.RedisManagerCommand,
"/redis/connection/pubsub": src.RedisPubSub,
"/redis/connection/info": src.RedisManagerGetInfo,
"/gek": gek,
"/redis/connection/get-command": src.RedisManagerGetCommandList,
}


for route, handle := range routes {
handler.Add(route, handle)
}
Expand All @@ -72,9 +85,6 @@ func main() {
} else {
url = "index.html"
}
//else {
// url = cacheDir + "/resources/dist/index.html"
//}
center, HasShadow, Fullscreenable, Closable, skipTaskBar := true, true, true, true, true
height, width := 800, 1280

Expand All @@ -91,38 +101,50 @@ func main() {
return
})
a.On(astilectron.EventNameAppClose, func(e astilectron.Event) (deleteListener bool) {
a.Close()
fmt.Println("astilectron.EventNameAppClose")
return
})
a.On(astilectron.EventNameAppCmdQuit, func(e astilectron.Event) (deleteListener bool) {
a.Close()
fmt.Println("astilectron.EventNameAppCmdQuit")
return
})

src.Window = ws[0]
if DEBUG {
src.Window.OpenDevTools()
}
ws[0].OnMessage(func(m *astilectron.EventMessage) (v interface{}) {
opensslHandler := openssl.New()
var s string
err := m.Unmarshal(&s)
if err != nil {
return "{}"
}

info := strings.Split(s, "___::___")
data := make(map[string]interface{})
if len(info) == 1 {
data = nil
} else {
err := json.Unmarshal([]byte(info[1]), &data)
s, err := opensslHandler.DecryptString(src.SecretKey, info[1])
if err != nil {
astilog.Errorf("Decrypt Error", err.Error())
return err.Error()
}
if err := json.Unmarshal(s, &data); err != nil {
astilog.Errorf("UnmarshalData Error", err.Error())
return err.Error()
}
}
return handler.Handle(info[0], data)
//if info[0] != "/gek" {
// sb, err := opensslHandler.EncryptString(src.SecretKey, rest)
// if err != nil {
// astilog.Errorf("Encrypt Error", err.Error())
// return err.Error()
// }
// return string(sb)
//}
//return rest
})

return nil
},
Windows: []*bootstrap.Window{{
Expand Down Expand Up @@ -158,3 +180,11 @@ func GetCacheDir() string {
})
return cacheDir
}

func gek(_ map[string]interface{}) string {
return src.JSON(src.ResponseData{
Status: 200,
Msg: "success",
Data: src.SecretKey,
})
}
13 changes: 12 additions & 1 deletion server/src/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,18 @@ func RedisManagerConnectionList(_ map[string]interface{}) string {
if err != nil {
return JSON(ResponseData{5000, "获取列表失败:" + err.Error(), nil})
}
return JSON(ResponseData{200, "获取列表成功", connectionList})
var conns []struct {
ID int64 `json:"id"`
Title string `json:"title"`
}
for _, conn := range connectionList {
conns = append(conns, struct {
ID int64 `json:"id"`
Title string `json:"title"`
}{ID: conn.ID, Title: conn.Title})
}

return JSON(ResponseData{200, "获取列表成功", conns})
}

func getFromInterfaceOrFloat64ToInt(id interface{}) int {
Expand Down
1 change: 1 addition & 0 deletions server/src/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ var (
totalConnection = 0
connectionList []connection
ConnectionFile string
SecretKey string
)
38 changes: 38 additions & 0 deletions server/src/openssl_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package src

import (
"fmt"
"github.com/Luzifer/go-openssl"
"testing"
)

func Test_ExampleOpenSSL_EncryptBytes(t *testing.T) {
plaintext := "Hello World!"
passphrase := "z4yH36a6zerhfE5427ZV"

o := openssl.New()

enc, err := o.EncryptBytes(passphrase, []byte(plaintext))
if err != nil {
fmt.Printf("An error occurred: %s\n", err)
}

fmt.Printf("Encrypted text: %s\n", string(enc))
}

func Test_ExampleOpenSSL_DecryptBytes(t *testing.T) {
opensslEncrypted := "U2FsdGVkX1+5JiqOUtaMCsVQcqSUIaVR1spb7PBZQGE="
passphrase := "z4yH36a6zerhfE5427ZV"

o := openssl.New()

dec, err := o.DecryptBytes(passphrase, []byte(opensslEncrypted))
if err != nil {
fmt.Printf("An error occurred: %s\n", err)
}

fmt.Printf("Decrypted text: %s\n", string(dec))

// Output:
// Decrypted text: hallowelt
}
Loading

0 comments on commit 40f66d9

Please sign in to comment.