2014-08-17 17:31:53 -05:00
|
|
|
# -*- coding: binary -*-
|
2013-01-02 19:14:44 -06:00
|
|
|
|
|
|
|
|
module Msf::Module::Deprecated
|
|
|
|
|
|
|
|
|
|
# Additional class methods for deprecated modules
|
|
|
|
|
module ClassMethods
|
2019-08-22 11:16:03 -05:00
|
|
|
attr_accessor :deprecation_date
|
2020-02-06 10:23:32 -06:00
|
|
|
attr_accessor :deprecated_names
|
2020-06-08 22:58:45 +01:00
|
|
|
attr_accessor :deprecation_reason
|
2019-08-22 11:16:03 -05:00
|
|
|
|
2013-01-02 19:14:44 -06:00
|
|
|
# Mark this module as deprecated
|
|
|
|
|
#
|
|
|
|
|
# Any time this module is run it will print warnings to that effect.
|
|
|
|
|
#
|
2020-06-08 22:58:45 +01:00
|
|
|
# @param date [Date,#to_s] The date on which this module will
|
2013-01-02 19:14:44 -06:00
|
|
|
# be removed
|
2020-06-08 22:58:45 +01:00
|
|
|
# @param reason [String] A description reason for this module being deprecated
|
2013-01-02 19:14:44 -06:00
|
|
|
# @return [void]
|
2020-06-08 22:58:45 +01:00
|
|
|
def deprecated(date, reason = nil)
|
2019-08-22 11:16:03 -05:00
|
|
|
self.deprecation_date = date
|
2020-06-08 22:58:45 +01:00
|
|
|
self.deprecation_reason = reason
|
2019-08-22 11:16:03 -05:00
|
|
|
|
|
|
|
|
# NOTE: fullname isn't set until a module has been added to a set, which is after it is evaluated
|
|
|
|
|
add_warning do
|
2020-06-08 22:58:45 +01:00
|
|
|
details = [
|
|
|
|
|
"*%red" + "The module #{fullname} is deprecated!".center(88) + "%clr*",
|
|
|
|
|
"*" + "This module will be removed on or about #{date}".center(88) + "*"
|
|
|
|
|
]
|
|
|
|
|
details << "*#{reason.center(88)}*" if reason.present?
|
|
|
|
|
|
|
|
|
|
details
|
2019-08-22 11:16:03 -05:00
|
|
|
end
|
2013-01-02 19:14:44 -06:00
|
|
|
end
|
2013-08-30 16:28:33 -05:00
|
|
|
|
2019-08-22 11:16:03 -05:00
|
|
|
# Mark this module as moved from another location. This adds an alias to
|
|
|
|
|
# the module so that it can still be used by its old name and will print a
|
2020-02-06 10:23:32 -06:00
|
|
|
# warning informing the use of the new name.
|
2013-01-02 19:14:44 -06:00
|
|
|
#
|
2019-08-22 11:16:03 -05:00
|
|
|
# @param from [String] the previous `fullname` of the module
|
|
|
|
|
def moved_from(from)
|
2020-02-06 10:23:32 -06:00
|
|
|
self.deprecated_names << from
|
2019-08-22 11:16:03 -05:00
|
|
|
|
|
|
|
|
if const_defined?(:Aliases)
|
|
|
|
|
const_get(:Aliases).append from
|
|
|
|
|
else
|
|
|
|
|
const_set(:Aliases, [from])
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# NOTE: aliases are not set until after initialization, so might as well
|
|
|
|
|
# use the block form of alert here too.
|
|
|
|
|
add_warning do
|
2020-02-06 10:23:32 -06:00
|
|
|
if fullname == from
|
2019-08-22 11:16:03 -05:00
|
|
|
[ "*%red" + "The module #{fullname} has been moved!".center(88) + "%clr*",
|
2019-11-01 10:22:40 -05:00
|
|
|
"*" + "You are using #{realname}".center(88) + "*" ]
|
2019-08-22 11:16:03 -05:00
|
|
|
end
|
|
|
|
|
end
|
2014-04-23 23:03:02 -04:00
|
|
|
end
|
|
|
|
|
end
|
2013-08-30 16:28:33 -05:00
|
|
|
|
2013-01-02 19:14:44 -06:00
|
|
|
# Extends with {ClassMethods}
|
|
|
|
|
def self.included(base)
|
|
|
|
|
base.extend(ClassMethods)
|
2020-02-06 10:23:32 -06:00
|
|
|
base.deprecated_names = []
|
2013-01-02 19:14:44 -06:00
|
|
|
end
|
|
|
|
|
end
|