aboutsummaryrefslogtreecommitdiffhomepage
path: root/examples
diff options
context:
space:
mode:
authorGravatar Dieter Plaetinck <dieter@plaetinck.be>2009-05-07 22:23:55 +0200
committerGravatar Dieter Plaetinck <dieter@plaetinck.be>2009-05-07 22:23:55 +0200
commit1a9bc2950b4235276c25ce9ec4f5a6d2e8cc9ac0 (patch)
treed2b8c0539532eaa5eb3193dcd58ff030c25628aa /examples
parent9ac714c239cd99cb186f5871a6d05040aab73c24 (diff)
cookie support: correct invocations of script, various fixes. almost a basic working version
Diffstat (limited to 'examples')
-rwxr-xr-xexamples/scripts/cookies.sh71
1 files changed, 60 insertions, 11 deletions
diff --git a/examples/scripts/cookies.sh b/examples/scripts/cookies.sh
index 02fb471..9f6d202 100755
--- a/examples/scripts/cookies.sh
+++ b/examples/scripts/cookies.sh
@@ -1,5 +1,9 @@
#!/bin/bash
# this is an example script of how you could manage your cookies..
+# we use the cookies.txt format (See http://kb.mozillazine.org/Cookies.txt)
+# This is one textfile with entries like this:
+# kb.mozillazine.org FALSE / FALSE 1146030396 wikiUserID 16993
+# domain alow-read-other-subdomains path http-required expiration name value
# you probably want your cookies config file in your $XDG_CONFIG_HOME ( eg $HOME/.config/uzbl/cookies)
# MAYBE TODO: allow user to edit cookie before saving. this cannot be done with zenity :(
@@ -23,23 +27,68 @@ else
file=./examples/configs/cookies #useful when developing
fi
-if [ -d $XDG_DATA_HOME/uzbl/cookies ]
-then
- cookie_dir=$XDG_DATA_HOME/uzbl/cookies
-else
- cookie_dir=./examples/data
-fi
+#cookie_file=$XDG_DATA_HOME/uzbl/cookies.txt
+cookie_file=./examples/data/cookies.txt
which zenity &>/dev/null || exit 2
-uri=$6
-uri=${uri/http:\/\/} # strip 'http://' part
+# Example cookie:
+# test_cookie=CheckForPermission; expires=Thu, 07-May-2009 19:17:55 GMT; path=/; domain=.doubleclick.net
+
+# uri=$6
+# uri=${uri/http:\/\/} # strip 'http://' part
+# host=${uri/\/*/}
action=$8 # GET/PUT
+host=$9
+shift
+path=$9
+shift
cookie=$9
-host=${uri/\/*/}
+field_domain=$host
+field_path=$path
+field_name=
+field_value=
+field_exp='end_session'
+
+
+# FOR NOW LETS KEEP IT SIMPLE AND JUST ALWAYS PUT AND ALWAYS GET
+function parse_cookie () {
+ IFS=$';'
+ first_pair=1
+ for pair in $cookie
+ do
+ if [ "$first_pair" == 1 ]
+ then
+ field_name=${i%%=*}
+ field_value=${i#*=}
+ first_pair=0
+ else
+ read -r pair <<< "$pair" #strip leading/trailing wite space
+ key=${i%%=*}
+ val=${i#*=}
+ [ "$key" == expires ] && field_exp=`date -u -d "$val" +'%s'`
+ # TODO: domain
+ [ "$key" == path ] && field_path=$val
+ fi
+ done
+ unset IFS
+}
+
+# match cookies in cookies.txt againsh hostname and path
+function get_cookie () {
+ path_esc=${path//\//\\/}
+ cookie=`awk "/^[^\t]*$host\t[^\t]*\t$path_esc/" cookie_file 2>/dev/null | tail -n 1`
+ [ -n "$cookie" ]
+}
+
+[ $action == PUT ] && parse_cookie && echo -e "$field_domain\tFALSE\t$field_path\tFALSE\t$field_exp\t$field_name\t$field_value" >> $cookie_file
+[ $action == GET ] && get_cookie && echo "$cookie"
+
+exit
+# TODO: implement this later.
# $1 = section (TRUSTED or DENY)
# $2 =url
function match () {
@@ -47,11 +96,11 @@ function match () {
}
function fetch_cookie () {
- cookie=`cat $cookie_dir/$host.cookie`
+ cookie=`cat $cookie_file/$host.cookie`
}
function store_cookie () {
- echo $cookie > $cookie_dir/$host.cookie
+ echo $cookie > $cookie_file/$host.cookie
}
if match TRUSTED $host