From f7e023d8616b18a97271abdb9cc8c380008f3aff Mon Sep 17 00:00:00 2001 From: shylinux Date: Mon, 7 Dec 2020 16:14:57 +0800 Subject: [PATCH] opt some --- base/ssh/connect.go | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/base/ssh/connect.go b/base/ssh/connect.go index a94e5a3b..24bb8fc2 100644 --- a/base/ssh/connect.go +++ b/base/ssh/connect.go @@ -1,8 +1,6 @@ package ssh import ( - "fmt" - ice "github.com/shylinux/icebergs" "github.com/shylinux/icebergs/base/aaa" "github.com/shylinux/icebergs/base/mdb" @@ -14,6 +12,7 @@ import ( "golang.org/x/crypto/ssh/terminal" "encoding/json" + "fmt" "io" "net" "os" @@ -24,19 +23,19 @@ import ( func _ssh_conn(m *ice.Message, conn net.Conn, username, hostport string) (*ssh.Client, error) { methods := []ssh.AuthMethod{} methods = append(methods, ssh.KeyboardInteractive(func(user, instruction string, questions []string, echos []bool) (res []string, err error) { - for _, k := range questions { - switch strings.TrimSpace(strings.ToLower(k)) { - case "verification code:": - if m.Option("verify") == "" { - verify := "" - fmt.Println("verify code: \n") - fmt.Println("verify code: ") + for _, q := range questions { + p := strings.TrimSpace(strings.ToLower(q)) + switch { + case strings.HasSuffix(p, "verification code:"): + if verify := m.Option("verify"); verify == "" { + fmt.Printf(q) fmt.Scanf("%6s", &verify) + res = append(res, verify) - return + } else { + res = append(res, aaa.TOTP_GET(verify, 6, 30)) } - res = append(res, aaa.TOTP_GET(m.Option("verify"), 6, 30)) - case "password:": + case strings.HasSuffix(p, "password:"): res = append(res, m.Option(aaa.PASSWORD)) default: }