Module: Msf::Module::Alert::ClassMethods
- Defined in:
- lib/msf/core/module/alert.rb
Overview
This mixin provides a way for alert messages to be added to module classes
and instances, retrieved from module classes and instances, and displayed
from module instances. The two alert levels provided by this mixin are
:error and :warning, though other levels or display methods can be
added by subclasses/other mixins if desired by overriding #alert_user
method (calling super as necessary), adding a proxy method like
#add_warning that calls #add_alert or
#add_alert and optionally a helper retrieval method like
#warnings.
Instance Attribute Summary collapse
-
#alerts ⇒ Object
protected
Returns the value of attribute alerts.
Instance Method Summary collapse
-
#add_alert(level, msg, &block) ⇒ Object
protected
Add a message (or block that generates messages) to a module.
-
#add_error(msg = nil, &block) ⇒ true?
Add an error that will be provided to the user as early possible when using the module, either when they select it with the
usecommand, when the module is about to start running, or when the module generates its output. -
#add_info(msg = nil, &block) ⇒ true?
Add an info message that will be provided to the user as early possible when using this instance of a module, either when they select it with the
usecommand, when the module is about to start running, or when the module generates its output. -
#add_warning(msg = nil, &block) ⇒ true?
Add a warning that will be provided to the user as early possible when using the module, either when they select it with the
usecommand, when the module is about to start running, or when the module generates its output. -
#errors ⇒ Array<String, Proc>
A list of error message strings, or blocks (see #get_alerts).
-
#get_alerts(level) ⇒ Array<String, Proc>
A list of
levelalerts, either in string or block form. -
#infos ⇒ Array<String, Proc>
A list of info message strings, or blocks (see #get_alerts).
-
#usable? ⇒ true, false
This method allows modules to tell the framework if they are usable on the system that they are being loaded on in a generic fashion.
-
#warnings ⇒ Array<String, Proc>
A list of warning message strings, or blocks (see #get_alerts).
Instance Attribute Details
#alerts ⇒ Object (protected)
Returns the value of attribute alerts.
105 106 107 |
# File 'lib/msf/core/module/alert.rb', line 105 def alerts @alerts end |
Instance Method Details
#add_alert(level, msg, &block) ⇒ Object (protected)
Add a message (or block that generates messages) to a module. This message will be displayed once to the user by every instance of this module.
110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/msf/core/module/alert.rb', line 110 def add_alert(level, msg, &block) self.alerts ||= {} self.alerts[level] ||= [] if block self.alerts[level] << block true elsif msg self.alerts[level] << msg true end end |
#add_error(msg = nil, &block) ⇒ true?
Add an error that will be provided to the user as early possible when
using the module, either when they select it with the use command, when
the module is about to start running, or when the module generates its
output. Adding an error will cause #is_usable to return false.
39 40 41 |
# File 'lib/msf/core/module/alert.rb', line 39 def add_error(msg = nil, &block) add_alert(:error, msg, &block) end |
#add_info(msg = nil, &block) ⇒ true?
Add an info message that will be provided to the user as early possible when using
this instance of a module, either when they select it with the use
command, when the module is about to start running, or when the module
generates its output.
54 55 56 |
# File 'lib/msf/core/module/alert.rb', line 54 def add_info(msg = nil, &block) add_alert(:info, msg, &block) end |
#add_warning(msg = nil, &block) ⇒ true?
Add a warning that will be provided to the user as early possible when
using the module, either when they select it with the use command, when
the module is about to start running, or when the module generates its
output.
24 25 26 |
# File 'lib/msf/core/module/alert.rb', line 24 def add_warning(msg = nil, &block) add_alert(:warning, msg, &block) end |
#errors ⇒ Array<String, Proc>
Returns a list of error message strings, or blocks (see #get_alerts).
66 67 68 |
# File 'lib/msf/core/module/alert.rb', line 66 def errors get_alerts(:error) end |
#get_alerts(level) ⇒ Array<String, Proc>
Returns A list of level alerts, either in string
or block form. Blocks expect to be executed in the context of a fully
initialized module instance and will return nil if the alert they are
looking for does not apply or a string or array of strings, each
representing an alert.
82 83 84 85 86 |
# File 'lib/msf/core/module/alert.rb', line 82 def get_alerts(level) # Initialize here if needed, thanks to weird metaprogramming side-effects self.alerts ||= {} self.alerts[level] || [] end |
#infos ⇒ Array<String, Proc>
Returns a list of info message strings, or blocks (see #get_alerts).
72 73 74 |
# File 'lib/msf/core/module/alert.rb', line 72 def infos get_alerts(:info) end |
#usable? ⇒ true, false
This method allows modules to tell the framework if they are usable on the system that they are being loaded on in a generic fashion. By default, all modules are indicated as being usable. An example of where this is useful is if the module depends on something external to ruby, such as a binary.
This looks to have been abandoned at some point in the past, but it may be time to resurrect it.
99 100 101 |
# File 'lib/msf/core/module/alert.rb', line 99 def usable? errors.empty? end |
#warnings ⇒ Array<String, Proc>
Returns a list of warning message strings, or blocks (see #get_alerts).
60 61 62 |
# File 'lib/msf/core/module/alert.rb', line 60 def warnings get_alerts(:warning) end |