14 November 2004

-- Site News -- Installing MT-Captcha (aka SCode)

This site has recently started to attract spammers, extolling the virtues of viagra, cialis, and large penises in general. Since the Movable Type interface is relatively slow, deleting these spams has become a bit of a pain.

There are several methods of defence, ranging from simply removing the 'post message' button and forcing everyone to preview, to installing Jay Allen's MT-Blacklist, or a script which disables comments after a set period of time. Elise Bauer of the Learning Movable Type blog has an extensive description of the various approaches.

The best solution for minimal admin-interaction (i.e. the best solution for lazy folks like yours truly) appears to be James Seng's MT-Captcha, an MT plugin which adds a graphical security code which the commenter has to read and type in (thus defeating the automated spam bots). Apparently captcha stands for "Completely Automated Public Turing test to tell Computers and Humans Apart."

Fink hell
Unfortunately, in order to draw the images, MT-Captcha requires that you install the perl module gd. I had previously downloaded and attempted to install this using these instructions but got lost in a maze of dependencies and fink hell. However today I stumbled across a promisingly-titled document How To Install gd version 1.8.4 on Mac OSX on DarwinPorts!

However, this meant I had to install darwinports ...

Next up, DarwinPorts
I set about following the site's instructions:

% cd ~
% mkdir darwinports
% cvs -d :pserver:anonymous@anoncvs.opendarwin.org:/Volumes/src/cvs/od login
% cvs -d :pserver:anonymous@anoncvs.opendarwin.org:/Volumes/src/cvs/od co -P darwinports
% cd ~/darwinports/base
% ./configure
% make
% sudo make install

Unfortunately I hit a problem almost immediately. The second cvs command left me with this error:

cvs checkout: in directory darwinports:
cvs checkout: cannot open CVS/Entries for reading: No such file or directory
cvs [checkout aborted]: cannot write : No such file or directory

After a few minutes of Googling I discovered that this error was likely the result of already having a directory called darwinports (i.e. there is an mistake in the instructions). I removed the directory and tried the second cvs command again, and hey presto! Screenfuls of stuff scrolling past as darwinports downloads! This lasted several minutes on my half megabit ADSL.

Eventually it finished and I moved onto the next step. After switching directories as instructed I entered ./configure. Cue lots more scrolling, only to come to a premature end with this message:

Please install the X11 SDK packages from the Xcode Developer Tools CD
configure: error: Broken X11 install. No X11 headers

And then X11
Argh! I thought I had already installed XCode 1.1 back when I was getting tintin++ to work. Apparently I didn't install the X11 part of XCode. Popping in the XCode 1.1 CD confirmed that it was missing. A lengthy 35 minute install later (the last 1% of which took 15 minutes), I was back to the Terminal to try and configure darwinports again. This time ./configure went smoothly, and make and sudo make install both completed without incident.

Finally, gd
Now to install gd! Referring back to the How To Install gd version 1.8.4 on Mac OSX document, the first instruction was to type sudo port install gd. Naturally this didn't work (does any unix software work first time?) - 'port' was not recognised. Adding export PATH=$PATH:/opt/local/bin to my ~/.profile file fixed the problem. After a 5 minutes or so I ended up with a screen like this:

$ sudo port install gd
---> Fetching jpeg
---> Attempting to fetch jpegsrc.v6b.tar.gz from http://www.ijg.org/files
---> Verifying checksum(s) for jpeg
---> Extracting jpeg
---> Applying patches to jpeg
---> Configuring jpeg
---> Building jpeg with target all
---> Staging jpeg into destroot
---> Installing jpeg 6b_0
---> Activating jpeg 6b_0
---> Fetching libpng
---> Attempting to fetch libpng-1.2.6.tar.bz2 from http://voxel.dl.sourceforge.net/libpng
---> Verifying checksum(s) for libpng
---> Extracting libpng
---> Configuring libpng
---> Building libpng with target all
---> Staging libpng into destroot
---> Installing libpng 1.2.6_0
---> Activating libpng 1.2.6_0
---> Fetching gd
---> Attempting to fetch gd-1.8.4.tar.gz from http://www.boutell.com/gd/http/
---> Verifying checksum(s) for gd
---> Extracting gd
---> Applying patches to gd
---> Configuring gd
---> Building gd with target all
---> Staging gd into destroot
---> Installing gd 1.8.4_3
---> Activating gd 1.8.4_3

