r5109 - in trunk/varnish-tools: . cookie-stripper
kristian at varnish-cache.org
kristian at varnish-cache.org
Fri Aug 13 20:53:43 CEST 2010
Author: kristian
Date: 2010-08-13 20:53:42 +0200 (Fri, 13 Aug 2010)
New Revision: 5109
Added:
trunk/varnish-tools/cookie-stripper/
trunk/varnish-tools/cookie-stripper/varnish_cookie_strip.sh
Log:
tools/cookie-stripper: Script to generate simple VCL that strips specific
cookies.
Added: trunk/varnish-tools/cookie-stripper/varnish_cookie_strip.sh
===================================================================
--- trunk/varnish-tools/cookie-stripper/varnish_cookie_strip.sh (rev 0)
+++ trunk/varnish-tools/cookie-stripper/varnish_cookie_strip.sh 2010-08-13 18:53:42 UTC (rev 5109)
@@ -0,0 +1,104 @@
+#!/bin/sh
+# Author: Kristian Lyngstol <kristian at bohemians.org>
+# Date: August 2010
+# More info: http://kristianlyng.wordpress.com
+# License: Consider it public domain.
+#
+
+usage() {
+ echo
+ echo "Varnish Cookie-strip VCL generator"
+ echo "Copyright (C) 2010 Kristian Lyngstol <kristian at bohemians.org>"
+ echo
+ echo "$0 [-b backend:port] [-i indentation] [-c cookie] [-c cookie] ..."
+ echo "Generates VCL for Varnish to strip cookies."
+ echo " -c <cookie>\tStrip cookie named \`cookie'. Can be"
+ echo " \tspecified multiple times"
+ echo " -b <host:port>\tAlso generate the backend definition to use"
+ echo " \ta web server at host:port as the backend. Both"
+ echo " \thost AND port, separated by colon, must be specified"
+ echo " -t <indent>\tUse \`indent' when indenting the code, instead of"
+ echo " \t4 spaces."
+ echo " -i \tCreate case-insensitive cookie matching"
+ echo
+ echo "Example: $0 -b localhost:8181 -c __utmz -c __utma > /etc/varnish/default.vcl"
+ echo
+ echo "The VCL generated is for Varnish 2.1 and beyond and with the"
+ echo "-b option there is no need to add or modify the final VCL to"
+ echo "make Varnish \"just work\""
+}
+ind() {
+ echo -n "$indent"
+}
+
+TEMP=`getopt -o hb:c:it: -n $0 -- "$@"`
+
+if [ $? != 0 ] ; then echo "$(usage)" >&2 ; exit 1 ; fi
+
+eval set -- "$TEMP"
+
+icase=""
+indent=" "
+backend=""
+cookiestring=""
+
+
+while true ; do
+ case "$1" in
+ -b) backend="$2"; shift 2;;
+ -i) icase="(?i)"; shift 1;;
+ -t) indent="$2"; shift 2;;
+ -c) cookiestrip="$cookiestrip $2"; shift 2;;
+ -h) usage; exit 0 ;;
+ --) shift; break ;;
+ *) echo "Internal error! See $0 -h" ; exit 1 ;;
+ esac
+done
+
+host=`echo $backend | sed s/:.*//`
+port=`echo $backend | sed s/.*://`
+
+if [ ! -z "$backend" ]; then
+ if [ -z "$host" ] || [ -z "$port" ]; then
+ echo "Invalid backend \"$backend\"" 1>&2
+ echo "$(usage)" 1>&2
+ exit 1;
+ fi
+
+
+ echo "backend default {"
+ ind
+ echo ".host = \"$host\";"
+ ind
+ echo ".port = \"$port\";"
+ echo "}"
+ echo
+fi
+
+if [ -z "$cookiestrip" ] && [ -z "$backend" ]; then
+ echo "No -c or -b option specified." 1>&2
+ echo "$(usage)" 1>&2
+ exit 2;
+fi
+
+echo "sub vcl_recv {"
+for a in $cookiestrip; do
+ ind
+ echo "# Remove cookie $a"
+ ind
+ echo -n 'set req.http.cookie = regsub(req.http.cookie,';
+ echo -n "\"${icase}$a=[^;]*;?( |$)\""
+ echo ',"");'
+done
+
+echo
+ind
+echo "# Remove the cookie header if it's empty after cleanup"
+ind
+echo 'if (req.http.cookie ~ "^ *$") {'
+ind
+ind
+echo 'remove req.http.cookie;'
+ind
+echo '}'
+echo '}'
Property changes on: trunk/varnish-tools/cookie-stripper/varnish_cookie_strip.sh
___________________________________________________________________
Added: svn:executable
+ *
More information about the varnish-commit
mailing list