#!/usr/bin/perl use strict; $|=1; my $exc_ext = join('|', qw/js pm/); my $re_ext = qr/$exc_ext/i; my @dir = qw!/home/user/data/www/site1.ru /home/user/data/www/site2.ru!; my @files = (); print STDERR "Get folders\n"; while (my $d = shift @dir) { # print STDERR "= $d\n"; opendir D, $d; my @fd = grep { $_ !~ /^\.+$/ } readdir D; push @files, map { "$d/$_" } grep { -f "$d/$_" && $_ !~ /${re_ext}$/ } @fd; push @dir, map { "$d/$_" } grep { -d "$d/$_" } @fd; closedir D; } ### FILES my $cf= scalar(@files); print STDERR "Files changes: $cf \n"; my $i = 1; my $j = 0; foreach my $file (@files) { my $cn = int(100*($i++/$cf)); print STDERR "\r[",('*'x$cn),('.'x(100-$cn)),"] $cn%"; local $/ = undef; open F, $file; my $f = ; close F; if ($f =~ /<(iframe|script|asp)/io) { $j++; # print "== $file\n$f\n"; open F, ">$file"; print F rm_asp(rm_script(rm_iframe($f))); close F; } } print STDERR "\nremoved: $j / all: $cf\n"; sub rm_iframe { my $text = shift; $text =~ s!]*>.*?!!igsm; return $text; } sub rm_asp { my $text = shift; $text =~ s!]*>.*?]*>!!igsm; return $text; } sub rm_script { my $text = shift; $text =~ s!]*src\s*\=\s*['"]http.*?!!igsm; $text =~ s!!!igsm; return $text; }