Home : Products : Links 2.0 : Customization :

Products: Links 2.0: Customization: Vorras Antibot on Add page mod: Edit Log

Here is the list of edits for this post
Vorras Antibot on Add page mod
Hey all!
After several days of trying different things, I got it to work! The Vorras Antibot is a randomly-generated graphic that contains letters and numbers, which must be entered correctly to be able to add a link. It looks like this:



This should stop spam submissions cold. The download of the Antibot code is here: http://www.vorras.com/products/antibot/

I placed the files like so:

public www directory - (which includes your Links-generated pages)
-- images directory containing images used by Antibot.

public cgi-bin - (which includes your add.cgi, search.cgi, etc)
-- data directory containing...
---- .dat files
-- Antibot directory containing...
----config.py, config.pyc, parseidat.py, png.py, png.pyc

Set the Antibot config file to point to your image directory (path and url), and ignore the FormAction setting, we won't be using it. Set the template line like this:

template = 'antibot_form.html'

The script is written in Python, not Perl, and is very particlar about whitespace - both blank lines and wrong indents will cause errors. Also be sure to set the correct path Python that your server uses; mine was different than what was written in the code. The changes to the Antibot code, beside the config file, is this in png.py:

try:
fd = open('./admin/templates/'+template, 'r')
except IOError:
print 'Could not open template file'
sys.exit(0)

This will direct Antibot to use the new template you will create in the links/templates directory. The original code looks like this: fd = open('templates/'+template, 'r')

That's all for the non-Links code. Now, open site_html_templates.pl, and add this to the add routine:

sub site_html_add_form {
# --------------------------------------------------------
# This routine determines how the add form page will look like.
#
&html_print_headers;
my $category = shift;
my $antibot_form = &get_antibot_form;
my $sequence => ($in{'sequence'}),
my $realsequence => ($in{'realsequence'}),

$category ?
($category = qq~$category <input type="hidden" name="Category" value="$category">~) :
($category = &build_select_field_clean ("Category", "$in{'Category'}"));
my $altcategories = &build_select_field_clean ("AltCategories","$in{'AltCategories'}","AltCategories","multiple Size=3");

print &load_template ('add.html', {
Category => $category,
Keywords => $keywords,
AltCategories => $altcategories,
antibot_form => $antibot_form,
sequence => $sequence,
realsequence => $realsequence,

%in,
%globals
});
}


And create this new sub:

# antibot mod >
sub site_html_antibot_form {
# --------------------------------------------------------
# This routine will build an antibot form insert.

return &load_template ('antibot_form.html', {
%in,
%rec,
%globals
} );
}
# < antibot mod



Next add this to db_utils.db:

# antibot mod >
sub get_antibot_form {
#------------------------------------
# Get the antibot form for Add page.
$output = `./antibot/png.py`;
return $output;
}

# < antibot mod


Note that those are `backticks`, not 'single quotes'.

Now go into your add.cgi, and make these changes...



sub main {
# --------------------------------------------------------
local (%in) = &parse_form;

# We are processing the form.
if (keys %in != 0) {
$in{'antibot_check'} ? &addit : &site_html_add_failure;
}

# Otherwise we are displaying the form (in site_html.pl).
else {
if ($db_single_category) {
my %is_valid = map { $_ => 1 } &category_list;
$ENV{'HTTP_REFERER'} =~ s,/[^/]+\.[^/]+$,,;
$ENV{'HTTP_REFERER'} =~ m,$build_root_url/(.+?)/?$,;
$is_valid{$1} ? &site_html_add_form ($1) : &site_html_add_form ();
}
else {
&site_html_add_form ();
}
}
}

sub addit {
#----------------------------------
# Checks entry for correct antibot code
use SHA;
use CGI;

my $q = new CGI;
if ($in{'sequence'}) {
$seq = ($in{'sequence'});
$realseq = ($in{'realsequence'});
$context = new SHA;
$context->reset();
$seq = $context->hexhash($seq);
$seq =~ s/ //g;
if ($realseq eq $seq) {
&process_form;
}
else {
print $q->header("text/html");
print "<p><b>Wrong A!</b></p>";
}
}
else {
print $q->header("text/html");
print "<p><b>Wrong B!</b></p>";
}
} #end sub addit




This part was the key to making Antibot work! Smile
I plan on making better error messages than "Wrong!"... (The A and B were part of my testing...)

Now make a new template. The one I post here is the same as what the script comes with, except that I removed the form action and submit and /form tags. Call it antibot_form.html.

<table bordercolor="#c0c080" bgcolor="#c0c080" width="300" border="0"><tr>
<td colspan="2">
<font face="arial, helvetica" size="2">
Please enter the characters you see in the box<br>
</font>
</td></tr>
<td valign="top">
<img border="3" src="xxxxIMAGEURLxxxx">
</td><td NOWRAP>
<input type=text size=10 name=sequence>
<input type=hidden size=10 name=realsequence value="xxxxREALSEQUENCExxxx">
</td></tr>
<tr><td colspan="2">
<font face="arial, helvetica" size="1">
by <a target=new href="
http://www.vorras.com/products/antibot/">Vorras Antibot 1.0</a>
</font>
</td>
</tr></table>


Last, a few changes to your add.html template. Put this where you want the form to appear:

<!-- begin antibot form -->
<%antibot_form%>
<!-- end antibot form -->

And change your submit button to include this:

<input
type="submit"
name="antibot_check"
value="Add Resource" />



That should do it! Wink
Any problems, post away...


Leonard
aka PerlFlunkie

Last edited by:

PerlFlunkie: Jan 18, 2005, 7:25 PM

Edit Log: