Skip to content

Commit

Permalink
Merge pull request #2 from Halo1236/pr@dev@stage
Browse files Browse the repository at this point in the history
Pr@dev@stage
  • Loading branch information
Halo1236 authored Aug 8, 2023
2 parents fcda680 + f3a244e commit 581580d
Show file tree
Hide file tree
Showing 20 changed files with 460 additions and 151 deletions.
172 changes: 165 additions & 7 deletions go-client/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +161,171 @@
]
},
"macos": {
"terminal": [],
"remotedesktop": [],
"databases": []
"terminal": [
{
"name": "terminal",
"display_name": "Terminal",
"protocol": [
"ssh"
],
"comment": "Terminal是MacOS操作系统上的虚拟终端应用软件,位于“实用工具”文件夹内。",
"download_url": "内置",
"type": "linux",
"path": "Terminal",
"arg_format": "-{protocol} {username}@{host} -P {port} -pw {value}",
"match_first": [],
"is_internal": true,
"is_default": true,
"is_set": true
},
{
"name": "securecrt",
"display_name": "SecureCRT",
"protocol": [
"ssh"
],
"comment": "SecureCRT是VanDyke Software所开发销售的一个SSH、Telnet客户端和虚拟终端软件。\n\n!!!手动下载安装,点击保存启用!!!",
"download_url": "https://www.vandyke.com/cgi-bin/releases.php?product=securecrt",
"type": "linux",
"path": "/Applications/SecureCRT.app/Contents/MacOS/SecureCRT",
"arg_format": "/N {name} /T /SSH2 /ACCEPTHOSTKEYS /p {port} /password {value} /L {username} {host}",
"match_first": [],
"is_internal": false,
"is_default": false,
"is_set": false
}
],
"remotedesktop": [
{
"name": "mstsc",
"display_name": "Microsoft Remote Desktop",
"protocol": [
"rdp"
],
"comment": "Microsoft Remote Desktop是一款强大的微软远程连接工具,可以从几乎任何地方连接到远程PC和您的工作资源。\n\n!!!手动下载安装,点击保存启用!!!",
"download_url": "内置",
"type": "windows",
"path": "/Applications/Microsoft Remote Desktop.app",
"arg_format": "",
"match_first": [],
"is_internal": true,
"is_default": true,
"is_set": false
}
],
"filetransfer": [
{
"name": "filezilla",
"display_name": "Filezilla",
"protocol": [
"sftp"
],
"comment": "FileZilla Client是一款免费、开源的 FTP 客户端。它支持FTP、SFTP。\n\n!!!手动下载安装,点击保存启用!!!",
"download_url": "https://filezilla-project.org/download.php?type=client",
"type": "linux",
"path": "/Applications/FileZilla.app/Contents/MacOS/filezilla",
"arg_format": "{protocol}://{username}:{value}@{host}:{port}",
"match_first": [],
"is_internal": false,
"is_default": false,
"is_set": false
}
],
"databases": [
{
"name": "dbeaver",
"display_name": "DBeaver Community",
"protocol": [
"oracle",
"mysql",
"postgresql",
"mariadb"
],
"comment": "DBeaver Community是一个通用的数据库管理工具和SQL客户端,支持MySQL、PostgreSQL、Oracle以及其他兼容JDBC的数据库。\n\n!!!手动下载安装,点击保存启用!!!",
"download_url": "https://dbeaver.io/download/",
"type": "databases",
"path": "/Applications/DBeaver.app/Contents/MacOS/dbeaver",
"arg_format": "-con name={name}|driver={protocol}|user={username}|password={value}|database={dbname}|host={host}|port={port}|save=false|connect=true",
"match_first": [],
"is_internal": false,
"is_default": false,
"is_set": false
}
]
},
"linux": {
"terminal": [],
"remotedesktop": [],
"databases": []
"terminal": [
{
"name": "terminal",
"display_name": "Terminal",
"protocol": [
"ssh"
],
"comment": "Terminal是MacOS操作系统上的虚拟终端应用软件,位于“实用工具”文件夹内。",
"download_url": "内置",
"type": "linux",
"path": "Terminal",
"arg_format": "-{protocol} {username}@{host} -P {port} -pw {value}",
"match_first": [],
"is_internal": true,
"is_default": true,
"is_set": true
}
],
"remotedesktop": [ {
"name": "remmina",
"display_name": "Remmina",
"protocol": [
"rdp"
],
"comment": "Remmina 是一个使用 GTK+ 开发的远程桌面客户端,提供了 RDP、VNC、XDMCP、SSH 等远程连接协议的支持。",
"download_url": "https://remmina.org/how-to-install-remmina/-内置",
"type": "windows",
"path": "remmina",
"arg_format": "",
"match_first": [],
"is_internal": true,
"is_default": true,
"is_set": true
}],
"filetransfer": [
{
"name": "filezilla",
"display_name": "Filezilla",
"protocol": [
"sftp"
],
"comment": "FileZilla Client是一款免费、开源的 FTP 客户端。它支持FTP、SFTP。",
"download_url": "https://filezilla-project.org/download.php?type=client",
"type": "linux",
"path": "",
"arg_format": "{protocol}://{username}:{value}@{host}:{port}",
"match_first": [],
"is_internal": false,
"is_default": false,
"is_set": false
}
],
"databases": [
{
"name": "dbeaver",
"display_name": "DBeaver Community",
"protocol": [
"oracle",
"mysql",
"postgresql",
"mariadb"
],
"comment": "DBeaver Community是一个通用的数据库管理工具和SQL客户端,支持MySQL、PostgreSQL、Oracle以及其他兼容JDBC的数据库。",
"download_url": "https://dbeaver.io/download/",
"type": "databases",
"path": "",
"arg_format": "-con name={name}|driver={protocol}|user={username}|password={value}|database={dbname}|host={host}|port={port}|save=false|connect=true",
"match_first": [],
"is_internal": false,
"is_default": false,
"is_set": false
}
]
}
}
}
11 changes: 1 addition & 10 deletions go-client/pkg/awaken/awaken.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,7 @@ func (r *Rouse) HandleSSH(appConfig *config.AppConfig) {
}

