diff options
author | Dieter Plaetinck <dieter@plaetinck.be> | 2009-05-31 18:34:44 +0200 |
---|---|---|
committer | Dieter Plaetinck <dieter@plaetinck.be> | 2009-05-31 18:34:44 +0200 |
commit | 4fbcb2837c40036b2677470c07deaefc19996a86 (patch) | |
tree | 167bc6dc6b875ba59680c35108a5c3345cfede7b /examples | |
parent | 19861c22bc98358b379d4ebde0b07fd94f819e54 (diff) |
notify user of stuff re: cookies + save_cookie function
Diffstat (limited to 'examples')
-rwxr-xr-x | examples/scripts/cookies.sh | 34 |
1 files changed, 30 insertions, 4 deletions
diff --git a/examples/scripts/cookies.sh b/examples/scripts/cookies.sh index ecb6d60..efac322 100755 --- a/examples/scripts/cookies.sh +++ b/examples/scripts/cookies.sh @@ -1,4 +1,7 @@ #!/bin/bash + +# THIS IS EXPERIMENTAL AND COULD BE INSECURE !!!!!! + # 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: @@ -31,7 +34,13 @@ [ -d ./examples/data/ ] && cookie_file=./examples/data/cookies.txt #useful when developing [ -z "$cookie_file" ] && exit 1 - +# if this variable is set, we will use it to inform you when and which cookies we store, and when/which we send. +#notifier= +#notifier=notify-send +notify_wrapper () { + echo "$@" >> $HOME/cookielog +} +notifier=notify_wrapper which zenity &>/dev/null || exit 2 # Example cookie: @@ -53,6 +62,10 @@ field_name= field_value= field_exp='end_session' +function notify () { + [ -n "$notifier" ] && $notifier "$@" +} + # FOR NOW LETS KEEP IT SIMPLE AND JUST ALWAYS PUT AND ALWAYS GET function parse_cookie () { @@ -80,19 +93,32 @@ function parse_cookie () { # 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` + search="^[^\t]*$host\t[^\t]*\t$path_esc" + cookie=`awk "/$search/" $cookie_file 2>/dev/null | tail -n 1` if [ -z "$cookie" ] then + notify "Get_cookie: search: $search in $cookie_file -> no result" false else + notify "Get_cookie: search: $search in $cookie_file -> result: $cookie" read domain alow_read_other_subdomains path http_required expiration name value <<< "$cookie" cookie="$name=$value" - #echo "COOKIE $cookie" >> $HOME/cookielog true fi } -[ $action == PUT ] && parse_cookie && echo -e "$field_domain\tFALSE\t$field_path\tFALSE\t$field_exp\t$field_name\t$field_value" >> $cookie_file +function save_cookie () { + if parse_cookie + then + data="$field_domain\tFALSE\t$field_path\tFALSE\t$field_exp\t$field_name\t$field_value" + notify "save_cookie: adding $data to $cookie_file" + echo -e "$data" >> $cookie_file + else + notify "not saving a cookie. since we don't have policies yet, parse_cookie must have returned false. this is a bug" + fi +} + +[ $action == PUT ] && save_cookie [ $action == GET ] && get_cookie && echo "$cookie" exit |