Annotation of loncom/publisher/lonpubdir.pm, revision 1.21

1.1       www         1: # The LearningOnline Network with CAPA
1.16      albertel    2: # (Publication Handler
                      3: #
1.21    ! foxr        4: # $Id: lonpubdir.pm,v 1.20 2002/01/18 16:48:41 albertel Exp $
1.16      albertel    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/
1.1       www        27: #
                     28: # 
                     29: # (TeX Content Handler
                     30: #
1.17      harris41   31: # YEAR=2000
1.1       www        32: # 05/29/00,05/30,10/11 Gerd Kortemeyer)
                     33: #
                     34: # 11/28,11/29,11/30,12/01,12/02,12/04,12/23 Gerd Kortemeyer
1.17      harris41   35: # YEAR=2001
1.1       www        36: # 03/23 Guy Albertelli
                     37: # 03/24,03/29 Gerd Kortemeyer)
1.17      harris41   38: # 03/31,04/03,05/09,06/23,08/18,08/20 Gerd Kortemeyer
                     39: # 12/15 Scott Harrison
1.19      www        40: # 12/28 Gerd Kortemeyer
1.1       www        41: #
1.17      harris41   42: ###
1.1       www        43: 
                     44: package Apache::lonpubdir;
                     45: 
                     46: use strict;
                     47: use Apache::File;
                     48: use File::Copy;
                     49: use Apache::Constants qw(:common :http :methods);
