Created
April 16, 2010 02:33
-
-
Save avit/367932 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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