diff --git a/backend/services/connection_service.go b/backend/services/connection_service.go index 5f7732d..659f0bb 100644 --- a/backend/services/connection_service.go +++ b/backend/services/connection_service.go @@ -122,12 +122,14 @@ func (c *connectionService) buildOption(config types.ConnectionConfig) (*redis.O } option := &redis.Options{ - Username: config.Username, - Password: config.Password, - DialTimeout: time.Duration(config.ConnTimeout) * time.Second, - ReadTimeout: time.Duration(config.ExecTimeout) * time.Second, - WriteTimeout: time.Duration(config.ExecTimeout) * time.Second, - TLSConfig: tlsConfig, + Username: config.Username, + Password: config.Password, + DialTimeout: time.Duration(config.ConnTimeout) * time.Second, + ReadTimeout: time.Duration(config.ExecTimeout) * time.Second, + WriteTimeout: time.Duration(config.ExecTimeout) * time.Second, + TLSConfig: tlsConfig, + DisableIndentity: true, + IdentitySuffix: "tinyrdm_", } if config.Network == "unix" { option.Network = "unix" @@ -138,10 +140,14 @@ func (c *connectionService) buildOption(config types.ConnectionConfig) (*redis.O } } else { option.Network = "tcp" + port := 6379 + if config.Port > 0 { + port = config.Port + } if len(config.Addr) <= 0 { - option.Addr = fmt.Sprintf("127.0.0.1:%d", config.Port) + option.Addr = fmt.Sprintf("127.0.0.1:%d", port) } else { - option.Addr = fmt.Sprintf("%s:%d", config.Addr, config.Port) + option.Addr = fmt.Sprintf("%s:%d", config.Addr, port) } } if sshClient != nil { diff --git a/backend/utils/convert/cmd_convert.go b/backend/utils/convert/cmd_convert.go index 0986560..fb111de 100644 --- a/backend/utils/convert/cmd_convert.go +++ b/backend/utils/convert/cmd_convert.go @@ -2,10 +2,6 @@ package convutil import ( "encoding/base64" - "github.com/vrischmann/userdir" - "os" - "os/exec" - "path" "strings" sliceutil "tinyrdm/backend/utils/slice" ) @@ -39,8 +35,7 @@ func (c CmdConvert) Encode(str string) (string, bool) { if len(args) <= 0 || !containHolder { args = append(args, base64Content) } - cmd := exec.Command(c.EncodePath, args...) - output, err := cmd.Output() + output, err := runCommand(c.EncodePath, args...) if err != nil || len(output) <= 0 || string(output) == "[RDM-ERROR]" { return str, false } @@ -67,8 +62,7 @@ func (c CmdConvert) Decode(str string) (string, bool) { if len(args) <= 0 || !containHolder { args = append(args, base64Content) } - cmd := exec.Command(c.DecodePath, args...) - output, err := cmd.Output() + output, err := runCommand(c.DecodePath, args...) if err != nil || len(output) <= 0 || string(output) == "[RDM-ERROR]" { return str, false } @@ -80,13 +74,3 @@ func (c CmdConvert) Decode(str string) (string, bool) { } return string(outputContent[:n]), true } - -func (c CmdConvert) writeExecuteFile(content []byte, filename string) (string, error) { - filepath := path.Join(userdir.GetConfigHome(), "TinyRDM", "decoder", filename) - _ = os.Mkdir(path.Dir(filepath), 0777) - err := os.WriteFile(filepath, content, 0777) - if err != nil { - return "", err - } - return filepath, nil -} diff --git a/backend/utils/convert/common.go b/backend/utils/convert/common.go new file mode 100644 index 0000000..61bf01c --- /dev/null +++ b/backend/utils/convert/common.go @@ -0,0 +1,17 @@ +package convutil + +import ( + "github.com/vrischmann/userdir" + "os" + "path" +) + +func writeExecuteFile(content []byte, filename string) (string, error) { + filepath := path.Join(userdir.GetConfigHome(), "TinyRDM", "decoder", filename) + _ = os.Mkdir(path.Dir(filepath), 0777) + err := os.WriteFile(filepath, content, 0777) + if err != nil { + return "", err + } + return filepath, nil +} diff --git a/backend/utils/convert/common_nonwindows.go b/backend/utils/convert/common_nonwindows.go new file mode 100644 index 0000000..b03e2ba --- /dev/null +++ b/backend/utils/convert/common_nonwindows.go @@ -0,0 +1,12 @@ +//go:build !windows + +package convutil + +import ( + "os/exec" +) + +func runCommand(name string, arg ...string) ([]byte, error) { + cmd := exec.Command(name, arg...) + return cmd.Output() +} diff --git a/backend/utils/convert/common_windows.go b/backend/utils/convert/common_windows.go new file mode 100644 index 0000000..3d7581c --- /dev/null +++ b/backend/utils/convert/common_windows.go @@ -0,0 +1,14 @@ +//go:build windows + +package convutil + +import ( + "os/exec" + "syscall" +) + +func runCommand(name string, arg ...string) ([]byte, error) { + cmd := exec.Command(name, arg...) + cmd.SysProcAttr = &syscall.SysProcAttr{HideWindow: true} + return cmd.Output() +} diff --git a/backend/utils/convert/php_convert.go b/backend/utils/convert/php_convert.go index 041e638..2e74359 100644 --- a/backend/utils/convert/php_convert.go +++ b/backend/utils/convert/php_convert.go @@ -1,9 +1,5 @@ package convutil -import ( - "os/exec" -) - type PhpConvert struct { CmdConvert } @@ -51,12 +47,12 @@ func NewPhpConvert() *PhpConvert { } var err error - if err = exec.Command(c.DecodePath, "-v").Err; err != nil { + if _, err = runCommand(c.DecodePath, "-v"); err != nil { return nil } var filepath string - if filepath, err = c.writeExecuteFile([]byte(phpDecodeCode), "php_decoder.php"); err != nil { + if filepath, err = writeExecuteFile([]byte(phpDecodeCode), "php_decoder.php"); err != nil { return nil } c.DecodeArgs = []string{filepath, "decode"} diff --git a/backend/utils/convert/pickle_convert.go b/backend/utils/convert/pickle_convert.go index d8f56bf..e17cf13 100644 --- a/backend/utils/convert/pickle_convert.go +++ b/backend/utils/convert/pickle_convert.go @@ -1,7 +1,5 @@ package convutil -import "os/exec" - type PickleConvert struct { CmdConvert } @@ -42,18 +40,18 @@ func NewPickleConvert() *PickleConvert { } c.DecodePath, c.EncodePath = "python3", "python3" var err error - if err = exec.Command(c.DecodePath, "--version").Err; err != nil { + if _, err = runCommand(c.DecodePath, "--version"); err != nil { c.DecodePath, c.EncodePath = "python", "python" - if err = exec.Command(c.DecodePath, "--version").Err; err != nil { + if _, err = runCommand(c.DecodePath, "--version"); err != nil { return nil } } // check if pickle available - if err = exec.Command(c.DecodePath, "-c", "import pickle").Err; err != nil { + if _, err = runCommand(c.DecodePath, "-c", "import pickle"); err != nil { return nil } var filepath string - if filepath, err = c.writeExecuteFile([]byte(pickleDecodeCode), "pickle_decoder.py"); err != nil { + if filepath, err = writeExecuteFile([]byte(pickleDecodeCode), "pickle_decoder.py"); err != nil { return nil } c.DecodeArgs = []string{filepath, "decode"} diff --git a/frontend/src/consts/support_redis_type.js b/frontend/src/consts/support_redis_type.js index 00b1f0b..b3ffcb0 100644 --- a/frontend/src/consts/support_redis_type.js +++ b/frontend/src/consts/support_redis_type.js @@ -33,7 +33,7 @@ export const typesColor = { [types.SET]: '#F59E0B', [types.ZSET]: '#EF4444', [types.STREAM]: '#EC4899', - [types.JSON]: '#374254', + [types.JSON]: '#828766', } /** @@ -47,7 +47,7 @@ export const typesBgColor = { [types.SET]: '#FDF1DF', [types.ZSET]: '#FAEAED', [types.STREAM]: '#FDE6F1', - [types.JSON]: '#C1C1D3', + [types.JSON]: '#ECECD9', } // export const typesName = Object.fromEntries(Object.entries(types).map(([key, value]) => [key, value.name]))