sqlmap/lib/core/update.py

97 lines
3.2 KiB
Python
Raw Normal View History

2008-10-15 19:38:22 +04:00
#!/usr/bin/env python
"""
2008-10-15 19:56:32 +04:00
$Id$
2008-10-15 19:38:22 +04:00
2012-01-11 18:59:46 +04:00
Copyright (c) 2006-2012 sqlmap developers (http://www.sqlmap.org/)
2010-10-15 03:18:29 +04:00
See the file 'doc/COPYING' for copying permission
2008-10-15 19:38:22 +04:00
"""
import re
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 subprocess import PIPE
from subprocess import Popen as execute
from lib.core.common import dataToStdout
2010-10-21 02:09:03 +04:00
from lib.core.common import getUnicode
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
from lib.core.settings import IS_WIN
2011-01-30 14:36:03 +03:00
from lib.core.settings import UNICODE_ENCODING
2010-10-29 14:51:09 +04:00
from lib.core.subprocessng import pollProcess
2008-10-15 19:38:22 +04:00
def update():
if not conf.updateAll:
2008-10-15 19:38:22 +04:00
return
2010-01-18 17:59:24 +03:00
rootDir = paths.SQLMAP_ROOT_PATH
infoMsg = "updating sqlmap to latest development version from the "
infoMsg += "subversion repository"
2010-01-18 17:05:23 +03:00
logger.info(infoMsg)
2010-01-18 17:59:24 +03:00
2010-01-18 17:05:23 +03:00
try:
import pysvn
2010-01-18 17:59:24 +03:00
debugMsg = "sqlmap will update itself using installed python-svn "
debugMsg += "third-party library, http://pysvn.tigris.org/"
logger.debug(debugMsg)
2010-01-18 17:05:23 +03:00
def notify(event_dict):
2011-01-30 14:36:03 +03:00
action = getUnicode(event_dict['action'])
2010-01-18 18:20:50 +03:00
index = action.find('_')
prefix = action[index + 1].upper() if index != -1 else action.capitalize()
2010-01-18 17:59:24 +03:00
2010-01-18 17:05:23 +03:00
if action.find('_update') != -1:
return
2010-01-18 17:59:24 +03:00
2010-01-18 17:05:23 +03:00
if action.find('_completed') == -1:
2010-10-21 02:09:03 +04:00
dataToStdout("%s\t%s\n" % (prefix, event_dict['path']))
2010-01-18 17:05:23 +03:00
else:
2011-01-30 14:36:03 +03:00
revision = getUnicode(event_dict['revision'], UNICODE_ENCODING)
2010-01-18 17:05:23 +03:00
index = revision.find('number ')
2010-01-18 17:59:24 +03:00
2010-01-18 17:05:23 +03:00
if index != -1:
revision = revision[index+7:].strip('>')
2010-01-18 17:59:24 +03:00
2010-01-18 17:05:23 +03:00
logger.info('updated to the latest revision %s' % revision)
2010-01-18 17:59:24 +03:00
2010-01-18 17:05:23 +03:00
client = pysvn.Client()
client.callback_notify = notify
try:
client.update(rootDir)
except pysvn.ClientError, e:
2012-01-07 19:47:38 +04:00
errMsg = "unable to update sqlmap from subversion: '%s'. " % str(e)
errMsg += "You are strongly advised to checkout "
errMsg += "the clean copy from repository manually "
if IS_WIN:
errMsg += "(e.g. Right click -> TortoiseSVN -> Checkout... and type "
errMsg += "\"https://svn.sqlmap.org/sqlmap/trunk/sqlmap\" into field \"URL of repository\")"
else:
errMsg += "(e.g. \"svn checkout https://svn.sqlmap.org/sqlmap/trunk/sqlmap sqlmap-dev\")"
logger.error(errMsg)
2010-01-18 17:59:24 +03:00
except ImportError, _:
debugMsg = "sqlmap will try to update itself using 'svn' command"
logger.debug(debugMsg)
dataToStdout("\r[%s] [INFO] update in progress " % time.strftime("%X"))
process = execute("svn update %s" % rootDir, shell=True, stdout=PIPE)
2010-01-18 17:05:23 +03:00
pollProcess(process)
svnStdout, _ = process.communicate()
if svnStdout:
2010-01-18 17:59:24 +03:00
revision = re.search("revision\s+([\d]+)", svnStdout, re.I)
2011-02-01 01:51:14 +03:00
2010-01-18 17:59:24 +03:00
if revision:
logger.info('updated to the latest revision %s' % revision.group(1))
if IS_WIN:
infoMsg = "for Windows platform it's recommended "
infoMsg += "to use a TortoiseSVN GUI client for updating "
2011-05-24 20:34:08 +04:00
infoMsg += "purposes (http://tortoisesvn.net/downloads.html)"
logger.info(infoMsg)