|
16 | 16 | from lib.core.data import conf |
17 | 17 | from lib.core.data import logger |
18 | 18 | from lib.core.data import paths |
19 | | -from lib.core.exception import sqlmapUnsupportedFeatureException |
20 | 19 | from lib.core.settings import IS_WIN |
| 20 | +from lib.core.settings import REVISION |
21 | 21 | from lib.core.settings import UNICODE_ENCODING |
22 | 22 | from lib.core.subprocessng import pollProcess |
23 | 23 |
|
24 | 24 | def update(): |
25 | 25 | if not conf.updateAll: |
26 | 26 | return |
27 | 27 |
|
28 | | - errMsg = "sqlmap is now hosted on GitHub at https://github.com/sqlmapproject/sqlmap. " |
29 | | - errMsg += "The --update switch is currently outdated and not working. Please, " |
30 | | - errMsg += "update sqlmap running 'git pull' for the time being" |
31 | | - raise sqlmapUnsupportedFeatureException, errMsg |
32 | | - |
33 | 28 | rootDir = paths.SQLMAP_ROOT_PATH |
34 | 29 |
|
35 | | - infoMsg = "updating sqlmap to latest development version from the " |
36 | | - infoMsg += "subversion repository" |
| 30 | + infoMsg = "updating sqlmap to the latest development version from the " |
| 31 | + infoMsg += "GitHub repository" |
37 | 32 | logger.info(infoMsg) |
38 | 33 |
|
39 | | - try: |
40 | | - import pysvn |
41 | | - |
42 | | - debugMsg = "sqlmap will update itself using installed python-svn " |
43 | | - debugMsg += "third-party library, http://pysvn.tigris.org/" |
44 | | - logger.debug(debugMsg) |
45 | | - |
46 | | - def notify(event_dict): |
47 | | - action = getUnicode(event_dict['action']) |
48 | | - index = action.find('_') |
49 | | - prefix = action[index + 1].upper() if index != -1 else action.capitalize() |
50 | | - |
51 | | - if action.find('_update') != -1: |
52 | | - return |
53 | | - |
54 | | - if action.find('_completed') == -1: |
55 | | - dataToStdout("%s\t%s\n" % (prefix, event_dict['path'])) |
56 | | - else: |
57 | | - revision = getUnicode(event_dict['revision'], UNICODE_ENCODING) |
58 | | - index = revision.find('number ') |
59 | | - |
60 | | - if index != -1: |
61 | | - revision = revision[index+7:].strip('>') |
62 | | - |
63 | | - logger.info('updated to the latest revision %s' % revision) |
64 | | - |
65 | | - client = pysvn.Client() |
66 | | - client.callback_notify = notify |
67 | | - |
68 | | - try: |
69 | | - client.update(rootDir) |
70 | | - except pysvn.ClientError, e: |
71 | | - errMsg = "unable to update sqlmap from subversion: '%s'. " % str(e) |
72 | | - errMsg += "You are strongly advised to checkout " |
73 | | - errMsg += "the clean copy from repository manually " |
74 | | - if IS_WIN: |
75 | | - errMsg += "(e.g. Right click -> TortoiseSVN -> Checkout... and type " |
76 | | - errMsg += "\"https://svn.sqlmap.org/sqlmap/trunk/sqlmap\" into field \"URL of repository\")" |
77 | | - else: |
78 | | - errMsg += "(e.g. \"svn checkout https://svn.sqlmap.org/sqlmap/trunk/sqlmap sqlmap-dev\")" |
79 | | - logger.error(errMsg) |
80 | | - |
81 | | - except ImportError, _: |
82 | | - debugMsg = "sqlmap will try to update itself using 'svn' command" |
83 | | - logger.debug(debugMsg) |
84 | | - |
85 | | - dataToStdout("\r[%s] [INFO] update in progress " % time.strftime("%X")) |
86 | | - process = execute("svn update %s" % rootDir, shell=True, stdout=PIPE) |
87 | | - pollProcess(process) |
88 | | - svnStdout, _ = process.communicate() |
| 34 | + debugMsg = "sqlmap will try to update itself using 'git' command" |
| 35 | + logger.debug(debugMsg) |
89 | 36 |
|
90 | | - if svnStdout: |
91 | | - revision = re.search("revision\s+([\d]+)", svnStdout, re.I) |
| 37 | + dataToStdout("\r[%s] [INFO] update in progress " % time.strftime("%X")) |
| 38 | + process = execute("git pull %s" % rootDir, shell=True, stdout=PIPE, stderr=PIPE) |
| 39 | + pollProcess(process) |
| 40 | + stdout, _ = process.communicate() |
92 | 41 |
|
93 | | - if revision: |
94 | | - logger.info('updated to the latest revision %s' % revision.group(1)) |
| 42 | + if not process.returncode: |
| 43 | + logger.info("%s the latest revision '%s'" % ("already at" if "Already" in stdout else "updated to", REVISION)) |
95 | 44 |
|
96 | | - if IS_WIN: |
97 | | - infoMsg = "for Windows platform it's recommended " |
98 | | - infoMsg += "to use a TortoiseSVN GUI client for updating " |
99 | | - infoMsg += "purposes (http://tortoisesvn.net/downloads.html)" |
100 | | - logger.info(infoMsg) |
| 45 | + if IS_WIN: |
| 46 | + infoMsg = "for Windows platform it's recommended " |
| 47 | + infoMsg += "to use a GitHub for Windows client for updating " |
| 48 | + infoMsg += "purposes (http://windows.github.com/)" |
| 49 | + logger.info(infoMsg) |
0 commit comments