Yes, I made as you wrote: I closed the file and re-open with > property and all are working)) this is our last code
#!/usr/bin/perl -w
use strict;
use warnings;
use Cwd qw();
my $path = Cwd::cwd();
my $date = localtime();
my $count=0;
my $count_file = 0;
my $report = "$path/report_$date.txt";
open (FINDIT, "find $path -name '*.js' -type f -print |") || die "Coul
+dn't execute find!\n";
while (my $filename = <FINDIT>) {
$count_file++;
open (TABLETKA, "$filename") || die "Can't open $filename: $!\n";
my @lines = <TABLETKA>;
seek(TABLETKA,0,0);
my @clean = <TABLETKA>;
foreach (@lines) {
if ($_ =~ m#(document\.write\('<iframe.*)(</iframe>'\);)#)
+ {
foreach (@clean) {
$count++;
if ( s{([[:space:]];document\.write\('<iframe.*)(</iframe>
+'\);)}{ //eof} ) {
close (TABLETKA);
open (APP, ">$filename") || die "Can't open FOR WRITING $f
+ilename: $!\n";
print APP @clean;
close (APP);
open (REPORT, ">>$report") || die "Can't open a report.txt
+: $!\n";
chomp($filename);
print REPORT "$count_file. FILE: $filename\nINFECTED LINE
+NUMBER: $count\nCLEANING DATE: $date\n\n";
close (REPORT);
$count = 0;
}
elsif ( s{([^[:space:]])(;document\.write\('<iframe.*)(</i
+frame>'\);)}{$1; //eof} ) {
close (TABLETKA);
open (APP, ">$filename") || die "Can't open FOR WRITING $f
+ilename: $!\n";
print APP @clean;
close (APP);
open (REPORT, ">>$report") || die "Can't open a report.txt
+: $!\n";
chomp($filename);
print REPORT "$count_file. FILE: $filename\nINFECTED LINE
+NUMBER: $count\nCLEANING DATE: $date\n\n";
close (REPORT);
$count = 0;
}
elsif ( s{(;document\.write\('<iframe.*)(</iframe>'\);)}{
+//eof} ) {
close (TABLETKA);
open (APP, ">$filename") || die "Can't open FOR WRITING $f
+ilename: $!\n";
print APP @clean;
close (APP);
open (REPORT, ">>$report") || die "Can't open a report.txt
+: $!\n";
chomp($filename);
print REPORT "$count_file. FILE: $filename\nINFECTED LINE
+NUMBER: $count\nCLEANING DATE: $date\n\n";
close (REPORT);
$count = 0;
}
}
}
}
}
Enough codes make shapes. (Hamidjon)
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|