-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfirefox.go
70 lines (59 loc) · 1.38 KB
/
firefox.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package gocookie
import (
"database/sql"
"net/http"
"time"
_ "modernc.org/sqlite"
)
const queryFirefoxCookie = `SELECT name, value, host, path, expiry, isSecure, isHttpOnly FROM moz_cookies`
type firefox struct {
cookiePath string
}
func newFirefox(cookiePath string) Browser {
return &firefox{
cookiePath: cookiePath,
}
}
func (f *firefox) GetName() string {
return string(Firefox)
}
func (f *firefox) GetCookies(domainFilter domainFilter) ([]*http.Cookie, error) {
cookiesDB, err := sql.Open("sqlite", "file:"+f.cookiePath+"?mode=ro")
if err != nil {
return nil, err
}
defer cookiesDB.Close()
rows, err := cookiesDB.Query(queryFirefoxCookie)
if err != nil {
return nil, err
}
var cookies []*http.Cookie
for rows.Next() {
var (
name string
value string
host string
path string
expiry int64
isSecure int
isHTTPOnly int
)
if err = rows.Scan(&name, &value, &host, &path, &expiry, &isSecure, &isHTTPOnly); err != nil {
return nil, err
}
if domainFilter != nil && !domainFilter(host) {
continue
}
// fmt.Println(name, value, host, path, expiry, isSecure, isHTTPOnly)
cookies = append(cookies, &http.Cookie{
Name: name,
Value: value,
Domain: host,
Path: path,
Expires: time.Unix(expiry, 0),
Secure: isSecure > 0,
HttpOnly: isHTTPOnly > 0,
})
}
return cookies, nil
}