And that's it! gd is now installed.

Now onto MT-Captcha...
The instructions for installing MT-Captcha itself are quite simple. All you have to do is insert some code into your MT templates. However after making the necessary changes and rebuilding I got lots of these errors:

MT::App::Comments=HASH(0x815db34) print() on closed filehandle OUTFILE at lib/MT/SCode.pm line 5

This turned out to be incorrect permissions on my MT-Catchpa temporary folder. Setting the owner of that folder to www (UID 70) cured the rebuilding errors. However, my security code was still not appearing! According to James Seng if your image doesn't appear it is always related to your gd install. After much frustration I finally realised that my install was missing GD.pm! Seeing as how I know absolutely nothing about perl, I failed to appreciate that gd and GD.pm are two different things, and we need to install both.

Not just gd, GD.pm too
So, after some more googling, I found that GD.pm (version 2.17) can be found here. After downloading and expanding it, perl Makefile.PL resulted in hundreds of error messages:

GD.xs: In function `newDynamicCtx':
GD.xs:440: error: structure has no member named `gd_free'
GD.xs: In function `gd_cloneDim':
GD.xs:460: error: structure has no member named `alpha'
GD.xs:460: error: structure has no member named `alpha'
GD.xs:466: error: structure has no member named `thick'
GD.xs:466: error: structure has no member named `thick'
GD.xs: In function `XS_GD__Image_newFromPngData':
GD.xs:595: error: structure has no member named `gd_free'
GD.xs: In function `XS_GD__Image_newFromGdData':
GD.xs:614: error: structure has no member named `gd_free'
GD.xs: In function `XS_GD__Image_newFromGd2Data':
GD.xs:631: error: structure has no member named `gd_free'
GD.xs: In function `XS_GD__Image_newFromJpegData':
GD.xs:651: error: structure has no member named `gd_free'
GD.xs: In function `XS_GD__Image_newFromWBMPData':
GD.xs:676: error: structure has no member named `gd_free'
GD.xs: In function `XS_GD__Image_copyRotate90':
GD.xs:1189: error: invalid lvalue in assignment
GD.xs:1189: error: invalid lvalue in assignment
GD.xs: In function `XS_GD__Image_copyRotate180':
GD.xs:1210: error: invalid lvalue in assignment
GD.xs:1210: error: invalid lvalue in assignment
GD.xs: In function `XS_GD__Image_copyRotate270':
GD.xs:1231: error: invalid lvalue in assignment
GD.xs:1231: error: invalid lvalue in assignment
GD.xs: In function `XS_GD__Image_copyFlipHorizontal':
GD.xs:1252: error: invalid lvalue in assignment
GD.xs:1252: error: invalid lvalue in assignment
GD.xs: In function `XS_GD__Image_copyFlipVertical':
GD.xs:1273: error: invalid lvalue in assignment
GD.xs:1273: error: invalid lvalue in assignment
GD.xs: In function `XS_GD__Image_copyTranspose':
GD.xs:1294: error: invalid lvalue in assignment
GD.xs:1294: error: invalid lvalue in assignment
GD.xs: In function `XS_GD__Image_copyReverseTranspose':
GD.xs:1315: error: invalid lvalue in assignment
GD.xs:1315: error: invalid lvalue in assignment
GD.xs: In function `XS_GD__Image_rotate180':
GD.xs:1335: error: invalid lvalue in assignment
GD.xs:1335: error: invalid lvalue in assignment
GD.xs:1336: error: invalid lvalue in assignment
GD.xs:1336: error: invalid lvalue in assignment
GD.xs: In function `XS_GD__Image_flipHorizontal':
GD.xs:1353: error: invalid lvalue in assignment
GD.xs:1353: error: invalid lvalue in assignment
GD.xs:1354: error: invalid lvalue in assignment
GD.xs:1354: error: invalid lvalue in assignment
GD.xs: In function `XS_GD__Image_flipVertical':
GD.xs:1371: error: invalid lvalue in assignment
GD.xs:1371: error: invalid lvalue in assignment
GD.xs:1372: error: invalid lvalue in assignment
GD.xs:1372: error: invalid lvalue in assignment
GD.xs: In function `XS_GD__Image_stringFT':
GD.xs:2085: error: `gdFTStringExtra' undeclared (first use in this function)
GD.xs:2085: error: (Each undeclared identifier is reported only once
GD.xs:2085: error: for each function it appears in.)
GD.xs:2085: error: parse error before "strex"
GD.xs:2104: error: `strex' undeclared (first use in this function)
GD.xs:2108: error: `gdFTEX_LINESPACE' undeclared (first use in this function)
GD.xs:2112: error: `gdFTEX_CHARMAP' undeclared (first use in this function)
GD.xs:2114: error: `gdFTEX_Unicode' undeclared (first use in this function)
GD.xs:2116: error: `gdFTEX_Shift_JIS' undeclared (first use in this function)
GD.xs:2118: error: `gdFTEX_Big5' undeclared (first use in this function)
GD.xs:2140: warning: assignment makes pointer from integer without a cast
GD.xs: In function `XS_GD__Image_stringFTCircle':
GD.xs:2188: warning: assignment makes pointer from integer without a cast
GD.xs: In function `XS_GD__Font_DESTROY':
GD.xs:2353: warning: comparison between pointer and integer
GD.xs:2354: warning: comparison between pointer and integer
GD.xs:2355: warning: comparison between pointer and integer
GD.xs:2356: warning: comparison between pointer and integer
GD.xs:2357: warning: comparison between pointer and integer
GD.xs: In function `XS_GD__Font_Small':
GD.xs:2369: warning: assignment makes pointer from integer without a cast
GD.xs: In function `XS_GD__Font_Large':
GD.xs:2380: warning: assignment makes pointer from integer without a cast
GD.xs: In function `XS_GD__Font_Giant':
GD.xs:2391: warning: assignment makes pointer from integer without a cast
GD.xs: In function `XS_GD__Font_MediumBold':
GD.xs:2402: warning: assignment makes pointer from integer without a cast
GD.xs: In function `XS_GD__Font_Tiny':
GD.xs:2413: warning: assignment makes pointer from integer without a cast
make: *** [GD.o] Error 1

