Have dosendpr.cgi clean up after itself, rather than having a separate

script to do the job.

Suggested by:	wosch
This commit is contained in:
Ceri Davies 2004-02-16 14:38:05 +00:00
parent 62ba1925fa
commit b38382e9a8
Notes: svn2git 2020-12-08 03:00:23 +00:00
svn path=/www/; revision=20040
2 changed files with 6 additions and 50 deletions

View file

@ -8,7 +8,7 @@
# GNU General Public License Version 2.
# (http://www.gnu.ai.mit.edu/copyleft/gpl.html)
#
# $FreeBSD: www/en/cgi/dosendpr.cgi,v 1.15 2004/01/03 21:24:51 ceri Exp $
# $FreeBSD: www/en/cgi/dosendpr.cgi,v 1.16 2004/02/16 14:34:23 ceri Exp $
require "html.pl";
@ -146,6 +146,11 @@ if (defined($codeentered) && $codeentered && $db_hash{$codeentered} &&
}
delete $db_hash{"$codeentered"};
foreach $randomcode (keys %db_hash) {
if ( ($currenttime - $expiretime) <= $db_hash{$randomcode}) {
delete $db_hash{"$randomcode"};
}
}
$db_obj->sync(); # to flush
flock(DB_FH, LOCK_UN);
undef $db_obj; # removing the last reference to the DB

View file

@ -1,49 +0,0 @@
#!/usr/bin/perl -T
#
# $FreeBSD$
# Copyright (c) 2003 Eric Anderson
#
# When www/en/cgi/sendpr-code.cgi creates a submission code to validate
# that the submitter is not a script, the code only gets removed if the
# user continues through www/en/cgi/dosendpr.cgi.
# This script can be run periodically from cron to ensure that the DBM
# doesn't grow without bound.
use DB_File;
use Fcntl qw(:DEFAULT :flock);
use strict;
$ENV{"PATH"} = "/bin:/usr/bin";
$ENV{"TMPDIR"} = "/tmp";
my ($fd, $db_obj, %db_hash, $currenttime, $randomcode, $expiretime, $dbpath);
############################################
$dbpath = "/tmp/sendpr-code.db";
$expiretime = 2700; # seconds until code expires
############################################
$currenttime = time();
# 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: $!" }
}
foreach $randomcode (keys %db_hash) {
if ( ($currenttime - $expiretime) <= $db_hash{$randomcode}) {
delete $db_hash{"$randomcode"};
}
}
$db_obj->sync(); # to flush
flock(DB_FH, LOCK_UN);
undef $db_obj;
untie %db_hash or warn "untie: $!";