mirror of
https://github.com/aljazceru/cowrie.git
synced 2026-01-31 12:04:24 +01:00
* Fix some dblog brokenness
* Set the ttylog column for mysql to "MEDIUMBLOB" * Limit the ttylog size written to the database to 10 Megabytes git-svn-id: https://kippo.googlecode.com/svn/trunk@121 951d7100-d841-11de-b865-b3884708a8e2
This commit is contained in:
@@ -27,7 +27,7 @@ CREATE TABLE IF NOT EXISTS `session` (
|
||||
`endtime` datetime default NULL,
|
||||
`sensor` varchar(50) NOT NULL,
|
||||
`ip` varchar(15) NOT NULL default '',
|
||||
`ttylog` blob,
|
||||
`ttylog` mediumblob,
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `starttime` (`starttime`,`sensor`)
|
||||
) ;
|
||||
|
||||
@@ -43,7 +43,7 @@ class DBLogger(object):
|
||||
return matches.groups()[0]
|
||||
|
||||
def emit(self, ev):
|
||||
if ev['system'] == '-':
|
||||
if ev['system'] == '-' or not len(ev['message']):
|
||||
return
|
||||
match = self.re_unique.match(ev['system'])
|
||||
if not match:
|
||||
@@ -69,6 +69,14 @@ class DBLogger(object):
|
||||
for i in [x for x in self.sessions if self.sessions[x] == session]:
|
||||
del self.sessions[i]
|
||||
|
||||
def ttylog(self, session):
|
||||
ttylog = None
|
||||
if session in self.ttylogs:
|
||||
f = file(self.ttylogs[session])
|
||||
ttylog = f.read(10485760)
|
||||
f.close()
|
||||
return ttylog
|
||||
|
||||
# We have to return an unique ID
|
||||
def createSession(self, ip):
|
||||
return 0
|
||||
|
||||
@@ -19,14 +19,9 @@ class DBLogger(dblog.DBLogger):
|
||||
return int(cursor.lastrowid)
|
||||
|
||||
def handleConnectionLost(self, session, args):
|
||||
ttylog = None
|
||||
if session in self.ttylogs:
|
||||
f = file(self.ttylogs[session])
|
||||
ttylog = f.read()
|
||||
f.close()
|
||||
sql = 'UPDATE `session` SET `endtime` = FROM_UNIXTIME(%s)' + \
|
||||
', `ttylog` = %s WHERE `id` = %s'
|
||||
params = (self.nowUnix(), ttylog, session)
|
||||
params = (self.nowUnix(), self.ttylog(session), session)
|
||||
cursor = self.db.cursor()
|
||||
cursor.execute(sql, params)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user