Minor refactoring

This commit is contained in:
Miroslav Stampar 2019-05-13 11:51:47 +02:00
parent 10be8a12bd
commit 15ef0f872f
5 changed files with 10 additions and 7 deletions

View File

@ -10,6 +10,7 @@ import re
import subprocess import subprocess
from lib.core.common import getText from lib.core.common import getText
from lib.core.common import openFile
def getRevisionNumber(): def getRevisionNumber():
""" """
@ -36,7 +37,7 @@ def getRevisionNumber():
while True: while True:
if filePath and os.path.isfile(filePath): if filePath and os.path.isfile(filePath):
with open(filePath, "r") as f: with openFile(filePath, "r") as f:
content = f.read() content = f.read()
filePath = None filePath = None
if content.startswith("ref: "): if content.startswith("ref: "):

View File

@ -18,7 +18,7 @@ from lib.core.enums import OS
from thirdparty import six from thirdparty import six
# sqlmap version (<major>.<minor>.<month>.<monthly commit>) # sqlmap version (<major>.<minor>.<month>.<monthly commit>)
VERSION = "1.3.5.81" VERSION = "1.3.5.82"
TYPE = "dev" if VERSION.count('.') > 2 and VERSION.split('.')[-1] != '0' else "stable" TYPE = "dev" if VERSION.count('.') > 2 and VERSION.split('.')[-1] != '0' else "stable"
TYPE_COLORS = {"dev": 33, "stable": 90, "pip": 34} TYPE_COLORS = {"dev": 33, "stable": 90, "pip": 34}
VERSION_STRING = "sqlmap/%s#%s" % ('.'.join(VERSION.split('.')[:-1]) if VERSION.count('.') > 2 and VERSION.split('.')[-1] == '0' else VERSION, TYPE) VERSION_STRING = "sqlmap/%s#%s" % ('.'.join(VERSION.split('.')[:-1]) if VERSION.count('.') > 2 and VERSION.split('.')[-1] == '0' else VERSION, TYPE)

View File

@ -18,6 +18,7 @@ from lib.core.common import dataToStdout
from lib.core.common import getSafeExString from lib.core.common import getSafeExString
from lib.core.common import getLatestRevision from lib.core.common import getLatestRevision
from lib.core.common import getText from lib.core.common import getText
from lib.core.common import openFile
from lib.core.common import pollProcess from lib.core.common import pollProcess
from lib.core.common import readInput from lib.core.common import readInput
from lib.core.data import conf from lib.core.data import conf
@ -82,7 +83,7 @@ def update():
filepath = os.path.join(paths.SQLMAP_ROOT_PATH, "lib", "core", "settings.py") filepath = os.path.join(paths.SQLMAP_ROOT_PATH, "lib", "core", "settings.py")
if os.path.isfile(filepath): if os.path.isfile(filepath):
with open(filepath, "rb") as f: with openFile(filepath, "rb") as f:
version = re.search(r"(?m)^VERSION\s*=\s*['\"]([^'\"]+)", f.read()).group(1) version = re.search(r"(?m)^VERSION\s*=\s*['\"]([^'\"]+)", f.read()).group(1)
logger.info("updated to the latest version '%s#dev'" % version) logger.info("updated to the latest version '%s#dev'" % version)
success = True success = True

View File

@ -21,6 +21,7 @@ import time
from lib.core.common import dataToStdout from lib.core.common import dataToStdout
from lib.core.common import getSafeExString from lib.core.common import getSafeExString
from lib.core.common import openFile
from lib.core.common import saveConfig from lib.core.common import saveConfig
from lib.core.common import unArrayizeValue from lib.core.common import unArrayizeValue
from lib.core.compat import xrange from lib.core.compat import xrange
@ -648,9 +649,8 @@ def download(taskid, target, filename):
if os.path.isfile(path): if os.path.isfile(path):
logger.debug("(%s) Retrieved content of file %s" % (taskid, target)) logger.debug("(%s) Retrieved content of file %s" % (taskid, target))
with open(path, 'rb') as inf: content = openFile(path, "rb").read()
file_content = inf.read() return jsonize({"success": True, "file": encodeBase64(content, binary=False)})
return jsonize({"success": True, "file": encodeBase64(file_content, binary=False)})
else: else:
logger.warning("[%s] File does not exist %s" % (taskid, target)) logger.warning("[%s] File does not exist %s" % (taskid, target))
return jsonize({"success": False, "message": "File does not exist"}) return jsonize({"success": False, "message": "File does not exist"})

View File

@ -56,6 +56,7 @@ from lib.core.common import getSafeExString
from lib.core.common import hashDBRetrieve from lib.core.common import hashDBRetrieve
from lib.core.common import hashDBWrite from lib.core.common import hashDBWrite
from lib.core.common import normalizeUnicode from lib.core.common import normalizeUnicode
from lib.core.common import openFile
from lib.core.common import paths from lib.core.common import paths
from lib.core.common import readInput from lib.core.common import readInput
from lib.core.common import singleTimeLogMessage from lib.core.common import singleTimeLogMessage
@ -597,7 +598,7 @@ def storeHashesToFile(attack_dict):
infoMsg = "writing hashes to a temporary file '%s' " % filename infoMsg = "writing hashes to a temporary file '%s' " % filename
logger.info(infoMsg) logger.info(infoMsg)
with open(filename, "w+") as f: with openFile(filename, "w+") as f:
for item in items: for item in items:
f.write(item) f.write(item)