mirror of https://github.com/cowrie/cowrie.git
fully commented
This commit is contained in:
parent
d2ba56e8c0
commit
013b37171d
|
@ -1,10 +1,10 @@
|
||||||
|
# -*- test-case-name: cowrie.test.utils -*-
|
||||||
# Copyright (c) 2009-2014 Upi Tamminen <desaster@gmail.com>
|
# Copyright (c) 2009-2014 Upi Tamminen <desaster@gmail.com>
|
||||||
# See the COPYRIGHT file for more information
|
# See the COPYRIGHT file for more information
|
||||||
|
|
||||||
# Should be compatible with user mode linux
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
This module contains ...
|
Should be compatible with user mode linux
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import struct
|
import struct
|
||||||
|
@ -12,18 +12,13 @@ import struct
|
||||||
OP_OPEN, OP_CLOSE, OP_WRITE, OP_EXEC = 1, 2, 3, 4
|
OP_OPEN, OP_CLOSE, OP_WRITE, OP_EXEC = 1, 2, 3, 4
|
||||||
TYPE_INPUT, TYPE_OUTPUT, TYPE_INTERACT = 1, 2, 3
|
TYPE_INPUT, TYPE_OUTPUT, TYPE_INTERACT = 1, 2, 3
|
||||||
|
|
||||||
def ttylog_write(logfile, len, direction, stamp, data=None):
|
|
||||||
"""
|
|
||||||
"""
|
|
||||||
with open(logfile, 'ab') as f:
|
|
||||||
sec, usec = int(stamp), int(1000000 * (stamp - int(stamp)))
|
|
||||||
f.write(struct.pack('<iLiiLL', 3, 0, len, direction, sec, usec))
|
|
||||||
f.write(data)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def ttylog_open(logfile, stamp):
|
def ttylog_open(logfile, stamp):
|
||||||
"""
|
"""
|
||||||
|
Initialize new tty log
|
||||||
|
|
||||||
|
@param logfile: logfile name
|
||||||
|
@param stamp: timestamp
|
||||||
"""
|
"""
|
||||||
with open(logfile, 'ab') as f:
|
with open(logfile, 'ab') as f:
|
||||||
sec, usec = int(stamp), int(1000000 * (stamp - int(stamp)))
|
sec, usec = int(stamp), int(1000000 * (stamp - int(stamp)))
|
||||||
|
@ -31,8 +26,29 @@ def ttylog_open(logfile, stamp):
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def ttylog_write(logfile, length, direction, stamp, data=None):
|
||||||
|
"""
|
||||||
|
Write to tty log
|
||||||
|
|
||||||
|
@param logfile: timestamp
|
||||||
|
@param length: length
|
||||||
|
@param direction: 0 or 1
|
||||||
|
@param stamp: timestamp
|
||||||
|
@param data: data
|
||||||
|
"""
|
||||||
|
with open(logfile, 'ab') as f:
|
||||||
|
sec, usec = int(stamp), int(1000000 * (stamp - int(stamp)))
|
||||||
|
f.write(struct.pack('<iLiiLL', 3, 0, length, direction, sec, usec))
|
||||||
|
f.write(data)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def ttylog_close(logfile, stamp):
|
def ttylog_close(logfile, stamp):
|
||||||
"""
|
"""
|
||||||
|
Close tty log
|
||||||
|
|
||||||
|
@param logfile: logfile name
|
||||||
|
@param stamp: timestamp
|
||||||
"""
|
"""
|
||||||
with open(logfile, 'ab') as f:
|
with open(logfile, 'ab') as f:
|
||||||
sec, usec = int(stamp), int(1000000 * (stamp - int(stamp)))
|
sec, usec = int(stamp), int(1000000 * (stamp - int(stamp)))
|
||||||
|
|
Loading…
Reference in New Issue