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/rex/script/base.rb
Views: 1904
1
# -*- coding: binary -*-
2
module Rex
3
module Script
4
class Base
5
6
class OutputSink
7
def print(msg); end
8
def print_line(msg); end
9
def print_status(msg); end
10
def print_good(msg); end
11
def print_error(msg); end
12
alias_method :print_bad, :print_error
13
def print_warning(msg); end
14
end
15
16
attr_accessor :client, :framework, :path, :error, :args
17
attr_accessor :session, :sink, :workspace
18
19
def initialize(client, path)
20
self.client = client
21
self.framework = client.framework
22
self.path = path
23
self.sink = OutputSink.new
24
25
if(client.framework.db and client.framework.db.active)
26
self.workspace = client.framework.db.find_workspace( client.workspace.to_s ) || client.framework.db.workspace
27
end
28
29
# Convenience aliases
30
self.session = self.client
31
end
32
33
def output
34
client.user_output || self.sink
35
end
36
37
def completed
38
raise Rex::Script::Completed
39
end
40
41
def run(args=[])
42
self.args = args = args.flatten
43
begin
44
eval(::File.read(self.path, ::File.size(self.path)), binding )
45
rescue ::Interrupt
46
rescue ::Rex::Script::Completed
47
rescue ::Exception => e
48
self.error = e
49
raise e
50
end
51
end
52
53
def print(*args); output.print(*args); end
54
def print_status(*args); output.print_status(*args); end
55
def print_error(*args); output.print_error(*args); end
56
def print_good(*args); output.print_good(*args); end
57
def print_line(*args); output.print_line(*args); end
58
59
end
60
end
61
end
62
63
64