aboutsummaryrefslogtreecommitdiffhomepage
path: root/examples
diff options
context:
space:
mode:
authorGravatar Dieter Plaetinck <dieter@plaetinck.be>2009-05-04 21:28:00 +0200
committerGravatar Dieter Plaetinck <dieter@plaetinck.be>2009-05-04 21:28:00 +0200
commit1ba4dfe07bce046854c4d9b29403aea7b0cc3c40 (patch)
treed189a5bdd2c7efa67723c6253e7f0012235b787c /examples
parent1df72478dc583a4457821f020683616e08bbc0d9 (diff)
sample cookie handler and config file
Diffstat (limited to 'examples')
-rw-r--r--examples/configs/cookies22
-rwxr-xr-xexamples/scripts/cookies.sh62
2 files changed, 84 insertions, 0 deletions
diff --git a/examples/configs/cookies b/examples/configs/cookies
new file mode 100644
index 0000000..9b7374a
--- /dev/null
+++ b/examples/configs/cookies
@@ -0,0 +1,22 @@
+# This file demonstrates how one *could* manage his cookies. this file is used by the example cookie handler script.
+# stick to this format.
+# trusted -> always store what we get, send what we have (TODO: by default, or when requested?)
+# deny -> deny storing + sending
+
+# if you don't like to edit this file manually, you could even write a script that adds/removes entries using sed, and call the script from uzbl with a keybind...
+
+
+TRUSTED
+bbs.archlinux.org
+archlinux.org
+linux.com
+
+
+
+
+DENY
+www.icanhascheezburger.com
+
+
+
+# rest -> ask \ No newline at end of file
diff --git a/examples/scripts/cookies.sh b/examples/scripts/cookies.sh
new file mode 100755
index 0000000..69b786f
--- /dev/null
+++ b/examples/scripts/cookies.sh
@@ -0,0 +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)
+
+# 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