Reverting to GD.pm 1.33
This error totally stumped me. There's a thread here which discuses it along with a possible fix, but it might as well be Greek as far as I'm concerned! Finally I read a note here, which suggested that reverting to GD.pm version 1.33 would work on OS X. After a quick download of the older version, I was once again installing GD.pm as per the ReadMe file. This time, despite hundreds of make test errors, make install worked perfectly! A quick rebuild of the site and - wow, stop the presses! I virtually jumped out of my chair as the sweet sight of a graphical security code greeted my eyes!

PS: for perl idiots like myself, here is a useful command to see if GD is working:

perl -e "use GD"

If there are no errors then GD is working.

Back to reality
Alas, despite the appearance of my security numbers, all was not rosy. After turning off comment approval and posting a few test comments, it became rapidly apparent that the security code was not being checked at all. Any comment was accepted, no matter what number was input into the security code field! Back to the drawing board...

Finally, success!
After flailing around for a couple more hours, and reading every one of the 500 comments on the MT-Captcha page, I've finally figured it out. There is a typo in the ReadMe!!! Growl. The key passage is this:

+++++++++++++++++++++++++++++++++++
INSTALLATION MT 3.x
+++++++++++++++++++++++++++++++++++

From: http://www.setcomputing.com/blog/archives/computing/2004-September/incorporating_mtsecu.html

Follow Step 1 to 5 as above and then...

But this is wrong, wrong, wrong. What it should say is:

+++++++++++++++++++++++++++++++++++
INSTALLATION MT 3.x
+++++++++++++++++++++++++++++++++++

From: http://www.setcomputing.com/blog/archives/computing/2004-September/incorporating_mtsecu.html

Follow Step 1 to 7 as above and then...

Once I completed steps 6 and 7 from the MT 2.x instructions (editing Comments.pm and the templates), the security code check FINALLY started working. I'm on cloud nine! :-)

Posted by thoughton at November 14, 2004 11:17 PM to How To... | Internet | Site News | Web Design

Related entries

14 November 2004 - Installing MT-Blacklist
8 October 2004 - Spamadelic
18 November 2004 - Another Movable Type Captcha
13 December 2004 - MT-Captcha report card

Comments
Post a comment









Remember personal info?

:) ;) 8) :|
:( :P :X :?
:mad: :D :o :cry:
:shock: :blush: :roll:  




Please enter this security number in the space below (this prevents automated responses).