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

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

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