Annotation of loncom/cgi/thumbnail.gif, revision 1.3

1.1       www         1: #!/usr/bin/perl
                      2: 
                      3: # The LearningOnline Network with CAPA
                      4: # thumbnail.gif - a CGI script that ships out the thumbnail
                      5: #
                      6: # Copyright Michigan State University Board of Trustees
                      7: #
                      8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
                      9: #
                     10: # LON-CAPA is free software; you can redistribute it and/or modify
                     11: # it under the terms of the GNU General Public License as published by
                     12: # the Free Software Foundation; either version 2 of the License, or
                     13: # (at your option) any later version.
                     14: #
                     15: # LON-CAPA is distributed in the hope that it will be useful,
                     16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
                     17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     18: # GNU General Public License for more details.
                     19: #
                     20: # You should have received a copy of the GNU General Public License
                     21: # along with LON-CAPA; if not, write to the Free Software
                     22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
                     23: #
                     24: # /home/httpd/html/adm/gpl.txt
                     25: #
                     26: # http://www.lon-capa.org/
                     27: #
                     28: # YEAR=2001
                     29: # 8/15,9/28,12/11
                     30: #
                     31: ###
                     32: 
                     33: # Example usage: /cgi-bin/thumbnail.gif?url=...
                     34: 
1.2       www        35: 
1.1       www        36: use strict;
                     37: 
1.2       www        38: sub filelocation {
                     39:   my ($dir,$file) = @_;
                     40:   my $location;
                     41:   $file=~ s/^\s*(\S+)\s*$/$1/; ## strip off leading and trailing spaces
                     42:   if ($file=~m:^/~:) { # is a contruction space reference
                     43:     $location = $file;
                     44:     $location =~ s:/~(.*?)/(.*):/home/$1/public_html/$2:;
                     45:   } else {
                     46:     $file=~s/\/home\/httpd\/html//;
                     47:     $file=~s:^/*res::;
                     48:     if ( !( $file =~ m:^/:) ) {
                     49:       $location = $dir. '/'.$file;
                     50:     } else {
                     51:       $location = '/home/httpd/html/res'.$file;
                     52:     }
                     53:   }
                     54:   $location=~s://+:/:g; # remove duplicate /
                     55:   while ($location=~m:/\.\./:) {$location=~ s:/[^/]+/\.\./:/:g;} #remove dir/..
                     56:   return $location;
                     57: }
                     58: 
1.1       www        59: $|=1;   # Autoflush after each print/write
                     60: foreach (split(/&/,$ENV{'QUERY_STRING'})) {
                     61:     my ($name, $value) = split(/=/,$_);
                     62:     $value =~ tr/+/ /;
                     63:     $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
                     64:     if ($name eq 'url') {
                     65: 	$ENV{'form.'.$name}=$value;
                     66:     }
                     67: }
                     68: 
1.2       www        69: 
                     70: my $ofn=&filelocation('',$ENV{'form.url'});
                     71: my $fn=$ofn.'.thumbnail';
                     72: 
                     73: my $exists=1;
                     74: my $generate=0;
                     75: 
                     76: if (-e $ofn) {
                     77:    my ($dev,$ino,$mode,$nlink,
                     78:        $uid,$gid,$rdev,$size,
                     79:        $atime,$omtime,$ctime,
                     80:        $blksize,$blocks)=stat($ofn);
                     81:    if (-e $fn) {
                     82:        my ($dev,$ino,$mode,$nlink,
                     83:            $uid,$gid,$rdev,$size,
                     84:            $atime,$mtime,$ctime,
                     85:            $blksize,$blocks)=stat($fn);
                     86:        if ($omtime>$mtime) { $generate=1; }
                     87:    } else {
                     88:        $generate=1;
                     89:    }
                     90: } else {
                     91:     $exists=0;
                     92: }
                     93: 
                     94: # FIXME: generate thumbnail instead
                     95: if ($generate) { $exists=0; }
                     96: 
                     97: 
                     98: unless ($exists) {
                     99:    $fn='/home/httpd/html/res/adm/pages/nothumb.gif';
                    100: }
                    101: 
1.1       www       102: # Tell the server we are sending a gif graphic
                    103: print <<END;
                    104: Content-type: image/gif
                    105: 
                    106: END
                    107: 
                    108: open (IN,$fn);
                    109: binmode(STDOUT);
                    110: print join('',<IN>); # output image
                    111: $|=1; # be sure to flush before closing
                    112: close IN;
                    113: 
                    114: 
                    115: 
                    116: 
                    117: 
                    118: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>