func (r *Rouse) HandleDB(appConfig *config.AppConfig) {
command := r.Command
switch r.Protocol {
case "mysql", "mariadb":
command = structureMySQLCommand(command)
case "postgresql":
command = structurePostgreSQLCommand(command)
case "redis":
command = structureRedisCommand(command)
}
cmd := handleDB(r, command, appConfig)
cmd := handleDB(r, appConfig)
cmd.Run()
}

Expand Down
86 changes: 81 additions & 5 deletions go-client/pkg/awaken/awaken_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,95 @@ package awaken
import (
"fmt"
"go-client/global"
"go-client/pkg/config"
"os/exec"
"path/filepath"
"strconv"
"strings"
)

func getCommandFromArgs(connectInfo map[string]string, argFormat string) string {
for key, value := range connectInfo {
argFormat = strings.Replace(argFormat, "{"+key+"}", value, 1)
}
return argFormat
}

func awakenRDPCommand(filePath string) *exec.Cmd {
global.LOG.Debug(filePath)
cmd := exec.Command("open", filePath)
return cmd
}

func awakenCommand(command string) *exec.Cmd {
cmd := exec.Command(
"osascript", "-s", "h", "-e",
fmt.Sprintf(`tell application "Terminal" to do script "%s"`, command),
)
func awakenSSHCommand(r *Rouse, currentPath string, cfg *config.AppConfig) *exec.Cmd {
var appItem *config.AppItem
var appLst []config.AppItem
switch r.Protocol {
case "ssh":
appLst = cfg.MacOS.Terminal
case "sftp":
appLst = cfg.MacOS.FileTransfer
}

for _, app := range appLst {
if app.IsActive() && app.IsSupportProtocol(r.Protocol) {
appItem = &app
break
}
}
if appItem == nil {
return nil
}
var cmd *exec.Cmd
if appItem.IsInternal {
clientPath := filepath.Join(currentPath, "client")
command := fmt.Sprintf("%s %s -P %s", clientPath, r.Command, r.Value)
cmd = exec.Command(
"osascript", "-s", "h",
"-e", fmt.Sprintf(`tell application "%s" to do script "%s"`, appItem.DisplayName, command),
)
} else {
var appPath string
appPath = appItem.Path

connectMap := map[string]string{
"name": r.Name,
"protocol": r.Protocol,
"username": r.Username,
"value": r.Value,
"host": r.Host,
"port": strconv.Itoa(r.Port),
}
commands := getCommandFromArgs(connectMap, appItem.ArgFormat)
appPath = appItem.Path
cmd = exec.Command(appPath, strings.Split(commands, " ")...)
}
return cmd
}

func awakenDBCommand(r *Rouse, cfg *config.AppConfig) *exec.Cmd {
var appItem *config.AppItem
appLst := cfg.MacOS.Databases
for _, app := range appLst {
if app.IsSet && app.IsMatchProtocol(r.Protocol) {
appItem = &app
break
}
}
if appItem == nil {
return nil
}
appPath := appItem.Path

connectMap := map[string]string{
"name": r.Name,
"protocol": r.Protocol,
"username": r.Username,
"value": r.Value,
"host": r.Host,
"port": strconv.Itoa(r.Port),
"dbname": r.DBName,
}
commands := getCommandFromArgs(connectMap, appItem.ArgFormat)
return exec.Command(appPath, strings.Split(commands, " ")...)
}
41 changes: 40 additions & 1 deletion go-client/pkg/awaken/awaken_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,29 @@ package awaken
import (
"fmt"
"go-client/global"
"go-client/pkg/config"
"os/exec"
"path/filepath"
"strconv"
"strings"
)

func getCommandFromArgs(connectInfo map[string]string, argFormat string) string {
for key, value := range connectInfo {
argFormat = strings.Replace(argFormat, "{"+key+"}", value, 1)
}
return argFormat
}

func awakenRDPCommand(filePath string) *exec.Cmd {
global.LOG.Debug(filePath)
cmd := exec.Command("remmina", filePath)
return cmd
}

func awakenCommand(command string) *exec.Cmd {
func awakenSSHCommand(r *Rouse, currentPath string, cfg *config.AppConfig) *exec.Cmd {
clientPath := filepath.Join(currentPath, "client")
command := fmt.Sprintf("%s %s -P %s", clientPath, r.Command, r.Value)
cmd := new(exec.Cmd)
out, _ := exec.Command("bash", "-c", "echo $XDG_CURRENT_DESKTOP").CombinedOutput()
currentDesktop := strings.ToLower(strings.Trim(string(out), "\n"))
Expand All @@ -32,3 +44,30 @@ func awakenCommand(command string) *exec.Cmd {
}
return cmd
}

func awakenDBCommand(r *Rouse, cfg *config.AppConfig) *exec.Cmd {
var appItem *config.AppItem
appLst := cfg.Windows.Databases
for _, app := range appLst {
if app.IsSet && app.IsMatchProtocol(r.Protocol) {
appItem = &app
break
}
}
if appItem == nil {
return nil
}
appPath := appItem.Path

connectMap := map[string]string{
"name": r.Name,
"protocol": r.Protocol,
"username": r.Username,
"value": r.Value,
"host": r.Host,
"port": strconv.Itoa(r.Port),
"dbname": r.DBName,
}
commands := getCommandFromArgs(connectMap, appItem.ArgFormat)
return exec.Command(appPath, strings.Split(commands, " ")...)
}
Loading

0 comments on commit 581580d

Please sign in to comment.