Add session mode: signing in and adding to the cart.
With cart_mode = "session", dibs signs in to the shop's account and puts an item in the cart when it fires. The account's cookies are kept apart from the watcher's and stored encrypted, with the key in the OS keyring. Without a keyring, they're stored in a file only you can read. An alert now goes out right away, without a cart link, and a second one follows once the item is in the cart. If adding fails, the second alert carries the cart link instead. Amazon only accepts additions its page scripts have seen, so plugins can now press a button in headless Chrome with ctx:click. The TUI asks for one-time codes and shows the plugin's warning about account locks in a modal. 'dibs login' signs in from a terminal, or with --browser in a Chrome window, and 'dibs logout' deletes the cookies. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
e2cbc1a55c
commit
15a34e1f84
39 files changed
+3529
-163
No files matched your search
+28
-10
@@ -17,6 +17,7 @@ import (
|
||||
"git.security-command.org/Overlord/dibs/internal/fsutil"
|
||||
"git.security-command.org/Overlord/dibs/internal/fx"
|
||||
"git.security-command.org/Overlord/dibs/internal/ratelimit"
|
||||
"git.security-command.org/Overlord/dibs/internal/session"
|
||||
)
|
||||
|
||||
// Hosts, URLs and alerts untouched for forgetAfter are dropped, such as URLs
|
||||
@@ -25,14 +26,16 @@ import (
|
||||
const forgetAfter = config.MaxCooldown
|
||||
|
||||
type file struct {
|
||||
Hosts map[string]ratelimit.HostState `json:"hosts"`
|
||||
URLs map[string]time.Time `json:"urls"`
|
||||
Alerts map[string]alert.Sent `json:"alerts,omitempty"`
|
||||
FX *fx.Rates `json:"fx,omitempty"`
|
||||
Hosts map[string]ratelimit.HostState `json:"hosts"`
|
||||
URLs map[string]time.Time `json:"urls"`
|
||||
Alerts map[string]alert.Sent `json:"alerts,omitempty"`
|
||||
FX *fx.Rates `json:"fx,omitempty"`
|
||||
// Sessions are never forgotten, unlike the rest.
|
||||
Sessions map[string]session.Record `json:"sessions,omitempty"`
|
||||
}
|
||||
|
||||
// Store is the state file. It implements ratelimit.Persister, alert.Store
|
||||
// and fx.Store.
|
||||
// Store is the state file. It implements ratelimit.Persister, alert.Store,
|
||||
// fx.Store and session.Store.
|
||||
type Store struct {
|
||||
path string
|
||||
lock string
|
||||
@@ -133,10 +136,24 @@ func (s *Store) StoreRates(r *fx.Rates) {
|
||||
})
|
||||
}
|
||||
|
||||
func (s *Store) LoadSession(shop string) (session.Record, bool) {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
|
||||
r, ok := s.read().Sessions[shop]
|
||||
return r, ok
|
||||
}
|
||||
|
||||
func (s *Store) StoreSession(shop string, r session.Record) {
|
||||
s.update(func(f *file) {
|
||||
if r.Warned.IsZero() && len(r.Logins) == 0 { delete(f.Sessions, shop) } else { f.Sessions[shop] = r }
|
||||
})
|
||||
}
|
||||
|
||||
// read returns the file's contents, or empty state if there is none yet.
|
||||
// Callers hold mu.
|
||||
func (s *Store) read() *file {
|
||||
f := &file{Hosts: map[string]ratelimit.HostState{}, URLs: map[string]time.Time{}, Alerts: map[string]alert.Sent{}}
|
||||
f := &file{Hosts: map[string]ratelimit.HostState{}, URLs: map[string]time.Time{}, Alerts: map[string]alert.Sent{}, Sessions: map[string]session.Record{}}
|
||||
|
||||
data, err := os.ReadFile(s.path)
|
||||
switch {
|
||||
@@ -152,9 +169,10 @@ func (s *Store) read() *file {
|
||||
return f
|
||||
}
|
||||
|
||||
if f.Hosts == nil { f.Hosts = map[string]ratelimit.HostState{} }
|
||||
if f.URLs == nil { f.URLs = map[string]time.Time{} }
|
||||
if f.Alerts == nil { f.Alerts = map[string]alert.Sent{} }
|
||||
if f.Hosts == nil { f.Hosts = map[string]ratelimit.HostState{} }
|
||||
if f.URLs == nil { f.URLs = map[string]time.Time{} }
|
||||
if f.Alerts == nil { f.Alerts = map[string]alert.Sent{} }
|
||||
if f.Sessions == nil { f.Sessions = map[string]session.Record{} }
|
||||
|
||||
return f
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user