File:  [LON-CAPA] / loncom / publisher / lonpubdir.pm
Revision 1.19: download - view: text, annotated - select for diffs
Fri Dec 28 22:14:10 2001 UTC (22 years, 5 months ago) by www
Branches: MAIN
CVS tags: stable_2002_spring, HEAD
Title display

    1: # The LearningOnline Network with CAPA
    2: # (Publication Handler
    3: #
    4: # $Id: lonpubdir.pm,v 1.19 2001/12/28 22:14:10 www Exp $
    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: # (TeX Content Handler
   30: #
   31: # YEAR=2000
   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
   35: # YEAR=2001
   36: # 03/23 Guy Albertelli
   37: # 03/24,03/29 Gerd Kortemeyer)
   38: # 03/31,04/03,05/09,06/23,08/18,08/20 Gerd Kortemeyer
   39: # 12/15 Scott Harrison
   40: # 12/28 Gerd Kortemeyer
   41: #
   42: ###
   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);
   50: use Apache::loncacc;
   51: use Apache::loncommon();
   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:   }
   66: 
   67:   my $uname;
   68:   my $udom;
   69: 
   70:   ($uname,$udom)=
   71:     &Apache::loncacc::constructaccess(
   72:              $fn,$r->dir_config('lonDefDomain')); 
   73:   unless (($uname) && ($udom)) {
   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:   }
   80:      
   81:   $fn=~s/\/$//;
   82: 
   83:   unless ($fn) { 
   84:      $r->log_reason($ENV{'user.name'}.' at '.$ENV{'user.domain'}.
   85:          ' trying to list empty directory', $r->filename); 
   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:   
  103:   $r->print('<h1>Construction Space Directory <tt>'.$thisdisfn.'/</tt></h1>');
  104:   
  105:   if (($uname ne $ENV{'user.name'}) || ($udom ne $ENV{'user.domain'})) {
  106:           $r->print('<h3><font color=red>Co-Author: '.$uname.' at '.$udom.
  107:                '</font></h3>');
  108:   }
  109: 
  110: 
  111:   my $docroot=$r->dir_config('lonDocRoot');
  112: 
  113:   my $resdir=$docroot.'/res/'.$udom.'/'.$uname.$thisdisfn;
  114:   my $targetdir=$udom.'/'.$uname.$thisdisfn;
  115:   my $linkdir='/~'.$uname.$thisdisfn;
  116: 
  117:   $r->print('<table border=2>'.
  118:  '<tr><th>Filename</th><th>Metadata</th><th>Modified</th>'.
  119:  '<th>Status</th><th>&nbsp;</th></tr>');
  120: 
  121:   my $filename;
  122:   my $dirptr=16384;
  123: 
  124:   opendir(DIR,$fn);
  125:   my @files=sort(readdir(DIR));
  126:   foreach my $filename (@files) {
  127:      my ($cdev,$cino,$cmode,$cnlink,
  128:          $cuid,$cgid,$crdev,$csize,
  129:          $catime,$cmtime,$cctime,
  130:          $cblksize,$cblocks)=stat($fn.'/'.$filename);
  131: 
  132:      my $extension='';
  133:      if ($filename=~/\.(\w+)$/) { $extension=$1; }
  134:      if ($cmode&$dirptr) {
  135:          my $disfilename=$filename;
  136:          if ($filename eq '..') {
  137: 	     $disfilename='<i>Parent Directory</i>';
  138:          }
  139:          unless ((($filename eq '..') && ($thisdisfn eq '')) ||
  140:                  ($filename eq '.')) {
  141:            $r->print('<tr bgcolor=#BBBBFF'.
  142:            '><td><a href="'.$linkdir.'/'.$filename.'">'.$disfilename.
  143:  '</a></td><td>&nbsp;</td><td>'.localtime($cmtime).
  144:  '</td><td>&nbsp;</td><td>&nbsp;</td></tr>'
  145:            );
  146:          }
  147:      } elsif (&Apache::loncommon::fileembstyle($extension) ne 'hdn') {
  148:          my $status='Unpublished';
  149:          my $bgcol='#FFBBBB';
  150:          my $title='&nbsp;';
  151:          if (-e $resdir.'/'.$filename) {
  152:             my ($rdev,$rino,$rmode,$rnlink,
  153:                 $ruid,$rgid,$rrdev,$rsize,
  154:                 $ratime,$rmtime,$rctime,
  155:                 $rblksize,$rblocks)=stat($resdir.'/'.$filename);
  156:             if ($rmtime>=$cmtime) {
  157: 		$status='Published';
  158:                 $bgcol='#BBFFBB';
  159:                 $title=
  160:  '<a href="/res/'.$targetdir.'/'.$filename.'.meta" target=cat>'.
  161:  &Apache::lonnet::metadata($targetdir.'/'.$filename,'title').'</a>';
  162:             } else {
  163:                 $status='Modified';
  164:                 $bgcol='#FFFFBB';
  165:                 $title=
  166:  '<a href="/res/'.$targetdir.'/'.$filename.'.meta" target=cat>'.
  167:  &Apache::lonnet::metadata($targetdir.'/'.$filename,'title').'</a>';
  168:                 if 
  169:          (&Apache::loncommon::fileembstyle(($filename=~/\.(\w+)$/)) eq 'ssi') {
  170:                    $status.='<br><a href="/adm/diff?filename=/~'.$uname.
  171:                                          $thisdisfn.'/'.$filename.
  172: 		       '&versionone=priv" target=cat>Diffs</a>';
  173: 	        }
  174:             }   
  175:             $status.='<br><a href="/adm/retrieve?filename=/~'.$uname.
  176:               $thisdisfn.'/'.$filename.'" target=cat>Retrieve</a>';
  177: 	 }
  178:          $r->print('<tr bgcolor='.$bgcol.
  179:          '><td><a href="'.$linkdir.'/'.$filename.'">'.$filename.
  180:          '</a></td><td>'.$title.
  181:          '<td>'.localtime($cmtime).'</td><td>'.$status.'</td>'.
  182:      '<td><a target="_parent" href="/adm/publish?filename=/~'.$uname.
  183:                                       $thisdisfn.'/'.$filename.'">'.
  184:          'Publish</a></td></tr>');
  185:      } else {
  186: 	# "hidden" extension and not a directory, so hide it away.
  187:      }
  188:   }
  189:   closedir(DIR);
  190: 
  191:   $r->print('</table></body></html>');
  192:   return OK;  
  193: }
  194: 
  195: 1;
  196: __END__
  197: 
  198: =head1 NAME
  199: 
  200: Apache::lonpubdir - Publication Handler for Directories
  201: 
  202: =head1 SYNOPSIS
  203: 
  204: Invoked (for various locations) by /etc/httpd/conf/srm.conf:
  205: 
  206:  <LocationMatch "^/\~.*/$">
  207:  PerlAccessHandler       Apache::loncacc
  208:  SetHandler perl-script
  209:  PerlHandler Apache::lonpubdir
  210:  ErrorDocument     403 /adm/login
  211:  ErrorDocument     404 /adm/notfound.html
  212:  ErrorDocument     406 /adm/unauthorized.html
  213:  ErrorDocument	  500 /adm/errorhandler
  214:  </LocationMatch>
  215: 
  216:  <Location /adm/pubdir>
  217:  PerlAccessHandler       Apache::lonacc
  218:  SetHandler perl-script
  219:  PerlHandler Apache::lonpubdir
  220:  ErrorDocument     403 /adm/login
  221:  ErrorDocument     404 /adm/notfound.html
  222:  ErrorDocument     406 /adm/unauthorized.html
  223:  ErrorDocument	  500 /adm/errorhandler
  224:  </Location>
  225: 
  226: =head1 INTRODUCTION
  227: 
  228: This module publishes a directory of files.
  229: 
  230: This is part of the LearningOnline Network with CAPA project
  231: described at http://www.lon-capa.org.
  232: 
  233: =head1 HANDLER SUBROUTINE
  234: 
  235: This routine is called by Apache and mod_perl.
  236: 
  237: =over 4
  238: 
  239: =item *
  240: 
  241: read in information
  242: 
  243: =item *
  244: 
  245: start page output
  246: 
  247: =item *
  248: 
  249: run through list of files and attempt to publish unhidden files
  250: 
  251: =back
  252: 
  253: =cut

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