class gtkOutput(baseOutputPlugin): ''' Saves messages to kb.kb.getData('gtkOutput', 'queue'), messages are saved in the form of objects. @author: Andres Riancho ( [email protected] ) ''' def __init__(self): baseOutputPlugin.__init__(self) if not kb.kb.getData('gtkOutput', 'db') == []: # Restore it from the kb self._db = kb.kb.getData('gtkOutput', 'db') self.queue = kb.kb.getData('gtkOutput', 'queue') else: self.queue = Queue.Queue() kb.kb.save('gtkOutput', 'queue' , self.queue) # Create DB and add tables sessionName = cf.cf.getData('sessionName') dbName = os.path.join(get_home_dir(), 'sessions', 'db_' + sessionName) # Just in case the directory doesn't exist... try: os.mkdir(os.path.join(get_home_dir() , 'sessions')) except OSError, oe: # [Errno 17] File exists if oe.errno != 17: msg = 'Unable to write to the user home directory: ' + get_home_dir() raise w3afException( msg ) self._db = DB() # Check if the database already exists if os.path.exists(dbName): # Find one that doesn't exist for i in xrange(100): newDbName = dbName + '-' + str(i) if not os.path.exists(newDbName): dbName = newDbName break # Create DB! self._db.open(dbName) # Create table historyItem = HistoryItem(self._db) self._db.createTable(historyItem.getTableName(), historyItem.getColumns(), historyItem.getPrimaryKeyColumns()) kb.kb.save('gtkOutput', 'db', self._db)