PDA

View Full Version : Help in deleting no right mouse click code from 10k of pages on server


Cleo
2004-06-09, 11:21 AM
I've got over 10k in pages, 7 gigs total with images, that has no right mouse click code that I need to delete.

I have a few server scripts that will do search and replace on a server but they only work with one line of code at a time and if there is spaces in the file names and directories which seems to break the script and any of the pages and directories have spaces in the names. :(

I do already have a tar file downloaded so I may just have to do this locally and then re-upload everything but damn it is 7 gigs.

This is the code,
<script language="JavaScript1.2">
if (window.Event)
document.captureEvents(Event.MOUSEUP);

function nocontextmenu()
{
event.cancelBubble = true
event.returnValue = false;

return false;
}

function norightclick(e)
{
if (window.Event)
{
if (e.which == 2 || e.which == 3)
return false;
}
else
if (event.button == 2 || event.button == 3)
{
event.cancelBubble = true
event.returnValue = false;
return false;
}

}
if (document.layers) {
document.captureEvents(Event.MOUSEDOWN);
}
document.oncontextmenu = nocontextmenu;
document.onmousedown = norightclick;
document.onmouseup = norightclick;
//-->
</script>

DangerDave
2004-06-09, 06:01 PM
If you have the tar, you should only have to upload the changed HTML? yes?


I don't have a solution, but Ray - Webmastersguide/Strongbox, probably will... he should see this thread.

DD

venturi
2004-06-10, 02:24 AM
Cleo,

UltraEdit has a very robust Global Search and Replace function built into it that will walk thru multiple files and directories that will do this for you easily. You can download a trial version of it at ultraedit.com and if you end up liking the product (I love it and have been using it for almost 10yrs) registration is only about $40.

Cleo
2004-06-10, 08:05 AM
Looks like ultraedit.com is about the same thing as bbedit.com which I use all the time, but just like bbedit doesn't do batch find and replace on the server.

Actually I looked through more files and the code is slightly different in the way it is written in almost every page. |banghead|

I'm having a hell of a time getting the tarball to download from the server without it getting corrupt. Best can I do is 2.6 megs transfer speed with my cable modem so it takes something like 18 hours and then ends up being corrupt in the end.

I see that the server has rsync installed and my Mac also has rsync so I may end up mirroring the server's drive locally using rsync and just working on everything local. This way once it will still take a few days to get everything downloaded to my local drive but then only the changed files will get re-uploaded.

DangerDave
2004-06-10, 06:43 PM
If you are going to do it locally...

Try - http://www.abacre.com/afr/index.htm (Win)

DD

Entreri
2004-06-10, 11:29 PM
Wouldn't it be easier to correct one of your scripts so that they handle filenames and directories containing spaces and run your script in your shell? Although, constructing the actual search and replace regexp is going to be a challenge if the script you want to strip is slightly different in each pages as you mentionned. |dizzy| (Unless you want to remove all javascript, then it's nothing)

Also, I'm wondering why you're downloading the whole 7 gigs (including pictures) when you could download a tar containing only html files...

Entreri.

venturi
2004-06-11, 05:16 AM
good point Entreri!

use the --exclude [pattern] parameter to exclude all the .jpg files in the tarball and you'll reduce the size quite a bit (assuming that there's a bit of content in your directories.

Cleo
2004-06-11, 07:57 AM
Maybe I'm missing something but if I did a tar file and excluded the jpg, gif, wmv, etc. wouldn't I have a problem just replacing these files when I re-uploaded the html in keeping the directory structure as everything is in scatted nested directories all over the place?

DangerDave
2004-06-11, 06:13 PM
Maybe I'm missing something but if I did a tar file...... Not if the orig dir structure still existed? Are you moving the pages Cleo or just changing them?

DD

Cleo
2004-06-11, 06:59 PM
To remove the code from the pages I don't have to move them. Can you un-tar something and have it replace only the html files while keeping the directories and files untouched?

But I'm thinking now it would probably be a good idea to also remove all the spaces from the directories, html files, and jpgs if I did decide to download this mess.

The more I think about it I'm thinking it would probably be best to download one directory at a time and fix them slowly. I have very good find and replace tools on my Mac including a nice editor with Grep and GoLive as some very good site site maintenance tools for getting rid of all the spaces and fixing broken links.

