Files
metasploit-gs/lib/msf/base/persistent_storage/flatfile.rb
T

62 lines
1.6 KiB
Ruby
Raw Normal View History

# -*- coding: binary -*-
2005-11-09 03:28:21 +00:00
module Msf
class PersistentStorage
# This class persists the state of the framework to a flatfile in a human
# readable format. At the moment, the level of information it conveys is
# rather basic and ugly, but this is just a prototype, so it will be improved.
# Oh yes, it will be improved.
class Flatfile < PersistentStorage
2013-08-30 16:28:33 -05:00
# Initializes the flatfile for storage based on the parameters specified.
# The hash must contain a FilePath attribute.
2013-12-26 10:14:41 -08:00
#
# @overload initialize(path)
# Initializes the flatfile with the set path.
2013-12-26 10:14:41 -08:00
# @param path [String] path of the flatfile.
2013-08-30 16:28:33 -05:00
def initialize(*params)
raise ArgumentError, "You must specify a file path" if (params.length == 0)
self.path = params[0]
end
# This method stores the current state of the framework in human readable
# form to a flatfile. This can be used as a reporting mechanism.
2013-12-26 10:14:41 -08:00
#
# @param framework [Msf:::Framework] the Framework to store.
# @return [void]
2013-08-30 16:28:33 -05:00
def store(framework)
# Open the supplied file path for writing.
self.fd = File.new(self.path, "w")
begin
store_general(framework)
ensure
self.fd.close
end
end
2005-11-09 03:28:21 +00:00
protected
2013-08-30 16:28:33 -05:00
attr_accessor :fd, :path # :nodoc:
# This method stores general information about the current state of the
# framework instance.
2013-12-26 10:14:41 -08:00
#
# @param framework [Msf::Framework] the Framework to store.
# @return [void]
2013-08-30 16:28:33 -05:00
def store_general(framework)
fd.print(
"\n" +
"Metasploit Framework Report\n" +
"===========================\n\n" +
"Generated: #{Time.now}\n\n")
end
Msf::PersistentStorage.add_storage_class('flatfile', self)
2005-11-09 03:28:21 +00:00
end
end
2012-04-15 23:35:38 -05:00
end