#!/usr/bin/perl -wT # # get-list: A script to return a requested list # # Copyright (c) 2004 by Ian Hickson # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA use strict; # be anal about stuff use CGI; # oh yeah, this is a CGI script use Digest::MD5; # allow us to safely encode user-given data use Fcntl ':flock'; # import LOCK_* constants local $ENV{PATH} = ''; my $query = CGI->new(); my $id = $query->param('id'); my $key = $query->param('key'); if (defined($id) and defined($key)) { my $md5 = Digest::MD5->new; $md5->add($id); $md5->add('.'); $md5->add($key); my $filename = '.data/'.($md5->hexdigest); open(my $lock, '+<', '.lock') or die $!; flock($lock, LOCK_EX); if (-f $filename) { print "Content-Type: application/xml\n\n"; print `/bin/cat $filename`; } else { print "Status: 403 Forbidden\nContent-Type: text/plain\n\nInvalid id or key.\n"; } close($lock); } else { print <