forked from tazjin/watchblob
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.go
49 lines (42 loc) · 942 Bytes
/
utils.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
package main
import (
"bufio"
"fmt"
"log"
"os"
"strings"
"syscall"
"golang.org/x/term"
)
func readUsername() (string, error) {
fmt.Printf("Username: ")
reader := bufio.NewReader(os.Stdin)
username, err := reader.ReadString('\n')
if err != nil {
return "", err
}
return strings.TrimSpace(username), err
}
func readPassword() (string, error) {
fmt.Printf("Password: ")
password, err := term.ReadPassword(syscall.Stdin)
if err != nil {
return "", err
}
fmt.Println()
return strings.TrimSpace(string(password)), err
}
func readToken(challenge *WatchguardResponse, token string) (string, error) {
if token == "" {
fmt.Println(challenge.Challenge)
var err error
reader := bufio.NewReader(os.Stdin)
token, err = reader.ReadString('\n')
if err != nil {
return "", err
}
} else {
log.Printf("got as challage: `%s`, select `%s`\n", challenge.Challenge, token)
}
return strings.TrimSpace(token), nil
}