Skip to content

Commit

Permalink
Merge pull request #47 from jumpserver/dev
Browse files Browse the repository at this point in the history
merge dev
  • Loading branch information
Halo1236 authored Oct 20, 2024
2 parents f28d087 + 7988189 commit 008d53e
Show file tree
Hide file tree
Showing 10 changed files with 326 additions and 20 deletions.
3 changes: 2 additions & 1 deletion go-client/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ build-client:
cp -R $(BASEPATH)/Scripts $(BUILDDIR)/darwin
cp -R $(BUILDDIR)/* $(BASEPATH)/../interface/bin/
cp $(BASEPATH)/config.json $(BASEPATH)/../interface/bin/
cp $(BASEPATH)/putty.exe $(BASEPATH)/../interface/bin/windows/
cp $(BASEPATH)/putty.exe $(BASEPATH)/../interface/bin/windows/
cp $(BASEPATH)/pkg/autoit/*.dll $(BASEPATH)/../interface/bin/windows/
38 changes: 35 additions & 3 deletions go-client/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -227,18 +227,50 @@
},
{
"name": "ssms17",
"display_name": "SQL Server Management Studio 17",
"display_name": "SQL Server Management Studio",
"protocol": [
"sqlserver"
],
"comment": {
"zh": "SQL Server Management Studio (SSMS) 是一种集成环境,用于管理从 SQL Server 到 Azure SQL 数据库的任何 SQL 基础结构。",
"en": "SQL Server Management Studio (SSMS) is an integrated environment for managing any SQL infrastructure, from SQL Server to Azure SQL Database."
},
"download_url": "https://download.microsoft.com/download/D/D/4/DD495084-ADA7-4827-ADD3-FC566EC05B90/SSMS-Setup-CHS.exe",
"download_url": "https://download.microsoft.com/download/9/f/8/9f8197f4-0f71-42a3-8717-b2817c77b820/SSMS-Setup-CHS.exe",
"type": "databases",
"path": "",
"arg_format": "-S {host},{port} -U {username} -P {value} -d {dbname}",
"arg_format": "",
"autoit": [
{
"cmd": "Wait",
"type": "sleep",
"element": "[REGEXPTITLE:连接到服务器|Connect]"
},
{
"cmd": "ControlSend",
"type": "{host},{port}",
"element": "[CLASS:Edit; INSTANCE:1]"
},
{
"cmd": "ControlSend",
"type": "SQL Server",
"element": "[NAME:comboBoxAuthentication]"
},
{
"cmd": "ControlSend",
"type": "{username}",
"element": "[CLASS:Edit; INSTANCE:2]"
},
{
"cmd": "ControlSend",
"type": "{value}",
"element": "[NAME:password]"
},
{
"cmd": "ControlClick",
"type": "connect",
"element": "[NAME:connect]"
}
],
"match_first": [],
"is_internal": false,
"is_default": false,
Expand Down
19 changes: 19 additions & 0 deletions go-client/go.sum
Original file line number Diff line number Diff line change
@@ -1,27 +1,38 @@
github.com/adrianriobo/goautoit v0.0.0-20210415141646-fc37def5a975 h1:3k1SNJREvY7Vb068kqfS4xXPJVIPhBXUBUHpyvV8W/w=
github.com/adrianriobo/goautoit v0.0.0-20210415141646-fc37def5a975/go.mod h1:tKnCmOA6c/aHEc/rnnRjPMVG3YfAfCMMMuYbW8caej4=
github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8=
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
github.com/cpuguy83/go-md2man/v2 v2.0.1 h1:r/myEWzV9lfsM1tFLgDyu0atFtJ1fXn261LKYj/3DxU=
github.com/cpuguy83/go-md2man/v2 v2.0.1/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1 h1:VkoXIwSboBpnk99O/KFauAEILuNHv5DVFKZMBN/gUgw=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/shadow1163/goautoit v0.0.0-20190627080114-4aa9ce277b8b h1:y3S4bf/aB15R/hYmPzhPQ43T/ae8EUFmpq1HB1SRfuo=
github.com/shadow1163/goautoit v0.0.0-20190627080114-4aa9ce277b8b/go.mod h1:W/p3CvwSrZFUdtEMhQn6+8Vj1LPQP3u43psKeB6zgYk=
github.com/spf13/cobra v1.4.0 h1:y+wJpx64xcgO1V+RcnwW0LEHxTKRi2ZDPSBjWnrg88Q=
github.com/spf13/cobra v1.4.0/go.mod h1:Wo4iy3BUC+X2Fybo0PDqwJIv3dNRiZLHQymsfxlB84g=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/yuin/goldmark v1.3.5 h1:dPmz1Snjq0kmkz159iL7S6WzdahUTHnHB5M56WFVifs=
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw=
go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
Expand All @@ -35,14 +46,18 @@ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACk
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20220321153916-2c7772ba3064 h1:S25/rfnfsMVgORT4/J61MJ7rdyseOZOyvLIrZEZ7s6s=
golang.org/x/crypto v0.0.0-20220321153916-2c7772ba3064/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/lint v0.0.0-20190930215403-16217165b5de h1:5hukYrvBGR8/eNkX5mdUezrA6JiaEZDtJb9Ei+1LlBs=
golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
golang.org/x/mod v0.4.2 h1:Gz96sIWK3OalVv/I/qNygP42zyoKp3xptRVCWRFEBvo=
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2 h1:CIJ76btIcR3eFI5EgSo6k1qKw9KJexJuRLI9G7Hp5wE=
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
Expand All @@ -56,15 +71,19 @@ golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1 h1:v+OssWQX+hTHEmOBgwxdZxK4
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.5 h1:ouewzE6p+/VEB31YYnTbEJdi8pFqKp4P4n85vwo3DHA=
golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
Expand Down
Binary file added go-client/pkg/autoit/AutoItX3.dll
Binary file not shown.
Binary file added go-client/pkg/autoit/AutoItX3_x64.dll
Binary file not shown.
221 changes: 221 additions & 0 deletions go-client/pkg/autoit/goautoit.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,221 @@
//go:build windows
// +build windows

package autoit

import (
"os"
"path/filepath"
"syscall"
"unsafe"
)

const (
SWShowNormal = 1
INTDEFAULT = -2147483647
DefaultMouseButton = "left"
)

// HWND -- window handle
type HWND uintptr

// RECT -- http://msdn.microsoft.com/en-us/library/windows/desktop/dd162897.aspx
type RECT struct {
Left, Top, Right, Bottom int32
}

// POINT --
type POINT struct {
X, Y int32
}

var (
dll64 *syscall.LazyDLL
controlClick *syscall.LazyProc
controlSend *syscall.LazyProc
run *syscall.LazyProc
winActivate *syscall.LazyProc
winWait *syscall.LazyProc
)

func LoadAuto() {
autoItX3 := "AutoItX3_x64.dll"
if (^uint(0) >> 63) == 0 {
autoItX3 = "AutoItX3.dll"
}
dll64 := syscall.NewLazyDLL(filepath.Join(filepath.Dir(os.Args[0]), autoItX3))
controlClick = dll64.NewProc("AU3_ControlClick")
controlSend = dll64.NewProc("AU3_ControlSend")
run = dll64.NewProc("AU3_Run")
winActivate = dll64.NewProc("AU3_WinActivate")
winWait = dll64.NewProc("AU3_WinWait")
}

// Run -- Run a windows program
// flag 3(max) 6(min) 9(normal) 0(hide)
func Run(szProgram string, args ...interface{}) int {
var szDir string
var flag int
var ok bool
if len(args) == 0 {
szDir = ""
flag = SWShowNormal
} else if len(args) == 1 {
if szDir, ok = args[0].(string); !ok {
panic("szDir must be a string")
}
flag = SWShowNormal
} else if len(args) == 2 {
if szDir, ok = args[0].(string); !ok {
panic("szDir must be a string")
}
if flag, ok = args[1].(int); !ok {
panic("flag must be a int")
}
} else {
panic("Too more parameter")
}
pid, _, lastErr := run.Call(strPtr(szProgram), strPtr(szDir), intPtr(flag))
if int(pid) == 0 {
println(lastErr)
}
return int(pid)
}

// WinWait -- wait window to active
func WinWait(szTitle string, args ...interface{}) int {
var szText string
var nTimeout int
var ok bool
if len(args) == 0 {
szText = ""
nTimeout = 0
} else if len(args) == 1 {
if szText, ok = args[0].(string); !ok {
panic("szText must be a string")
}
nTimeout = 0
} else if len(args) == 2 {
if szText, ok = args[0].(string); !ok {
panic("szText must be a string")
}
if nTimeout, ok = args[1].(int); !ok {
panic("nTimeout must be a int")
}
} else {
panic("Too more parameter")
}

handle, _, lastErr := winWait.Call(strPtr(szTitle), strPtr(szText), intPtr(nTimeout))
if int(handle) == 0 {
println(lastErr)
}
return int(handle)
}

// ControlClick -- Sends a mouse click command to a given control.
func ControlClick(title, text, control string, args ...interface{}) int {
var button string
var x, y, nClicks int
var ok bool

if len(args) == 0 {
button = DefaultMouseButton
nClicks = 1
x = INTDEFAULT
y = INTDEFAULT
} else if len(args) == 1 {
if button, ok = args[0].(string); !ok {
panic("button must be a string")
}
nClicks = 1
x = INTDEFAULT
y = INTDEFAULT
} else if len(args) == 2 {
if button, ok = args[0].(string); !ok {
panic("button must be a string")
}
if nClicks, ok = args[1].(int); !ok {
panic("nClicks must be a int")
}
x = INTDEFAULT
y = INTDEFAULT
} else if len(args) == 4 {
if button, ok = args[0].(string); !ok {
panic("button must be a string")
}
if nClicks, ok = args[1].(int); !ok {
panic("nClicks must be a int")
}
if x, ok = args[2].(int); !ok {
panic("x must be a int")
}
if y, ok = args[3].(int); !ok {
panic("y must be a int")
}
} else {
panic("Error parameters")
}
ret, _, lastErr := controlClick.Call(strPtr(title), strPtr(text), strPtr(control), strPtr(button), intPtr(nClicks), intPtr(x), intPtr(y))
if int(ret) == 0 {
println(lastErr)
}
return int(ret)
}

// WinActivate ( "title" [, "text"]) int
func WinActivate(title string, args ...interface{}) int {
text := ""
var ok bool
argsLen := len(args)
if argsLen > 1 {
panic("argument count > 2")
}
if argsLen == 1 {
if text, ok = args[0].(string); !ok {
panic("text must be a string")
}
}
ret, _, lastErr := winActivate.Call(strPtr(title), strPtr(text))
if int(ret) == 0 {
println(lastErr)
}
return int(ret)
}

// ControlSend -- Sends a string of characters to a control.
func ControlSend(title, text, control, sendText string, args ...interface{}) int {
var nMode int
var ok bool
if len(args) == 0 {
nMode = 0
} else if len(args) == 1 {
if nMode, ok = args[0].(int); !ok {
panic("nMode must be a int")
}
} else {
panic("Too more parameter")
}
ret, _, lastErr := controlSend.Call(strPtr(title), strPtr(text), strPtr(control), strPtr(sendText), intPtr(nMode))
if int(ret) == 0 {
println(lastErr)
}
return int(ret)
}

func findTermChr(buff []uint16) int {
for i, char := range buff {
if char == 0x0 {
return i
}
}
panic("not supposed to happen")
}

func intPtr(n int) uintptr {
return uintptr(n)
}

func strPtr(s string) uintptr {
return uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(s)))
}
Loading

0 comments on commit 008d53e

Please sign in to comment.