=begin Copyright 2010-2015 Tasos Laskos This file is part of the Arachni Framework project and is subject to redistribution and commercial restrictions. Please see the Arachni Framework web site for more information on licensing and terms of use. =end require 'zip' require 'fileutils' require_relative 'data' require_relative 'state' module Arachni # Stores and provides access to the state of the system. # # @author Tasos "Zapotek" Laskos class Snapshot # {Snapshot} error namespace. # # All {Snapshot} errors inherit from and live under it. # # @author Tasos "Zapotek" Laskos class Error < Arachni::Error # Raised when trying to read an invalid snapshot file. # # @author Tasos "Zapotek" Laskos class InvalidFile < Error end end class < e ne = Error::InvalidFile.new( "Invalid snapshot: #{snapshot} (#{e})" ) ne.set_backtrace e.backtrace raise ne end private def prepare_metadata { timestamp: Time.now, version: Arachni::VERSION, summary: summary } end def get_temporary_directory "#{Dir.tmpdir}/Arachni_Snapshot_#{Utilities.generate_token}/" end def extract( archive, directory ) Zip::File.open( archive ) do |zip_file| zip_file.each do |f| f_path = File.join( directory, f.name ) FileUtils.mkdir_p( File.dirname( f_path ) ) zip_file.extract( f, f_path ) unless File.exist?( f_path ) end end directory end def compress( directory, archive ) Zip::File.open( archive, Zip::File::CREATE ) do |zipfile| Dir[File.join(directory, '**', '**')].each do |file| zipfile.add( file.sub( directory, '' ), file ) end end archive end end reset end end