|
28 | 28 | import shutil |
29 | 29 | import sys |
30 | 30 | import tempfile |
| 31 | +import time |
31 | 32 | import urlparse |
32 | 33 | import zipfile |
33 | 34 |
|
|
37 | 38 | from subprocess import PIPE |
38 | 39 | from subprocess import Popen as execute |
39 | 40 |
|
40 | | -from lib.core.common import readInput |
41 | | -from lib.core.common import pollProcess |
42 | 41 | from lib.core.common import dataToStdout |
| 42 | +from lib.core.common import pollProcess |
| 43 | +from lib.core.common import readInput |
43 | 44 | from lib.core.data import conf |
44 | 45 | from lib.core.data import logger |
45 | 46 | from lib.core.data import paths |
@@ -202,37 +203,59 @@ def __updateMSSQLXML(): |
202 | 203 | logger.info(infoMsg) |
203 | 204 |
|
204 | 205 | def __updateSqlmap(): |
205 | | - infoMsg = "updating sqlmap directly from the repository" |
| 206 | + rootDir = paths.SQLMAP_ROOT_PATH |
| 207 | + |
| 208 | + infoMsg = "updating sqlmap to latest development version from the " |
| 209 | + infoMsg += "subversion repository" |
206 | 210 | logger.info(infoMsg) |
207 | | - rootDir = os.path.dirname(os.path.realpath(sys.argv[0])) |
| 211 | + |
208 | 212 | try: |
209 | 213 | import pysvn |
| 214 | + |
| 215 | + debugMsg = "sqlmap will update itself using installed python-svn " |
| 216 | + debugMsg += "third-party library, http://pysvn.tigris.org/" |
| 217 | + logger.debug(debugMsg) |
| 218 | + |
210 | 219 | def notify(event_dict): |
211 | 220 | action = str(event_dict['action']) |
| 221 | + |
212 | 222 | if action.find('_update') != -1: |
213 | 223 | return |
| 224 | + |
214 | 225 | index = action.find('_') |
215 | 226 | prefix = action[index + 1].upper() if index != -1 else action.capitalize() |
| 227 | + |
216 | 228 | if action.find('_completed') == -1: |
217 | 229 | print "%s %s" % (prefix, event_dict['path']) |
218 | 230 | else: |
219 | 231 | revision = str(event_dict['revision']) |
220 | 232 | index = revision.find('number ') |
| 233 | + |
221 | 234 | if index != -1: |
222 | 235 | revision = revision[index+7:].strip('>') |
| 236 | + |
223 | 237 | logger.info('updated to the latest revision %s' % revision) |
| 238 | + |
224 | 239 | client = pysvn.Client() |
225 | 240 | client.callback_notify = notify |
226 | 241 | client.update(rootDir) |
227 | | - except ImportError: |
228 | | - process = execute("svn update %s" % (rootDir), shell=True, stdout=None, stderr=PIPE) |
| 242 | + except ImportError, _: |
| 243 | + debugMsg = "sqlmap will try to update itself using 'svn' command" |
| 244 | + logger.debug(debugMsg) |
| 245 | + |
| 246 | + process = execute("svn update %s" % rootDir, shell=True, stdout=PIPE, stderr=PIPE) |
229 | 247 |
|
| 248 | + dataToStdout("\r[%s] [INFO] update in progress " % time.strftime("%X")) |
230 | 249 | pollProcess(process) |
231 | 250 | svnStdout, svnStderr = process.communicate() |
232 | 251 |
|
233 | 252 | if svnStderr: |
234 | 253 | errMsg = svnStderr.strip() |
235 | 254 | logger.error(errMsg) |
| 255 | + elif svnStdout: |
| 256 | + revision = re.search("revision\s+([\d]+)", svnStdout, re.I) |
| 257 | + if revision: |
| 258 | + logger.info('updated to the latest revision %s' % revision.group(1)) |
236 | 259 |
|
237 | 260 | def update(): |
238 | 261 | if not conf.updateAll: |
|
0 commit comments