From 46ddb58bcd2c0e7e3be27ed903ddce91eb14cc85 Mon Sep 17 00:00:00 2001 From: keis Date: Sun, 12 Dec 2010 16:52:38 +0100 Subject: basic blacklisting in cookies plugin --- examples/config/config | 4 ++++ examples/data/plugins/cookies.py | 36 ++++++++++++++++++++++++++++++------ 2 files changed, 34 insertions(+), 6 deletions(-) (limited to 'examples') diff --git a/examples/config/config b/examples/config/config index 213bb88..29f5fbc 100644 --- a/examples/config/config +++ b/examples/config/config @@ -122,6 +122,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 --------------------------------------- diff --git a/examples/data/plugins/cookies.py b/examples/data/plugins/cookies.py index 225a6af..0264471 100644 --- a/examples/data/plugins/cookies.py +++ b/examples/data/plugins/cookies.py @@ -4,6 +4,8 @@ from collections import defaultdict import os, re +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()] @@ -88,7 +90,13 @@ xdg_data_home = os.environ.get('XDG_DATA_HOME', os.path.join(os.environ['HOME'], DefaultStore = TextStore(os.path.join(xdg_data_home, 'uzbl/cookies.txt')) SessionStore = ListStore() -def expires_with_session(cookie): +def accept_cookie(uzbl, cookie): + for component, match in uzbl.cookie_blacklist: + if match(cookie[component]) is not None: + return False + return True + +def expires_with_session(uzbl, cookie): return cookie[5] == '' def get_recipents(uzbl): @@ -102,11 +110,14 @@ def get_store(uzbl, session=False): return DefaultStore def add_cookie(uzbl, cookie): - for u in get_recipents(uzbl): - u.send('add_cookie %s' % cookie) - splitted = splitquoted(cookie) - get_store(uzbl, expires_with_session(splitted)).add_cookie(cookie, splitted) + 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: + uzbl.send('delete_cookie %s' % cookie) def delete_cookie(uzbl, cookie): for u in get_recipents(uzbl): @@ -114,15 +125,28 @@ def delete_cookie(uzbl, cookie): splitted = splitquoted(cookie) if len(splitted) == 6: - get_store(uzbl, expires_with_session(splitted)).delete_cookie(cookie, splitted) + 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) +def blacklist(uzbl, arg): + component, regexp = splitquoted(arg) + try: + component = symbolic[component] + except KeyError: + component = int(component) + assert component <= 5 + uzbl.cookie_blacklist.append((component, re.compile(regexp).match)) + def init(uzbl): connect_dict(uzbl, { 'ADD_COOKIE': add_cookie, 'DELETE_COOKIE': delete_cookie, + 'BLACKLIST_COOKIE': blacklist + }) + export_dict(uzbl, { + 'cookie_blacklist' : [] }) for cookie in get_store(uzbl, True): -- cgit v1.2.3