2013-02-14 15:32:17 +04:00
|
|
|
#!/usr/bin/env python
|
2008-10-15 19:38:22 +04:00
|
|
|
|
|
|
|
"""
|
2018-01-02 02:48:10 +03:00
|
|
|
Copyright (c) 2006-2018 sqlmap developers (http://sqlmap.org/)
|
2017-10-11 15:50:46 +03:00
|
|
|
See the file 'LICENSE' for copying permission
|
2008-10-15 19:38:22 +04:00
|
|
|
"""
|
|
|
|
|
2012-07-04 00:13:01 +04:00
|
|
|
import os
|
2008-10-15 19:38:22 +04:00
|
|
|
import re
|
2016-12-20 01:47:39 +03:00
|
|
|
import subprocess
|
2018-03-03 02:50:47 +03:00
|
|
|
import sys
|
2010-01-18 17:59:24 +03:00
|
|
|
import time
|
2008-10-15 19:38:22 +04:00
|
|
|
|
2010-01-18 17:05:23 +03:00
|
|
|
from lib.core.common import dataToStdout
|
2015-10-17 00:59:39 +03:00
|
|
|
from lib.core.common import getSafeExString
|
2013-01-09 20:04:23 +04:00
|
|
|
from lib.core.common import pollProcess
|
2008-10-15 19:38:22 +04:00
|
|
|
from lib.core.data import conf
|
|
|
|
from lib.core.data import logger
|
|
|
|
from lib.core.data import paths
|
2012-07-26 02:02:38 +04:00
|
|
|
from lib.core.revision import getRevisionNumber
|
2012-07-08 21:24:25 +04:00
|
|
|
from lib.core.settings import GIT_REPOSITORY
|
2011-03-18 19:35:30 +03:00
|
|
|
from lib.core.settings import IS_WIN
|
2018-03-03 02:27:21 +03:00
|
|
|
from lib.core.settings import UNICODE_ENCODING
|
2008-10-15 19:38:22 +04:00
|
|
|
|
2011-01-31 14:38:00 +03:00
|
|
|
def update():
|
2012-07-02 03:00:46 +04:00
|
|
|
if not conf.updateAll:
|
|
|
|
return
|
|
|
|
|
2012-07-04 00:13:01 +04:00
|
|
|
success = False
|
2010-01-18 17:59:24 +03:00
|
|
|
|
2015-10-22 21:51:05 +03:00
|
|
|
if not os.path.exists(os.path.join(paths.SQLMAP_ROOT_PATH, ".git")):
|
2012-07-04 00:13:01 +04:00
|
|
|
errMsg = "not a git repository. Please checkout the 'sqlmapproject/sqlmap' repository "
|
2018-03-13 12:37:13 +03:00
|
|
|
errMsg += "from GitHub (e.g. 'git clone --depth 1 %s sqlmap')" % GIT_REPOSITORY
|
2012-07-04 00:13:01 +04:00
|
|
|
logger.error(errMsg)
|
|
|
|
else:
|
2018-01-21 13:49:50 +03:00
|
|
|
infoMsg = "updating sqlmap to the latest development revision from the "
|
2012-07-04 00:13:01 +04:00
|
|
|
infoMsg += "GitHub repository"
|
|
|
|
logger.info(infoMsg)
|
2010-01-18 17:59:24 +03:00
|
|
|
|
2012-07-04 00:13:01 +04:00
|
|
|
debugMsg = "sqlmap will try to update itself using 'git' command"
|
|
|
|
logger.debug(debugMsg)
|
2011-03-18 19:26:39 +03:00
|
|
|
|
2012-07-04 00:13:01 +04:00
|
|
|
dataToStdout("\r[%s] [INFO] update in progress " % time.strftime("%X"))
|
2015-10-17 00:59:39 +03:00
|
|
|
|
|
|
|
try:
|
2018-03-03 02:27:21 +03:00
|
|
|
process = subprocess.Popen("git checkout . && git pull %s HEAD" % GIT_REPOSITORY, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=paths.SQLMAP_ROOT_PATH.encode(sys.getfilesystemencoding() or UNICODE_ENCODING))
|
2015-10-17 00:59:39 +03:00
|
|
|
pollProcess(process, True)
|
|
|
|
stdout, stderr = process.communicate()
|
|
|
|
success = not process.returncode
|
|
|
|
except (IOError, OSError), ex:
|
|
|
|
success = False
|
|
|
|
stderr = getSafeExString(ex)
|
2011-02-01 01:51:14 +03:00
|
|
|
|
2012-07-04 00:13:01 +04:00
|
|
|
if success:
|
2016-10-10 02:35:22 +03:00
|
|
|
logger.info("%s the latest revision '%s'" % ("already at" if "Already" in stdout else "updated to", getRevisionNumber()))
|
2012-07-04 00:13:01 +04:00
|
|
|
else:
|
2015-10-14 17:11:11 +03:00
|
|
|
if "Not a git repository" in stderr:
|
|
|
|
errMsg = "not a valid git repository. Please checkout the 'sqlmapproject/sqlmap' repository "
|
2018-03-13 12:37:13 +03:00
|
|
|
errMsg += "from GitHub (e.g. 'git clone --depth 1 %s sqlmap')" % GIT_REPOSITORY
|
2015-10-14 17:11:11 +03:00
|
|
|
logger.error(errMsg)
|
|
|
|
else:
|
|
|
|
logger.error("update could not be completed ('%s')" % re.sub(r"\W+", " ", stderr).strip())
|
2012-07-03 18:49:34 +04:00
|
|
|
|
2012-07-04 00:13:01 +04:00
|
|
|
if not success:
|
2012-07-03 18:49:34 +04:00
|
|
|
if IS_WIN:
|
|
|
|
infoMsg = "for Windows platform it's recommended "
|
|
|
|
infoMsg += "to use a GitHub for Windows client for updating "
|
2012-07-04 22:28:18 +04:00
|
|
|
infoMsg += "purposes (http://windows.github.com/) or just "
|
|
|
|
infoMsg += "download the latest snapshot from "
|
|
|
|
infoMsg += "https://github.com/sqlmapproject/sqlmap/downloads"
|
2012-07-03 18:49:34 +04:00
|
|
|
else:
|
2012-07-04 00:13:01 +04:00
|
|
|
infoMsg = "for Linux platform it's required "
|
|
|
|
infoMsg += "to install a standard 'git' package (e.g.: 'sudo apt-get install git')"
|
2011-04-12 18:25:17 +04:00
|
|
|
|
2012-07-03 18:34:11 +04:00
|
|
|
logger.info(infoMsg)
|