CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/lib/msf/core/module/deprecated.rb
Views: 1904
1
# -*- coding: binary -*-
2
3
module Msf::Module::Deprecated
4
5
# Additional class methods for deprecated modules
6
module ClassMethods
7
attr_accessor :deprecation_date
8
attr_accessor :deprecated_names
9
attr_accessor :deprecation_reason
10
11
# Mark this module as deprecated
12
#
13
# Any time this module is run it will print warnings to that effect.
14
#
15
# @param date [Date,#to_s] The date on which this module will
16
# be removed
17
# @param reason [String] A description reason for this module being deprecated
18
# @return [void]
19
def deprecated(date, reason = nil)
20
self.deprecation_date = date
21
self.deprecation_reason = reason
22
23
# NOTE: fullname isn't set until a module has been added to a set, which is after it is evaluated
24
add_warning do
25
details = [
26
"*%red" + "The module #{fullname} is deprecated!".center(88) + "%clr*",
27
"*" + "This module will be removed on or about #{date}".center(88) + "*"
28
]
29
details << "*#{reason.center(88)}*" if reason.present?
30
31
details
32
end
33
end
34
35
# Mark this module as moved from another location. This adds an alias to
36
# the module so that it can still be used by its old name and will print a
37
# warning informing the use of the new name.
38
#
39
# @param from [String] the previous `fullname` of the module
40
def moved_from(from)
41
self.deprecated_names << from
42
43
if const_defined?(:Aliases)
44
const_get(:Aliases).append from
45
else
46
const_set(:Aliases, [from])
47
end
48
49
# NOTE: aliases are not set until after initialization, so might as well
50
# use the block form of alert here too.
51
add_warning do
52
if fullname == from
53
[ "*%red" + "The module #{fullname} has been moved!".center(88) + "%clr*",
54
"*" + "You are using #{realname}".center(88) + "*" ]
55
end
56
end
57
end
58
end
59
60
# Extends with {ClassMethods}
61
def self.included(base)
62
base.extend(ClassMethods)
63
base.deprecated_names = []
64
end
65
end
66
67