diff --git a/lib/utils/api.py b/lib/utils/api.py index 9337fe000..15a1047b6 100644 --- a/lib/utils/api.py +++ b/lib/utils/api.py @@ -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)