X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=cgi%2Flibravatar.cgi;h=c0ff013013220b4aa104c55696c1e870d93f0daa;hb=45f1672bfee50ef8c2ec5938979ee409c5c3db87;hp=5fcd834f5b6c708afe568941ad4c326ef4202e53;hpb=814957c3387b68f31833d48c33674103f50bc266;p=debbugs.git diff --git a/cgi/libravatar.cgi b/cgi/libravatar.cgi old mode 100644 new mode 100755 index 5fcd834..c0ff013 --- a/cgi/libravatar.cgi +++ b/cgi/libravatar.cgi @@ -9,6 +9,7 @@ use Debbugs::Common; use Digest::MD5 qw(md5_hex); use File::LibMagic; use File::Temp qw(tempfile); +use Debbugs::Libravatar qw(:libravatar); use Libravatar::URL; @@ -16,6 +17,7 @@ use LWP::UserAgent; use HTTP::Request; use CGI::Simple; +use Cwd qw(abs_path); my $q = CGI::Simple->new(); @@ -34,14 +36,14 @@ if ($param{avatar} ne 'yes' or not defined $param{email} or not length $param{em # figure out what the md5sum of the e-mail is. my $email_md5sum = md5_hex(lc($param{email})); -my $cache_location = cache_location($email_md5sum); +my $cache_location = cache_location(email => lc($param{email})); # if we've got it, and it's less than one hour old, return it. if (cache_valid($cache_location)) { serve_cache($cache_location,$q); exit 0; } # if we don't have it, get it, and store it in the cache -$cache_location = retreive_libravatar(location => $cache_location, +$cache_location = retrieve_libravatar(location => $cache_location, email => lc($param{email}), ); if (not defined $cache_location) { @@ -61,21 +63,21 @@ sub serve_cache { $cache_location = $config{libravatar_default_image}; } my $fh = IO::File->new($cache_location,'r') or - error(404, "Failed to open cached image $cache_location"); + error($q,404, "Failed to open cached image $cache_location"); my $m = File::LibMagic->new() or - error(500,'Unable to create File::LibMagic object'); - my $mime_string = $m->checktype_filename($cache_location) or - error(500,'Bad file; no mime known'); + error($q,500,'Unable to create File::LibMagic object'); + my $mime_string = $m->checktype_filename(abs_path($cache_location)) or + error($q,500,'Bad file; no mime known'); print $q->header(-type => $mime_string, -expires => '+1d', ); - print STDOUT <$fh>; + print <$fh>; close($fh); } sub error { - my ($error,$text) = @_; + my ($q,$error,$text) = @_; $text //= ''; print $q->header(-status => $error); print "

$error: $text

";