2 # this is an example script of how you could manage your cookies..
3 # we use the cookies.txt format (See http://kb.mozillazine.org/Cookies.txt)
4 # This is one textfile with entries like this:
5 # kb.mozillazine.org FALSE / FALSE 1146030396 wikiUserID 16993
6 # domain alow-read-other-subdomains path http-required expiration name value
7 # you probably want your cookies config file in your $XDG_CONFIG_HOME ( eg $HOME/.config/uzbl/cookies)
8 # Note. in uzbl there is no strict definition on what a session is. it's YOUR job to clear cookies marked as end_session if you want to keep cookies only valid during a "session"
9 # MAYBE TODO: allow user to edit cookie before saving. this cannot be done with zenity :(
10 # TODO: different cookie paths per config (eg per group of uzbl instances)
12 # TODO: correct implementation.
13 # see http://curl.haxx.se/rfc/cookie_spec.html
14 # http://en.wikipedia.org/wiki/HTTP_cookie
16 # TODO : check expires= before sending.
17 # write sample script that cleans up cookies dir based on expires attribute.
18 # TODO: check uri against domain attribute. and path also.
19 # implement secure attribute.
20 # support blocking or not for 3rd parties
21 # http://kb.mozillazine.org/Cookies.txt
22 # don't always append cookies, sometimes we need to overwrite
24 [ -f /usr/share/uzbl/examples/configs/cookies ] && file=/usr/share/uzbl/examples/configs/cookies
25 [ -f $XDG_CONFIG_HOME/uzbl/cookies ] && file=$XDG_CONFIG_HOME/uzbl/cookies
26 [ -f ./examples/configs/cookies ] && file=./examples/configs/cookies #useful when developing
27 [ -z "$file" ] && exit 1
29 [ -d /usr/share/uzbl/examples/data ] && cookie_file=/usr/share/uzbl/examples/data/cookies.txt
30 [ -d $XDG_DATA_HOME/uzbl/ ] && cookie_file=$XDG_DATA_HOME/uzbl/cookies.txt
31 [ -d ./examples/data/ ] && cookie_file=./examples/data/cookies.txt #useful when developing
32 [ -z "$cookie_file" ] && exit 1
35 which zenity &>/dev/null || exit 2
38 # test_cookie=CheckForPermission; expires=Thu, 07-May-2009 19:17:55 GMT; path=/; domain=.doubleclick.net
41 # uri=${uri/http:\/\/} # strip 'http://' part
54 field_exp='end_session'
57 # FOR NOW LETS KEEP IT SIMPLE AND JUST ALWAYS PUT AND ALWAYS GET
58 function parse_cookie () {
63 if [ "$first_pair" == 1 ]
65 field_name=${pair%%=*}
66 field_value=${pair#*=}
69 read -r pair <<< "$pair" #strip leading/trailing wite space
72 [ "$key" == expires ] && field_exp=`date -u -d "$val" +'%s'`
74 [ "$key" == path ] && field_path=$val
80 # match cookies in cookies.txt againsh hostname and path
81 function get_cookie () {
82 path_esc=${path//\//\\/}
83 cookie=`awk "/^[^\t]*$host\t[^\t]*\t$path_esc/" $cookie_file 2>/dev/null | tail -n 1`
88 read domain alow_read_other_subdomains path http_required expiration name value <<< "$cookie"
90 #echo "COOKIE $cookie" >> $HOME/cookielog
95 [ $action == PUT ] && parse_cookie && echo -e "$field_domain\tFALSE\t$field_path\tFALSE\t$field_exp\t$field_name\t$field_value" >> $cookie_file
96 [ $action == GET ] && get_cookie && echo "$cookie"
101 # TODO: implement this later.
102 # $1 = section (TRUSTED or DENY)
105 sed -n "/$1/,/^\$/p" $file 2>/dev/null | grep -q "^$host"
108 function fetch_cookie () {
109 cookie=`cat $cookie_file/$host.cookie`
112 function store_cookie () {
113 echo $cookie > $cookie_file/$host.cookie
116 if match TRUSTED $host
118 [ $action == PUT ] && store_cookie $host
119 [ $action == GET ] && fetch_cookie && echo "$cookie"
120 elif ! match DENY $host
122 [ $action == PUT ] && cookie=`zenity --entry --title 'Uzbl Cookie handler' --text "Accept this cookie from $host ?" --entry-text="$cookie"` && store_cookie $host
123 [ $action == GET ] && fetch_cookie && cookie=`zenity --entry --title 'Uzbl Cookie handler' --text "Submit this cookie to $host ?" --entry-text="$cookie"` && echo $cookie