2011-04-22 20:44:13 +00:00
|
|
|
class ConvertBinary < ActiveRecord::Migration
|
|
|
|
|
|
|
|
|
|
|
|
class WebPage < ActiveRecord::Base
|
|
|
|
serialize :headers
|
|
|
|
end
|
2012-12-06 14:13:53 +00:00
|
|
|
|
2011-04-22 20:44:13 +00:00
|
|
|
class WebVuln < ActiveRecord::Base
|
|
|
|
serialize :params
|
|
|
|
end
|
2012-12-06 14:13:53 +00:00
|
|
|
|
2011-04-22 20:44:13 +00:00
|
|
|
def bfilter(str)
|
|
|
|
str = str.to_s
|
|
|
|
str.encoding = 'binary' if str.respond_to?('encoding=')
|
|
|
|
str.gsub(/[\x00\x7f-\xff]/, '')
|
|
|
|
end
|
2012-12-06 14:13:53 +00:00
|
|
|
|
2011-04-22 20:44:13 +00:00
|
|
|
def self.up
|
2012-12-06 14:33:46 +00:00
|
|
|
rename_column :web_pages, :body, :body_text
|
|
|
|
rename_column :web_pages, :request, :request_text
|
|
|
|
rename_column :web_vulns, :request, :request_text
|
|
|
|
rename_column :web_vulns, :proof, :proof_text
|
2012-12-06 14:13:53 +00:00
|
|
|
|
2011-04-22 20:44:13 +00:00
|
|
|
add_column :web_pages, :body, :binary
|
|
|
|
add_column :web_pages, :request, :binary
|
2012-12-06 14:13:53 +00:00
|
|
|
add_column :web_vulns, :request, :binary
|
2011-04-22 20:44:13 +00:00
|
|
|
add_column :web_vulns, :proof, :binary
|
2012-12-06 14:13:53 +00:00
|
|
|
|
2011-04-22 20:44:13 +00:00
|
|
|
WebPage.find(:all).each { |r| r.body = r.body_text; r.save! }
|
|
|
|
WebPage.find(:all).each { |r| r.request = r.request_text; r.save! }
|
|
|
|
WebVuln.find(:all).each { |r| r.proof = r.proof_text; r.save! }
|
|
|
|
WebVuln.find(:all).each { |r| r.request = r.request_text; r.save! }
|
2012-12-06 14:13:53 +00:00
|
|
|
|
2011-04-22 20:44:13 +00:00
|
|
|
remove_column :web_pages, :body_text
|
|
|
|
remove_column :web_pages, :request_text
|
|
|
|
remove_column :web_vulns, :request_text
|
|
|
|
remove_column :web_vulns, :proof_text
|
2012-12-06 14:33:46 +00:00
|
|
|
|
|
|
|
WebPage.connection.schema_cache.clear!
|
|
|
|
WebPage.reset_column_information
|
|
|
|
WebVuln.connection.schema_cache.clear!
|
|
|
|
WebVuln.reset_column_information
|
2011-04-22 20:44:13 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def self.down
|
|
|
|
|
2012-12-06 14:33:46 +00:00
|
|
|
rename_column :web_pages, :body, :body_binary
|
|
|
|
rename_column :web_pages, :request, :request_binary
|
|
|
|
rename_column :web_vulns, :request, :request_binary
|
|
|
|
rename_column :web_vulns, :proof, :proof_binary
|
|
|
|
|
2011-04-22 20:44:13 +00:00
|
|
|
add_column :web_pages, :body, :text
|
|
|
|
add_column :web_pages, :request, :text
|
|
|
|
add_column :web_vulns, :request, :text
|
|
|
|
add_column :web_vulns, :proof, :text
|
2012-12-06 14:13:53 +00:00
|
|
|
|
2011-04-22 20:44:13 +00:00
|
|
|
WebPage.find(:all).each { |r| r.body = bfilter(r.body_binary); r.save! }
|
|
|
|
WebPage.find(:all).each { |r| r.request = bfilter(r.request_binary); r.save! }
|
|
|
|
WebVuln.find(:all).each { |r| r.proof = bfilter(r.proof_binary); r.save! }
|
|
|
|
WebVuln.find(:all).each { |r| r.request = bfilter(r.request_binary); r.save! }
|
2012-12-06 14:13:53 +00:00
|
|
|
|
2011-04-22 20:44:13 +00:00
|
|
|
remove_column :web_pages, :body_binary
|
|
|
|
remove_column :web_pages, :request_binary
|
|
|
|
remove_column :web_vulns, :request_binary
|
|
|
|
remove_column :web_vulns, :proof_binary
|
2012-12-06 14:13:53 +00:00
|
|
|
|
2012-12-06 14:33:46 +00:00
|
|
|
WebPage.connection.schema_cache.clear!
|
|
|
|
WebPage.reset_column_information
|
|
|
|
WebVuln.connection.schema_cache.clear!
|
|
|
|
WebVuln.reset_column_information
|
2011-04-22 20:44:13 +00:00
|
|
|
end
|
|
|
|
end
|