diff options
author | Ceri Davies <ceri@FreeBSD.org> | 2004-01-07 23:25:45 +0000 |
---|---|---|
committer | Ceri Davies <ceri@FreeBSD.org> | 2004-01-07 23:25:45 +0000 |
commit | 055aa3398cdef2800571c9a3703600039309e996 (patch) | |
tree | 987b6a671747c228c7a7fe38af14fab5fc26ca2e /tools | |
parent | a67d458b279a3846a8071ec62df2a43967a6296c (diff) | |
download | doc-055aa3398cdef2800571c9a3703600039309e996.tar.gz doc-055aa3398cdef2800571c9a3703600039309e996.zip |
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.
PR: www/60375
Submitted by: Eric Anderson <anderson@centtech.com>
Notes
Notes:
svn path=/www/; revision=19526
Diffstat (limited to 'tools')
-rwxr-xr-x | tools/clean-sendpr-dbm.pl | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/tools/clean-sendpr-dbm.pl b/tools/clean-sendpr-dbm.pl new file mode 100755 index 0000000000..ca0353ff51 --- /dev/null +++ b/tools/clean-sendpr-dbm.pl @@ -0,0 +1,49 @@ +#!/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: $!"; + |