DangerDave
2004-06-11, 07:02 PM
Can you un-tar something and have it replace only the html files while keeping the directories and files untouched? Yes you can:)

DD

Cleo
2004-06-11, 07:26 PM
Originally posted by DangerDave
Yes you can:)

DD
Guess it is time for the man tar pages LOL

swedguy
2004-06-13, 10:53 AM
http://www.sponsororganizer.com/FreeScripts/cleo.html

Save the script as cleo.pl

Chmod it to 755

Run:
find /main/domain/dir \( -name '*.html' -o -name '*.php' -o -name '*.htm' \) -exec cleo.pl {} \;

It will run through all your .html, .php and .htm files and delete the code.
Remember that it will open and save all files, even the ones that doesn't have the code in it (it will just not change anything). So if you have any files that are owned by the webserver user, it _might_ change the owner to the user you run the script as.

I made a test run here on a bunch of files with and without the code in, and it worked like a charm. A hot advice is to make a test run in a temp folder :)

My ICQ is 252081 if you need any help.
Good luck if you decide to use it :)

swed

Cleo
2004-06-13, 11:03 AM
This looks interesting.

Could I do

find /home/foxy/web/members \( -name '*.html' -o -name '*.php' -o -name '*.htm' \) -exec ../../myscripts/remove-right-mouse-code.pl {} \;

and this way it would only do the member's directory?

swedguy
2004-06-13, 11:19 AM
Originally posted by Cleo
This looks interesting.

Could I do

find /home/foxy/web/members \( -name '*.html' -o -name '*.php' -o -name '*.htm' \) -exec ../../myscripts/remove-right-mouse-code.pl {} \;

and this way it would only do the member's directory?
It will do the /home/foxy/web/members directory and all it's sub-dirs.

If you only want to do the /home/foxy/web/members dir and no sub-dirs... do this:

find /home/foxy/web/members \( -name '*.html' -o -name '*.php' -o -name '*.htm' \) -maxdepth 1 -exec ../../myscripts/remove-right-mouse-code.pl {} \;

Cleo
2004-06-13, 12:07 PM
Something is wrong.

I'm getting this.

../../myscripts/remove-right-mouse-code.pl: line 5: syntax error near unexpected token `s/(/<'
../../myscripts/remove-right-mouse-code.pl: line 5: `s/(/<script language="JavaScript1\.2">.*?document\.captureEvents\(Event\.MOUSEUP\).*?document\.captureEvents\(Event.MOUSEDOWN\).*?<\/script>)//sm;'
../../myscripts/remove-right-mouse-code.pl: undef: command not found

swedguy
2004-06-13, 01:06 PM
Originally posted by Cleo
Something is wrong.

../../myscripts/remove-right-mouse-code.pl: undef: command not found
That's an odd one. undef is a standard Perl command.

What Perl version are you running?

Type this on your server: perl -v

What OS is your server running?

Cleo
2004-06-13, 01:16 PM
$ perl -v
This is perl, v5.8.3 built for i686-linux
Copyright 1987-2003, Larry Wall

$ uname -a
Linux ashburn 2.4.26 #1 SMP Wed Apr 14 10:20:52 CDT 2004 i686 unknown

airdick
2004-06-13, 03:09 PM
I hope nobody minds if I stick my nose in here. :) I've been following the thread hoping that a perl wizard would post some cool code that I can stash in my toolbox.

The errors that Cleo reports look to me like they were generated by the shell, not by perl. When I try to execute the perl script I get a different error. I can come close to reproducing the error if I attempt to run the script as a bash shell script (which we would expect to fail):

ejl@dangpow:~$ bash test.pl

test.pl: undef: command not found
test.pl: line 4: syntax error near unexpected token `s/(/<'
test.pl: line 4: `s/(/<script language="JavaScript1\.2">.*?document\.captureEvents\(Event\.MOUSEUP\).*?document\.captureEvents\(Event.MOUSEDOWN\).*?<\/script>)//sm;'

###########
Here is the error I get running the perl script:

ejl@dangpow:~$ ./test.pl some.html

