-
Notifications
You must be signed in to change notification settings - Fork 0
/
initappc.go
84 lines (80 loc) · 2.59 KB
/
initappc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package main
import (
"flag"
"fmt"
"gopher-scan/sshpakg"
"os"
"github.com/lxn/walk"
"github.com/lxn/walk/declarative"
)
func main() {
if len(os.Args) <= 1 {
console(false)
defer console(true)
startMainGUIWindows()
return
}
// So ... seems walk package dose not support console windows,
// obviously this is not the best way to call another console for ssh client
// but this is the only way that i could think of ... let me know if you find better way to do this.
sshCodeAuth := flag.String("auth", "1", "ssh auth type")
sshHostAddr := flag.String("addr", "127.0.0.1:22", "ssh remote host")
sshUserName := flag.String("user", "root", "ssh username")
sshPassWord := flag.String("pass", "toor", "ssh password")
sshPrivateK := flag.String("prvk", "pkey.pem", "ssh private key")
sshPkPassPH := flag.String("prph", "123", "ssh key passphrase")
flag.Parse()
var winSSHcli *walk.MainWindow
sshExecute := declarative.MainWindow{
AssignTo: &winSSHcli,
Visible: false,
}
go sshExecute.Run()
switch *sshCodeAuth {
case "1":
conn, err := sshpakg.DialWithPasswd(*sshHostAddr, *sshUserName, *sshPassWord)
if err != nil {
walk.MsgBox(winSSHcli, "Connection error", fmt.Sprintf("%v", err), walk.MsgBoxIconError)
return
}
if err := sshpakg.InitSSHSession(conn); err != nil {
walk.MsgBox(winSSHcli, "Connection error", fmt.Sprintf("%v", err), walk.MsgBoxIconError)
return
}
case "2":
conn, err := sshpakg.DialWithKey(*sshHostAddr, *sshUserName, *sshPrivateK)
if err != nil {
walk.MsgBox(winSSHcli, "Connection error", fmt.Sprintf("%v", err), walk.MsgBoxIconError)
return
}
if err := sshpakg.InitSSHSession(conn); err != nil {
walk.MsgBox(winSSHcli, "Connection error", fmt.Sprintf("%v", err), walk.MsgBoxIconError)
return
}
case "3":
conn, err := sshpakg.DialWithKeyWithPassphrase(*sshHostAddr, *sshUserName, *sshPrivateK, *sshPkPassPH)
if err != nil {
walk.MsgBox(winSSHcli, "Connection error", fmt.Sprintf("%v", err), walk.MsgBoxIconError)
return
}
if err := sshpakg.InitSSHSession(conn); err != nil {
walk.MsgBox(winSSHcli, "Connection error", fmt.Sprintf("%v", err), walk.MsgBoxIconError)
return
}
}
}
func console(show bool) {
var getWin = syscall.NewLazyDLL("kernel32.dll").NewProc("GetConsoleWindow")
var showWin = syscall.NewLazyDLL("user32.dll").NewProc("ShowWindow")
hwnd, _, _ := getWin.Call()
if hwnd == 0 {
return
}
if show {
var SWRESTORE uintptr = 9
showWin.Call(hwnd, SWRESTORE)
} else {
var SWHIDE uintptr = 0
showWin.Call(hwnd, SWHIDE)
}
}