usr bin env python import redis import random import json import sys i

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#! /usr/bin/env python
import redis
import random
import json
import sys
import socket
types = {dict: 'hmset', set: 'sadd', list: 'rpush', str: 'set'}
def routes():
return [('routes', {
"target_adometry_offenders": "local",
"target_source_whitelist": "local",
"target_source_blacklist": "local",
"target_referrer_host_blacklist": "local",
"target_geo_whitelist": "local",
"target_os_whitelist": "local",
"target_browser_whitelist": "local",
"target_click_limit": json.dumps(["throttler@" + socket.gethostname()]),
"target_money_limit": json.dumps(["throttler@" + socket.gethostname()]),
"target_click_limit_per_ip": json.dumps(["clipper@" + socket.gethostname()]),
"target_click_limit_per_source": json.dumps(["throttler@" + socket.gethostname()]),
"target_click_budget_limit": json.dumps(["throttler@" + socket.gethostname()]),
"throttler": json.dumps(["throttler@" + socket.gethostname()]),
"cityerl": json.dumps(["cityerl@" + socket.gethostname()]),
"clipper": json.dumps(["clipper@" + socket.gethostname()]),
"bank": json.dumps(["bank@" + socket.gethostname()]),
"statistique": json.dumps(["statistique@" + socket.gethostname()]),
"bidozer": json.dumps(["bidozer@" + socket.gethostname()]),
"euclid": json.dumps(["euclid@" + socket.gethostname()]),
"berliner": "local",
"ip_blacklist": "local",
"geo_whitelist": "local",
"click_too_slow": "local",
"click_too_fast": "local",
"double_click": json.dumps(["euclid@" + socket.gethostname()]),
"mismatch_ip": "local",
"mismatch_referrer": "local",
"mismatch_ua": "local"
})]
def harvest():
return routes()
def connect(host='127.0.0.1', port=6379, db=0):
return redis.StrictRedis(host=host, port=port, db=db)
def tool(seed):
return types.get(type(seed))
def seed(plowman, key, seed):
fun = plowman.__getattribute__(tool(seed))
if tool(seed) == 'sadd':
fun(key, *seed)
elif tool(seed) == 'rpush':
fun(key, *seed)
else:
fun(key, seed)
if __name__ == "__main__":
plowman = connect()
harvest = harvest()
plowman.flushall()
for (k, s) in harvest:
seed(plowman, k, s)