# Path: lib/settings.py
# CHECK_CONF_FILE = os.path.join(ROOT, 'conf/', 'conf.json')
# 
# Path: lib/config.py
# def load():
# def update(conf):
# def load_rule():
# def update_rule(rule):
# def rule_read(name, get_file_handle=None):
# def rule_write(name, rule):


import json
import redis
import base64
import urlparse
from hashlib import md5
from lib.settings import CHECK_CONF_FILE
from lib import config
'''

with open(CHECK_CONF_FILE) as conf:
    workerconf = json.load(conf)
    redisconf = {}
    redisconf['host'] = workerconf["redis_host"]
    redisconf['password'] = workerconf['redis_pass']
    redisconf['port'] = workerconf['redis_port']

conn = redis.StrictRedis(**redisconf)


def get_hash(host, uri, postdata):
    request = 'http://%s%s?' % (host, urlparse.urlparse(uri).path)
    dic = urlparse.urlparse(uri).query.split('&')
    for param in dic:
        if param != "" and "=" in param:
            request += param.split('=')[0]+'=&'
    request += "|"
    for param in postdata.split('&'):
        if param != "" and "=" in param:
            request += param.split('=')[0]+'=&'
    url_hash = md5(request).hexdigest()
    return url_hash


def content_deal(headers, host, method, postdata, uri, packet):
    u = urlparse.urlparse(uri)
    url = uri.split(u.netloc)[-1]
    white_domain = config.load()['white_domain']

# Path: lib/settings.py
# CHECK_CONF_FILE = os.path.join(ROOT, 'conf/', 'conf.json')
# 
# Path: lib/config.py
# def load():
# def update(conf):
# def load_rule():
# def update_rule(rule):
# def rule_read(name, get_file_handle=None):
# def rule_write(name, rule):


# Path: lib/redisopt.py
import json
import redis
import base64
import urlparse
from hashlib import md5
from lib.settings import CHECK_CONF_FILE
from lib import config

'''

with open(CHECK_CONF_FILE) as conf:
    workerconf = json.load(conf)
    redisconf = {}
    redisconf['host'] = workerconf["redis_host"]
    redisconf['password'] = workerconf['redis_pass']
    redisconf['port'] = workerconf['redis_port']

conn = redis.StrictRedis(**redisconf)


def get_hash(host, uri, postdata):
    request = 'http://%s%s?' % (host, urlparse.urlparse(uri).path)
    dic = urlparse.urlparse(uri).query.split('&')
    for param in dic:
        if param != "" and "=" in param:
            request += param.split('=')[0]+'=&'
    request += "|"
    for param in postdata.split('&'):
        if param != "" and "=" in param:
            request += param.split('=')[0]+'=&'
    url_hash = md5(request).hexdigest()
    return url_hash


def content_deal(headers, host, method, postdata, uri, packet):
    u = urlparse.urlparse(uri)
    url = uri.split(u.netloc)[-1]
    white_domain = config.load()['white_domain']

    black_domain = config.load()['black_domain']