Skip to content

Commit

Permalink
Add password prompt to sprofile utils
Browse files Browse the repository at this point in the history
  • Loading branch information
zachhuff386 committed Jul 27, 2024
1 parent 642a6c7 commit 4bd120e
Showing 1 changed file with 86 additions and 1 deletion.
87 changes: 86 additions & 1 deletion cli/sprofile/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@ import (
"strings"
"time"

"github.com/dropbox/godropbox/container/set"
"github.com/dropbox/godropbox/errors"
"github.com/pritunl/pritunl-client-electron/cli/errortypes"
"github.com/pritunl/pritunl-client-electron/cli/profile"
"github.com/pritunl/pritunl-client-electron/cli/service"
"github.com/pritunl/pritunl-client-electron/cli/terminal"
"github.com/pritunl/pritunl-client-electron/cli/utils"
"github.com/spf13/cobra"
)

var (
Expand Down Expand Up @@ -277,7 +280,82 @@ func GetAll() (sprfls []*Sprofile, err error) {
return
}

func Start(sprflId, mode, password string) (err error) {
func PasswordPrompt(sprfl *Sprofile) (pass string, err error) {
passModes := set.NewSet()

passModesStr := strings.Split(sprfl.PasswordMode, "_")
for _, passMode := range passModesStr {
passModes.Add(passMode)
}

if passModes.Contains("pin") {
part := terminal.ReadPassword("Pin")
if part == "" {
cobra.CheckErr("cmd: Pin is empty")
}
pass += part
}

if passModes.Contains("duo") {
part := terminal.ReadPassword("Duo Passcode")
if part == "" {
cobra.CheckErr("cmd: Duo Passcode is empty")
}
pass += part
}

if passModes.Contains("onelogin") {
part := terminal.ReadPassword("OneLogin Passcode")
if part == "" {
cobra.CheckErr("cmd: OneLogin Passcode is empty")
}
pass += part
}

if passModes.Contains("okta") {
part := terminal.ReadPassword("Okta Passcode")
if part == "" {
cobra.CheckErr("cmd: Okta Passcode is empty")
}
pass += part
}

if passModes.Contains("otp") {
part := terminal.ReadPassword("Authenticator Passcode")
if part == "" {
cobra.CheckErr("cmd: Authenticator Passcode is empty")
}
pass += part
}

if passModes.Contains("yubikey") {
part := terminal.ReadPassword("YubiKey")
if part == "" {
cobra.CheckErr("cmd: YubiKey is empty")
}
pass += part
}

if passModes.Contains("yubikey") {
part := terminal.ReadPassword("YubiKey")
if part == "" {
cobra.CheckErr("cmd: YubiKey is empty")
}
pass += part
}

if pass == "" {
part := terminal.ReadPassword("Password")
if part == "" {
cobra.CheckErr("cmd: Password is empty")
}
pass += part
}

return
}

func Start(sprflId, mode, password string, passwordPrompt bool) (err error) {
sprfl, err := Match(sprflId)
if err != nil {
return
Expand All @@ -302,6 +380,13 @@ func Start(sprflId, mode, password string) (err error) {

reqUrl := service.GetAddress() + "/profile"

if passwordPrompt {
password, err = PasswordPrompt(sprfl)
if err != nil {
return
}
}

authKey, err := service.GetAuthKey()
if err != nil {
return
Expand Down

0 comments on commit 4bd120e

Please sign in to comment.