Annotation of loncom/cgi/thumbnail.gif, revision 1.4
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: ###
29:
30: # Example usage: /cgi-bin/thumbnail.gif?url=...
31:
1.2 www 32:
1.1 www 33: use strict;
34:
1.2 www 35: sub filelocation {
36: my ($dir,$file) = @_;
37: my $location;
38: $file=~ s/^\s*(\S+)\s*$/$1/; ## strip off leading and trailing spaces
39: if ($file=~m:^/~:) { # is a contruction space reference
40: $location = $file;
41: $location =~ s:/~(.*?)/(.*):/home/$1/public_html/$2:;
42: } else {
43: $file=~s/\/home\/httpd\/html//;
44: $file=~s:^/*res::;
45: if ( !( $file =~ m:^/:) ) {
46: $location = $dir. '/'.$file;
47: } else {
48: $location = '/home/httpd/html/res'.$file;
49: }
50: }
51: $location=~s://+:/:g; # remove duplicate /
52: while ($location=~m:/\.\./:) {$location=~ s:/[^/]+/\.\./:/:g;} #remove dir/..
53: return $location;
54: }
55:
1.4 ! albertel 56: my %env;
! 57:
1.1 www 58: $|=1; # Autoflush after each print/write
59: foreach (split(/&/,$ENV{'QUERY_STRING'})) {
60: my ($name, $value) = split(/=/,$_);
61: $value =~ tr/+/ /;
62: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
63: if ($name eq 'url') {
1.4 ! albertel 64: $env{'form.'.$name}=$value;
1.1 www 65: }
66: }
67:
1.2 www 68:
1.4 ! albertel 69: my $ofn=&filelocation('',$env{'form.url'});
1.2 www 70: my $fn=$ofn.'.thumbnail';
71:
72: my $exists=1;
73: my $generate=0;
74:
75: if (-e $ofn) {
76: my ($dev,$ino,$mode,$nlink,
77: $uid,$gid,$rdev,$size,
78: $atime,$omtime,$ctime,
79: $blksize,$blocks)=stat($ofn);
80: if (-e $fn) {
81: my ($dev,$ino,$mode,$nlink,
82: $uid,$gid,$rdev,$size,
83: $atime,$mtime,$ctime,
84: $blksize,$blocks)=stat($fn);
85: if ($omtime>$mtime) { $generate=1; }
86: } else {
87: $generate=1;
88: }
89: } else {
90: $exists=0;
91: }
92:
93: # FIXME: generate thumbnail instead
94: if ($generate) { $exists=0; }
95:
96:
97: unless ($exists) {
98: $fn='/home/httpd/html/res/adm/pages/nothumb.gif';
99: }
100:
1.1 www 101: # Tell the server we are sending a gif graphic
102: print <<END;
103: Content-type: image/gif
104:
105: END
106:
107: open (IN,$fn);
108: binmode(STDOUT);
109: print join('',<IN>); # output image
110: $|=1; # be sure to flush before closing
111: close IN;
112:
113:
114:
115:
116:
117:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>