Mercurial > p > roundup > code
diff scripts/dump_dbm_sessions_db.py @ 6571:cd408eb748dd
Add small utility script for dumping dbm based databases.
Use it to dump dbm based files like db/sessions (records session keys)
or db/otks (records one time key for password recovery, data for rate
limiting logins and rest interface and other short duration data).
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Thu, 23 Dec 2021 02:20:53 -0500 |
| parents | |
| children | 61481d7bbb07 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/dump_dbm_sessions_db.py Thu Dec 23 02:20:53 2021 -0500 @@ -0,0 +1,35 @@ +#! /usr/bin/env python3 +"""Usage: dump_dbm_sessions_db.py [filename] + +Simple script to dump the otks and sessions dbm databases. Dumps +sessions db in current directory if no argument is given. + +Dump format: + + key: <timestamp> data + +where <timestamp> is the human readable __timestamp decoded from the +data object. + +"""" + +import dbm, marshal, sys +from datetime import datetime + +try: + file = sys.argv[1] +except IndexError: + file="sessions" + +try: + db = dbm.open(file) +except Exception: + print("Unable to open database: %s"%file) + exit(1) + +k = db.firstkey() +while k is not None: + d = marshal.loads(db[k]) + t = datetime.fromtimestamp(d['__timestamp']) + print("%s: %s %s"%(k, t, d)) + k = db.nextkey(k)
