Skip to content
Permalink
Browse files

Update usage count and last moved times

  • Loading branch information...
Raggaer committed Feb 22, 2019
1 parent 8844d12 commit e2f72faaa27ed06eab53a616c0376fbf54ab3358
Showing with 34 additions and 6 deletions.
  1. +34 −6 entry.go
@@ -4,11 +4,13 @@ import (
"fmt" "fmt"
"strconv" "strconv"
"strings" "strings"
"time"


"github.com/atotto/clipboard" "github.com/atotto/clipboard"
"github.com/lithammer/fuzzysearch/fuzzy" "github.com/lithammer/fuzzysearch/fuzzy"
"github.com/sethvargo/go-password/password" "github.com/sethvargo/go-password/password"
"github.com/tobischo/gokeepasslib/v2" "github.com/tobischo/gokeepasslib/v2"
"github.com/tobischo/gokeepasslib/v2/wrappers"
) )


const recycleBinGroup = "Recycle Bin" const recycleBinGroup = "Recycle Bin"
@@ -78,6 +80,8 @@ func editEntry(f *form, input string) {
if e.UUID.Compare(data.Id) { if e.UUID.Compare(data.Id) {
fmt.Printf("Entry '%s' modified\r\n", e.GetTitle()) fmt.Printf("Entry '%s' modified\r\n", e.GetTitle())
values := g.Entries[i].Values values := g.Entries[i].Values

// Update values slice
for i, v := range values { for i, v := range values {
if v.Key == "Title" { if v.Key == "Title" {
values[i].Value.Content = data.Title values[i].Value.Content = data.Title
@@ -92,6 +96,12 @@ func editEntry(f *form, input string) {
values[i].Value.Content = data.Password values[i].Value.Content = data.Password
} }
} }

// Update entry modified
g.Entries[i].Times.LastModificationTime = &wrappers.TimeWrapper{
Formatted: true,
Time: time.Now().In(time.UTC),
}
fmt.Print("Database was changed. Save database? (y/N): ") fmt.Print("Database was changed. Save database? (y/N): ")
activeForm = &form{ activeForm = &form{
Fn: databaseChangedSaveAlert, Fn: databaseChangedSaveAlert,
@@ -131,6 +141,10 @@ func deleteEntry(entry *gokeepasslib.Entry) bool {


// Add entry to recycle bin // Add entry to recycle bin
if g.Name != recycleBinGroup { if g.Name != recycleBinGroup {
entry.Times.LocationChanged = &wrappers.TimeWrapper{
Formatted: true,
Time: time.Now().In(time.UTC),
}
moveEntryToRecycleBin(entry) moveEntryToRecycleBin(entry)
} }
return true return true
@@ -143,17 +157,13 @@ func moveEntryToRecycleBin(entry *gokeepasslib.Entry) {
// Recycle bin group is at the root, if it does not exist we create it // Recycle bin group is at the root, if it does not exist we create it
for i, g := range database.Content.Root.Groups[0].Groups { for i, g := range database.Content.Root.Groups[0].Groups {
if g.Name == recycleBinGroup { if g.Name == recycleBinGroup {
e := gokeepasslib.NewEntry() database.Content.Root.Groups[0].Groups[i].Entries = append(database.Content.Root.Groups[0].Groups[i].Entries, *entry)
e.Values = append(entry.Values, gokeepasslib.ValueData{Key: "UserName", Value: gokeepasslib.V{Content: entry.GetContent("UserName")}})
e.Values = append(entry.Values, gokeepasslib.ValueData{Key: "Title", Value: gokeepasslib.V{Content: entry.GetTitle()}})
e.Values = append(entry.Values, gokeepasslib.ValueData{Key: "URL", Value: gokeepasslib.V{Content: entry.GetContent("URL")}})
e.Values = append(entry.Values, gokeepasslib.ValueData{Key: "Password", Value: gokeepasslib.V{Content: entry.GetPassword(), Protected: true}})
database.Content.Root.Groups[0].Groups[i].Entries = append(database.Content.Root.Groups[0].Groups[i].Entries, e)
return return
} }
} }
bin := gokeepasslib.NewGroup() bin := gokeepasslib.NewGroup()
bin.Name = recycleBinGroup bin.Name = recycleBinGroup
bin.Entries = append(bin.Entries, *entry)
database.Content.Root.Groups[0].Groups = append(database.Content.Root.Groups[0].Groups, bin) database.Content.Root.Groups[0].Groups = append(database.Content.Root.Groups[0].Groups, bin)
} }


@@ -270,6 +280,12 @@ func xp(args []string) {
if e == nil { if e == nil {
return return
} }
// Update entry access time
e.Times.LastAccessTime = &wrappers.TimeWrapper{
Formatted: true,
Time: time.Now().In(time.UTC),
}
e.Times.UsageCount++
clipboard.WriteAll(e.GetPassword()) clipboard.WriteAll(e.GetPassword())
fmt.Printf("Copied entry '%s' password to clipboard\r\n", e.GetTitle()) fmt.Printf("Copied entry '%s' password to clipboard\r\n", e.GetTitle())
} }
@@ -281,6 +297,12 @@ func xw(args []string) {
if e == nil { if e == nil {
return return
} }
// Update entry access time
e.Times.LastAccessTime = &wrappers.TimeWrapper{
Formatted: true,
Time: time.Now().In(time.UTC),
}
e.Times.UsageCount++
clipboard.WriteAll(e.GetContent("URL")) clipboard.WriteAll(e.GetContent("URL"))
fmt.Printf("Copied entry '%s' URL to clipboard\r\n", e.GetTitle()) fmt.Printf("Copied entry '%s' URL to clipboard\r\n", e.GetTitle())
} }
@@ -292,6 +314,12 @@ func xu(args []string) {
if e == nil { if e == nil {
return return
} }
// Update entry access time
e.Times.LastAccessTime = &wrappers.TimeWrapper{
Formatted: true,
Time: time.Now().In(time.UTC),
}
e.Times.UsageCount++
clipboard.WriteAll(e.GetContent("UserName")) clipboard.WriteAll(e.GetContent("UserName"))
fmt.Printf("Copied entry '%s' username to clipboard\r\n", e.GetTitle()) fmt.Printf("Copied entry '%s' username to clipboard\r\n", e.GetTitle())
} }

0 comments on commit e2f72fa

Please sign in to comment.
You can’t perform that action at this time.