diff options
Diffstat (limited to 'monitor/josef_leveldb.py')
| -rwxr-xr-x | monitor/josef_leveldb.py | 30 |
1 files changed, 21 insertions, 9 deletions
diff --git a/monitor/josef_leveldb.py b/monitor/josef_leveldb.py index 7ad43f3..769f6f3 100755 --- a/monitor/josef_leveldb.py +++ b/monitor/josef_leveldb.py @@ -4,6 +4,7 @@ import sys from josef_lib import * import leveldb +import ast SEP = ";" # db = None @@ -37,7 +38,7 @@ def db_open(fn='./cert_db'): if fn in dbs: return dbs[fn] else: - print "Opening " + fn + # print "Opening " + fn db = leveldb.LevelDB(fn) dbs[fn] = db return db @@ -60,7 +61,9 @@ def db_append(db, key, val): def db_add_domain_2(db_dir, key_in, val_in, db_in=None): if db_in == None: - val = str(hash(val_in)) + # print val_in + val = "###" + ast.literal_eval(val_in)["leaf_hash"] + # val = str(hash(val_in)) cert_db = db_open(db_dir + "certificates") cert_db.Put(val, val_in) @@ -116,15 +119,20 @@ def db_lookup_domain(db_dir, domain): res = [] if domain_list[-1] == "com": - key = '.'.join(domain_list[:-1]) db = db_open(db_dir + domain_list[-1]) + domain_list = domain_list[:-1] + key = '.'.join(domain_list) else: key = '.'.join(domain) db = db_open(db_dir + "other") - domain_list = domain_list[:-1] cur_domain = domain_list.pop() - intermediate = db.Get(cur_domain).split(SEP) + # print cur_domain + try: + intermediate = db.Get(cur_domain).split(SEP) + except KeyError: + return [] + last = False one_more = False while True: @@ -140,13 +148,16 @@ def db_lookup_domain(db_dir, domain): # Prune next_level = [] for item in intermediate: + # print item if match_domain(cur_domain, item): + # print item try: tmp = db.Get(item).split(SEP) + # print tmp for tmp_item in tmp: - try: - res.append(int(tmp_item)) - except: + if tmp_item[0:3] == "###": + res.append(tmp_item[3:]) + else: next_level.append(tmp_item) except KeyError: pass @@ -154,8 +165,9 @@ def db_lookup_domain(db_dir, domain): certs = [] cert_db = db_open(db_dir + "certificates") + # print res for item in res: - tmp = cert_db.Get(str(item)) + tmp = cert_db.Get("###" + str(item)) certs.append(tmp) return certs |