1.6       www        50: use Apache::loncacc;
1.17      harris41   51: use Apache::loncommon();
1.1       www        52: 
                     53: sub handler {
                     54: 
                     55:   my $r=shift;
                     56: 
                     57:   my $fn;
                     58: 
                     59:   if ($ENV{'form.filename'}) {
                     60:       $fn=$ENV{'form.filename'};
                     61:       $fn=~s/^http\:\/\/[^\/]+\/\~(\w+)/\/home\/$1\/public_html/;
                     62:       $fn=~s/\/[^\/]+$//;
                     63:   } else {
                     64:       $fn=$r->filename();
                     65:   }
1.6       www        66: 
                     67:   my $uname;
                     68:   my $udom;
                     69: 
1.9       www        70:   ($uname,$udom)=
1.6       www        71:     &Apache::loncacc::constructaccess(
1.9       www        72:              $fn,$r->dir_config('lonDefDomain')); 
                     73:   unless (($uname) && ($udom)) {
1.6       www        74:      $r->log_reason($uname.' at '.$udom.
                     75:          ' trying to publish file '.$ENV{'form.filename'}.
                     76:          ' ('.$fn.') - not authorized', 
                     77:          $r->filename); 
                     78:      return HTTP_NOT_ACCEPTABLE;
                     79:   }
1.1       www        80:      
1.3       www        81:   $fn=~s/\/$//;
1.1       www        82: 
                     83:   unless ($fn) { 
                     84:      $r->log_reason($ENV{'user.name'}.' at '.$ENV{'user.domain'}.
1.2       www        85:          ' trying to list empty directory', $r->filename); 
1.1       www        86:      return HTTP_NOT_FOUND;
                     87:   } 
                     88: 
                     89: # ----------------------------------------------------------- Start page output
                     90: 
                     91: 
                     92:   $r->content_type('text/html');
                     93:   $r->send_http_header;
                     94: 
                     95:   $r->print('<html><head><title>LON-CAPA Construction Space</title></head>');
                     96: 
                     97:   $r->print(
                     98:    '<body bgcolor="#FFFFFF"><img align=right src=/adm/lonIcons/lonlogos.gif>');
                     99: 
                    100:   my $thisdisfn=$fn;
                    101:   $thisdisfn=~s/^\/home\/$uname\/public_html//;
                    102:   
1.3       www       103:   $r->print('<h1>Construction Space Directory <tt>'.$thisdisfn.'/</tt></h1>');
1.6       www       104:   
                    105:   if (($uname ne $ENV{'user.name'}) || ($udom ne $ENV{'user.domain'})) {
1.21    ! foxr      106:           $r->print('<h3>Co-Author: '.$uname.' at '.$udom.
        !           107:                '</h3>');
1.6       www       108:   }
                    109: 
1.1       www       110: 
                    111:   my $docroot=$r->dir_config('lonDocRoot');
                    112: 
                    113:   my $resdir=$docroot.'/res/'.$udom.'/'.$uname.$thisdisfn;
1.19      www       114:   my $targetdir=$udom.'/'.$uname.$thisdisfn;
1.1       www       115:   my $linkdir='/~'.$uname.$thisdisfn;
                    116: 
1.2       www       117:   $r->print('<table border=2>'.
1.21    ! foxr      118:  '<tr><th>Actions</th><th>Name</th><th>Title</th>'.
        !           119:  '<th>Status</th><th>Last Modified</th></tr>');
1.1       www       120: 
1.2       www       121:   my $filename;
                    122:   my $dirptr=16384;
1.1       www       123: 
1.2       www       124:   opendir(DIR,$fn);
1.10      albertel  125:   my @files=sort(readdir(DIR));
1.11      albertel  126:   foreach my $filename (@files) {
1.2       www       127:      my ($cdev,$cino,$cmode,$cnlink,
                    128:          $cuid,$cgid,$crdev,$csize,
                    129:          $catime,$cmtime,$cctime,
                    130:          $cblksize,$cblocks)=stat($fn.'/'.$filename);
1.12      www       131: 
1.10      albertel  132:      my $extension='';
                    133:      if ($filename=~/\.(\w+)$/) { $extension=$1; }
1.15      matthew   134:      if ($cmode&$dirptr) {
1.21    ! foxr      135: 	 putdirectory($r, $thisdisfn, $linkdir, $filename, $cmtime);
1.17      harris41  136:      } elsif (&Apache::loncommon::fileembstyle($extension) ne 'hdn') {
1.2       www       137:          my $status='Unpublished';
1.19      www       138:          my $title='&nbsp;';
1.2       www       139:          if (-e $resdir.'/'.$filename) {
                    140:             my ($rdev,$rino,$rmode,$rnlink,
                    141:                 $ruid,$rgid,$rrdev,$rsize,
                    142:                 $ratime,$rmtime,$rctime,
                    143:                 $rblksize,$rblocks)=stat($resdir.'/'.$filename);
                    144:             if ($rmtime>=$cmtime) {
                    145: 		$status='Published';
1.19      www       146:                 $title=
                    147:  '<a href="/res/'.$targetdir.'/'.$filename.'.meta" target=cat>'.
                    148:  &Apache::lonnet::metadata($targetdir.'/'.$filename,'title').'</a>';
1.2       www       149:             } else {
                    150:                 $status='Modified';
1.19      www       151:                 $title=
                    152:  '<a href="/res/'.$targetdir.'/'.$filename.'.meta" target=cat>'.
                    153:  &Apache::lonnet::metadata($targetdir.'/'.$filename,'title').'</a>';
1.5       www       154:                 if 
1.17      harris41  155:          (&Apache::loncommon::fileembstyle(($filename=~/\.(\w+)$/)) eq 'ssi') {
1.7       www       156:                    $status.='<br><a href="/adm/diff?filename=/~'.$uname.
1.12      www       157:                                          $thisdisfn.'/'.$filename.
1.5       www       158: 		       '&versionone=priv" target=cat>Diffs</a>';
                    159: 	        }
1.2       www       160:             }   
1.13      www       161:             $status.='<br><a href="/adm/retrieve?filename=/~'.$uname.
                    162:               $thisdisfn.'/'.$filename.'" target=cat>Retrieve</a>';
1.2       www       163: 	 }
1.21    ! foxr      164: 	 $r->print('<tr>'.
        !           165: 		   '<td><a target="_parent" href="/adm/publish?filename=/~'.
        !           166: 		        $uname.$thisdisfn.'/'.$filename.'">'.'Publish</a>'.
        !           167: 		   '</td>'.
        !           168: 		   '<td>'.
        !           169: 		      '<a href="'.$linkdir.'/'.$filename.'">'.$filename.'</a>'.
        !           170: 		   '</td>'.
        !           171: 		   '<td>'.$title.'</td>'.
        !           172: 		   '<td>'.$status.'</td>'.
        !           173: 		   '<td>'.localtime($cmtime).'</td>'.
        !           174: 		   '</tr>');
1.14      albertel  175:      } else {
1.15      matthew   176: 	# "hidden" extension and not a directory, so hide it away.
1.2       www       177:      }
                    178:   }
                    179:   closedir(DIR);
                    180: 
                    181:   $r->print('</table></body></html>');
1.1       www       182:   return OK;  
                    183: }
