-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathcookiefire
executable file
·75 lines (55 loc) · 1.43 KB
/
cookiefire
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
71
72
73
#!/bin/bash
# -*- mode:sh -*-
die() {
echo >&2 "$*"
exit 1
}
cleanup() {
rm -f "$tmpfile"
}
trap cleanup EXIT INT QUIT TERM
# Run older ld (pseudo condition)
if [ "$#" == "0" ]; then
profile=default
elif [ "$#" == "1" ]; then
profile=$1
else
die "usage $0 [profile]"
fi;
extract_cookies() {
if [ "$#" -ge 1 ]; then
sqlfile="$1"
else
if tty -s; then
sqlfile=$(ls -t ~/.mozilla/firefox/*/cookies.sqlite | head -1)
sqlfile="-" # Will use 'cat' below to read stdin
fi
fi
if [ "$sqlfile" != "-" -a ! -r "$sqlfile" ]; then
echo "Error. File $sqlfile is not readable." >&2
exit 1
fi
# We have to copy cookies.sqlite, because FireFox has a lock on it
cat "$sqlfile" >> $tmpfile
# This is the format of the sqlite database:
# CREATE TABLE moz_cookies (id INTEGER PRIMARY KEY, name TEXT, value TEXT, host TEXT, path TEXT,expiry INTEGER, lastAccessed INTEGER, isSecure INTEGER, isHttpOnly INTEGER);
echo "# Netscape HTTP Cookie File"
sqlite3 -separator $'\t' $tmpfile <<- EOF
.mode tabs
.header off
select host,
case substr(host,1,1)='.' when 0 then 'FALSE' else 'TRUE' end,
path,
case isSecure when 0 then 'FALSE' else 'TRUE' end,
expiry,
name,
value
from moz_cookies;
EOF
cleanup
}
tmpfile="$(mktemp /tmp/cookies.sqlite.XXXXXXXXXX)"
curlcookies="$(mktemp /tmp/curlcookies.XXXXXXXXXX)"
echo $HOME/.mozilla/firefox/*.$profile/cookies.sqlite | { read cookie_file ;
extract_cookies "$cookie_file" ;
}