aboutsummaryrefslogtreecommitdiffhomepage
path: root/examples
diff options
context:
space:
mode:
authorGravatar Evgeny Grablyk <evgeny.grablyk@gmail.com>2009-05-05 21:37:48 +0300
committerGravatar Evgeny Grablyk <evgeny.grablyk@gmail.com>2009-05-05 21:37:48 +0300
commitcc3a1419a12c01c2cabd87da99cc4464f715d196 (patch)
tree0318cff0b2e0cc25b79d9ef73003292056a920a6 /examples
parent63a46f212c21697fbf8a73a80094d1db664a4b49 (diff)
Run away from a terribly wrong approach.
Diffstat (limited to 'examples')
-rwxr-xr-xexamples/scripts/cookies.sh61
1 files changed, 60 insertions, 1 deletions
diff --git a/examples/scripts/cookies.sh b/examples/scripts/cookies.sh
index bbeed2e..69b786f 100755
--- a/examples/scripts/cookies.sh
+++ b/examples/scripts/cookies.sh
@@ -1,3 +1,62 @@
#!/bin/bash
+# this is an example script of how you could manage your cookies..
+# you probably want your cookies config file in your $XDG_CONFIG_HOME ( eg $HOME/.config/uzbl/cookies)
-echo $8 $9 >> ck \ No newline at end of file
+# MAYBE TODO: allow user to edit cookie before saving. this cannot be done with zenity :(
+# TODO: different cookie paths per config (eg per group of uzbl instances)
+
+if [ -f /usr/share/uzbl/examples/configs/cookies ]
+then
+ file=/usr/share/uzbl/examples/configs/cookies
+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
+
+which zenity &>/dev/null || exit 2
+
+uri=$6
+action=$8 # GET/PUT
+host=${uri/\/*/}
+
+
+
+# $1 = section (TRUSTED or DENY)
+# $2 =url
+function match () {
+ sed -n "/$1/,/^\$/p" $file 2>/dev/null | grep -q "^$host"
+}
+
+function readcookie () {
+ cookie=
+ while read
+ do
+ cookie="$REPLY
+"
+ done
+}
+
+function fetch_cookie () {
+ cookie=`cat $cookie_dir/$host.cookie`
+}
+
+function store_cookie () {
+ echo $cookie > $cookie_dir/$host.cookie
+}
+
+if match TRUSTED $host
+then
+ [ $action == PUT ] && readcookie && store_cookie $host
+ [ $action == GET ] && fetch_cookie && echo "$cookie"
+elif ! match DENY $host
+then
+ [ $action == PUT ] && readcookie && zenity --question --title 'Uzbl Cookie handler' --text "Accept cookie from $host ? Contents:\n$cookie" && store_cookie $host
+ [ $action == GET ] && fetch_cookie && zenity --question --title 'Uzbl Cookie handler' --text "Submit cookie to $host ? Contents:\n$cookie" && echo $cookie
+fi
+exit 0