1.21    ! foxr      184: #
        !           185: #  Put out a directory table row:
        !           186: #    putdirectory(r, base, here, dirname, modtime)
        !           187: #      r       - Apache request object.
        !           188: #      reqfile - File in request.
        !           189: #      here    - Where we are in directory tree.
        !           190: #      dirname - Name of directory special file.
        !           191: #      modtime - Encoded modification time.
        !           192: # 
        !           193: sub putdirectory {
        !           194:     my ($r, $reqfile, $here, $dirname, $modtime) = @_;
        !           195:   
        !           196:     # construct the display filename: the directory name unless ..:
        !           197:     
        !           198:     my $disfilename = $dirname;
        !           199:     if ($dirname eq '..') {
        !           200: 	$disfilename = '<i>Parent Directory</i>';
        !           201:     }
        !           202:     unless (( ($dirname eq '..') && ($reqfile eq '')) ||
        !           203: 	    ($dirname eq '.')) {
        !           204: 	$r->print('<tr>'.
        !           205: 		  '<td>Click to cwd</td>'.
        !           206: 		  '<td><a href="'.$here.'/'.$dirname.'/">'.
        !           207: 		  $disfilename.'</a></td>'.
        !           208: 		        '<td>&nbsp;</td>'.
        !           209: 		  '<td>&nbsp;</td>'.
        !           210: 		  '<td>'.localtime($modtime).'</td>'.
        !           211: 		  '</tr>');
        !           212:     }	
        !           213:     return OK;
        !           214: }
1.4       www       215: 1;
                    216: __END__
1.17      harris41  217: 
                    218: =head1 NAME
                    219: 
                    220: Apache::lonpubdir - Publication Handler for Directories
                    221: 
                    222: =head1 SYNOPSIS
                    223: 
                    224: Invoked (for various locations) by /etc/httpd/conf/srm.conf:
                    225: 
1.18      harris41  226:  <LocationMatch "^/\~.*/$">
                    227:  PerlAccessHandler       Apache::loncacc
                    228:  SetHandler perl-script
                    229:  PerlHandler Apache::lonpubdir
                    230:  ErrorDocument     403 /adm/login
                    231:  ErrorDocument     404 /adm/notfound.html
                    232:  ErrorDocument     406 /adm/unauthorized.html
                    233:  ErrorDocument	  500 /adm/errorhandler
                    234:  </LocationMatch>
                    235: 
                    236:  <Location /adm/pubdir>
                    237:  PerlAccessHandler       Apache::lonacc
                    238:  SetHandler perl-script
                    239:  PerlHandler Apache::lonpubdir
                    240:  ErrorDocument     403 /adm/login
                    241:  ErrorDocument     404 /adm/notfound.html
                    242:  ErrorDocument     406 /adm/unauthorized.html
                    243:  ErrorDocument	  500 /adm/errorhandler
                    244:  </Location>
1.17      harris41  245: 
                    246: =head1 INTRODUCTION
                    247: 
1.18      harris41  248: This module publishes a directory of files.
1.17      harris41  249: 
                    250: This is part of the LearningOnline Network with CAPA project
                    251: described at http://www.lon-capa.org.
                    252: 
                    253: =head1 HANDLER SUBROUTINE
                    254: 
                    255: This routine is called by Apache and mod_perl.
                    256: 
                    257: =over 4
                    258: 
                    259: =item *
                    260: 
                    261: read in information
                    262: 
                    263: =item *
                    264: 
                    265: start page output
                    266: 
                    267: =item *
                    268: 
                    269: run through list of files and attempt to publish unhidden files
                    270: 
                    271: =back
                    272: 
                    273: =cut

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