Skip to content

Commit 17f7288

Browse files
committed
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).
1 parent a3f54f9 commit 17f7288

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

CHANGES.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ Features:
104104
issue23#msg24 could jump to the element with id msg24 in issue 23.
105105
Before this patch you would have two links issue23 and msg24
106106
separated by # (John Rouillard).
107+
- added small utility script to dump dbm based tracker databases
108+
(e.g. db/sessions). (John Rouillard)
107109

108110

109111
2021-07-13 2.1.0

scripts/README.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ add-issue
77
copy-user.py
88
Copy one or more Roundup users from one tracker instance to another.
99

10+
dump_dbm_sessions_db.py
11+
Simple script to dump a session style dbm database e.g. db/otks or
12+
db/sessions in readable form.
13+
1014
imapServer.py
1115
This IMAP server script that runs in the background and checks for new
1216
email from a variety of mailboxes.

scripts/dump_dbm_sessions_db.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#! /usr/bin/env python3
2+
"""Usage: dump_dbm_sessions_db.py [filename]
3+
4+
Simple script to dump the otks and sessions dbm databases. Dumps
5+
sessions db in current directory if no argument is given.
6+
7+
Dump format:
8+
9+
key: <timestamp> data
10+
11+
where <timestamp> is the human readable __timestamp decoded from the
12+
data object.
13+
14+
""""
15+
16+
import dbm, marshal, sys
17+
from datetime import datetime
18+
19+
try:
20+
file = sys.argv[1]
21+
except IndexError:
22+
file="sessions"
23+
24+
try:
25+
db = dbm.open(file)
26+
except Exception:
27+
print("Unable to open database: %s"%file)
28+
exit(1)
29+
30+
k = db.firstkey()
31+
while k is not None:
32+
d = marshal.loads(db[k])
33+
t = datetime.fromtimestamp(d['__timestamp'])
34+
print("%s: %s %s"%(k, t, d))
35+
k = db.nextkey(k)

0 commit comments

Comments
 (0)