bin/extract-cookies @ 2fb2516b42a4

Merge
author Steve Losh <steve@stevelosh.com>
date Mon, 09 May 2022 22:53:44 -0400
parents 579af8ed8dcb
children (none)
#!/usr/bin/env bash

# from https://gist.githubusercontent.com/spk/5014421/raw/0055721469fe0979afbe12b602444b50608e4a74/extract_cookies.sh

# extract_cookies > ~/.cookies.txt
# wget --load-cookies=~/.cookies.txt http://mysite.com
# or 
# curl --cookie ~/.cookies.txt http://mysite.com 

set -euo pipefail

cleanup() {
    rm -f $TMPFILE
    exit 1
}

trap cleanup \
    EXIT INT QUIT TERM

# 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);

# We have to copy cookies.sqlite, because FireFox has a lock on it
TMPFILE=`mktemp /tmp/cookies.sqlite.XXXXXXXXXX`
cat $1 >> $TMPFILE

sqlite3 -separator '    ' $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