From: Dieter Plaetinck Date: Mon, 4 May 2009 19:28:00 +0000 (+0200) Subject: sample cookie handler and config file X-Git-Url: http://git.maemo.org/git/?a=commitdiff_plain;h=1ba4dfe07bce046854c4d9b29403aea7b0cc3c40;p=uzbl-mobile sample cookie handler and config file --- diff --git a/README b/README index 2087b2a..ad57566 100644 --- a/README +++ b/README @@ -117,6 +117,8 @@ The script specific arguments are this: none * download: $8 url of item to download +* cookie handler + $8 GET/PUT KNOWN BUGS - Segfaults when using zoom commands (happens when max zoom already reached?). 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