Commit 77598c95 by fwkz

Applying validators to GLOBAL_OPTS when switching between modules.

parent cdbb42ce
...@@ -24,7 +24,15 @@ class Option(object): ...@@ -24,7 +24,15 @@ class Option(object):
self.data = WeakKeyDictionary() self.data = WeakKeyDictionary()
def __get__(self, instance, owner): def __get__(self, instance, owner):
return self.data.get(instance, GLOBAL_OPTS.get(self.label, self.default)) try:
return self.data[instance]
except KeyError:
pass
try:
return self._apply_widgets(GLOBAL_OPTS[self.label])
except KeyError:
return self.default
def __set__(self, instance, value): def __set__(self, instance, value):
self.data[instance] = self._apply_widgets(value) self.data[instance] = self._apply_widgets(value)
......
...@@ -293,6 +293,8 @@ class RoutersploitInterpreter(BaseInterpreter): ...@@ -293,6 +293,8 @@ class RoutersploitInterpreter(BaseInterpreter):
key, _, value = args[0].partition(' ') key, _, value = args[0].partition(' ')
if key in self.current_module.options: if key in self.current_module.options:
setattr(self.current_module, key, value) setattr(self.current_module, key, value)
if kwargs.get("global", False):
GLOBAL_OPTS[key] = value
utils.print_success({key: value}) utils.print_success({key: value})
else: else:
utils.print_error("You can't set option '{}'.\n" utils.print_error("You can't set option '{}'.\n"
...@@ -307,13 +309,8 @@ class RoutersploitInterpreter(BaseInterpreter): ...@@ -307,13 +309,8 @@ class RoutersploitInterpreter(BaseInterpreter):
@utils.module_required @utils.module_required
def command_setg(self, *args, **kwargs): def command_setg(self, *args, **kwargs):
key, _, value = args[0].partition(' ') kwargs['global'] = True
if key in self.current_module.options: self.command_set(*args, **kwargs)
GLOBAL_OPTS[key] = value
utils.print_success({key: value})
else:
utils.print_error("You can't set option '{}'.\n"
"Available options: {}".format(key, self.current_module.options))
@utils.stop_after(2) @utils.stop_after(2)
def complete_setg(self, text, *args, **kwargs): def complete_setg(self, text, *args, **kwargs):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment