#!/usr/bin/perl -w # wdict # Copyright (c) 1999 Jean-Marc Liotier. All rights reserved. # This program is free software; you can redistribute it # and/or modify it under the terms of the GPL # http://www.gnu.org/copyleft/gpl.html # # This programs depends on dict, URI::Escape and CGI.pm # # Dont forget that the file pointed to in $wordslog must be # writable by the HTTP server # # # Changelog : # # 20010717 : I'm now writing a changelog ! # # 20010717 : The shell call being very insecure, I'm now using # URI::Escape to sanitize user input. # # 20010723 : I noticed that browsers with the Gecko HTML renderer # act like they are ignoring the "pre" tag. Tell me if you have # a workaround. # # 20010719 : I fixed the HTML bug that caused browsers with the Gecko # HTML renderer to ignore the "PRE" tag in the query result. Gecko is # stricker than IE in enforcing the standard and my
# construct was a gross incorrection.
#
# 20020214 : "Don't ask what the number next to the button mean : I have no
# idea myself !" is now fixed. Thanks to Sami Rosenblad for the finding the
# bug : "Glancing at the source, I found the problem. The 'print' function
# that starts with p("Enter a new query"... contains another 'print' as one
# of its parameters. The inner 'print' prints what it's supposed to, and
# returns 1 for success to the outer 'print'."
# Enter here the location of the file where you wish to anonymously log requests
$wordslog = "/home/jim/www.ruwenzori.net/private/definedwords";
$VERSION = "0.3.3";
use CGI qw(:standard);
use URI::Escape;
my $word = param("word");
$already = `grep -c $word /var/www/private/definedwords`;
$served = `cat $wordslog | wc -l`;
print header();
print start_html(
-title=>'wdict - Web gateway to dictionnaries',
-author=>'jim@liotier.org',
-meta=>{'keywords'=>'dictionnary english dict webster jargon acronyms',
'description'=>'Search definitions in english dictionnaries'},
);
print p("wdict - Web gateway to dictionnaries
");
print p("A dict interface by Jim.
Over $served definitions served.");
print hr;
print start_form;
print p("Enter a new query",
textfield("word","$word"),
submit("Define"));
print p(scrolling_list(
-NAME => "availables",
-VALUES => [ qw(exact prefix substring suffix re regexp soundex lev) ],
-LABELS =>
{
exact => "Match words exactly",
prefix => "Match prefixes",
substring => "Match substring occurring anywhere in word",
suffix => "Match suffixes",
re => "POSIX 1003.2 (modern) regular expressions (BROKEN)",
regexp => "Old (basic) regular expressions (BROKEN)",
soundex => "Match using SOUNDEX algorithm",
lev => "Match words within Levenshtein distance one",
},
-SIZE => 1,
-MULTIPLE => 0
));
@strategy = param("availables");
print end_form;
if ($word)
{
$saferword = uri_escape ($word, "^A-Za-z");
print hr;
print p("The result of your query for \"$word\" is :");
$result = `dict -s @strategy -v $saferword | grep -v \'Trying .//.dictrc...\' | grep -v \'Trying /etc/dict.conf...\' | grep -v \'Trying localhost (127.0.0.1)\' | grep -v \'Msgid is \' | grep -v \'Configuration file\'`;
print p("$result
");
open LOGFILE, ">>$wordslog";
print LOGFILE "$word\n";
close LOGFILE;
if ($already == 0)
{
print p("You are the first person to ask for a definition of $word here !");
}
else
{
if ($already == 1)
{
print p("You are the second person to ask for a definition of $word here !");
}
else
{
print p("$word has already been defined $already times by wdict on Senecio before.");
}
}
}
print hr;
print p("Update 20010719 :
It seems that string escaping by
URI::Escape
is breaking regexp queries. I have not yet figured out how to get them to play nice together.
Maybe I'll have to find a better way to sanitize user input.
");
print p("Update 20010910 :
I had lots of fun writing this thing, and I'm still using it, but keep in
mind that there is now a less clunky
alternative you might want to try...
");
print hr;
print p();
print p("This is Ruwenzori.net.
The source code for this program
is covered by the GPL.");
print end_html