Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 162bafa

Browse files
committed
Fixes #5590
1 parent 1ce9c8a commit 162bafa

2 files changed

Lines changed: 55 additions & 12 deletions

File tree

lib/core/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from thirdparty.six import unichr as _unichr
2121

2222
# sqlmap version (<major>.<minor>.<month>.<monthly commit>)
23-
VERSION = "1.8.1.4"
23+
VERSION = "1.8.1.5"
2424
TYPE = "dev" if VERSION.count('.') > 2 and VERSION.split('.')[-1] != '0' else "stable"
2525
TYPE_COLORS = {"dev": 33, "stable": 90, "pip": 34}
2626
VERSION_STRING = "sqlmap/%s#%s" % ('.'.join(VERSION.split('.')[:-1]) if VERSION.count('.') > 2 and VERSION.split('.')[-1] == '0' else VERSION, TYPE)

sqlmapapi.py

Lines changed: 54 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,55 @@
1212
__import__("lib.utils.versioncheck") # this has to be the first non-standard import
1313

1414
import logging
15-
import optparse
1615
import os
1716
import warnings
1817

1918
warnings.filterwarnings(action="ignore", category=UserWarning)
2019
warnings.filterwarnings(action="ignore", category=DeprecationWarning)
2120

21+
try:
22+
from optparse import OptionGroup
23+
from optparse import OptionParser as ArgumentParser
24+
25+
ArgumentParser.add_argument = ArgumentParser.add_option
26+
27+
def _add_argument(self, *args, **kwargs):
28+
return self.add_option(*args, **kwargs)
29+
30+
OptionGroup.add_argument = _add_argument
31+
32+
except ImportError:
33+
from argparse import ArgumentParser
34+
35+
finally:
36+
def get_actions(instance):
37+
for attr in ("option_list", "_group_actions", "_actions"):
38+
if hasattr(instance, attr):
39+
return getattr(instance, attr)
40+
41+
def get_groups(parser):
42+
return getattr(parser, "option_groups", None) or getattr(parser, "_action_groups")
43+
44+
def get_all_options(parser):
45+
retVal = set()
46+
47+
for option in get_actions(parser):
48+
if hasattr(option, "option_strings"):
49+
retVal.update(option.option_strings)
50+
else:
51+
retVal.update(option._long_opts)
52+
retVal.update(option._short_opts)
53+
54+
for group in get_groups(parser):
55+
for option in get_actions(group):
56+
if hasattr(option, "option_strings"):
57+
retVal.update(option.option_strings)
58+
else:
59+
retVal.update(option._long_opts)
60+
retVal.update(option._short_opts)
61+
62+
return retVal
63+
2264
from lib.core.common import getUnicode
2365
from lib.core.common import setPaths
2466
from lib.core.data import logger
@@ -52,16 +94,17 @@ def main():
5294
setPaths(modulePath())
5395

5496
# Parse command line options
55-
apiparser = optparse.OptionParser()
56-
apiparser.add_option("-s", "--server", help="Run as a REST-JSON API server", action="store_true")
57-
apiparser.add_option("-c", "--client", help="Run as a REST-JSON API client", action="store_true")
58-
apiparser.add_option("-H", "--host", help="Host of the REST-JSON API server (default \"%s\")" % RESTAPI_DEFAULT_ADDRESS, default=RESTAPI_DEFAULT_ADDRESS, action="store")
59-
apiparser.add_option("-p", "--port", help="Port of the the REST-JSON API server (default %d)" % RESTAPI_DEFAULT_PORT, default=RESTAPI_DEFAULT_PORT, type="int", action="store")
60-
apiparser.add_option("--adapter", help="Server (bottle) adapter to use (default \"%s\")" % RESTAPI_DEFAULT_ADAPTER, default=RESTAPI_DEFAULT_ADAPTER, action="store")
61-
apiparser.add_option("--database", help="Set IPC database filepath (optional)")
62-
apiparser.add_option("--username", help="Basic authentication username (optional)", action="store")
63-
apiparser.add_option("--password", help="Basic authentication password (optional)", action="store")
64-
(args, _) = apiparser.parse_args()
97+
apiparser = ArgumentParser()
98+
apiparser.add_argument("-s", "--server", help="Run as a REST-JSON API server", action="store_true")
99+
apiparser.add_argument("-c", "--client", help="Run as a REST-JSON API client", action="store_true")
100+
apiparser.add_argument("-H", "--host", help="Host of the REST-JSON API server (default \"%s\")" % RESTAPI_DEFAULT_ADDRESS, default=RESTAPI_DEFAULT_ADDRESS)
101+
apiparser.add_argument("-p", "--port", help="Port of the the REST-JSON API server (default %d)" % RESTAPI_DEFAULT_PORT, default=RESTAPI_DEFAULT_PORT, type=int)
102+
apiparser.add_argument("--adapter", help="Server (bottle) adapter to use (default \"%s\")" % RESTAPI_DEFAULT_ADAPTER, default=RESTAPI_DEFAULT_ADAPTER)
103+
apiparser.add_argument("--database", help="Set IPC database filepath (optional)")
104+
apiparser.add_argument("--username", help="Basic authentication username (optional)")
105+
apiparser.add_argument("--password", help="Basic authentication password (optional)")
106+
(args, _) = apiparser.parse_known_args() if hasattr(apiparser, "parse_known_args") else apiparser.parse_args()
107+
65108

66109
# Start the client or the server
67110
if args.server:

0 commit comments

Comments
 (0)