Skip to content

Commit

Permalink
Merge pull request #10 from jumpserver/dev
Browse files Browse the repository at this point in the history
perf: api返回数据结构
  • Loading branch information
Halo1236 authored Aug 16, 2023
2 parents bf41b51 + 1a01290 commit b02527b
Show file tree
Hide file tree
Showing 15 changed files with 391 additions and 185 deletions.
3 changes: 3 additions & 0 deletions go-client/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,6 @@ build-client:

GOARCH=arm64 GOOS=linux $(CLIENTBUILD) -ldflags "$(LDFLAGS)" -o $(BUILDDIR)/linux-arm64/JumpServerClient $(CLIENTSRCFILE)
GOARCH=arm64 GOOS=linux $(CLIENTBUILD) -ldflags "$(LDFLAGS)" -o $(BUILDDIR)/linux-arm64/client $(SSHCSRCFILE)

cp -R $(BUILDDIR)/* $(BASEPATH)/../interface/bin/
cp $(BASEPATH)/config.json $(BASEPATH)/../interface/bin/
159 changes: 81 additions & 78 deletions go-client/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,23 @@
"filename": "Jumpserve Clients Config",
"windows": {
"terminal": [
{
"name": "putty",
"display_name": "PuTTY",
"protocol": [
"ssh",
"telnet"
],
"comment": "PuTTY是一个Telnet、SSH、rlogin纯TCP以及串行阜连线软件。",
"download_url": "内置",
"type": "linux",
"path": "putty.exe",
"arg_format": "-{protocol} {username}@{host} -P {port} -pw {value}",
"match_first": [],
"is_internal": true,
"is_default": true,
"is_set": true
},
{
"name": "xshell",
"display_name": "XShell",
Expand Down Expand Up @@ -35,23 +52,6 @@
"is_internal": false,
"is_default": false,
"is_set": false
},
{
"name": "putty",
"display_name": "PuTTY",
"protocol": [
"ssh",
"telnet"
],
"comment": "PuTTY是一个Telnet、SSH、rlogin纯TCP以及串行阜连线软件。",
"download_url": "内置",
"type": "linux",
"path": "putty.exe",
"arg_format": "-{protocol} {username}@{host} -P {port} -pw {value}",
"match_first": [],
"is_internal": true,
"is_default": true,
"is_set": true
}
],
"remotedesktop": [
Expand Down Expand Up @@ -172,27 +172,11 @@
"download_url": "内置",
"type": "linux",
"path": "Terminal",
"arg_format": "-{protocol} {username}@{host} -P {port} -pw {value}",
"arg_format": "{protocol} {username}@{host} -p {port} -P {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": [
Expand All @@ -210,7 +194,7 @@
"match_first": [],
"is_internal": true,
"is_default": true,
"is_set": false
"is_set": true
}
],
"filetransfer": [
Expand All @@ -232,6 +216,32 @@
}
],
"databases": [
{
"name": "terminal",
"display_name": "Terminal",
"protocol": [
"oracle",
"mysql",
"postgresql",
"mariadb",
"redis"
],
"comment": "Terminal是MacOS操作系统上的虚拟终端应用软件,位于“实用工具”文件夹内。",
"download_url": "内置",
"type": "linux",
"path": "Terminal",
"arg_format": "",
"match_first": [
"oracle",
"mysql",
"postgresql",
"mariadb",
"redis"
],
"is_internal": true,
"is_default": false,
"is_set": true
},
{
"name": "dbeaver",
"display_name": "DBeaver Community",
Expand All @@ -246,7 +256,8 @@
"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": [],
"match_first": [
],
"is_internal": false,
"is_default": false,
"is_set": false
Expand All @@ -261,71 +272,63 @@
"protocol": [
"ssh"
],
"comment": "Terminal是MacOS操作系统上的虚拟终端应用软件,位于“实用工具”文件夹内",
"comment": "Terminal是Linux操作系统上的虚拟终端应用软件",
"download_url": "内置",
"type": "linux",
"path": "Terminal",
"arg_format": "-{protocol} {username}@{host} -P {port} -pw {value}",
"arg_format": "{protocol} {username}@{host} -p {port} -P {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": [
"remotedesktop": [
{
"name": "filezilla",
"display_name": "Filezilla",
"name": "remmina",
"display_name": "Remmina",
"protocol": [
"sftp"
"rdp"
],
"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}",
"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": false,
"is_default": false,
"is_set": false
"is_internal": true,
"is_default": true,
"is_set": true
}
],
"filetransfer": [],
"databases": [
{
"name": "dbeaver",
"display_name": "DBeaver Community",
"name": "terminal",
"display_name": "Terminal",
"protocol": [
"oracle",
"mysql",
"postgresql",
"mariadb"
"mariadb",
"redis"
],
"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,
"comment": "Terminal是Linux操作系统上的虚拟终端应用软件。",
"download_url": "内置",
"type": "linux",
"path": "Terminal",
"arg_format": "",
"match_first": [
"oracle",
"mysql",
"postgresql",
"mariadb",
"redis"
],
"is_internal": true,
"is_default": false,
"is_set": false
"is_set": true
}
]
}
}
}
88 changes: 63 additions & 25 deletions go-client/pkg/awaken/awaken.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"go-client/global"
"go-client/pkg/config"
"io/ioutil"
"net/url"
"os"
"path/filepath"
"regexp"
Expand All @@ -25,31 +26,59 @@ type File struct {
Content string `json:"content"`
}

type Info struct {
type Endpoint struct {
Host string `json:"host"`
Port int `json:"port"`
}

type Token struct {
ID string `json:"id"`
Value string `json:"value"`
}

type Asset struct {
ID string `json:"id"`
Category string `json:"category"`
Type string `json:"type"`
Name string `json:"name"`
Address string `json:"address"`
DBInfo `json:"info"`
}

type DBInfo struct {
DBName string `json:"db_name"`
UseSsl string `json:"use_ssl"`
AllowInvalidCert string `json:"allow_invalid_cert"`
}

type Info struct {
Version string `json:"version"`
Name string `json:"name"`
Value string `json:"value"`
Protocol string `json:"protocol"`
Host string `json:"host"`
Port int `json:"port"`
Username string `json:"username"`
Command string `json:"command"`
DBName string `json:"dbname"`
Asset `json:"asset"`
Endpoint `json:"endpoint"`
Token `json:"token"`
File `json:"file"`
}

type DBCommand struct {
User string `json:"user"`
Password string `json:"password"`
Host string `json:"host"`
Port string `json:"port"`
DBName string `json:"dbname"`
}

type Rouse struct {
Info
}

func (r *Rouse) getUserName() string {
username := r.Token.ID
if r.Protocol == "ssh" || r.Protocol == "sftp" {
username = "JMS-" + username
}
return username
}

func (r *Rouse) getName() string {
name, _ := url.QueryUnescape(r.Name)
return name
}

func removeCurRdpFile() {
re := regexp.MustCompile(".*\\.rdp$")
dir := filepath.Dir(os.Args[0])
Expand All @@ -63,7 +92,8 @@ func removeCurRdpFile() {

func (r *Rouse) HandleRDP(appConfig *config.AppConfig) {
removeCurRdpFile()
filePath := filepath.Join(filepath.Dir(os.Args[0]), r.File.Name+".rdp")
fileName, _ := url.QueryUnescape(r.File.Name)
filePath := filepath.Join(filepath.Dir(os.Args[0]), fileName+".rdp")
err := ioutil.WriteFile(filePath, []byte(r.Content), os.ModePerm)
if err != nil {
global.LOG.Error(err.Error())
Expand All @@ -74,8 +104,7 @@ func (r *Rouse) HandleRDP(appConfig *config.AppConfig) {
}

func (r *Rouse) HandleSSH(appConfig *config.AppConfig) {
currentPath := filepath.Dir(os.Args[0])
cmd := handleSSH(r, currentPath, appConfig)
cmd := handleSSH(r, appConfig)
cmd.Run()
}

Expand All @@ -84,16 +113,25 @@ func (r *Rouse) HandleDB(appConfig *config.AppConfig) {
cmd.Run()
}

func (r *Rouse) HandleCommand(appConfig *config.AppConfig) {
cmd := handleCommand(r, appConfig)
cmd.Run()
}

func (r *Rouse) Run() {
protocol := r.Protocol
appConfig := config.GetConf()

switch protocol {
case "rdp":
r.HandleRDP(&appConfig)
case "ssh", "sftp":
r.HandleSSH(&appConfig)
case "mysql", "mariadb", "postgresql", "redis", "oracle", "sqlserver":
r.HandleDB(&appConfig)
if r.Command == "" {
switch protocol {
case "rdp":
r.HandleRDP(&appConfig)
case "ssh", "sftp":
r.HandleSSH(&appConfig)
case "mysql", "mariadb", "postgresql", "redis", "oracle", "sqlserver":
r.HandleDB(&appConfig)
}
} else {
r.HandleCommand(&appConfig)
}

}
Loading

0 comments on commit b02527b

Please sign in to comment.