Skip to content

Instantly share code, notes, and snippets.

@avit
Created April 16, 2010 02:33
Show Gist options
  • Save avit/367932 to your computer and use it in GitHub Desktop.
Save avit/367932 to your computer and use it in GitHub Desktop.
#! /usr/bin/env ruby
require 'find'
PATTERN = Regexp.new '(\r\n\r\n)?<script>[^\n]+</script>\n<!--[a-f0-9]{32}-->'
def kill_virus(dir)
Find.find(dir) do |path|
if File.file?(path)
text = File.read(path)
if text =~ PATTERN
text.gsub! PATTERN, ''
File.open(path, 'w') { |f| f.write(text); puts "cleaned: #{path}" }
end
end
end
end
ARGV.each do |a|
if File.directory? a
kill_virus(a)
else
puts "Not a directory: #{a}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment