2012-06-29 05:18:28 +00:00
|
|
|
# -*- coding: binary -*-
|
2010-02-10 17:27:40 +00:00
|
|
|
|
2010-02-11 00:18:37 +00:00
|
|
|
msfbase = __FILE__
|
|
|
|
while File.symlink?(msfbase)
|
2013-08-30 21:28:33 +00:00
|
|
|
msfbase = File.expand_path(File.readlink(msfbase), File.dirname(msfbase))
|
2010-02-11 00:18:37 +00:00
|
|
|
end
|
|
|
|
inc = File.dirname(msfbase) + '/../../..'
|
|
|
|
$:.unshift(inc)
|
|
|
|
|
|
|
|
require 'rex/zip'
|
2010-02-10 17:27:40 +00:00
|
|
|
|
|
|
|
out = "test.zip"
|
|
|
|
dir = "/var/www"
|
|
|
|
|
|
|
|
|
|
|
|
def add_file(zip, path)
|
2013-08-30 21:28:33 +00:00
|
|
|
zip.add_file(path)
|
2010-02-10 17:27:40 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
# If it's a directory, Walk the directory and add each item
|
|
|
|
#
|
|
|
|
def add_files(zip, path, recursive = nil)
|
|
|
|
|
2013-08-30 21:28:33 +00:00
|
|
|
if (not add_file(zip, path))
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
|
|
|
|
if (recursive and File.stat(path).directory?)
|
|
|
|
begin
|
|
|
|
dir = Dir.open(path)
|
|
|
|
rescue
|
|
|
|
# skip this file
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
|
|
|
|
dir.each { |f|
|
|
|
|
next if (f == '.')
|
|
|
|
next if (f == '..')
|
|
|
|
|
|
|
|
full_path = path + '/' + f
|
|
|
|
st = File.stat(full_path)
|
|
|
|
if (st.directory?)
|
|
|
|
puts "adding dir #{full_path}"
|
|
|
|
add_files(zip, full_path, recursive)
|
|
|
|
elsif (st.file?)
|
|
|
|
puts "adding file #{full_path}"
|
|
|
|
add_file(zip, full_path)
|
|
|
|
end
|
|
|
|
}
|
|
|
|
end
|
2010-02-10 17:27:40 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
2010-02-11 00:18:37 +00:00
|
|
|
zip = Rex::Zip::Archive.new
|
2010-02-10 17:27:40 +00:00
|
|
|
add_files(zip, dir, TRUE)
|
|
|
|
zip.save_to(out)
|