aboutsummaryrefslogblamecommitdiff
path: root/initappc.go
blob: 4049aff9d404acc5406acca795726f88dbd351a9 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13
14













                                          

                                    



















































                                                                                                                       















                                                                                    
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)
	}
}

Snix LLC Git Repository Holder Copyright(C) 2022 All Rights Reserved Email To Snix.IR