# Blosxom Plugin: recaptcha # Author(s): Lars Engel > # Version: 2008-04-11 # Documentation: See the bottom of this file or type: perldoc recaptcha # Requirements: The Blosxom writeback plugin and the Perl module # for using recaptcha by Andy Armstrong. # And of course a recaptcha account at package recaptcha; # --- Configurable variables ----- # Your recaptcha private key my $private_key = 'Your private key here'; # Your recaptcha public key my $pub_key = 'Your private key here'; # ---------- # Use this to display messages from recaptcha such as submitting a invalid response $msg = ''; # -------------------------------- $form = 1; my $c = 1; use Captcha::reCAPTCHA; use CGI; # # Use this method in the writeback module to validate the captcha # sub validate{ my $q = CGI->new; my $challenge = $q->param( 'recaptcha_challenge_field' ); my $response = $q->param( 'recaptcha_response_field' ); # Verify submission my $result = $c->check_answer( $private_key, $ENV{'REMOTE_ADDR'}, $challenge, $response ); if ( $result->{is_valid} ) { return 0; } else { # Error $error = $result->{error}; $msg = "Sorry, that did not work. Please try again.
($error)"; return 1; } } sub start { $c = Captcha::reCAPTCHA->new; $form = $c->get_html($pub_key); 1; } 1; __END__ =head1 NAME Blosxom Plug-in: recaptcha =head1 SYNOPSIS Provides CAPTCHA checking for writebacks (and some related) plugins. The plugin uses the services of ReCaptcha. . =head2 QUICK START Drop this plug-in file into your plug-ins directory (whatever you set as C<$plugin_dir> in blosxom.cgi). Name it so that it will be loaded by blosxom before writebacks plugin. For example if writebacks is called F<1writebacks>, name F as F<05recaptcha>. Modify your F or where ever your Writeback form is located that it displays the recaptcha form C<$recaptcha::form> and the potential error message C<$recaptcha::msg>, e.g. $recaptcha::form $recaptcha::msg Modify your writeback plugin in a place before the comment is saved to a file so that you ran the validation method F before. The method returns zero if the validation was successful or one otherwise. For instance can you look up the following piece of code in the F method foreach ( ('', split /\//, $path) ) { $p .= "/$_"; $p =~ s!^/!!; -d "$writeback_dir/$p" or mkdir "$writeback_dir/$p", 0777; chmod (0777,"$writeback_dir/$p"); } and modify that it looks like this: if(recaptcha::validate()>0){ return 1; } foreach ( ('', split /\//, $path) ) { $p .= "/$_"; $p =~ s!^/!!; -d "$writeback_dir/$p" or mkdir "$writeback_dir/$p", 0777; chmod (0777,"$writeback_dir/$p"); } Last but not least add your private and public key from ReCaptcha to the recaptcha module. =back =head2 VARIABLES C<$recaptcha::form> Contains the ReCaptcha form C<$wbcaptcha::msg> Contains a message if the captcha response is invalid C<$wbcaptcha::private_key> Your recaptcha private key C<$wbcaptcha::pub_key> Your recaptcha public key =end text =back =head1 INSTALLATION Drop wbcaptcha into your plug-ins directory (C<$blosxom::plugin_dir>). Name it so that it will be loaded by blosxom before writebacks plugin. For example if writebacks is called F<1writebacks>, name F as F<05recaptcha>. =head1 CONFIGURATION =head2 (REQUIRED) Add your reCaptcha keys Add your reCaptcha keys as described in QUICK START, add the recaptcha form and message to your writeback form as described in QUICK START. =head1 AUTHOR Lars Engel , http://blog.berlund.de =head1 SEE ALSO Blosxom Plugin Docs: http://www.raelity.org/apps/blosxom/plugin.shtml ReCaptcha: http://recaptcha.net/ ReCaptcha Perl module: http://search.cpan.org/dist/Captcha-reCAPTCHA/lib/Captcha/reCAPTCHA.pm =head1 BUGS Address bug reports and comments to . =head1 LICENSE GNU General Public License v2.0,