TWiki
>
TWiki/ Web
>
CaptchaPlugin
(revision 9) (raw view)
Edit
Attach
---+!! <nop>%TOPIC% A visual confirmation plugin, known as Captcha, for new user registration. This plugin prevents automated scripts in creating users and spam your wiki with their url's to get a better google ranking. %TOC% ------ ---++ Syntax Rules * The tag %<nop>CAPTCHAURL% expands to the url of the image containing the scrambled text; * The tag %<nop>CAPTCHAHASH% expands to the hash matching the image. ---++ Examples * N/A ---++ Plugin Settings Plugin settings are stored as preferences variables. To reference a plugin setting write ==%<nop><plugin>_<setting>%==, i.e. ==%<nop>INTERWIKIPLUGIN_SHORTDESCRIPTION%== * One line description, is shown in the %TWIKIWEB%.TextFormattingRules topic: * Set SHORTDESCRIPTION = Plugin for Captcha verification / visual confirmation of new user registration. * Debug plugin: (See output in =data/debug.txt=) * Set DEBUG = 0 * Custom settings (defaults shown): * Number of characters for Captcha: * Set LENGTH = 5 * The characters that you want to use in Captcha: * Set CHARACTERS = abcdefghijklmnopqrstuvwxyz%&?@!1234567890 Additionally, the following settings can be added to =lib/LocalSite.cfg=. In time, the above options will be moved to that file too. * $TWiki::cfg{Plugins}{CaptchaPlugin}{Expiry}=3600; # time in seconds after which a captcha will expire and be removed * $TWiki::cfg{Plugins}{CaptchaPlugin}{EnableSave}=1; # enable captcha for topic save ---++ Plugin Installation Instructions __Note:__ You do not need to install anything on the browser to use this plugin. The following instructions are for the administrator who installs the plugin on the server where TWiki is running. * Download the ZIP file from the Plugin web (see below) * Unzip ==%TOPIC%.zip== in your twiki installation directory. Content: | *File:* | *Description:* | | ==data/TWiki/CaptchaPlugin.txt== | Plugin topic | | ==data/TWiki/CaptchaPlugin.txt,v== | Plugin topic repository | | ==register-4.1.2.patch== | Patch for the register module | | ==templates/oopscaptcha.tmpl== | Error template | | ==lib/TWiki/Plugins/%TOPIC%.pm== | Plugin Perl module | | ==pub/TWiki/CaptchaPlugin/fonts/== | Fonts directory | | ==pub/TWiki/CaptchaPlugin/fonts/*== | A collection of free fonts to get you started | | ==pub/TWiki/CaptchaPlugin/_db== | Hash database directory | | ==pub/TWiki/CaptchaPlugin/img== | Image directory | * Apply the patch ==register-4.1.2.patch== to ==lib/TWiki/UI/Register.pm== (alternatively, patch Register.pm manually, see section below), be sure to make a backup so you can revert the patch if you want to disable the plugin: * cd /path/to/twiki * cp lib/TWiki/UI/Register.pm lib/TWiki/UI/Register.pm.dist * patch < ../register.patch * Restrict access to the files, for example, by including the following in your httpd.conf: <pre> <Directory "/path/to/twiki/pub/TWiki/%TOPIC%/_db"> deny from all </Directory> <Directory "/path/to/twiki/pub/TWiki/CaptchaPlugin/fonts"> deny from all </Directory> <Directory "/path/to/twiki/pub/TWiki/CaptchaPlugin/img"> deny from all </Directory> </pre> * Enable the plugin via the =bin/configure= script * Install necessary !TrueType fonts in to ==pub/TWiki/%TOPIC%/fonts/== * This allows the plugin to randomly choose the fonts to use * Test if the installation was successful: * Create a topic containing ==<IMG SRC="%<nop>CAPTCHAURL%">== and ==%<nop>CAPTCHAHASH%== * When loading this topic you should see an obfuscated character string loaded as a png and a hexadecimal hash. * Check whether the hash database is properly protected by going to the url http://my.twiki.server/my/twiki/path/pub/TWiki/%TOPIC%/db/hashes.pag, you should see a permission denied message. * Now edit your TWiki.TWikiRegistration topic * Display the image !%CAPTCHAURL% somewhere in your form, along with a text instructing new users to copy the obfuscated text into the appropriate text input. * Add the appropriate text input as ==Twk1CaptchaString== * Add a hidden input as ==Twk1CaptchaHash== having as value !%CAPTCHAHASH% * For example, add this to your TWiki.TWikiRegistration: <pre> <tr> <td valign="top" align="right"><IMG SRC="%<nop>CAPTCHAURL%">: <br /> (..) </td> <td><input type="hidden" name="Twk1CaptchaHash" value="%<nop>CAPTCHAHASH%"> <input type="text" name="Twk1CaptchaString" size="5"></td> =<font color="red">**</font>= </tr> </pre> * That's it. ---+++ Captcha on topic edit If you want to protect edits by Main.TWikiGuest with a captcha, add the following line to your =lib/LocalSite.cfg=: <pre>$TWiki::cfg{Plugins}{CaptchaPlugin}{EnableSave} = 1;</pre> Of course, you will need the !Twk1CaptchaHash and !Twk1CaptchaString input fields somewhere in your edit template. For example, if you are using the default pattern skin, change =templates/edit.pattern.tmpl=. Find: <pre> %<nop>TMPL:DEF{"textarea"}%<textarea class="twikiEditboxStyleProportional" id="topic" name="text" rows="%<nop>EDITBOXHEIGHT%" cols="%<nop>EDITBOXWIDTH%" style='%<nop>EDITBOXSTYLE%' onkeydown='handleKeyDown(event)'>%<nop>TEXT%</textarea><script type="text/javascript">initTextAreaHeight();</script> %<nop>TMPL:END% </pre> and add before TMPL:END: <pre> %<nop>TMPL:DEF{"textarea"}%<textarea class="twikiEditboxStyleProportional" id="topic" name="text" rows="%<nop>EDITBOXHEIGHT%" cols="%<nop>EDITBOXWIDTH%" style='%<nop>EDITBOXSTYLE%' onkeydown='handleKeyDown(event)'>%<nop>TEXT%</textarea><script type="text/javascript">initTextAreaHeight();</script> <IMG SRC="%CAPTCHAURL%"/> <input type="hidden" name="Twk1CaptchaHash" value="%CAPTCHAHASH%"/> <input type="text" name="Twk1CaptchaString" size="5"/> %<nop>TMPL:END% </pre> You might want to hide the captcha for logged in users (context authenticated), see TWiki.VarIF for more information on conditional rendering. ---+++ Manually patching the register binary Refer to the patch file. ---++++ Guide for TWiki 4.0.5 Find these lines in ==lib/TWiki/UI/Register.pm==: <pre> } # generate user entry </pre> Insert the code below directly *BEFORE* the line containing the curly bracket '{': <pre> # verify captcha my %database; my $vcHash = $data->{CaptchaHash}; my $vcTxt = $data->{CaptchaString}; open(LOCKFILE,">".&TWiki::Func::getPubDir()."/TWiki/CaptchaPlugin/_db/hashes.lock"); flock(LOCKFILE,2); dbmopen(%database, &TWiki::Func::getPubDir()."/TWiki/CaptchaPlugin/_db/hashes",0644); my ($time,$txt) = split(',',$database{$vcHash}); if ( not(lc($txt) eq lc($vcTxt)) || ($txt eq '') ) { dbmclose(%database); close(LOCKFILE); throw TWiki::OopsException( 'captcha', web => $data->{webName}, topic => $topic, def => 'invalid_vcstr', params => [ "wrong" ] ); } dbmclose(%database); close(LOCKFILE); </pre> Now find: <pre> # 'WikiName' omitted because they can't # change it, and 'Confirm' is a duplicate push( @{$data->{form}}, $form ) unless ($name eq 'WikiName' || $name eq 'Confirm'); </pre> and change the last line to: <pre> # 'WikiName' omitted because they can't # change it, and 'Confirm' is a duplicate push( @{$data->{form}}, $form ) unless ($name eq 'WikiName' || $name eq 'Confirm' || $name eq 'CaptchaHash' || $name eq 'CaptchaString'); </pre> ---++ Further Development * Refactor to comply with TWiki's convention * Remove created .png files -> is already done on expiry, right? * Adjustable font size range * Adjustable height and width * Option of Black and White only ---++ Plugin Info | Plugin Author: | TWiki:Main.KoenMartens, TWiki:Main.KwangErnLiew | | Plugin Version: | 06 Aug 2007 1.5-pre1 | | Change History: | | | 08 Aug 2007: | Added support for captcha on topic save (thanks TWiki:Main.KwangErnLiew), fixed some minor bugs, added some free fonts | | 06 Aug 2007: | Colourised fonts; Randomised font type, font size, background colour, and font positioning; Fixed hash display on user pages; Modified oopscaptcha.tmpl | | 03 Aug 2006: | Renamed to %TOPIC%, adapted to Dakar (TWiki 4.0.x). | | 03 Jan 2006: | Fixed some problems with expiry, also optimised according to TWiki:TWiki.TWikiPlugins#FastPluginHints. | | 10 Oct 2005: | Strip hash and text from arguments to register binary, or they will end up in the newly created user topic. | | 07 Oct 2005: | Initial version | | TWiki Dependency: | $TWiki::Plugins::VERSION 1.1 | | CPAN Dependencies: | GD, Digest::MD5 | | Other Dependencies: | none | | Perl Version: | 5.005 | | License: | GPL ([[http://www.gnu.org/copyleft/gpl.html][GNU General Public License]]) | | TWiki:Plugins/Benchmark: | %TWIKIWEB%.GoodStyle 98%, %TWIKIWEB%.FormattedSearch 98%, TWiki.TWikiRegistration (patched) 85% | | Plugin Home: | http://TWiki.org/cgi-bin/view/Plugins/%TOPIC% | | Feedback: | http://TWiki.org/cgi-bin/view/Plugins/%TOPIC%Dev | | Appraisal: | http://TWiki.org/cgi-bin/view/Plugins/%TOPIC%Appraisal | __Related Topics:__ %TWIKIWEB%.TWikiPreferences, %TWIKIWEB%.TWikiPlugins
Edit
|
Attach
|
P
rint version
|
H
istory
:
r10
<
r9
<
r8
<
r7
<
r6
|
B
acklinks
|
V
iew topic
|
Raw edit
|
More topic actions...
Topic revision: r9 - 08 Aug 2007 - 10:30:05 -
KoenMartens
?
TWiki/
Log In
or
Register
TWiki/ Web
Users
Groups
Index
Search
Changes
Notifications
RSS Feed
Statistics
Preferences
User Reference
ATasteOfTWiki
TextFormattingRules
TWikiVariables
FormattedSearch
QuerySearch
TWikiDocGraphics
TWikiSkinBrowser
InstalledPlugins
Admin Maintenance
Reference Manual
AdminToolsCategory
InterWikis
ManagingWebs
TWikiSiteTools
TWikiPreferences
WebPreferences
Categories
Admin Documentation
Admin Tools
Developer Doc
User Documentation
User Tools
Webs
Abacos
Acbahia
AnpedGT16
ArcoDigital
Argumento
Avsan
CalculoB
Ceb
Cetad
CetadObserva
Cibercultura
Ciberfem
CiberParque
ColoquioCiags
Coloquiofasa
ConexoesSaberes
Cpdteste
Cppd
Creche
Cridi
Da
DACN
DCE
DelzaTeste
DeniseCarla
DepHistoria
DicionarioBelasartes
Ecologia
EDC
Educandow
EduMus
EleicoesReitor2010
Encima
Enearte
Estruturas
EstruturasEng
FACED
FAT
FepFaced
GEC
GeneticaBiodiversidade
GeneticaBiodiversidade3
GeneticaBiodiversidade
Gepindi
GetecEng
Godofredofilho
GrupoAlgebra
ICI010
Informev
Ites
LabioComp
LEG
Lepeja
Letras
LivroLivreSalvador
Main
MaisUm
Mata07
Mefes
MefesCpd
MetaReciclagem
Neclif
NelsonPretto
Nuclear
Numcad
Nutricao
Observa
OrfaosdeRua
PauloCostaLima
PdI
PescandoLetras
PETFilosofia
Pgif
PGNUT
PortalPpga
PosCultura
Pospetroigeo
PPGAC
PPGE
PpggBio
Ppggenbio
Pretto
Proad
PROGESP
ProjetoLencois
Quimica
RadioFACED
RadioTeatro
RadioWeb
Riosymposium10
Ripe
Salasdoctai
Sat
Sedu
SemBio
SeminarioPibid
SimoneLucena
Sociologia
SSL
Tabuleiro
TabuleirosUfba
TCinema
TerritoriosDigitais
TWiki
Twikidea
UFBAIrece
UniversidadeNova
VizinhoEstrangeiro
XIISNHCT
Български
English
Español
日本語
Português
Copyright � by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki?
Send feedback