Unmatched ( before HERE mark in regex m/( << HERE / at ./test.pl line 4.


ejl@dangpow:~$ find . -name some.html -exec test.pl {} \;

Unmatched ( before HERE mark in regex m/( << HERE / at ./test.pl line 4.

###########
ejl@dangpow:~$ cat test.pl

#!/usr/bin/perl -pi

undef $/;
s/(/<script language="JavaScript1\.2">.*?document\.captureEvents\(Event\.MOUSEUP\).*?document\.captureEvents\(Event.MOUSEDOWN\).*?<\/script>)//sm;

###########
ejl@dangpow:~$ /usr/bin/perl -v

This is perl, v5.6.1 built for i686-linux

ejl@dangpow:~$ uname -a

Linux dangpow 2.4.26 #1 SMP Tue Apr 20 20:19:50 PDT 2004 i686 unknown

swedguy
2004-06-13, 03:12 PM
Damn me |pcsucks|

An extra / snuck itself into the script when I pasted it into cleo.html

I've uploaded the correct one now. Sorry about that :(

swedguy
2004-06-13, 03:16 PM
Originally posted by airdick

###########
Here is the error I get running the perl script:

ejl@dangpow:~$ ./test.pl some.html

Unmatched ( before HERE mark in regex m/( << HERE / at ./test.pl line 4.


ejl@dangpow:~$ find . -name some.html -exec test.pl {} \;

Unmatched ( before HERE mark in regex m/( << HERE / at ./test.pl line 4.

###########

Same error as I got when I tried to run the posted code. It was an extra / there in the beginning.

Thanks for looking up the bash part :)

Cleo
2004-06-13, 03:52 PM
Did you upload the new script?

Did a copy and paste of what you have there and got the same error.

Which / am I suppose to remove?

airdick
2004-06-13, 05:26 PM
This is kind of interesting. What happens when you run these two commands:

file /usr/bin/perl

and

/usr/bin/perl -v

Cleo
2004-06-13, 05:35 PM
Gives you all kinds of interesting info :)

On my laptop

% file /usr/bin/perl
/usr/bin/perl: Mach-O executable ppc

% /usr/bin/perl -v

This is perl, v5.8.1-RC3 built for darwin-thread-multi-2level
(with 1 registered patch, see perl -V for more detail)

Copyright 1987-2003, Larry Wall

Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.

Complete documentation for Perl, including FAQ lists, should be found on
this system using `man perl' or `perldoc perl'. If you have access to the
Internet, point your browser at http://www.perl.com/, the Perl Home Page.

On my server
$ file /usr/bin/perl
/usr/bin/perl: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), for GNU/Linux 2.0.0, dynamically linked (uses shared libs), not stripped

$ /usr/bin/perl -v

This is perl, v5.8.3 built for i686-linux

Copyright 1987-2003, Larry Wall

Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.

Complete documentation for Perl, including FAQ lists, should be found on
this system using `man perl' or `perldoc perl'. If you have access to the
Internet, point your browser at http://www.perl.com/, the Perl Home Page.

airdick
2004-06-13, 05:56 PM
I'm stumped. You're still getting the errors you first reported, right? With the "undef: command not found" stuff?

I don't get any errors when I run the new script. Here is how I tried it:

1. Copied all of the text from the browser window at the URL http://www.sponsororganizer.com/FreeScripts/cleo.html

2. pasted it into the vi editor in a terminal window on a linux system

3. saved and exited script.

4. chmod +x the new script

5. executed the script

Can you show us the contents of the script as it is on the system you're running it on? (cat remove-right-mouse-code.pl )

swedguy
2004-06-13, 06:27 PM
I just went through the Perl 5.8 Changelog (I tried the script on 5.6) and nothing interesting in there. Thought they might've changed something.

If you just try this little script


#!/usr/bin/perl

$var = 'hello';
print $var;


Does it work?

Cleo
2004-06-13, 06:29 PM
I'm getting this error

myscripts/remove-right-mouse-code.pl: undef: command not found
myscripts/remove-right-mouse-code.pl: line 5: syntax error near unexpected token `s/(/<'
myscripts/remove-right-mouse-code.pl: line 5: `s/(/<script language="JavaScript1\.2">.*?document\.captureEvents\(Event\.MOUSEUP\).*?document\.captureEvents\(Event.MOUSEDOWN\).*?<\/script>)//

I have my scripts in a non public directory so I can't do a link but here is a copy and paste from it.
#!/usr/bin/perl -pi

undef $/;
s/<script language="JavaScript1\.2">.*?document\.captureEvents\(Event\.MOUSEUP\).*?document\.captureEvents\(Event.MOUSEDOWN\).*?<\/script>//sm;

Cleo
2004-06-13, 06:36 PM
$ myscripts/test.pl
hello
$

swedguy
2004-06-13, 06:39 PM
Hmm, something is wrong here.

Originally posted by Cleo
myscripts/remove-right-mouse-code.pl: line 5: syntax error near unexpected token `s/(/<'
myscripts/remove-right-mouse-code.pl: line 5: `s/(/<script language="JavaScript1\.2">.*?document\.captureEvents\(Event\.MOUSEUP\).*?document\.captureEvents\(Event.MOUSEDOWN\).*?<\/script>)//


Originally posted by Cleo

#!/usr/bin/perl -pi

undef $/;
s/<script language="JavaScript1\.2">.*?document\.captureEvents\(Event\.MOUSEUP\).*?document\.captureEvents\(Event.MOUSEDOWN\).*?<\/script>//sm;
The remove-right-mouse-code.pl script is not the same as the one that produced the error. The error comes from the old code.

swedguy
2004-06-13, 06:42 PM
I could sort of reproduce the error in two ways.

1. Don't have a #!/usr/bin/perl -pi as the first line.

2. Have a space before #!/usr/bin/perl -pi

Cleo
2004-06-13, 06:43 PM
I took at the empty lines in the script and got this error.

Unmatched ( in regex; marked by <-- HERE in m/( <-- HERE / at myscripts/remove-right-mouse-code.pl line 3.

airdick
2004-06-13, 06:43 PM
I'm betting on a blank first line.. :)

ooopss. i was a little slow on the reply. Now all that's left is the perl debugging.

swedguy
2004-06-13, 06:51 PM
Originally posted by Cleo
I took at the empty lines in the script and got this error.

Unmatched ( in regex; marked by <-- HERE in m/( <-- HERE / at myscripts/remove-right-mouse-code.pl line 3.
Awsome, then the problem was an empty line and you are still using the old code :)

It's probably stuck in your cache. Here's a new url for you: http://www.sponsororganizer.com/FreeScripts/cleo2.html

And remember, no empty lines in the beginning :)

Cleo
2004-06-13, 07:44 PM
We Have Liftoff!

No errors in telnet and when I run top I see find running.

There is 7 gigs in there so I guess this will take awhile.

|smooch|

swedguy
2004-06-13, 07:52 PM
|bananna|

venturi
2004-06-13, 08:00 PM
Wow! This thread turned into a Perl workshop overnight! :)

Cool stuff SwedeGuy. |shake|

Cleo
2004-06-13, 08:11 PM
This has turned into a very interesting thread.

I really wish I knew more about this stuff. I know just enough to be somewhat dangerous. LOL

I already checked some pages and the script is working very well.

The directories and files are still full of spaces but it isn't that big of a deal.

Entreri
2004-06-14, 01:51 AM
Here are my 2 cents on this thread...

1. Be sure to backup your stuff - unless you have absolute faith - before running a search-and-replace script. If you cancel the script while it is working, you might wreck one file. (Plus, without any logging or output, you cannot know which file may be messed-up)

2. The script obviously cannot strip what it doesn't know. Therefore, where you wrote the right-clicking script differently, it won't strip it. Sure, one could make the regular expression a bit more flexible but it's troubles that could be avoided.

Here are two suggestions to avoid those problems in the future :

1. If you gotta use Javascript, you might consider using *one* centralized included javascript. In our situation, you could have modified the javascript in question at will or it would make a single line to search-and-strip in all your files.

Ex.


<SCRIPT language=javascript src=http://blah/blockrightclick.js></SCRIPT>
2. Or, you could add comments that act as tags around code to clearly identify those blocks.


<!-- RightClickStart -->
<script>

my script to block right-click here

</script>
<!-- RightClickEnd -->


Then, if you think one of the files does not use the same block of code, or you want to modify the block of code, or remove it altogether, those tags make it very easy to do so.

Entreri.

Cleo
2004-06-14, 08:30 AM
Yeah I made a tarball of the whole site before running this just incase something went horribly wrong.

As for the code I would never do something like this. This whole site was done in FrontPage with the server extensions by someone that had no idea what they were doing over 6 years.

I've looked through many of the pages and have yet to find any pages with this code still in them so it looks like this worked extremely well.

Rorschach
2004-06-17, 11:25 PM
*cough*

man sed