I need to scan all js files in my server and remove the line that contains:
document.write("<script type='text/javascript' src='http://*
I need to set it on cron to do every day. I think i will need to create a shell to do it.
Can you help me?
I need to scan all js files in my server and remove the line that contains:
document.write("<script type='text/javascript' src='http://*
I need to set it on cron to do every day. I think i will need to create a shell to do it.
Can you help me?
Probably SED is what you are looking for:
sed -i 's/document\.write[(]"<script type[=].text\/javascript. src[=].http:\/\/./\/\*code removed\*\//g' *.js
My example input file:
document.write("<script type='text/javascript' src='http://*
document.write("<script type='text/javascript' src='http://*
document.write("<script type='text/javascript' src='http://*
asddocument.write("<script type='text/javascript' src='http://*
document.write("<script type='text/javascript' src='http://*asd
asdasd
is transformed into:
/*code removed*/
/*code removed*/
/*code removed*/
asd/*code removed*/
/*code removed*/asd
asdasd
Please keep in mind, that if you want to prevent scripts on your webspace to load additional data, than all of these mechanisms are insuffient!
This (and many other variants) will be a threat, but not matched by these patterns:
var secretVariable = document;
secretVariable.write("<script type='text/javascript' src='http://some.evil.code'/>");
If that is the exact line, and you want to remove the entire line (and not just parse out that text), then you can use egrep -v
to print all lines except the matching one.
egrep -v "document.write\(\"<script type='text/javascript' src='http://" oldfile > newfile
Here is the find statement to process all .js files:
for f in $(find /directory/path -name '*.js'); do egrep -v "document.write\(\"<script type='text/javascript' src='http://" $f > TT ; mv TT $f ; done