5 # THIS IS EXPERIMENTAL AND COULD BE INSECURE !!!!!!
7 # this is an example bash script of how you could manage your cookies. it is very raw and basic and not as good as cookies.py
8 # we use the cookies.txt format (See http://kb.mozillazine.org/Cookies.txt)
9 # This is one textfile with entries like this:
10 # kb.mozillazine.org FALSE / FALSE 1146030396 wikiUserID 16993
11 # domain alow-read-other-subdomains path http-required expiration name value
12 # you probably want your cookies config file in your $XDG_CONFIG_HOME ( eg $HOME/.config/uzbl/cookies)
13 # 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"
14 # MAYBE TODO: allow user to edit cookie before saving. this cannot be done with zenity :(
15 # TODO: different cookie paths per config (eg per group of uzbl instances)
17 # TODO: correct implementation.
18 # see http://curl.haxx.se/rfc/cookie_spec.html
19 # http://en.wikipedia.org/wiki/HTTP_cookie
21 # TODO : check expires= before sending.
22 # write sample script that cleans up cookies dir based on expires attribute.
23 # TODO: check uri against domain attribute. and path also.
24 # implement secure attribute.
25 # support blocking or not for 3rd parties
26 # http://kb.mozillazine.org/Cookies.txt
27 # don't always append cookies, sometimes we need to overwrite
29 cookie_config=${XDG_CONFIG_HOME:-${HOME}/.config}/uzbl/cookies
30 [ "x$cookie_config" = x ] && exit 1
31 [ -d "${XDG_DATA_HOME:-${HOME}/.local/share}/uzbl/" ] &&\
32 cookie_data=${XDG_DATA_HOME:-${HOME}/.local/share}/uzbl/cookies.txt || exit 1
37 # echo "$@" >> $HOME/cookielog
39 #notifier=notifier_wrapper
41 # if this variable is set, we will use it to inform you when and which cookies we store, and when/which we send.
42 # it's primarily used for debugging
44 which zenity &>/dev/null || exit 2
47 # test_cookie=CheckForPermission; expires=Thu, 07-May-2009 19:17:55 GMT; path=/; domain=.doubleclick.net
50 # uri=${uri/http:\/\/} # strip 'http://' part
64 field_exp='end_session'
67 [ -n "$notifier" ] && $notifier "$@"
71 # FOR NOW LETS KEEP IT SIMPLE AND JUST ALWAYS PUT AND ALWAYS GET
77 if [ "x$first_pair" = x1 ]
79 field_name=${pair%%=*}
80 field_value=${pair#*=}
83 echo "$pair" | read -r pair #strip leading/trailing wite space
86 [ "$key" == expires ] && field_exp=`date -u -d "$val" +'%s'`
88 [ "$key" == path ] && field_path=$val
94 # match cookies in cookies.txt against hostname and path
96 path_esc=${path//\//\\/}
97 search="^[^\t]*$host\t[^\t]*\t$path_esc"
98 cookie=`awk "/$search/" $cookie_data 2>/dev/null | tail -n 1`
101 notify "Get_cookie: search: $search in $cookie_data -> no result"
104 notify "Get_cookie: search: $search in $cookie_data -> result: $cookie"
106 read domain alow_read_other_subdomains path http_required expiration name \
108 cookie="$name=$value"
116 data="$field_domain\tFALSE\t$field_path\tFALSE\t$field_exp\t$field_name\t$field_value"
117 notify "save_cookie: adding $data to $cookie_data"
118 echo -e "$data" >> $cookie_data
120 notify "not saving a cookie. since we don't have policies yet, parse_cookie must have returned false. this is a bug"
124 [ "x$action" = xPUT ] && save_cookie
125 [ "x$action" = xGET ] && get_cookie && echo "$cookie"
130 # TODO: implement this later.
131 # $1 = section (TRUSTED or DENY)
134 sed -n "/$1/,/^\$/p" $cookie_config 2>/dev/null | grep -q "^$host"
138 cookie=`cat $cookie_data`
142 echo $cookie > $cookie_data
145 if match TRUSTED $host
147 [ "x$action" = xPUT ] && store_cookie $host
148 [ "x$action" = xGET ] && fetch_cookie && echo "$cookie"
149 elif ! match DENY $host
151 [ "x$action" = xPUT ] && cookie=`zenity --entry --title 'Uzbl Cookie handler' --text "Accept this cookie from $host ?" --entry-text="$cookie"` && store_cookie $host
152 [ "x$action" = xGET ] && fetch_cookie && cookie=`zenity --entry --title 'Uzbl Cookie handler' --text "Submit this cookie to $host ?" --entry-text="$cookie"` && echo $cookie