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 if [ -f /usr/share/uzbl/examples/configs/cookies ]
26 file=/usr/share/uzbl/examples/configs/cookies
28 file=./examples/configs/cookies #useful when developing
31 #cookie_file=$XDG_DATA_HOME/uzbl/cookies.txt
32 cookie_file=./examples/data/cookies.txt
34 which zenity &>/dev/null || exit 2
37 # test_cookie=CheckForPermission; expires=Thu, 07-May-2009 19:17:55 GMT; path=/; domain=.doubleclick.net
40 # uri=${uri/http:\/\/} # strip 'http://' part
53 field_exp='end_session'
56 # FOR NOW LETS KEEP IT SIMPLE AND JUST ALWAYS PUT AND ALWAYS GET
57 function parse_cookie () {
62 if [ "$first_pair" == 1 ]
64 field_name=${pair%%=*}
65 field_value=${pair#*=}
68 read -r pair <<< "$pair" #strip leading/trailing wite space
71 [ "$key" == expires ] && field_exp=`date -u -d "$val" +'%s'`
73 [ "$key" == path ] && field_path=$val
79 # match cookies in cookies.txt againsh hostname and path
80 function get_cookie () {
81 path_esc=${path//\//\\/}
82 cookie=`awk "/^[^\t]*$host\t[^\t]*\t$path_esc/" $cookie_file 2>/dev/null | tail -n 1`
87 read domain alow_read_other_subdomains path http_required expiration name value <<< "$cookie"
89 #echo "COOKIE $cookie" >> $HOME/cookielog
94 [ $action == PUT ] && parse_cookie && echo -e "$field_domain\tFALSE\t$field_path\tFALSE\t$field_exp\t$field_name\t$field_value" >> $cookie_file
95 [ $action == GET ] && get_cookie && echo "$cookie"
100 # TODO: implement this later.
101 # $1 = section (TRUSTED or DENY)
104 sed -n "/$1/,/^\$/p" $file 2>/dev/null | grep -q "^$host"
107 function fetch_cookie () {
108 cookie=`cat $cookie_file/$host.cookie`
111 function store_cookie () {
112 echo $cookie > $cookie_file/$host.cookie
115 if match TRUSTED $host
117 [ $action == PUT ] && store_cookie $host
118 [ $action == GET ] && fetch_cookie && echo "$cookie"
119 elif ! match DENY $host
121 [ $action == PUT ] && cookie=`zenity --entry --title 'Uzbl Cookie handler' --text "Accept this cookie from $host ?" --entry-text="$cookie"` && store_cookie $host
122 [ $action == GET ] && fetch_cookie && cookie=`zenity --entry --title 'Uzbl Cookie handler' --text "Submit this cookie to $host ?" --entry-text="$cookie"` && echo $cookie