about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--README.md2
-rw-r--r--main.go28
2 files changed, 24 insertions, 6 deletions
diff --git a/README.md b/README.md
index 95e53115dcf0..1846a8beab7e 100644
--- a/README.md
+++ b/README.md
@@ -16,7 +16,7 @@ will be linked here in the future.
 ## Installation
 
 Make sure you have Go installed and `GOPATH` configured, then simply
-`go get github.com/tazjin/watchblob`.
+`go get github.com/tazjin/watchblob/...`.
 
 ## Usage
 
diff --git a/main.go b/main.go
index b556d606dd86..93a85324f192 100644
--- a/main.go
+++ b/main.go
@@ -7,6 +7,7 @@ import (
 	"net/http"
 	"os"
 	"strings"
+	"golang.org/x/crypto/ssh/terminal"
 )
 
 // The XML response returned by the WatchGuard server
@@ -21,16 +22,20 @@ type Resp struct {
 func main() {
 	args := os.Args[1:]
 
-	if len(args) != 3 {
-		fmt.Fprintf(os.Stderr, "Usage: watchblob <vpn-host> <username> <password>\n")
+	if len(args) != 1 {
+		fmt.Fprintln(os.Stderr, "Usage: watchblob <vpn-host>")
 		os.Exit(1)
 	}
 
 	host := args[0]
-	username := args[1]
-	password := args[2]
 
-	challenge, err := triggerChallengeResponse(&host, &username, &password)
+	username, password, err := readCredentials()
+	if err != nil {
+		fmt.Fprintf(os.Stderr, "Could not read credentials: %v\n", err)
+	}
+
+	fmt.Println("Requesting challenge from %s as user %s\n", host, *username)
+	challenge, err := triggerChallengeResponse(&host, username, password)
 
 	if err != nil || challenge.LogonStatus != 4 {
 		fmt.Fprintln(os.Stderr, "Did not receive challenge from server")
@@ -49,6 +54,19 @@ func main() {
 	fmt.Printf("Login succeeded, you may now (quickly) authenticate OpenVPN with %d as your password\n", token)
 }
 
+func readCredentials() (*string, *string, error) {
+	fmt.Printf("Username: ")
+	reader := bufio.NewReader(os.Stdin)
+	username, err := reader.ReadString('\n')
+
+	fmt.Printf("Password: ")
+	passwordBytes, err := terminal.ReadPassword(1)
+	password := string(passwordBytes)
+
+	// If an error occured, I don't care about which one it is.
+	return &username, &password, err
+}
+
 func triggerChallengeResponse(host *string, username *string, password *string) (r Resp, err error) {
 	return request(templateUrl(host, templateChallengeTriggerUri(username, password)))
 }