Initial commit
This commit is contained in:
commit
8ccfbe20db
3 changed files with 139 additions and 0 deletions
35
README.md
Normal file
35
README.md
Normal file
|
|
@ -0,0 +1,35 @@
|
||||||
|
# curlfire
|
||||||
|
Run curl with the current firefox cookies. This is useful for interacting with logged in websites.
|
||||||
|
|
||||||
|
# Attribution
|
||||||
|
|
||||||
|
This code is Adapted from [this Stack Exchange answer](https://superuser.com/questions/666167/how-do-i-use-firefox-cookies-with-wget)
|
||||||
|
# Usage
|
||||||
|
|
||||||
|
```
|
||||||
|
# Fetch google with the cookies from the default profile
|
||||||
|
curlfire http://www.google.com/
|
||||||
|
|
||||||
|
# Fetch google with the cookies from the blah profile
|
||||||
|
curlfire -P blah http://www.google.com/
|
||||||
|
|
||||||
|
# Getting cookies
|
||||||
|
cookiefire > /tmp/cookies
|
||||||
|
curl -b /tmp/cookies http://www.google.com/
|
||||||
|
```
|
||||||
|
|
||||||
|
# Installation
|
||||||
|
```
|
||||||
|
cd ~
|
||||||
|
git clone https://github.com/talwrii/curlfire
|
||||||
|
echo 'PATH=$PATH:~/curlfire' >> ~/.bashrc
|
||||||
|
```
|
||||||
|
|
||||||
|
# Alternative and prior work
|
||||||
|
|
||||||
|
* Adapted from [this stack overflow answer](https://superuser.com/questions/666167/how-do-i-use-firefox-cookies-with-wget)
|
||||||
|
* Firebug and friends allow you to copy requests as curl. This can be suitable for debugging.
|
||||||
|
* Cookies can be exported manually from within firefox
|
||||||
|
|
||||||
|
All of these approaches can be problematic when automating tasks.
|
||||||
|
|
||||||
75
cookiefire
Executable file
75
cookiefire
Executable file
|
|
@ -0,0 +1,75 @@
|
||||||
|
#!/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" ;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
29
curlfire
Executable file
29
curlfire
Executable file
|
|
@ -0,0 +1,29 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
#!/bin/bash
|
||||||
|
set -o errexit
|
||||||
|
set -o nounset
|
||||||
|
set -o pipefail
|
||||||
|
profile=default
|
||||||
|
skip=
|
||||||
|
ARGS=()
|
||||||
|
for var in "$@"; do
|
||||||
|
# Ignore known bad arguments
|
||||||
|
case "$var" in
|
||||||
|
-P)
|
||||||
|
skip=yes
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
if [ -z "$skip" ]; then
|
||||||
|
ARGS+=("$var")
|
||||||
|
else
|
||||||
|
profile=$var
|
||||||
|
fi;
|
||||||
|
skip=
|
||||||
|
esac;
|
||||||
|
done
|
||||||
|
|
||||||
|
|
||||||
|
curlcookies="$(mktemp /tmp/curlcookies.XXXXXXXXXX)"
|
||||||
|
cookiefire "$profile" > "$curlcookies"
|
||||||
|
curl -b "$curlcookies" "$ARGS" ;
|
||||||
Loading…
Reference in a new issue