2012-06-29 05:18:28 +00:00
|
|
|
# -*- coding: binary -*-
|
2010-02-24 23:07:08 +00:00
|
|
|
module Rex
|
|
|
|
module Script
|
|
|
|
class Base
|
|
|
|
|
2013-08-30 21:28:33 +00:00
|
|
|
class OutputSink
|
|
|
|
def print(msg); end
|
|
|
|
def print_line(msg); end
|
|
|
|
def print_status(msg); end
|
|
|
|
def print_good(msg); end
|
|
|
|
def print_error(msg); end
|
2016-11-16 01:20:42 +00:00
|
|
|
alias_method :print_bad, :print_error
|
2013-08-30 21:28:33 +00:00
|
|
|
def print_warning(msg); end
|
|
|
|
end
|
|
|
|
|
|
|
|
attr_accessor :client, :framework, :path, :error, :args
|
|
|
|
attr_accessor :session, :sink, :workspace
|
|
|
|
|
|
|
|
def initialize(client, path)
|
|
|
|
self.client = client
|
|
|
|
self.framework = client.framework
|
|
|
|
self.path = path
|
|
|
|
self.sink = OutputSink.new
|
|
|
|
|
|
|
|
if(client.framework.db and client.framework.db.active)
|
|
|
|
self.workspace = client.framework.db.find_workspace( client.workspace.to_s ) || client.framework.db.workspace
|
|
|
|
end
|
|
|
|
|
|
|
|
# Convenience aliases
|
|
|
|
self.session = self.client
|
|
|
|
end
|
|
|
|
|
|
|
|
def output
|
|
|
|
client.user_output || self.sink
|
|
|
|
end
|
|
|
|
|
|
|
|
def completed
|
|
|
|
raise Rex::Script::Completed
|
|
|
|
end
|
|
|
|
|
|
|
|
def run(args=[])
|
|
|
|
self.args = args = args.flatten
|
|
|
|
begin
|
|
|
|
eval(::File.read(self.path, ::File.size(self.path)), binding )
|
|
|
|
rescue ::Interrupt
|
|
|
|
rescue ::Rex::Script::Completed
|
|
|
|
rescue ::Exception => e
|
|
|
|
self.error = e
|
|
|
|
raise e
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def print(*args); output.print(*args); end
|
|
|
|
def print_status(*args); output.print_status(*args); end
|
|
|
|
def print_error(*args); output.print_error(*args); end
|
|
|
|
def print_good(*args); output.print_good(*args); end
|
|
|
|
def print_line(*args); output.print_line(*args); end
|
2010-02-24 23:07:08 +00:00
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|