last improvements + last now uses a plain text file instead of anydbm

git-svn-id: https://kippo.googlecode.com/svn/trunk@150 951d7100-d841-11de-b865-b3884708a8e2
This commit is contained in:
desaster
2010-06-29 20:00:02 +00:00
parent d8b1b0df63
commit 0d70a7b4e0
2 changed files with 34 additions and 12 deletions

View File

@@ -11,14 +11,21 @@ commands = {}
class command_last(HoneyPotCommand):
def call(self):
db = anydbm.open('%s/lastlog.db' % \
config().get('honeypot', 'data_path'), 'c')
count = 0
for k in sorted(db.keys(), key=int, reverse=True):
self.writeln(db[k])
count += 1
if count >= 25:
break
fn = '%s/lastlog.txt' % (config().get('honeypot', 'data_path'),)
if not os.path.exists(fn):
return
l = list(self.args)
numlines = 25
while len(l):
arg = l.pop(0)
if not arg.startswith('-'):
continue
elif arg[1:].isdigit():
numlines = int(arg[1:])
elif arg == '-n' and len(l) and l[0].isdigit():
numlines = int(l.pop(0))
data = utils.tail(file(fn), numlines)
self.writeln(''.join(data))
commands['/usr/bin/last'] = command_last
# vim: set sw=4 et: