summaryrefslogtreecommitdiff
path: root/monitor
diff options
context:
space:
mode:
Diffstat (limited to 'monitor')
-rwxr-xr-xmonitor/josef_experimental.py2
-rwxr-xr-xmonitor/josef_leveldb.py34
2 files changed, 3 insertions, 33 deletions
diff --git a/monitor/josef_experimental.py b/monitor/josef_experimental.py
index f1a38b9..433bb77 100755
--- a/monitor/josef_experimental.py
+++ b/monitor/josef_experimental.py
@@ -34,7 +34,7 @@ db = db_open("./tmpdatabase")
# db_add_domain_2(db, "www.cox.b.com", "{dummydata}")
# print db_lookup_domain(db, "www.cox.b.com")
# print db.Get("www.cox.b.com")
-# db_add_domain_2(db, "www.cox.a.com", "{dummydata3}")
+db_add_domain_2(db, "www.cox.a.com", "{dummydata3}")
print db_lookup_domain(db, "www.cox.a.com")
# print db.Get("com")
# print db.Get("a.com")
diff --git a/monitor/josef_leveldb.py b/monitor/josef_leveldb.py
index 1d3bdbd..74498c7 100755
--- a/monitor/josef_leveldb.py
+++ b/monitor/josef_leveldb.py
@@ -35,7 +35,6 @@ def db_open(fn='./cert_db'):
return db
def db_append(db, key, val):
- # print "Appending " + val
if db is None:
print "ERROR: NO DATABASE SET!"
return
@@ -44,20 +43,14 @@ def db_append(db, key, val):
tmp = db.Get(key)
except KeyError:
tmp = ""
- # print "Key: ", key, "Val: ", val, "Found: ", tmp
tmpl = tmp.split(SEP)
if val in tmpl:
pass
else:
- # print tmpl
tmpl.append(val)
- # print tmpl
db.Put(key,SEP.join(tmpl))
- # print "Storing " + SEP.join(tmpl)
def db_add_domain_2(db, key, val):
- # print "Calling: key:",key," val:",val
- # print "Appending " + val
if db is None:
print "ERROR: NO DATABASE SET!"
return
@@ -69,27 +62,14 @@ def db_add_domain_2(db, key, val):
return
else:
tmpl.append(val)
- # print "Putting key:",key," val:",SEP.join(tmpl)
db.Put(key,SEP.join(tmpl))
except KeyError:
- # print "Putting key:",key," val:",SEP.join([val])
db.Put(key,SEP.join([val]))
new_key = key.split('.',1)[-1]
if new_key != key:
db_add_domain_2(db,new_key,key)
- # tmpl = tmp.split(SEP)
- # if val in tmpl:
- # pass
- # else:
- # # print tmpl
- # tmpl.append(val)
- # # print tmpl
- # db.Put(key,SEP.join(tmpl))
- # print "Storing " + SEP.join(tmpl)
-
-
def db_add_domain(db, domain, data):
if db is None:
print "ERROR: NO DATABASE SET!"
@@ -102,10 +82,8 @@ def db_add_domain(db, domain, data):
next_k = item
else:
next_k = item + '.' + k
- # print "Appending ", k, next_k
db_append(db, k, next_k)
k = next_k
- # print "Appending ", k, data
db_append(db, k, data)
@@ -115,12 +93,12 @@ def db_add_certs(db, data):
return
for cert in data:
try:
- db_add_domain(db, cert["subject"].split("CN=")[1], str(cert))
+ db_add_domain_2(db, cert["subject"].split("CN=")[1], str(cert))
except IndexError:
pass
try:
for line in cert["SAN"].split("DNS:")[1:]:
- db_add_domain(db, line, str(cert))
+ db_add_domain_2(db, line, str(cert))
except KeyError:
pass
except IndexError:
@@ -150,26 +128,18 @@ def db_lookup_domain(db, domain):
next_level = []
# print intermediate
for item in intermediate:
- # print item
- # if item[0] == '{':
- # res.append(item)
if match_domain(cur_domain, item):
- # print item
try:
tmp = db.Get(item).split(SEP)
- # print tmp
for tmp_item in tmp:
if tmp_item[0] == '{':
res.append(tmp_item)
else:
next_level.append(tmp_item)
except KeyError:
- # print "Could not find " + item
pass
intermediate = next_level
- # if last:
- # return res
return res