2023-08-21 13:52:06 +02:00
|
|
|
//go:build !noautofill
|
2023-07-18 22:08:37 +02:00
|
|
|
|
2023-07-17 03:23:26 +02:00
|
|
|
package autofill
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
|
|
|
|
"github.com/atotto/clipboard"
|
2023-09-12 02:54:46 +02:00
|
|
|
"github.com/quexten/goldwarden/autofill/autotype"
|
2023-07-17 03:23:26 +02:00
|
|
|
"github.com/quexten/goldwarden/client"
|
2023-09-20 03:05:44 +02:00
|
|
|
"github.com/quexten/goldwarden/ipc/messages"
|
2023-07-17 03:23:26 +02:00
|
|
|
)
|
|
|
|
|
2023-09-20 03:05:44 +02:00
|
|
|
func GetLoginByUUID(uuid string, client client.Client) (messages.DecryptedLoginCipher, error) {
|
|
|
|
resp, err := client.SendToAgent(messages.GetLoginRequest{
|
2023-07-17 03:23:26 +02:00
|
|
|
UUID: uuid,
|
|
|
|
})
|
|
|
|
if err != nil {
|
2023-09-20 03:05:44 +02:00
|
|
|
return messages.DecryptedLoginCipher{}, err
|
2023-07-17 03:23:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
switch resp.(type) {
|
2023-09-20 03:05:44 +02:00
|
|
|
case messages.GetLoginResponse:
|
|
|
|
castedResponse := (resp.(messages.GetLoginResponse))
|
2023-07-17 03:23:26 +02:00
|
|
|
return castedResponse.Result, nil
|
2023-09-20 03:05:44 +02:00
|
|
|
case messages.ActionResponse:
|
|
|
|
castedResponse := (resp.(messages.ActionResponse))
|
|
|
|
return messages.DecryptedLoginCipher{}, errors.New("Error: " + castedResponse.Message)
|
2023-07-17 03:23:26 +02:00
|
|
|
default:
|
2023-09-20 03:05:44 +02:00
|
|
|
return messages.DecryptedLoginCipher{}, errors.New("Wrong response type")
|
2023-07-17 03:23:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-20 03:05:44 +02:00
|
|
|
func ListLogins(client client.Client) ([]messages.DecryptedLoginCipher, error) {
|
|
|
|
resp, err := client.SendToAgent(messages.ListLoginsRequest{})
|
2023-07-17 03:23:26 +02:00
|
|
|
if err != nil {
|
2023-09-20 03:05:44 +02:00
|
|
|
return []messages.DecryptedLoginCipher{}, err
|
2023-07-17 03:23:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
switch resp.(type) {
|
2023-09-20 03:05:44 +02:00
|
|
|
case messages.GetLoginsResponse:
|
|
|
|
castedResponse := (resp.(messages.GetLoginsResponse))
|
2023-07-17 03:23:26 +02:00
|
|
|
return castedResponse.Result, nil
|
2023-09-20 03:05:44 +02:00
|
|
|
case messages.ActionResponse:
|
|
|
|
castedResponse := (resp.(messages.ActionResponse))
|
|
|
|
return []messages.DecryptedLoginCipher{}, errors.New("Error: " + castedResponse.Message)
|
2023-07-17 03:23:26 +02:00
|
|
|
default:
|
2023-09-20 03:05:44 +02:00
|
|
|
return []messages.DecryptedLoginCipher{}, errors.New("Wrong response type")
|
2023-07-17 03:23:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-06 02:41:50 +01:00
|
|
|
func Run(layout string, client client.Client) {
|
2023-08-21 18:37:34 +02:00
|
|
|
logins, err := ListLogins(client)
|
2023-07-17 03:23:26 +02:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
autofillEntries := []AutofillEntry{}
|
|
|
|
for _, login := range logins {
|
|
|
|
autofillEntries = append(autofillEntries, AutofillEntry{
|
|
|
|
Name: login.Name,
|
|
|
|
Username: login.Username,
|
|
|
|
UUID: login.UUID,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
RunAutofill(autofillEntries, func(uuid string, c chan bool) {
|
2023-08-21 18:37:34 +02:00
|
|
|
login, err := GetLoginByUUID(uuid, client)
|
2023-07-17 03:23:26 +02:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2023-07-18 22:08:37 +02:00
|
|
|
|
2023-12-06 02:41:50 +01:00
|
|
|
autotype.TypeString(string(login.Username)+"\t"+string(login.Password), layout)
|
2023-07-18 22:08:37 +02:00
|
|
|
|
|
|
|
clipboard.WriteAll(login.TwoFactorCode)
|
2023-07-17 03:23:26 +02:00
|
|
|
c <- true
|
|
|
|
})
|
|
|
|
}
|