diff --git a/mutn.go b/mutn.go index 0f05f07..acf9d2c 100644 --- a/mutn.go +++ b/mutn.go @@ -72,13 +72,13 @@ func main() { field = 0 case "username", "-u": field = 1 - case "url", "-l": - field = 2 - case "note", "-n": - field = 3 case "totp", "-t": fmt.Println("TOTP code will be copied to clipboard - your clipboard will be kept up to date with the current TOTP code until this process is closed") - field = 5 // TODO Update field after removed from notes (breaking sshyp entry compatibility) + field = 2 + case "url", "-l": + field = 3 + case "note", "-n": + field = 4 default: cli.HelpCopy() } @@ -90,10 +90,12 @@ func main() { field = 0 case "username", "-u": field = 1 - case "url", "-l": + case "totp", "-t": field = 2 - case "note", "-n": + case "url", "-l": field = 3 + case "note", "-n": + field = 4 case "rename", "-r": cli.RenameCli(targetLocation) default: diff --git a/src/cli/add.go b/src/cli/add.go index 5aaa525..e7c0ddb 100644 --- a/src/cli/add.go +++ b/src/cli/add.go @@ -28,16 +28,17 @@ func AddEntry(targetLocation string, hidePassword bool, entryType uint8) { password = backend.StringGen(inputInt("Password length:", -1), inputBinary("Generate a complex (special characters) password?"), 0.2) } + totp := inputHidden("TOTP secret:") url := input("URL:") if inputBinary("Add a note to this entry?") { note, _ := editNote([]string{}) - unencryptedEntry = append([]string{password, username, url}, note...) + unencryptedEntry = append([]string{password, username, totp, url}, note...) } else { - unencryptedEntry = []string{password, username, url} + unencryptedEntry = []string{password, username, totp, url} } } else { note, _ := editNote([]string{}) - unencryptedEntry = append([]string{"", "", ""}, note...) + unencryptedEntry = append([]string{"", "", "", ""}, note...) } // write and preview the new entry diff --git a/src/cli/edit.go b/src/cli/edit.go index 0b8d384..236d29f 100644 --- a/src/cli/edit.go +++ b/src/cli/edit.go @@ -34,11 +34,13 @@ func EditEntryField(targetLocation string, hidePassword bool, field int) { case 1: unencryptedEntry[field] = input("Username:") case 2: + unencryptedEntry[field] = inputHidden("TOTP secret:") + case 3: unencryptedEntry[field] = input("URL:") - case 3: // edit notes fields + case 4: // edit notes fields // store note and non-note data separately - nonNoteData := unencryptedEntry[:3] - noteData := unencryptedEntry[3:] + nonNoteData := unencryptedEntry[:4] + noteData := unencryptedEntry[4:] // edit the note editedNote, noteEdited := editNote(noteData) diff --git a/src/cli/entryReader.go b/src/cli/entryReader.go index 5196b6e..7d431bc 100644 --- a/src/cli/entryReader.go +++ b/src/cli/entryReader.go @@ -34,17 +34,26 @@ func EntryReader(decryptedEntry []string, hidePassword bool, syncEnabled bool) { fmt.Print(ansiDirectoryHeader + "Username:" + backend.AnsiReset + "\n" + decryptedEntry[1] + "\n\n") } case 2: - // if the third field (url) is not empty, print it + // if the third field (TOTP secret) is not empty, print it if decryptedEntry[2] != "" { - fmt.Print(ansiDirectoryHeader + "URL:" + backend.AnsiReset + "\n" + decryptedEntry[2] + "\n\n") + if !hidePassword { + fmt.Print(ansiDirectoryHeader + "TOTP Secret:" + backend.AnsiReset + "\n" + ansiShownPassword + decryptedEntry[2] + backend.AnsiReset + "\n\n") + } else { + fmt.Print(ansiDirectoryHeader + "TOTP Secret:" + backend.AnsiReset + "\n" + ansiEmptyDirectoryWarning + "End command in \"show\" or \"-s\" to view" + backend.AnsiReset + "\n\n") + } } case 3: + // if the fourth field (url) is not empty, print it + if decryptedEntry[3] != "" { + fmt.Print(ansiDirectoryHeader + "URL:" + backend.AnsiReset + "\n" + decryptedEntry[3] + "\n\n") + } + case 4: // print the notes header fmt.Println(ansiDirectoryHeader + "Notes:" + backend.AnsiReset) // combine remaining fields into a single string (for markdown rendering) var markdownNotes []string - for field := 3; field < len(decryptedEntry); field++ { + for field := 4; field < len(decryptedEntry); field++ { markdownNotes = append(markdownNotes, decryptedEntry[field]) } r, _ := glamour.NewTermRenderer(glamour.WithStylesFromJSONBytes(glamourStyle()), glamour.WithPreservedNewLines(), glamour.WithWordWrap(width)) diff --git a/src/cli/printInfo.go b/src/cli/printInfo.go index fd2f124..2db2b7d 100644 --- a/src/cli/printInfo.go +++ b/src/cli/printInfo.go @@ -37,12 +37,13 @@ This program comes with absolutely no warranty; type "mutn version" for details. password|-pw| Copy the password of an entry to your clipboard username|-u Copy the username of an entry to your clipboard totp|-t Copy the TOTP code of an entry to your clipboard - url|-l Copy the url of an entry to your clipboard + url|-l Copy the URL of an entry to your clipboard note|-n Copy the note of an entry to your clipboard edit: password|-pw| Change the password of an entry username|-u Change the username of an entry - url|-l Change the url attached to an entry + totp|-t Change the TOTP secret of an entry + url|-l Change the URL attached to an entry note|-n Change the note attached to an entry rename|-r Rename or relocate an entry gen: @@ -77,7 +78,8 @@ func HelpEdit() { edit: password|-pw| Change the password of an entry username|-u Change the username of an entry - url|-l Change the url attached to an entry + totp|-t Change the TOTP secret of an entry + url|-l Change the URL attached to an entry note|-n Change the note attached to an entry rename|-r Rename or relocate an entry` + "\n\n") os.Exit(0) @@ -91,7 +93,7 @@ func HelpCopy() { password|-pw| Copy the password in an entry to your clipboard username|-u Copy the username in an entry to your clipboard totp|-t Copy the TOTP code of an entry to your clipboard - url|-l Copy the url in an entry to your clipboard + url|-l Copy the URL in an entry to your clipboard note|-n Copy the first note line in an entry to your clipboard` + "\n\n") os.Exit(0) }