aboutsummaryrefslogtreecommitdiffhomepage
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/config/config15
-rw-r--r--examples/data/plugins/cookies.py176
-rwxr-xr-xexamples/data/scripts/auth.py2
-rwxr-xr-xexamples/data/scripts/download.sh1
-rwxr-xr-xexamples/data/scripts/follow.sh2
-rwxr-xr-xexamples/data/scripts/formfiller.sh2
-rwxr-xr-xexamples/data/scripts/load_cookies.sh20
-rwxr-xr-xexamples/data/scripts/per-site-settings.py2
-rwxr-xr-xexamples/data/scripts/scheme.py2
-rwxr-xr-xexamples/data/scripts/session.sh6
10 files changed, 209 insertions, 19 deletions
diff --git a/examples/config/config b/examples/config/config
index a6651bf..f2d55b0 100644
--- a/examples/config/config
+++ b/examples/config/config
@@ -42,7 +42,6 @@ set scripts_dir = @data_home/uzbl:@prefix/share/uzbl/examples/data:scripts
# These handlers can't be moved to the new event system yet as we don't
# support events that can wait for a response from a script.
-set cookie_handler = talk_to_socket @cache_home/uzbl/cookie_daemon_socket
set scheme_handler = sync_spawn @scripts_dir/scheme.py
set authentication_handler = sync_spawn @scripts_dir/auth.py
set download_handler = sync_spawn @scripts_dir/download.sh
@@ -50,7 +49,7 @@ set download_handler = sync_spawn @scripts_dir/download.sh
# === Dynamic event handlers =================================================
# Open link in new window
-@on_event NEW_WINDOW sh 'uzbl-browser ${8:+-u "$8"}' %r
+@on_event NEW_WINDOW sh 'uzbl-browser ${1:+-u "$1"}' %r
# Open in current window
#@on_event NEW_WINDOW uri %s
# Open in new tab
@@ -122,6 +121,10 @@ set progress.pending =
set useragent = Uzbl (Webkit @{WEBKIT_MAJOR}.@{WEBKIT_MINOR}.@{WEBKIT_MICRO}) (@(+uname -sm)@ [@ARCH_UZBL]) (Commit @COMMIT)
+# === Configure cookie blacklist ========================================================
+# Drop google analytics tracking cookies
+#request BLACKLIST_COOKIE name '^__utm.$'
+
# === Key binding configuration ==============================================
# --- Internal modmapping and ignoring ---------------------------------------
@@ -183,7 +186,7 @@ set ebind = @mode_bind global,-insert
# --- Mouse bindings ---------------------------------------------------------
# Middle click open in new window
-@bind <Button2> = sh 'if [ "$8" ]; then uzbl-browser -u "$8"; else echo "uri $(xclip -o | sed s/\\\@/%40/g)" > "$UZBL_FIFO"; fi' '\@SELECTED_URI'
+@bind <Button2> = sh 'if [ "$1" ]; then uzbl-browser -u "$1"; else echo "uri $(xclip -o | sed s/\\\@/%40/g)" > "$UZBL_FIFO"; fi' '\@SELECTED_URI'
# --- Keyboard bindings ------------------------------------------------------
@@ -270,9 +273,9 @@ set ebind = @mode_bind global,-insert
# Yanking & pasting binds
@cbind yu = sh 'echo -n "$UZBL_URI" | xclip'
-@cbind yU = sh 'echo -n $8 | xclip' \@SELECTED_URI
+@cbind yU = sh 'echo -n "$1" | xclip' \@SELECTED_URI
@cbind yy = sh 'echo -n "$UZBL_TITLE" | xclip'
-@cbind yY = sh 'echo -n $8 | xclip' \@SELECTED_URI
+@cbind yY = sh 'echo -n "$1" | xclip' \@SELECTED_URI
# Clone current window
@cbind c = sh 'uzbl-browser -u "$UZBL_URI"'
@@ -391,6 +394,8 @@ set stack = @mode_config stack
set default_mode = command
# === Post-load misc commands ================================================
+sync_spawn_exec @scripts_dir/load_cookies.sh
+sync_spawn_exec @scripts_dir/load_cookies.sh @data_home/uzbl/session-cookies.txt
# Set the "home" page.
set uri = uzbl.org/doesitwork/@COMMIT
diff --git a/examples/data/plugins/cookies.py b/examples/data/plugins/cookies.py
new file mode 100644
index 0000000..c9fe2c3
--- /dev/null
+++ b/examples/data/plugins/cookies.py
@@ -0,0 +1,176 @@
+""" Basic cookie manager
+ forwards cookies to all other instances connected to the event manager"""
+
+from collections import defaultdict
+import os, re
+
+# these are symbolic names for the components of the cookie tuple
+symbolic = {'domain': 0, 'path':1, 'name':2, 'value':3, 'scheme':4, 'expires':5}
+
+_splitquoted = re.compile("( |\\\".*?\\\"|'.*?')")
+def splitquoted(text):
+ return [str(p.strip('\'"')) for p in _splitquoted.split(text) if p.strip()]
+
+# allows for partial cookies
+# ? allow wildcard in key
+def match(key, cookie):
+ for k,c in zip(key,cookie):
+ if k != c:
+ return False
+ return True
+
+class NullStore(object):
+ def add_cookie(self, rawcookie, cookie):
+ pass
+
+ def delete_cookie(self, rkey, key):
+ pass
+
+class ListStore(list):
+ def add_cookie(self, rawcookie, cookie):
+ self.append(rawcookie)
+
+ def delete_cookie(self, rkey, key):
+ self[:] = [x for x in self if not match(key, splitquoted(x))]
+
+class TextStore(object):
+ def __init__(self, filename):
+ self.filename = filename
+
+ def as_event(self, cookie):
+ if cookie[0].startswith("#HttpOnly_"):
+ domain = cookie[0][len("#HttpOnly_"):]
+ elif cookie[0].startswith('#'):
+ return None
+ else:
+ domain = cookie[0]
+ return (domain,
+ cookie[2],
+ cookie[5],
+ cookie[6],
+ 'https' if cookie[3] == 'TRUE' else 'http',
+ cookie[4])
+
+ def as_file(self, cookie):
+ return (cookie[0],
+ 'TRUE' if cookie[0].startswith('.') else 'FALSE',
+ cookie[1],
+ 'TRUE' if cookie[4] == 'https' else 'FALSE',
+ cookie[5],
+ cookie[2],
+ cookie[3])
+
+ def add_cookie(self, rawcookie, cookie):
+ assert len(cookie) == 6
+
+ # delete equal cookies (ignoring expire time, value and secure flag)
+ self.delete_cookie(None, cookie[:-3])
+
+ first = not os.path.exists(self.filename)
+ with open(self.filename, 'a') as f:
+ if first:
+ print >> f, "# HTTP Cookie File"
+ print >> f, '\t'.join(self.as_file(cookie))
+
+ def delete_cookie(self, rkey, key):
+ if not os.path.exists(self.filename):
+ return
+
+ # read all cookies
+ with open(self.filename, 'r') as f:
+ cookies = f.readlines()
+
+ # write those that don't match the cookie to delete
+ with open(self.filename, 'w') as f:
+ for l in cookies:
+ c = self.as_event(l.split('\t'))
+ if c is None or not match(key, c):
+ print >> f, l,
+
+xdg_data_home = os.environ.get('XDG_DATA_HOME', os.path.join(os.environ['HOME'], '.local/share'))
+DefaultStore = TextStore(os.path.join(xdg_data_home, 'uzbl/cookies.txt'))
+SessionStore = TextStore(os.path.join(xdg_data_home, 'uzbl/session-cookies.txt'))
+
+def match_list(_list, cookie):
+ for component, match in _list:
+ if match(cookie[component]) is not None:
+ return True
+ return False
+
+# accept a cookie only when:
+# a. there is no whitelist and the cookie is in the blacklist
+# b. the cookie is in the whitelist and not in the blacklist
+def accept_cookie(uzbl, cookie):
+ if uzbl.cookie_whitelist:
+ if match_list(uzbl.cookie_whitelist, cookie):
+ return not match_list(uzbl.cookie_blacklist, cookie)
+ return False
+
+ return not match_list(uzbl.cookie_blacklist, cookie)
+
+def expires_with_session(uzbl, cookie):
+ return cookie[5] == ''
+
+def get_recipents(uzbl):
+ """ get a list of Uzbl instances to send the cookie too. """
+ # This could be a lot more interesting
+ return [u for u in uzbl.parent.uzbls.values() if u is not uzbl]
+
+def get_store(uzbl, session=False):
+ if session:
+ return SessionStore
+ return DefaultStore
+
+def add_cookie(uzbl, cookie):
+ splitted = splitquoted(cookie)
+ if accept_cookie(uzbl, splitted):
+ for u in get_recipents(uzbl):
+ u.send('add_cookie %s' % cookie)
+
+ get_store(uzbl, expires_with_session(uzbl, splitted)).add_cookie(cookie, splitted)
+ else:
+ logger.debug('cookie %r is blacklisted' % splitted)
+ uzbl.send('delete_cookie %s' % cookie)
+
+def delete_cookie(uzbl, cookie):
+ for u in get_recipents(uzbl):
+ u.send('delete_cookie %s' % cookie)
+
+ splitted = splitquoted(cookie)
+ if len(splitted) == 6:
+ get_store(uzbl, expires_with_session(uzbl, splitted)).delete_cookie(cookie, splitted)
+ else:
+ for store in set([get_store(uzbl, session) for session in (True, False)]):
+ store.delete_cookie(cookie, splitted)
+
+# add a cookie matcher to a whitelist or a blacklist.
+# a matcher is a (component, re) tuple that matches a cookie when the
+# "component" part of the cookie matches the regular expression "re".
+# "component" is one of the keys defined in the variable "symbolic" above,
+# or the index of a component of a cookie tuple.
+def add_cookie_matcher(_list, arg):
+ component, regexp = splitquoted(arg)
+ try:
+ component = symbolic[component]
+ except KeyError:
+ component = int(component)
+ assert component <= 5
+ _list.append((component, re.compile(regexp).search))
+
+def blacklist(uzbl, arg):
+ add_cookie_matcher(uzbl.cookie_blacklist, arg)
+
+def whitelist(uzbl, arg):
+ add_cookie_matcher(uzbl.cookie_whitelist, arg)
+
+def init(uzbl):
+ connect_dict(uzbl, {
+ 'ADD_COOKIE': add_cookie,
+ 'DELETE_COOKIE': delete_cookie,
+ 'BLACKLIST_COOKIE': blacklist,
+ 'WHITELIST_COOKIE': whitelist
+ })
+ export_dict(uzbl, {
+ 'cookie_blacklist' : [],
+ 'cookie_whitelist' : []
+ })
diff --git a/examples/data/scripts/auth.py b/examples/data/scripts/auth.py
index 9c1b4fc..592a2c6 100755
--- a/examples/data/scripts/auth.py
+++ b/examples/data/scripts/auth.py
@@ -46,7 +46,7 @@ def getText(authInfo, authHost, authRealm):
return rv, output
if __name__ == '__main__':
- rv, output = getText(sys.argv[8], sys.argv[9], sys.argv[10])
+ rv, output = getText(sys.argv[1], sys.argv[2], sys.argv[3])
if (rv == gtk.RESPONSE_OK):
print output;
else:
diff --git a/examples/data/scripts/download.sh b/examples/data/scripts/download.sh
index df7a571..c410ad2 100755
--- a/examples/data/scripts/download.sh
+++ b/examples/data/scripts/download.sh
@@ -6,7 +6,6 @@
# that path.
# if nothing is printed to stdout, the download will be cancelled.
-shift 7
. $UZBL_UTIL_DIR/uzbl-dir.sh
# the URL that is being downloaded
diff --git a/examples/data/scripts/follow.sh b/examples/data/scripts/follow.sh
index 2d666a2..d1560bf 100755
--- a/examples/data/scripts/follow.sh
+++ b/examples/data/scripts/follow.sh
@@ -3,8 +3,6 @@
# This script is just a wrapper around follow.js that lets us change uzbl's mode
# after a link is selected.
-shift 7
-
# if socat is installed then we can change Uzbl's input mode once a link is
# selected; otherwise we just select a link.
if ! which socat >/dev/null 2>&1; then
diff --git a/examples/data/scripts/formfiller.sh b/examples/data/scripts/formfiller.sh
index 6e04573..c6822e6 100755
--- a/examples/data/scripts/formfiller.sh
+++ b/examples/data/scripts/formfiller.sh
@@ -53,8 +53,6 @@ MODELINE="> vim:ft=formfiller"
[ -d "$(dirname $UZBL_FORMS_DIR)" ] || exit 1
[ -d $UZBL_FORMS_DIR ] || mkdir $UZBL_FORMS_DIR || exit 1
-shift 7
-
action=$1
domain=$(echo $UZBL_URI | sed 's/\(http\|https\):\/\/\([^\/]\+\)\/.*/\2/')
diff --git a/examples/data/scripts/load_cookies.sh b/examples/data/scripts/load_cookies.sh
new file mode 100755
index 0000000..17ec2ad
--- /dev/null
+++ b/examples/data/scripts/load_cookies.sh
@@ -0,0 +1,20 @@
+#!/bin/sh
+
+if [ "$1" != "" ]; then
+ cookie_file=$1
+else
+ cookie_file=${XDG_DATA_HOME:-$HOME/.local/share}/uzbl/cookies.txt
+fi
+
+awk -F \\t '
+BEGIN {
+ scheme["TRUE"] = "https";
+ scheme["FALSE"] = "http";
+}
+$0 ~ /^#HttpOnly_/ {
+printf("add_cookie \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\"\n", substr($1,length("#HttpOnly_"),length($1)), $3, $6, $7, scheme[$4], $5)
+}
+$0 !~ /^#/ {
+printf("add_cookie \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\"\n", $1, $3, $6, $7, scheme[$4], $5)
+}
+' $cookie_file
diff --git a/examples/data/scripts/per-site-settings.py b/examples/data/scripts/per-site-settings.py
index febfd0f..89df4e6 100755
--- a/examples/data/scripts/per-site-settings.py
+++ b/examples/data/scripts/per-site-settings.py
@@ -100,7 +100,7 @@ def write_to_socket(commands, sockpath):
if __name__ == '__main__':
sockpath = os.environ['UZBL_SOCKET']
url = urlparse.urlparse(os.environ['UZBL_URI'])
- filepath = sys.argv[8]
+ filepath = sys.argv[1]
mode = os.stat(filepath)[stat.ST_MODE]
diff --git a/examples/data/scripts/scheme.py b/examples/data/scripts/scheme.py
index 0916466..4b0b7ca 100755
--- a/examples/data/scripts/scheme.py
+++ b/examples/data/scripts/scheme.py
@@ -13,7 +13,7 @@ def detach_open(cmd):
print 'USED'
if __name__ == '__main__':
- uri = sys.argv[8]
+ uri = sys.argv[1]
u = urlparse.urlparse(uri)
if u.scheme == 'mailto':
detach_open(['xterm', '-e', 'mail', u.path])
diff --git a/examples/data/scripts/session.sh b/examples/data/scripts/session.sh
index 36e0c19..ee09cf2 100755
--- a/examples/data/scripts/session.sh
+++ b/examples/data/scripts/session.sh
@@ -30,12 +30,6 @@ fi
UZBL="uzbl-browser -c $UZBL_CONFIG_FILE" # add custom flags and whatever here.
-if [ $# -gt 1 ]; then
- # this script is being run from uzbl, rather than standalone
- # discard the uzbl arguments
- shift 7
-fi
-
scriptfile=$(readlink -f $0) # this script
act="$1"