Refactor the "confirmation code" stuff into a general purpose script.
confirm-code.cgi contains a preconfigured list of databases and their parameters. When a request comes in, the database in the request's 'db' parameter is checked for validity, and a code is generated, stored in the appropriate database and returned. Use this new script in send-pr.sgml and remove sendpr-code.cgi which is now superceded.
This commit is contained in:
parent
2863055355
commit
251299c4db
Notes:
svn2git
2020-12-08 03:00:23 +00:00
svn path=/www/; revision=26515
4 changed files with 71 additions and 127 deletions
|
@ -1,4 +1,4 @@
|
|||
# $FreeBSD: www/en/cgi/Makefile,v 1.27 2005/11/06 22:29:45 ceri Exp $
|
||||
# $FreeBSD: www/en/cgi/Makefile,v 1.28 2005/12/04 12:50:17 ceri Exp $
|
||||
|
||||
.if exists(../Makefile.conf)
|
||||
.include "../Makefile.conf"
|
||||
|
@ -19,6 +19,7 @@ DATA+= ftp.mirrors
|
|||
DATA+= html.pl
|
||||
|
||||
CGI=
|
||||
CGI+= confirm-code.cgi
|
||||
CGI+= cvsweb.cgi
|
||||
CGI+= dosendpr.cgi
|
||||
CGI+= ftp.cgi
|
||||
|
@ -35,7 +36,6 @@ CGI+= ports.cgi
|
|||
CGI+= query-pr.cgi
|
||||
CGI+= query-pr-summary.cgi
|
||||
CGI+= search.cgi
|
||||
CGI+= sendpr-code.cgi
|
||||
CGI+= url.cgi
|
||||
|
||||
.SUFFIXES: .C .cgi
|
||||
|
|
|
@ -1,18 +1,21 @@
|
|||
#!/usr/bin/perl -T
|
||||
#
|
||||
# $FreeBSD: www/en/cgi/confirm-code.cgi,v 1.4 2004/12/13 22:43:05 ceri Exp $
|
||||
# $FreeBSD: www/en/cgi/confirm-code.cgi,v 1.5 2005/11/11 08:58:06 ceri Exp $
|
||||
#
|
||||
# Copyright (c) 2003 Eric Anderson
|
||||
# Copyright (c) 2005 Ceri Davies <ceri@FreeBSD.org>
|
||||
|
||||
use DB_File;
|
||||
use Fcntl qw(:DEFAULT :flock);
|
||||
use strict;
|
||||
use POSIX qw(strftime);
|
||||
|
||||
require 'cgi-lib.pl';
|
||||
|
||||
$ENV{"PATH"} = "/bin:/usr/bin";
|
||||
$ENV{"TMPDIR"} = "/tmp";
|
||||
|
||||
my($fd, $db_obj, %db_hash, $currenttime, $randomcode, $pngbindata, $randompick, $pnmlist, $i);
|
||||
my($expiretime, $pnmcat, $pnmtopng, $pnmdatadir, $dbpath);
|
||||
my(%db, $expiretime, $rfc1123_expiry, $pnmcat, $pnmtopng, $pnmdatadir, $dbpath, $FORM_db);
|
||||
|
||||
############################################
|
||||
# generate 8 character code from A-Z0-9 (no I,O,0,1 for clarity)
|
||||
|
@ -22,52 +25,81 @@ my @availchars = qw(A B C D E F G H J K L M N P Q R S T U V W X Y Z
|
|||
$pnmcat = "/usr/local/bin/pnmcat";
|
||||
$pnmtopng = "/usr/local/bin/pnmtopng";
|
||||
$pnmdatadir = "../gifs/";
|
||||
$dbpath = "/tmp/sendpr-code.db";
|
||||
$expiretime = 2700; # seconds until code expires
|
||||
$expiretime = 0; # Default for the Expires: header
|
||||
############################################
|
||||
|
||||
# The code databases that we know about. If a query comes in for
|
||||
# anything else, we return a zero byte "image" (rather than an image
|
||||
# with a rude word in, which was tempting).
|
||||
|
||||
%db = (
|
||||
# The querypr one is not used, but stands as an example.
|
||||
# querypr => {
|
||||
# path => '/tmp/querypr-code.db',
|
||||
# lifespan => 2700,
|
||||
# },
|
||||
sendpr => {
|
||||
path => '/tmp/sendpr-code.db',
|
||||
lifespan => 2700,
|
||||
},
|
||||
);
|
||||
|
||||
&ReadParse(*in);
|
||||
$FORM_db = $in{"db"}; $FORM_db ||= "junk";
|
||||
|
||||
$currenttime = time();
|
||||
$rfc1123_expiry = strftime "%a, %b %d %H:%M:%S %Y %Z",
|
||||
gmtime($currenttime + $expiretime);
|
||||
|
||||
# DB stuff here
|
||||
$db_obj = tie(%db_hash, 'DB_File', $dbpath, O_CREAT|O_RDWR, 0644)
|
||||
if (exists($db{$FORM_db})) {
|
||||
$dbpath = $db{$FORM_db}->{'path'};
|
||||
$expiretime = $db{$FORM_db}->{'lifespan'};
|
||||
|
||||
# DB stuff here
|
||||
$db_obj = tie(%db_hash, 'DB_File', $dbpath, O_CREAT|O_RDWR, 0644)
|
||||
or die "dbcreate $dbpath $!";
|
||||
$fd = $db_obj->fd;
|
||||
open(DB_FH, "+<&=$fd") or die "fdopen $!";
|
||||
$fd = $db_obj->fd;
|
||||
open(DB_FH, "+<&=$fd") or die "fdopen $!";
|
||||
|
||||
unless (flock (DB_FH, LOCK_EX | LOCK_NB)) {
|
||||
unless (flock (DB_FH, LOCK_EX)) { die "flock: $!" }
|
||||
}
|
||||
|
||||
&gencode;
|
||||
|
||||
while ($db_hash{$randomcode}) {
|
||||
# it already exists so:
|
||||
# we check age (over x seconds old?)
|
||||
# if it is, override with new date
|
||||
# if not, generate a new code
|
||||
if ( ($currenttime - $expiretime) <= $db_hash{$randomcode}) {
|
||||
&gencode;
|
||||
} else {
|
||||
delete $db_hash{"$randomcode"};
|
||||
unless (flock (DB_FH, LOCK_EX | LOCK_NB)) {
|
||||
unless (flock (DB_FH, LOCK_EX)) { die "flock: $!" }
|
||||
}
|
||||
}
|
||||
|
||||
$db_hash{$randomcode} = $currenttime;
|
||||
&gencode;
|
||||
|
||||
$db_obj->sync(); # to flush
|
||||
flock(DB_FH, LOCK_UN);
|
||||
undef $db_obj; # removing the last reference to the DB
|
||||
# closes it. Closing DB_FH is implicit.
|
||||
untie %db_hash;
|
||||
while ($db_hash{$randomcode}) {
|
||||
# it already exists so:
|
||||
# we check age (over x seconds old?)
|
||||
# if it is, override with new date
|
||||
# if not, generate a new code
|
||||
if ( ($currenttime - $expiretime) <= $db_hash{$randomcode}) {
|
||||
&gencode;
|
||||
} else {
|
||||
delete $db_hash{"$randomcode"};
|
||||
}
|
||||
}
|
||||
|
||||
$/ = "";
|
||||
$db_hash{$randomcode} = $currenttime;
|
||||
|
||||
$db_obj->sync(); # to flush
|
||||
flock(DB_FH, LOCK_UN);
|
||||
undef $db_obj; # removing the last reference to the DB
|
||||
# closes it. Closing DB_FH is implicit.
|
||||
untie %db_hash;
|
||||
|
||||
$/ = "";
|
||||
|
||||
open(BUILDPNG, "$pnmcat -lr $pnmlist | $pnmtopng 2>/dev/null |");
|
||||
$pngbindata = <BUILDPNG>;
|
||||
close(BUILDPNG);
|
||||
} else {
|
||||
$pngbindata = undef;
|
||||
};
|
||||
|
||||
open(BUILDPNG, "$pnmcat -lr $pnmlist | $pnmtopng 2>/dev/null |");
|
||||
$pngbindata = <BUILDPNG>;
|
||||
print "Pragma: no-cache\n";
|
||||
print "Expires: $rfc1123_expiry\n";
|
||||
print "Content-type: image/png\n\n";
|
||||
print "$pngbindata";
|
||||
close(BUILDPNG);
|
||||
|
||||
############################################
|
||||
sub gencode {
|
||||
|
@ -80,4 +112,3 @@ sub gencode {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,87 +0,0 @@
|
|||
#!/usr/bin/perl -T
|
||||
#
|
||||
# $FreeBSD: www/en/cgi/sendpr-code.cgi,v 1.5 2005/11/11 08:58:06 ceri Exp $
|
||||
#
|
||||
# Copyright (c) 2003 Eric Anderson
|
||||
# Copyright (c) 2005 Ceri Davies <ceri@FreeBSD.org>
|
||||
|
||||
use DB_File;
|
||||
use Fcntl qw(:DEFAULT :flock);
|
||||
use POSIX qw(strftime);
|
||||
use strict;
|
||||
|
||||
$ENV{"PATH"} = "/bin:/usr/bin";
|
||||
$ENV{"TMPDIR"} = "/tmp";
|
||||
|
||||
my($fd, $db_obj, %db_hash, $currenttime, $randomcode, $pngbindata, $randompick, $pnmlist, $i);
|
||||
my($expiretime, $rfc1123_expiry, $pnmcat, $pnmtopng, $pnmdatadir, $dbpath);
|
||||
|
||||
############################################
|
||||
# generate 8 character code from A-Z0-9 (no I,O,0,1 for clarity)
|
||||
my @availchars = qw(A B C D E F G H J K L M N P Q R S T U V W X Y Z
|
||||
2 3 4 5 6 7 8 9);
|
||||
|
||||
$pnmcat = "/usr/local/bin/pnmcat";
|
||||
$pnmtopng = "/usr/local/bin/pnmtopng";
|
||||
$pnmdatadir = "../gifs/";
|
||||
$dbpath = "/tmp/sendpr-code.db";
|
||||
$expiretime = 2700; # seconds until code expires
|
||||
############################################
|
||||
|
||||
$currenttime = time();
|
||||
$rfc1123_expiry = strftime "%a, %b %d %H:%M:%S %Y %Z", gmtime($currenttime + $expiretime);
|
||||
|
||||
# DB stuff here
|
||||
$db_obj = tie(%db_hash, 'DB_File', $dbpath, O_CREAT|O_RDWR, 0644)
|
||||
or die "dbcreate $dbpath $!";
|
||||
$fd = $db_obj->fd;
|
||||
open(DB_FH, "+<&=$fd") or die "fdopen $!";
|
||||
|
||||
unless (flock (DB_FH, LOCK_EX | LOCK_NB)) {
|
||||
unless (flock (DB_FH, LOCK_EX)) { die "flock: $!" }
|
||||
}
|
||||
|
||||
&gencode;
|
||||
|
||||
while ($db_hash{$randomcode}) {
|
||||
# it already exists so:
|
||||
# we check age (over x seconds old?)
|
||||
# if it is, override with new date
|
||||
# if not, generate a new code
|
||||
if ( ($currenttime - $expiretime) <= $db_hash{$randomcode}) {
|
||||
&gencode;
|
||||
} else {
|
||||
delete $db_hash{"$randomcode"};
|
||||
}
|
||||
}
|
||||
|
||||
$db_hash{$randomcode} = $currenttime;
|
||||
|
||||
$db_obj->sync(); # to flush
|
||||
flock(DB_FH, LOCK_UN);
|
||||
undef $db_obj; # removing the last reference to the DB
|
||||
# closes it. Closing DB_FH is implicit.
|
||||
untie %db_hash;
|
||||
|
||||
$/ = "";
|
||||
|
||||
open(BUILDPNG, "$pnmcat -lr $pnmlist | $pnmtopng 2>/dev/null |");
|
||||
$pngbindata = <BUILDPNG>;
|
||||
print "Pragma: no-cache\n";
|
||||
print "Expires: $rfc1123_expiry\n";
|
||||
print "Content-type: image/png\n\n";
|
||||
print "$pngbindata";
|
||||
close(BUILDPNG);
|
||||
|
||||
############################################
|
||||
sub gencode {
|
||||
srand( time() ^ ($$ + ($$ << 15)) );
|
||||
|
||||
for ($i = 0; $i < 8; $i++) {
|
||||
$randompick = $availchars[int(rand(@availchars))];
|
||||
$randomcode .= "$randompick";
|
||||
$pnmlist .= "$pnmdatadir$randompick\.pnm ";
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" [
|
||||
<!ENTITY date "$FreeBSD: www/en/send-pr.sgml,v 1.48 2005/11/16 20:07:13 linimon Exp $">
|
||||
<!ENTITY date "$FreeBSD: www/en/send-pr.sgml,v 1.49 2005/11/16 23:44:16 linimon Exp $">
|
||||
<!ENTITY title "Submit a FreeBSD problem report">
|
||||
<!ENTITY copyright "This gnats pr-submission mechanism Copyright © 1996
|
||||
The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.">
|
||||
|
@ -134,7 +134,7 @@
|
|||
|
||||
<label for="code-confirm">Finally, please enter the code from the image
|
||||
below to prove you're not a robot: <br><br>
|
||||
<img src="http://www.FreeBSD.org/cgi/sendpr-code.cgi?dummy=1"
|
||||
<img src="http://www.FreeBSD.org/cgi/confirm-code.cgi?db=sendpr"
|
||||
alt="Random text; if you cannot see the image, please email &bugbusters;"
|
||||
border="0" height="24"></label>
|
||||
<input type="text" name="code-confirm" id="code-confirm" size="8"><br><br>
|
||||
|
|
Loading…
Reference in a new issue