This commit is contained in:
Miroslav Stampar 2015-03-09 22:01:59 +01:00
parent 02fb5058c2
commit 9bd41ed99d

View File

@ -29,6 +29,7 @@ from lib.core.datatype import AttribDict
from lib.core.defaults import _defaults
from lib.core.enums import CONTENT_STATUS
from lib.core.enums import PART_RUN_CONTENT_TYPES
from lib.core.exception import SqlmapConnectionException
from lib.core.log import LOGGER_HANDLER
from lib.core.optiondict import optDict
from lib.core.subprocessng import Popen
@ -66,8 +67,11 @@ class Database(object):
logger.debug("REST-JSON API %s connected to IPC database" % who)
def disconnect(self):
self.cursor.close()
self.connection.close()
if self.cursor:
self.cursor.close()
if self.connection:
self.connection.close()
def commit(self):
self.connection.commit()
@ -252,8 +256,11 @@ class LogRecorder(logging.StreamHandler):
def setRestAPILog():
if hasattr(conf, "api"):
conf.database_cursor = Database(conf.database)
conf.database_cursor.connect("client")
try:
conf.database_cursor = Database(conf.database)
conf.database_cursor.connect("client")
except sqlite3.OperationalError, ex:
raise SqlmapConnectionException, "%s ('%s')" % (ex, conf.database)
# Set a logging handler that writes log messages to a IPC database
logger.removeHandler(LOGGER_HANDLER)