/[docman2]/docman.php
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /docman.php

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1.1.1 by dpavlin, Sun Jul 21 18:15:47 2002 UTC revision 1.32 by dpavlin, Mon Jul 29 14:17:05 2002 UTC
# Line 20  Line 20 
20  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
21  // CONFIGURATION OPTIONS  // CONFIGURATION OPTIONS
22    
23  //      error_reporting(4) ;            // how verbose ?          error_reporting(E_ALL) ;                // how verbose ?
24    
25          // from where to include auth_*.php modules?          // from where to include auth_*.php modules?
26          $gblIncDir = "/data/docman2";          $gblIncDir = "/data/docman2";
27    
28          // force download (so it won't open in associated application)          // force download on view (so it won't open in associated application)
29          $gblForceDownload = 1;          $gblForceDownload = 0;
30    
31          // date format          // date format
32          $gblDateFmt="Y-m-d";          $gblDateFmt="Y-m-d";
# Line 84  Line 84 
84          LoadLanguage($HTTP_SERVER_VARS["HTTP_ACCEPT_LANGUAGE"]);          LoadLanguage($HTTP_SERVER_VARS["HTTP_ACCEPT_LANGUAGE"]);
85    
86          // for security and configuration          // for security and configuration
87          $realm="$HTTP_HOST";    // FIX          $realm=$HTTP_SERVER_VARS["HTTP_HOST"];
88    
89          $fsDocumentRoot = dirname($HTTP_SERVER_VARS[SCRIPT_FILENAME]);          $fsDocumentRoot = dirname($HTTP_SERVER_VARS["SCRIPT_FILENAME"]);
90          if ($fsDocumentRoot == "") Error("Configuration error","Can't get SCRIPT_FILENAME from your web server. Please set <tt>\$fsDocumentRoot</tt> in <tt>\$</tt>");          if ($fsDocumentRoot == "") Error("Configuration error","Can't get SCRIPT_FILENAME from your web server. Please set <tt>\$fsDocumentRoot</tt> in <tt>\$</tt>",1);
91    
92          // globals for later          // globals for later
93          $gblLogin = $PHP_AUTH_USER;          $gblLogin = HTTP_SERVER_VAR("PHP_AUTH_USER");
94          $gblPasswd = $PHP_AUTH_PW;          $gblPasswd = HTTP_SERVER_VAR("PHP_AUTH_PW");
95    
96  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
97    
# Line 109  function LoadLanguage($lang) { Line 109  function LoadLanguage($lang) {
109    
110  function StartHTML($title,$text="") {  function StartHTML($title,$text="") {
111    
112          global $html,$fsDocumentRoot;          global $html,$fsDocumentRoot,$gblTitle,$HTTP_SERVER_VARS;
113    
114          $title = $gblTitle." ".$title ;          $host  = $HTTP_SERVER_VARS["HTTP_HOST"] ;
115          $host  = $GLOBALS["HTTP_HOST"] ;          $self  = $HTTP_SERVER_VARS["PHP_SELF"] ;
         $self  = $GLOBALS["PHP_SELF"] ;  
116    
117          if (file_exists("$fsDocumentRoot/docman.css")) {          if (file_exists("$fsDocumentRoot/docman.css")) {
118                  $css=dirname($self)."/docman.css";                  $css=dirname($self)."/docman.css";
119          } else {          } else {
120                  $css=$self."?STYLE=get&css=$css";                  $css=$self."?STYLE=get";
121          }          }
122    
123          include("$html/head.html");          include("$html/head.html");
# Line 138  function EndHTML() { Line 137  function EndHTML() {
137          } else {          } else {
138                  $url .= md5($gblLogin.$gblPasswd);                  $url .= md5($gblLogin.$gblPasswd);
139          }          }
140          if (isset($gblLogin) && $gblLogin != "" && ($gblPasswd == "" || !isset($gblPasswd))) {          if ( (  (isset($gblLogin) && $gblLogin != "") ||
141                    (!isset($gblLogin) || $gblLogin == "")
142                 ) && ($gblPasswd == "" || !isset($gblPasswd))) {
143                  $url_title="login";                  $url_title="login";
144                  $url .= "&force_login=1";                  $url .= "&force_login=1";
145          } else {          } else {
146                  $url_title="relogin";                  $url_title="relogin";
147          }          }
148          include("$html/footer.html");          include("$html/footer.html");
149          //phpinfo();  
150            global $debug;
151            if ($debug) print $debug;
152  } // end function EndHTML  } // end function EndHTML
153    
154  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
155    
156  function DetailPage($fsRoot,$relDir,$fn) {  function DetailPage($fsRoot,$relDir,$fn) {
157                    
158          global $gblEditable, $gblImages, $webRoot, $html ;          global $gblEditable, $gblImages,
159          $self = $GLOBALS["PHP_SELF"] ;                  $gblDateFmt, $gblTimeFmt,
160                    $gblPermNote,
161                    $webRoot, $html,
162                    $HTTP_SERVER_VARS ;
163            $self = $HTTP_SERVER_VARS["PHP_SELF"] ;
164    
165          $relPath  = $relDir . "/" . $fn ;          $relPath  = $relDir . "/" . $fn ;
166          $fsPath   = $fsRoot . $relPath ;          $fsPath   = $fsRoot . $relPath ;
# Line 161  function DetailPage($fsRoot,$relDir,$fn) Line 168  function DetailPage($fsRoot,$relDir,$fn)
168    
169          $exists   = file_exists($fsPath) ;          $exists   = file_exists($fsPath) ;
170          $ext      = strtolower(strrchr($relPath,".")) ;          $ext      = strtolower(strrchr($relPath,".")) ;
171          $editable = ( $ext=="" || strstr(join(" ",$gblEditable),$ext)) ;          $editable = ( $ext=="" || strstr(join(" ",$gblEditable),$ext)) &&
172          $writable = is_writeable($fsPath) ;                  check_perm($relPath,trperm_w);
173            $writable = is_writeable($fsPath) && check_perm($relPath,trperm_w) ;
174            $writable_dir = is_writeable($fsDir) && check_perm($relDir,trperm_w) ;
175          $file_lock = CheckLock($fsPath);          $file_lock = CheckLock($fsPath);
176    
177          if (!$editable && !$exists)          if (!$editable && !$exists)
178                  Error(_("Creation unsupported for type"),$relPath) ;                  Error("Creation denied","Can't create <tt>$relPath</tt>") ;
179          if (!exists && !is_writeable($fsDir) )          if (!$exists && !$writable_dir )
180                  Error(_("Creation denied"),$relDir) ;                  Error("Creation denied","Can't write in directory <tt>$relDir</tt> while creating <tt>$relPath</tt>for which user has permissions.",1);
181    
182          $text  = _("Use this page to view, modify or ") ;          $text  = _("Use this page to view, modify or ") ;
183          if (is_dir($fsPath)) {          if (is_dir($fsPath)) {
# Line 180  function DetailPage($fsRoot,$relDir,$fn) Line 189  function DetailPage($fsRoot,$relDir,$fn)
189          $title = "("._("Detail Page").")" ;          $title = "("._("Detail Page").")" ;
190          StartHTML($title, $text) ;          StartHTML($title, $text) ;
191    
192          echo "<H3>" . $relDir . "/" . $fn . "</H3>" ;          print "<H3>".$relDir.$fn."</H3>";
193    
194          if ($exists) {  // get file info          if ($exists) {  // get file info
195                  $fsize = filesize($fsPath) ;                  $fsize = filesize($fsPath) ;
196                  $fmodified = date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]", filemtime($fsPath)) ;                  $fmodified = date("$gblDateFmt $gblTimeFmt", filemtime($fsPath)) ;
197                  $faccessed = date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]", fileatime($fsPath)) ;                  $faccessed = date("$gblDateFmt $gblTimeFmt", fileatime($fsPath)) ;
198                  $fuid=fileowner($fsPath);                  $fuid=fileowner($fsPath);
199                  $fgid=filegroup($fsPath);                  $fgid=filegroup($fsPath);
200                  $userinfo = posix_getpwuid($fuid);                  $userinfo = posix_getpwuid($fuid);
# Line 199  function DetailPage($fsRoot,$relDir,$fn) Line 209  function DetailPage($fsRoot,$relDir,$fn)
209                  $fstr = fread($fh,filesize($fsPath)) ;                  $fstr = fread($fh,filesize($fsPath)) ;
210                  fclose($fh) ;                  fclose($fh) ;
211                  $fstr = htmlentities( $fstr ) ;                  $fstr = htmlentities( $fstr ) ;
 ?>  
212    
213  <FORM ACTION="<?= $self ; ?>" METHOD="POST">                  include("$html/DetailPage-edit.html");
 <SPAN TITLE="Click [SAVE] to store updated contents.">  
         <B>DOCUMENT CONTENTS</B>  
 </SPAN><BR>  
 <TEXTAREA NAME="FILEDATA" ROWS=18 COLS=70 WRAP="OFF"><?php  
 echo($fstr) ; ?></TEXTAREA>  
 <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ; ?>">  
 <INPUT TYPE="HIDDEN" NAME="FN" VALUE="<?= $fn ; ?>">  
 <INPUT TYPE="HIDDEN" NAME="POSTACTION" VALUE="SAVE">  
 <INPUT TYPE="HIDDEN" SIZE=48 MAXLENGTH=255 NAME="RELPATH"  
         VALUE="<?= $relPath ; ?>">  
 <br>  
 <INPUT TYPE="RESET" VALUE="UNDO ALL CHANGES">  
 <INPUT TYPE="SUBMIT" VALUE="SAVE">  
 </FORM>  
   
 <?php  
214          }          }
215          if ( !$file_lock && $ext!="" && strstr(join(' ',$gblImages),$ext) ) {            if ( !$file_lock && $ext!="" && strstr(join(' ',$gblImages),$ext) ) {  
216                  $info  = getimagesize($fsPath) ;                  $info  = getimagesize($fsPath) ;
217                  $tstr = "<IMG SRC=\"$webRoot".urlpath($relPath)."\" BORDER=0 " ;                  $tstr = "<IMG SRC=\"$self?A=V&D=".urlpath(dirname($relPath))."&F=".urlpath(basename($relPath))."\" BORDER=0 " ;
218                  $tstr .= $info[3] . " ALT=\"" . $fn . " - " ;                  $tstr .= $info[3] . " ALT=\"" . $fn . " - " ;
219                  $tstr .= (int)(($fsize+1023)/1024) . "Kb\">" ;                  $tstr .= (int)(($fsize+1023)/1024) . "Kb\">" ;
220  //              echo htmlentities($tstr) . "<BR><BR>" . $tstr ;  //              echo htmlentities($tstr) . "<BR><BR>" . $tstr ;
221                  echo $tstr ;                  echo $tstr ;
222          }          }
223    
 ?>  
   
 <FORM ACTION="<?= $self ; ?>" METHOD="POST">  
 <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ; ?>">  
 <INPUT TYPE="HIDDEN" NAME="FN" VALUE="<?= $fn ; ?>">  
 <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="CANCEL"><BR>  
224    
225  <?php          print '<FORM ACTION="'.$self.'" METHOD="POST">
226                    <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="'.$relDir.'">
227                    <INPUT TYPE="HIDDEN" NAME="FN" VALUE="'.$fn.'">
228                    <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="CANCEL"><BR>
229                    ';
230    
231          if ($file_lock) {          if ($file_lock && check_perm($relDir.$fn,trperm_w)) {
232  ?>                  include("$html/DetailPage-unlock.html");
 <hr>  
 <SPAN TITLE="Check OK and click UNLOCK to remove lock on file.">  
 <B>OK TO FORCE LOCK REMOVAL ON "<?= $fn ; ?>" HELD BY <?= $file_lock ?>? </B></SPAN>  
 <INPUT TYPE="CHECKBOX" NAME="CONFIRM">  
 <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="UNLOCK">  
 <?  
233          } // file_lock          } // file_lock
234    
235          if (substr($fn,0,4) == ".del") {          if (substr($fn,0,4) == ".del") {
# Line 256  echo($fstr) ; ?></TEXTAREA> Line 241  echo($fstr) ; ?></TEXTAREA>
241          }          }
242    
243          if ($exists && $writable) {          if ($exists && $writable) {
244  ?>                  include("$html/DetailPage-undelete.html");
245                    include("$html/DetailPage-rename.html");
 <HR>  
 <a name="undelete">  
 <SPAN TITLE="Check OK and click [<?= $action ?>] to <?= $desc ?>.">  
 <B>OK TO <?= $action ?> "<?= $fn ; ?>"? </B></SPAN>  
 <INPUT TYPE="CHECKBOX" NAME="CONFIRM">  
 <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="<?= $action ?>">  
   
 <HR>  
 <a name="rename">  
 <SPAN TITLE="Check OK and click [RENAME] to rename.">  
 <B>OK TO RENAME "<?= $fn ; ?>" TO  
 <INPUT TYPE="TEXT" SIZE=24 MAXLENGTH=255 NAME="NEWNAME" VALUE="<?= $fn ?>">  
 ? </B></SPAN>  
 <INPUT TYPE="CHECKBOX" NAME="CONFIRM">  
 <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="RENAME">  
246    
247  <?php          }
248          }       // exists && writable          
249  ?>          if (check_perm($relDir.$fn,$gblPermNote)) {
250  <HR>                  include("$html/DetailPage-note.html");
251  <a name="note">          }
 <B>NOTE FOR "<?= $fn ; ?>":  
 <INPUT TYPE="TEXT" SIZE=50 MAXLENGTH=255 NAME="NOTE" VALUE="<?= ReadNote($fsPath) ?>">  
 </B></SPAN>  
 <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="NOTE">  
   
 </FORM>  
252    
253  <?php          print "</FORM>";
254    
255          $name=basename("$fsDir/$fn");          $name=basename("$fsDir/$fn");
256          $logname=dirname("$fsDir/$fn")."/.log/$name";          $logname=dirname("$fsDir/$fn")."/.log/$name";
# Line 472  function MockIcon($txt) { Line 436  function MockIcon($txt) {
436    
437  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
438    
439  function GifIcon($txt) {  function GifIcon($txt = "") {
440          global $gblIconLocation ;          global $gblIconLocation, $gblImages ;
441    
442          switch (strtolower($txt)) {          switch (strtolower($txt)) {
         case ".bmp" :  
         case ".gif" :  
         case ".jpg" :  
         case ".jpeg":  
         case ".tif" :  
         case ".tiff":  
                 $d = "image2.gif" ;  
                 break ;  
443          case ".doc" :          case ".doc" :
444                  $d = "layout.gif" ;                  $d = "layout.gif" ;
445                  break ;                  break ;
# Line 561  function GifIcon($txt) { Line 517  function GifIcon($txt) {
517                  $d = "quill.gif";                  $d = "quill.gif";
518                  break;                  break;
519          default :          default :
520                  $d = "generic.gif" ;                  if (in_array(strtolower($txt),$gblImages)) {
521                            $d = "image2.gif" ;
522                    } else {
523                            $d = "generic.gif" ;
524                    }
525          }          }
526    
527    
528          return "<IMG SRC=\"$gblIconLocation" . $d . "\" BORDER=0>" ;          return "<IMG SRC=\"$gblIconLocation" . $d . "\" BORDER=0>" ;
529  } // end function GifIcon  } // end function GifIcon
530    
# Line 572  function GifIcon($txt) { Line 533  function GifIcon($txt) {
533  function Navigate($fsRoot,$relDir) {  function Navigate($fsRoot,$relDir) {
534    
535          global $gblEditable, $gblIcon, $gblModDays, $webRoot, $gblHide,          global $gblEditable, $gblIcon, $gblModDays, $webRoot, $gblHide,
536                  $HTTP_GET_VARS, $html;                  $gblIgnoreUnknownFileType, $gblRepositoryDir,
537                    $gblLogin, $gblUserName, $gblDateFmt, $gblTimeFmt,
538                    $gblPermNote,
539                    $fsRealmDir, $realm, $realm_sep,
540                    $html, $realm_config,
541                    $HTTP_GET_VARS, $HTTP_SERVER_VARS;
542            
543            $self     = $HTTP_SERVER_VARS["PHP_SELF"] ;
544    
545          $self     = $GLOBALS["PHP_SELF"] ;          $relDir = chopsl($relDir)."/";
546            $fsDir = $fsRoot.$relDir;       // current directory
547    
548          if ($relDir == "") $relDir = "/";          if (!is_dir($fsDir)) Error("Dir not found","Directory <tt>$relDir<tt> not found on filesystem at <tt>$fsDir</tt>",1) ;
549    
550          $fsDir = $fsRoot.$relDir."/";   // current directory          global $debug;
551            $debug .= "[$gblLogin|$relDir] before >";
552    
553          if (!is_dir($fsDir)) Error("Dir not found",$relDir) ;          if (! check_perm($relDir,trperm_b))
554                    Error("Access denied","User <tt>$gblLogin</tt> tried to access <tt>$relDir</tt> without valid trustee.",1);
555            $debug .= "< afeter";
556    
557          $hide_items=",$gblHide,";          $hide_items=",$gblHide,";
558    
559  #display_all_trustee();          $dirList = array();
560  print "-- $fsDir --";          $fileList = array();
561    
562          // read directory contents          // read directory contents
563          if ( !($dir = @opendir($fsDir)) )          if ( !($dir = @opendir($fsDir)) )
564                  Error("Read Access denied",$relDir) ;                  Error("Read Access denied",$relDir,1) ;
565          while ($item = readdir($dir)) {          while ($item = readdir($dir)) {
 print "$item, ";  
566                  if ( substr($item,0,1) == "." || strstr($hide_items,",$item,") ) continue ;                  if ( substr($item,0,1) == "." || strstr($hide_items,",$item,") ) continue ;
567                  if ((is_dir($fsDir.$item) || is_link ($fsDir.$item)) && check_perm($relDir.$item,trperm_b)) {                  if (is_dir($fsDir.$item) || is_link ($fsDir.$item)) {
568                          $dirList[$item] = $item ;                          if (check_perm($relDir.$item,trperm_b)) {
569                          $dirNote[$item] = ReadNote($fsDir.$item);                                  $dirList[$item] = $item ;
570                  } else if ( is_file($fsDir.$item) && check_perm($relDir.$item,trperm_r) ) {                                  $dirNote[$item] = ReadNote($fsDir.$item);
571                          $fileList[$item] = $item ;                                        }
572                          $fileDate[$item] = filemtime($fsDir.$item) ;                  } else if (is_file($fsDir.$item)) {
573                          $fileSize[$item] = filesize($fsDir.$item) ;                          if (check_perm($relDir.$item,trperm_r)) {
574                          $fileNote[$item] = ReadNote($fsDir.$item);                                  $fileList[$item] = $item ;              
575                                    $fileDate[$item] = filemtime($fsDir.$item) ;
576                                    $fileSize[$item] = filesize($fsDir.$item) ;
577                                    $fileNote[$item] = ReadNote($fsDir.$item);
578                            }
579                  } else {                  } else {
580                    // unknown file type                          if (! $gblIgnoreUnknownFileType) Error("File Type Error", "Item <tt>".$fsDir.$item."</tt> is not file, directory or link. If you want to ignore errors like this, set <tt>\$gblIgnoreUnknownFileType = 1</tt> in <tt>$realm_config</tt>.",1);
                   // $text = "Could not determine file type of " ;  
                   // Error("File Error", $text.$relDir."/".$item) ;  
                   // exit ;  
581                  }                  }
582          }          }
583          closedir($dir) ;          closedir($dir) ;
584    
585          // scan deleted files          // scan deleted files
586          if ( $GLOBALS[show_deleted] == 1 && ($dir = @opendir("$fsDir/.del")) ) {          if ( HTTP_GET_VAR("show_deleted") == 1 && ($dir = @opendir("$fsDir/.del")) ) {
587                  while ($item = readdir($dir)) {                  while ($item = readdir($dir)) {
588                          if ( substr($item,0,1) == "." || strstr($hide_items,",$item,") || !check_perm($relDir.$item,trperm_w) ) continue ;                          if ( substr($item,0,1) == "." || strstr($hide_items,",$item,") || !check_perm($relDir.$item,trperm_w) ) continue ;
589                          $fileList[$item] = ".del/$item" ;                                        if (is_file($fsDir.".del/$item")) {
590                          $fileDate[$item] = filemtime($fsDir.".del/$path") ;                                  $fileList[$item] = ".del/$item" ;              
591                          $fileSize[$item] = filesize($fsDir.".del/$path") ;                                  $fileDate[$item] = filemtime($fsDir.".del/$item") ;
592                          $fileNote[$item] = ReadNote($fsDir.".del/$item");                                  $fileSize[$item] = filesize($fsDir.".del/$item") ;
593                                    $fileNote[$item] = ReadNote($fsDir.".del/$item");
594                            } else {
595                                    $dirList[$item] = ".del/$item" ;                
596                                    $dirNote[$item] = ReadNote($fsDir.".del/$item");
597                            }
598                  }                  }
599                  closedir($dir) ;                  closedir($dir) ;
600          }          }
# Line 626  print "$item, "; Line 603  print "$item, ";
603    
604          // start navigation page          // start navigation page
605          $text  = "Use this page to add, delete";          $text  = "Use this page to add, delete";
606          if (! isset($show_deleted)) {          if (! isset($HTTP_GET_VARS["show_deleted"])) {
607                  $text .= ", <a href=$self?D=".urlencode($relDir)."&show_deleted=1>undelete</a>";                  $text .= ", <a href=$self?D=".urlencode($relDir)."&show_deleted=1>undelete</a>";
608          }          }
609          $text .= " or revise files on this web site." ;          $text .= " or revise files on this web site." ;
610          $text .= "<br>Examine list of files <a href=\"$self?A=Ch1\">changed in last day</a> or <a href=\"$self?A=Ch\">all changes</a>.";          $text .= "<br>Examine list of files <a href=\"$self?A=Ch1\">changed in last day</a> or <a href=\"$self?A=Ch\">all changes</a>.";
611          StartHTML("(Navigate)",$text) ;          StartHTML("(Navigate)",$text) ;
612    
613          echo "<TABLE BORDER=0 CELLPADDING=2          print "<TABLE BORDER=0 CELLPADDING=2 CELLSPACING=3 WIDTH=\"100%\">" ;
                 CELLSPACING=3 WIDTH=\"100%\">" ;  
614    
615          // updir bar              // updir (parent) bar  
616          if (chopsl($fsDir) != chopsl($fsRoot)) {          if (chopsl($fsDir) != chopsl($fsRoot)) {
617                  $parent = dirname($relDir) ;                  $parent = dirname($relDir) ;
618                  if ($parent == "") $parent = "/" ;                  if ($parent == "") $parent = "/" ;
# Line 652  print "$item, "; Line 628  print "$item, ";
628                  return $out;                  return $out;
629          }          }
630    
631          $dsort = $HTTP_GET_VARS[dsort];          $dsort = HTTP_GET_VAR("dsort");
632          if (! isset($dsort)) $dsort = "name";   // default directory sort          if (! isset($dsort)) $dsort = "name"; // default directory sort
633    
634          $dsort_arr = array(          $dsort_arr = array(
635                  "name" => array ("rname", "note"),                  "name" => array ("rname", "note"),
# Line 662  print "$item, "; Line 638  print "$item, ";
638                  "rnote" => array ("name", "note")                  "rnote" => array ("name", "note")
639                  );                  );
640    
641          $fsort = $HTTP_GET_VARS[fsort];          $fsort = HTTP_GET_VAR("fsort");
642          if (! isset($fsort)) $fsort = "name";   // default directory sort          if (! isset($fsort)) $fsort = "name"; // default directory sort
643    
644          $fsort_arr = array(          $fsort_arr = array(
645                  "name" => array ("rname", "note", "date", "size"),                  "name" => array ("rname", "note", "date", "size"),
# Line 679  print "$item, "; Line 655  print "$item, ";
655          $D="D=".urlencode($relDir);          $D="D=".urlencode($relDir);
656    
657          function self_args($arr = array()) {          function self_args($arr = array()) {
658                    global $self;
659                  $arg = implode("&",$arr);                  $arg = implode("&",$arr);
660                  if ($arg) {                  if ($arg) {
661                          return $self."?".$arg;                          return $self."?".$arg;
# Line 715  print "$item, "; Line 692  print "$item, ";
692    
693                          $dir = $dirList[$key];                          $dir = $dirList[$key];
694    
695                          $info_url=self_args(array("A" => "A=E", "F" => "F=".urlencode($dir)));                          $info_url=self_args(array("A"=>"A=E", "F"=>"F=".urlencode($dir), "D"=>$D));
696                          $dir_url=$self."?D=".urlencode($relDir.$dir);                          if (substr($dir,0,5) == ".del/") {
697                                    $dir = substr($dir,5,strlen($dir)-5);
698                                    $deleted = " <a href=\"$info_url#undelete\"><SPAN CLASS=deleted TITLE=\"deleted\">deleted</span></a>";
699                            } else {
700                                    $deleted = "";
701                            }
702            
703                            $dir_url=$self."?D=".urlencode(chopsl($relDir)."/".$dir);
704                            if (check_perm($relDir.$dir,$gblPermNote)) {
705                                    $note_html="<a href=\"$info_url#note\">".$gblIcon("note")."</a>".$dirNote[$key];
706                            } else {
707                                    $note_html=$dirNote[$key];
708                            }
709    
710                          include("$html/Navigate-dirEntry.html");                          include("$html/Navigate-dirEntry.html");
711    
712                  }  // iterate over dirs                  }  // iterate over dirs
# Line 788  print "$item, "; Line 778  print "$item, ";
778    
779                  $file_lock=CheckLock($path);                  $file_lock=CheckLock($path);
780    
781                  $file_url_html="<A HREF=\"$self?A=V&F=".urlencode($file);                  $file_url_html="<A HREF=\"$self?A=V&D=".urlencode($relDir)."&F=".urlencode($file);
                 $file_url_html.="&D=".urlencode($relDir);  
782                  $file_url_html.="\" TITLE=\"View file\">" ;                  $file_url_html.="\" TITLE=\"View file\">" ;
783    
784                  if (substr($file,0,5) != ".del/") {                  if (substr($file,0,5) != ".del/") {
785                          $file_url_html .= $file . "</A>" . $a ;                          $file_url_html .= $file . "</A>" . $a ;
786                  } else {                  } else {
787                          $file_url_html .= substr($file,5,strlen($file)-5) . "</a> <SPAN CLASS=RED TITLE=\"deleted\"> <a href=\"$info_url#undelete\">deleted</a> </span>";                          $file_url_html .= substr($file,5,strlen($file)-5) . "</a> <a href=\"$info_url#undelete\"><SPAN CLASS=deleted TITLE=\"deleted\">deleted</span></a>";
788                  }                  }
789    
790                  $note_html="<a href=\"$info_url#note\">".$gblIcon("note")."</a>".ReadNote($path);                  if (check_perm($relDir.$file,$gblPermNote)) {
791                            $note_html="<a href=\"$info_url#note\">".$gblIcon("note")."</a>".$fileNote[$key];
792                    } else {
793                            $note_html=$fileNote[$key];
794                    }
795    
796                  $ext = strtolower(strrchr($file,".")) ;                  $ext = strtolower(strrchr($file,".")) ;
797    
798                  if ($file_lock) {                  if ($file_lock) {
799                          if ($file_lock == $GLOBALS[gblUserName]) {                          if ($file_lock == $gblUserName) {
800                                  $b.="<A HREF=\"$self?A=Ci&F=".urlencode($file);                                  $b.="<A HREF=\"$self?A=Ci&D=".urlencode($relDir)."&F=".urlencode($file);
                                 $b.="&D=".urlencode($relDir);  
801                                  $b.="\" TITLE=\"Checkin (update) file on server\">" ;                                  $b.="\" TITLE=\"Checkin (update) file on server\">" ;
802                                  $file_url_html=$b;                                  $file_url_html=$b;
803                                  $b.=$gblIcon("checkin")."</A>" ;                                  $b.=$gblIcon("checkin")."</A>" ;
# Line 819  print "$item, "; Line 811  print "$item, ";
811                                  $file_url_html = "$file $a";                                  $file_url_html = "$file $a";
812                          }                          }
813                  } else {                  } else {
814                          $b.="<A HREF=\"$self?A=Co&F=".urlencode($file);                          if (check_perm($relDir.$file,trperm_w)) {
815                          $b.="&D=".urlencode($relDir);                                  $b.="<A HREF=\"$self?A=Co&D=".urlencode($relDir)."&F=".urlencode($file);
816                          $b.="\" TITLE=\"Checkout file for edit\">" ;                                  $b.="\" TITLE=\"Checkout file for edit\">" ;
817                          $b.=$gblIcon("checkout")."</A>" ;                                  $b.=$gblIcon("checkout")."</A>";
818                            }
819    
820                          if ( $ext=="" || strstr(join(" ",$gblEditable),$ext) ) {                            if ( $ext=="" || strstr(join(" ",$gblEditable),$ext) ) {  
821                                  $b.="<A HREF=\"$self?A=C&F=".urlencode($file);                                  $b.="<A HREF=\"$self?A=C&D=".urlencode($relDir)."&F=".urlencode($file);
                                 $b.="&D=".urlencode($relDir);  
822                                  $b.="\" TITLE=\"List contents\">" ;                                  $b.="\" TITLE=\"List contents\">" ;
823                                  $b.=$gblIcon("view")."</A>" ;                                  $b.=$gblIcon("view")."</A>" ;
824                          } else {                          } else {
# Line 834  print "$item, "; Line 826  print "$item, ";
826                          }                          }
827                  }                  }
828    
829                  $mod = date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]",$mod);                  $mod = date("$gblDateFmt $gblTimeFmt",$mod);
830    
831                  include("$html/Navigate-fileEntry.html");                  include("$html/Navigate-fileEntry.html");
832    
833            }  // iterate over files            }  // iterate over files
834          } else {  // end if no files          } else {  // end if no files
835  ?>                  include("$html/Navigate-noFiles.html");
  <TR><TD></TD><TD COLSPAN=5 CLASS=LST>  
   No files in this directory  
  </TD></TR>  
 <?  
836          }          }
837    
838          if ($emptyDir && $relDir != "") {          if ($emptyDir && $relDir != "") {
839  ?>                  include("$html/Navigate-emptyDir.html");
   
 <FORM METHOD="POST" ACTION="<?= $self ?>">  
  <TR><TD></TD><TD COLSPAN=5 CLASS=BAR>  
   <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ?>">  
   OK TO DELETE THIS EMPTY FOLDER?  
   <INPUT TYPE="CHECKBOX" NAME="CONFIRM">  
   <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="DELETE">  
  </TD></TR>  
 </FORM>  
   
 <?php  
840          } // end if emptyDir          } // end if emptyDir
 ?>  
841    
842  <TR><TD></TD><TD COLSPAN=5><HR></TD></TR>          include("$html/Navigate-hr.html");      
843    
844  <?          if (file_exists("$fsRealmDir/$realm".$realm_sep."info.inc")) {
845  if (file_exists(".info.inc")) {                  print "<TR><TD></TD><TD COLSPAN=5>";
846          print "<TR><TD></TD><TD COLSPAN=5>";                  include("$fsRealmDir/$realm".$realm_sep."info.inc");
847          include(".info.inc");                  print "</TD></TR>";
848          print "</TD></TR>                  include("$html/Navigate-hr.html");      
849          <TR><TD></TD><TD COLSPAN=5><HR></TD></TR>";          } elseif (file_exists("$gblRepositoryDir/.info.inc")) {
850  }                  print "<TR><TD></TD><TD COLSPAN=5>";
851  ?>                  include("$gblRepositoryDir/.info.inc");
852                    print "</TD></TR>";
853                    include("$html/Navigate-hr.html");      
854            }
855    
856            include("$html/Navigate-createNew.html");
857    
858  <FORM METHOD="POST" ACTION="<?= $self ?>">          print "</TABLE>";
 <TR><TD></TD><TD COLSPAN=5 CLASS=BAR>CREATE NEW  
  <INPUT TYPE="RADIO" NAME="T" VALUE="D" CHECKED>DIRECTORY -OR-  
  <INPUT TYPE="RADIO" NAME="T" VALUE="F">FILE : &nbsp;&nbsp;  
  <NOBR>NAME <INPUT TYPE="TEXT" NAME="FN" SIZE=14>  
  <INPUT TYPE="HIDDEN" NAME="POSTACTION" VALUE="CREATE">  
  <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ?>">  
  <INPUT TYPE="SUBMIT" VALUE="CREATE" NAME="CREATE">  
  </NOBR>  
  <NOBR>OR <A HREF="<?= $self ?>?A=U&D=<?= urlencode($relDir) ?>">UPLOAD</A> A FILE</NOBR>  
 </TD></TR>  
 </FORM>  
 </TABLE>  
859    
 <?php  
860          EndHTML() ;          EndHTML() ;
861  } // end function Navigate  } // end function Navigate
862    
# Line 896  if (file_exists(".info.inc")) { Line 864  if (file_exists(".info.inc")) {
864    
865  function UploadPage($fsRoot, $relDir, $filename="") {  function UploadPage($fsRoot, $relDir, $filename="") {
866    
867          $self = $GLOBALS["PHP_SELF"] ;          global $html, $HTTP_SERVER_VARS;
         if ($relDir == "") $relDir = "/" ;  
 ?>  
868    
869  <P><TABLE BORDER=0 CELLPADDING=5><TR><TD WIDTH=5></TD><TD CLASS=BAR>          $self = $HTTP_SERVER_VARS["PHP_SELF"] ;
870  <FORM ENCTYPE="multipart/form-data" METHOD="POST"          include("$html/UploadPage.html");
  ACTION="<?= $self ?>">  
 DESTINATION DIRECTORY:<B><?= " " . $relDir ?></B>  
 <? if (isset($filename) && $filename!="") { ?>  
 <br>DESTINATION FILE:<B><?= " " . $filename ?></B>  
 <INPUT TYPE="HIDDEN" NAME="FILENAME" VALUE="<?= $filename ?>">  
 <? } ?>  
 <P>PATHNAME OF LOCAL FILE<BR>  
 <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ?>">  
 <INPUT TYPE="HIDDEN" NAME="POSTACTION" VALUE="UPLOAD">  
 <INPUT SIZE=30 TYPE="FILE" NAME="FN"></P>  
 <P><INPUT TYPE="SUBMIT" VALUE="UPLOAD"></P>  
 <P>If the <B>[BROWSE...]</B> button is not displayed,<BR>  
 you must upgrade to an RFC1867-compliant browser.</P>  
 <P>Your browser:<BR><?= $GLOBALS["HTTP_USER_AGENT"] ?></P>  
 </FORM>  
 </TD></TR>  
 <TR><TD></TD><TD>  
 <FORM METHOD="POST" ACTION="<?= $self ?>">  
 <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ?>"><BR>  
 <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="CANCEL">  
 </FORM>  
 </TD></TR></TABLE></P>  
871    
 <?php    
872  } // end function UploadPage  } // end function UploadPage
873    
874  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
875    
876  function Error($title,$text="") {  // Error with sysadmin flag are reported to error_log or hidden from
877          StartHTML("(".$title.")",$text) ;  // users
878          echo "<P ALIGN=center>Hit your Browser's Back Button.</P>" ;  
879          EndHTML() ;  function Error($title,$text="",$sysadmin=0,$no_404=0) {
880            global $gblSeparateAdminMessages,
881                    $gblMailAdminMessages,$realm,
882                    $HTTP_SERVER_VARS;
883            if (! headers_sent() && ! $no_404) header("HTTP/1.0 404 Not Found");
884            if ($sysadmin) {
885                    if ($gblSeparateAdminMessages) {
886                            $user="Your administrator ";
887                            if ($gblMailAdminMessages) {
888                                    mail($HTTP_SERVER_VARS["SERVER_ADMIN"], "docman $realm error message: $title", strip_tags($text));
889                                    $user.="<tt>".$HTTP_SERVER_VARS["SERVER_ADMIN"]."</tt> ";
890                            }
891                            $user.="has been notified about error" ;
892                            StartHTML("($title)",$user);
893                            echo "<P ALIGN=center>Hit your Browser's Back Button.</P>" ;
894                            EndHTML();
895                            error_log("docman $realm: ".strip_tags($text));
896                    } else {
897                            StartHTML("ADMIN: ".$title,$text) ;
898                            echo "<P ALIGN=center>Hit your Browser's Back Button.</P>" ;
899                            EndHTML();
900                    }
901            } else {
902                    StartHTML("(".$title.")",$text) ;
903                    echo "<P ALIGN=center>Hit your Browser's Back Button.</P>" ;
904                    EndHTML() ;
905            }
906          exit ;          exit ;
907  } // end function Error  } // end function Error
908    
909  //////////////////////////////////////////////////////////////////  function LogIt($target,$msg, $changelog=0) {
910    
911  function LogIt($target,$msg) {          global $gblDateFmt, $gblTimeFmt, $gblUserName, $gblFsRoot;
912    
913          $dir=dirname($target);          $dir=dirname($target);
914          if (! file_exists($dir."/.log")) {          if (! file_exists($dir."/.log")) {
915                  if (! @mkdir($dir."/.log",0700)) Error("docman installation problem","can't create log directory <tt>$dir/.log</tt>");                  if (! @mkdir($dir."/.log",0700)) Error("docman installation problem","can't create log directory <tt>$dir/.log</tt>",1);
916          }          }
917          $file=basename($target);          $file=basename($target);
918    
919          $log=fopen("$dir/.log/$file","a+");          $log=fopen("$dir/.log/$file","a+");
920          fputs($log,date("$GLOBALS[gblDateFmt]\t$GLOBALS[gblTimeFmt]").          fputs($log,date("$gblDateFmt\t$gblTimeFmt").
921                  "\t$GLOBALS[gblUserName]\t$msg\n");                  "\t$gblUserName\t$msg\n");
922            fclose($log);
923    
924            if (! $changelog) return;
925    
926            $log=fopen("$gblFsRoot/.changelog","a+");
927            if (substr($target,0,strlen($gblFsRoot)) == $gblFsRoot)
928                    $target=substr($target,strlen($gblFsRoot),strlen($target)-strlen($gblFsRoot));
929            $msg=str_replace("\t"," ",$msg);
930            fputs($log,time()."\t$target\t$gblUserName\t$msg\n");
931          fclose($log);          fclose($log);
932    
933            // FIX: implement e-mail notification based on $changelog
934            // permission
935  }  }
936    
937    
# Line 967  function WriteNote($target,$msg) { Line 947  function WriteNote($target,$msg) {
947          $file=basename($target);          $file=basename($target);
948    
949          $note=fopen("$dir/.note/$file","w");          $note=fopen("$dir/.note/$file","w");
950            if (! $note) {
951                    Error("Error writing note","Can't open note file <tt>$dir/.note/$file</tt> for writing",1);
952            }
953          fputs($note,"$msg\n");          fputs($note,"$msg\n");
954          fclose($note);          fclose($note);
955    
956          Logit($target,"added note $msg");          LogIt($target,"added note $msg");
957    
958  }  }
959    
# Line 1007  function MoveTo($source,$folder) { Line 990  function MoveTo($source,$folder) {
990    
991  function Lock($target) {  function Lock($target) {
992    
993            global $gblUserName;
994    
995          $target=stripSlashes($target);          $target=stripSlashes($target);
996          $dir=dirname($target);          $dir=dirname($target);
997          if (! file_exists($dir."/.lock")) {          if (! file_exists($dir."/.lock")) {
# Line 1015  function Lock($target) { Line 1000  function Lock($target) {
1000          $file=basename($target);          $file=basename($target);
1001    
1002          if (file_exists("$dir/.lock/$file")) {          if (file_exists("$dir/.lock/$file")) {
1003                  Logit($target,"attempt to locked allready locked file!");                  LogIt($target,"attempt to locked allready locked file!");
1004          } else {          } else {
1005                  $lock=fopen("$dir/.lock/$file","w");                  $lock=fopen("$dir/.lock/$file","w");
1006                  fputs($lock,"$GLOBALS[gblUserName]\n");                  fputs($lock,"$gblUserName\n");
1007                  fclose($lock);                  fclose($lock);
1008    
1009                  Logit($target,"file locked");                  LogIt($target,"file locked");
1010          }          }
1011    
1012  }  }
# Line 1048  function Unlock($target) { Line 1033  function Unlock($target) {
1033          $file=basename($target);          $file=basename($target);
1034          if (file_exists($dir."/.lock/$file")) {          if (file_exists($dir."/.lock/$file")) {
1035                  unlink("$dir/.lock/$file");                  unlink("$dir/.lock/$file");
1036                  Logit($target,"file unlocked");                  LogIt($target,"file unlocked");
1037          } else {          } else {
1038                  Logit($target,"attempt to unlocked non-locked file!");                  LogIt($target,"attempt to unlocked non-locked file!");
1039          }          }
1040    
1041  }  }
# Line 1067  function urlpath($url) { Line 1052  function urlpath($url) {
1052  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
1053    
1054  function safe_rename($fromdir,$fromfile,$tofile) {  function safe_rename($fromdir,$fromfile,$tofile) {
1055    
1056            global $gblNumBackups;
1057    
1058          function try_rename($from,$to) {          function try_rename($from,$to) {
1059  #               print "$from -> $to\n";  #               print "$from -> $to\n";
1060                  if (file_exists($from) && is_writeable(dirname($to))) {                  if (file_exists($from) && is_writeable(dirname($to))) {
1061                          rename($from,$to);                          return rename($from,$to);
1062                    } else {
1063                            return 0;
1064                  }                  }
1065          }          }
1066    
1067          function try_dir($todir) {          function try_dir($todir) {
1068                  if (! file_exists($todir)) {                  if (! file_exists($todir)) {
1069                          mkdir($todir,0700);                          @mkdir($todir,0700);
1070                  }                  }
1071          }          }
1072    
# Line 1086  function safe_rename($fromdir,$fromfile, Line 1076  function safe_rename($fromdir,$fromfile,
1076    
1077  #       print "<pre>$fromdir / $fromfile -> $todir / $tofile\n\n";  #       print "<pre>$fromdir / $fromfile -> $todir / $tofile\n\n";
1078    
1079          try_rename("$fromdir/$fromfile","$todir/$tofile");          if (! try_rename("$fromdir/$fromfile","$todir/$tofile")) Error("Rename error","Can't rename file <tt>$fromfile</tt> to <tt>$tofile</tt>",1);
1080          try_dir("$todir/.log");          try_dir("$todir/.log");
1081          try_rename("$fromdir/.log/$fromfile","$todir/.log/$tofile");          try_rename("$fromdir/.log/$fromfile","$todir/.log/$tofile");
1082          try_dir("$todir/.note");          try_dir("$todir/.note");
# Line 1094  function safe_rename($fromdir,$fromfile, Line 1084  function safe_rename($fromdir,$fromfile,
1084          try_dir("$todir/.lock");          try_dir("$todir/.lock");
1085          try_rename("$fromdir/.lock/$fromfile","$todir/.lock/$tofile");          try_rename("$fromdir/.lock/$fromfile","$todir/.lock/$tofile");
1086          try_dir("$todir/.bak");          try_dir("$todir/.bak");
1087          for($i=0;$i<=$GLOBALS[gblNumBackups];$i++) {          for($i=0;$i<=$gblNumBackups;$i++) {
1088                  try_rename("$fromdir/.bak/$i/$fromfile","$todir/.bak/$i/$tofile");                  try_rename("$fromdir/.bak/$i/$fromfile","$todir/.bak/$i/$tofile");
1089          }          }
1090  }  }
# Line 1120  function rrmdir($dir) { Line 1110  function rrmdir($dir) {
1110    
1111  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
1112    
1113  function ChangeLog($target,$msg) {  function DisplayChangeLog($day) {
   
         global $gblFsRoot;  
         $log=fopen("$gblFsRoot/.changelog","a+");  
         if (substr($target,0,strlen($gblFsRoot)) == $gblFsRoot)  
                 $target=substr($target,strlen($gblFsRoot),strlen($target)-strlen($gblFsRoot));  
         $msg=str_replace("\t"," ",$msg);  
         fputs($log,time()."\t$target\t$GLOBALS[gblUserName]\t$msg\n");  
         fclose($log);  
1114    
1115  }          global $gblFsRoot, $gblDateFmt, $gblTimeFmt,
1116                    $HTTP_SERVER_VARS;
1117    
1118  function DisplayChangeLog($day) {          $self  = $HTTP_SERVER_VARS["PHP_SELF"];
1119    
         global $gblFsRoot;  
1120          if (!file_exists("$gblFsRoot/.changelog")) return;          if (!file_exists("$gblFsRoot/.changelog")) return;
1121          $log=fopen("$gblFsRoot/.changelog","r");          $log=fopen("$gblFsRoot/.changelog","r");
1122          $logarr = array();          $logarr = array();
# Line 1152  function DisplayChangeLog($day) { Line 1134  function DisplayChangeLog($day) {
1134          print "<table border=0 width=100%>\n";          print "<table border=0 width=100%>\n";
1135          while ($e = array_shift($logarr)) {          while ($e = array_shift($logarr)) {
1136                  $cl=$cl1; $cl1=$cl2; $cl2=$cl;                  $cl=$cl1; $cl1=$cl2; $cl2=$cl;
1137                  $date = date("$GLOBALS[gblDateFmt]", $e[0]);                  $date = date($gblDateFmt, $e[0]);
1138                  $time = date("$GLOBALS[gblTimeFmt]", $e[0]);                  $time = date($gblTimeFmt, $e[0]);
1139                  $dir = dirname($e[1]);                  $dir = dirname($e[1]);
1140                  $file = basename($e[1]);                  $file = basename($e[1]);
1141                  print "<tr><td$cl>$date</td><td$cl>$time</td><td$cl><a href=\"$GLOBALS[PHP_SELF]?D=".urlencode($dir)."\">$dir</a>/$file</td><td$cl>$e[2]</td><td$cl>$e[3]</td></tr>\n";                  print "<tr><td$cl>$date</td><td$cl>$time</td><td$cl><a href=\"$HTTP_SERVER_VARS[PHP_SELF]?D=".urlencode($dir)."\">$dir</a>/$file</td><td$cl>$e[2]</td><td$cl>$e[3]</td></tr>\n";
1142          }          }
1143          print "</table>";          print "</table>";
1144          print "<p>".GifIcon(up)." Back to <a href=$GLOBALS[PHP_SELF]>front page</a>.</p>";          print "<p>".GifIcon("up")." Back to <a href=\"$self\">front page</a>.</p>";
1145  }  }
1146    
1147  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
1148    
1149  function Download($path) {  function Download($path,$force=0) {
1150          global $HTTP_USER_AGENT;          global $HTTP_SERVER_VARS,$mime_type;
1151          $file=basename($path);  
1152            // default transfer-encoding
1153            $encoding = "binary";
1154    
1155            // known transfer encodings
1156            $encoding_ext = array(
1157                    "gz" => "x-gzip",
1158                    "Z" => "x-compress",
1159            );
1160    
1161            $file = basename($path);
1162          $size = filesize($path);          $size = filesize($path);
1163          //header("Content-Type: application/octet-stream");  
1164          header("Content-Type: application/force-download");          $ext_arr = explode(".",$file);
1165          header("Content-Length: $size");          $ext = array_pop($ext_arr);
1166            if (isset($encoding_ext[$ext])) {
1167                    $encoding = $encoding_ext[$ext];
1168                    $ext = array_pop($ext_arr);
1169            }
1170    
1171            if ($force || !isset($mime_type[$ext])) {
1172                    header("Content-Type: application/force-download");
1173            } else {
1174                    header("Content-Type: $mime_type[$ext]");
1175            }
1176    
1177          // IE5.5 just downloads index.php if we don't do this          // IE5.5 just downloads index.php if we don't do this
1178          if(preg_match("/MSIE 5.5/", $HTTP_USER_AGENT)) {          if(preg_match("/MSIE 5.5/", $HTTP_SERVER_VARS["HTTP_USER_AGENT"])) {
1179                  header("Content-Disposition: filename=$file");                  header("Content-Disposition: filename=$file");
1180          } else {          } else {
1181                  header("Content-Disposition: attachment; filename=$file");                  header("Content-Disposition: attachment; filename=$file");
1182          }          }
1183          header("Content-Transfer-Encoding: binary");  
1184            header("Content-Transfer-Encoding: $encoding");
1185          $fh = fopen($path, "r");          $fh = fopen($path, "r");
1186          fpassthru($fh);          fpassthru($fh);
1187  }  }
# Line 1186  function Download($path) { Line 1190  function Download($path) {
1190  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
1191    
1192  function chopsl($path) {  function chopsl($path) {
         if (substr($path,strlen($path)-1,1) == "/") $path=substr($path,0,strlen($path)-1);  
1193          $path=str_replace("//","/",$path);          $path=str_replace("//","/",$path);
1194            if (substr($path,strlen($path)-1,1) == "/") $path=substr($path,0,strlen($path)-1);
1195          return $path;          return $path;
1196  }  }
1197    
# Line 1201  function chopsl($path) { Line 1205  function chopsl($path) {
1205          by Vyacheslav Zavadsky <zavadsky@braysystems.com>          by Vyacheslav Zavadsky <zavadsky@braysystems.com>
1206  */  */
1207    
1208  define(trmask_not,1 << 0);  define('trmask_not',1 << 0);
1209  define(trmask_clear,1 << 1);  define('trmask_clear',1 << 1);
1210  define(trmask_deny,1 << 2);  define('trmask_deny',1 << 2);
1211  define(trmask_one_level,1 << 3);  define('trmask_one_level',1 << 3);
1212  define(trmask_group,1 << 4);  define('trmask_group',1 << 4);
1213    
1214  define(trperm_r,1 << 5);  define('trperm_r',1 << 5);
1215  define(trperm_w,1 << 6);  define('trperm_w',1 << 6);
1216  define(trperm_b,1 << 7);  define('trperm_b',1 << 7);
1217  define(trperm_n,1 << 8);  define('trperm_n',1 << 8);
1218    
1219  $trustee_a2n = array(  $trustee_a2n = array(
1220          '!' => trmask_not,          '!' => trmask_not,
# Line 1258  if (! file_exists($trustee_conf)) { Line 1262  if (! file_exists($trustee_conf)) {
1262          $error="<tt>".dirname($trustee_php)."</tt> must be writable by web server user";          $error="<tt>".dirname($trustee_php)."</tt> must be writable by web server user";
1263  } elseif (file_exists($trustee_php) && !is_writable($trustee_php)) {  } elseif (file_exists($trustee_php) && !is_writable($trustee_php)) {
1264          $error="trustees cache file <tt>$trustee_php</tt> exists, but is not writable by web server";          $error="trustees cache file <tt>$trustee_php</tt> exists, but is not writable by web server";
1265  } elseif (1 || filemtime($trustee_conf) >= filemtime($trustee_php)) {  } elseif (@filemtime($trustee_conf) >= @filemtime($trustee_php)) {
1266          $fp_php=@fopen($trustee_php,"w");          $fp_php=@fopen($trustee_php,"w");
1267          fputs($fp_php,"<?php // don't edit by hand!\n");          fputs($fp_php,"<?php // don't edit by hand!\n");
1268    
# Line 1267  if (! file_exists($trustee_conf)) { Line 1271  if (! file_exists($trustee_conf)) {
1271          $groups_arr = array();          $groups_arr = array();
1272          $perm_arr = array();          $perm_arr = array();
1273    
         $error=0;  
   
1274          $tr_arr = array();          $tr_arr = array();
1275    
1276          while (! feof($fp_conf)) {          while (! feof($fp_conf)) {
# Line 1296  if (! file_exists($trustee_conf)) { Line 1298  if (! file_exists($trustee_conf)) {
1298                                                  $error.="trustee error in line '$l' [Unknown modifier '$ch']<br>\n";                                                  $error.="trustee error in line '$l' [Unknown modifier '$ch']<br>\n";
1299                                          }                                          }
1300                                  }                                  }
1301                                  $tr_arr[$path][$user] |= $perm;                                  if (isset($tr_arr[$path][$user])) {
1302                                            $tr_arr[$path][$user] |= $perm;
1303                                    } else {
1304                                            $tr_arr[$path][$user] = $perm;
1305                                    }
1306                          }                          }
1307                  }                  }
1308          }          }
# Line 1335  if (! file_exists($trustee_conf)) { Line 1341  if (! file_exists($trustee_conf)) {
1341          fclose($fp_php);          fclose($fp_php);
1342  }  }
1343    
1344  if ($error) {  if (isset($error)) {
1345          Error("Trustee error",$error);          Error("Trustee error",$error,1);
1346  } else {  } else {
1347          include("$trustee_php");          include_once("$trustee_php");
1348  }  }
1349    
1350  return 1;  return 1;
# Line 1346  return 1; Line 1352  return 1;
1352  }//init_trustee  }//init_trustee
1353    
1354  function in_group($user,$group) {  function in_group($user,$group) {
1355          return in_array($groups[$group],$user);          global $groups;
1356            return in_array($user,$groups[$group]);
1357  }  }
1358    
1359  // helper function  // helper function
1360  function unroll_perm($u,$t,$user,$perm) {  function unroll_perm($u,$t,$perm,$one_level) {
1361          // check user  
1362          if ($t & trmask_not && ($u==$user)) continue;          if ($t & trmask_one_level && !$one_level) return $perm;
         if (!($t & trmask_not) && ($u!=$user)) continue;  
1363    
1364          if ($t & trmask_deny) {          if ($t & trmask_deny) {
1365                  if ($t & trmask_clear) {                  if ($t & trmask_clear) {
1366                          $perm[deny] &= ~$t;                          $perm['deny'] &= ~$t;
1367                  } else {                  } else {
1368                          $perm[deny] |= $t;                          $perm['deny'] |= $t;
1369                  }                  }
1370          } elseif ($t & trmask_clear) {          } elseif ($t & trmask_clear) {
1371                  $perm[allow] &= ~$t;                  $perm['allow'] &= ~$t;
1372          } else {          } else {
1373                  $perm[allow] |= $t;                  $perm['allow'] |= $t;
1374          }          }
1375          return $perm;          return $perm;
1376  }// end of helper function  }// end of helper function
1377    
1378  function check_trustee($user,$path) {  function check_trustee($user,$path) {
1379          global $trustees;          global $trustees,$HAVE_TRUSTEE;
1380          $perm[allow] = 0;          $perm['allow'] = 0;
1381          $perm[deny] = 0;          $perm['deny'] = 0;
1382    
1383            // do we use trustees?
1384            if (! $HAVE_TRUSTEE) return $perm;
1385    
1386            if (! isset($trustees)) Error("Trustees not found","Can't find in-memory trustee structure <tt>\$trustees</tt>. Probably bug in code. Contact <tt>dpavlin@rot13.org</tt>",1);
1387    
1388    global $debug;
1389    $debug .= "<br>check_trustee $path ... ";
1390    
1391          $path_arr=explode("/",$path);          $path_arr=explode("/",$path);
1392          $path = "/";          $tmppath = "/";
1393          while (count($path_arr)) {          while (count($path_arr)) {
1394                  if (substr($path,strlen($path)-1,1) != "/") $path.="/";                  $tmppath.=array_shift($path_arr);
1395                  $path.=array_shift($path_arr);  $debug.= ">> $tmppath ";
1396                  $tr = $trustees[$path];  
1397                    if (! isset($trustees[$tmppath])) continue;
1398                    $tr = $trustees[$tmppath];
1399    
1400                    $one_level = (!count($path_arr));
1401    $debug.=" O($one_level) ";
1402    
1403                  if (isset($tr)) {                  if (isset($tr)) {
1404                          // first apply trustee for all                          // first apply trustee for all
1405                          if (isset($tr['*'])) {                          if (isset($tr['*']) && $user!="anonymous") {
1406                                  $perm = unroll_perm($user,$tr['*'],$user, $perm);                                  $perm = unroll_perm($user,$tr['*'],$perm, $one_level);
1407                                  unset($tr['*']);                                  unset($tr['*']);
1408                          }                          }
1409                          // then apply group policies                          // then apply not and group policies
1410                          foreach ($tr as $u=>$t) {                          foreach ($tr as $g=>$t) {
1411                                  if ($t & trmask_group && in_group($user,$u)) {                                  if ($t & trmask_not && $g != $user) {
1412                                            $t = $t & ~trmask_not;
1413                                            $perm = unroll_perm($user,$t,$perm, $one_level);
1414                                            unset($tr[$g]);
1415    
1416                                    } elseif ($t & trmask_group && in_group($user,$g)) {
1417                                          // resolv user                                          // resolv user
1418                                          $t = $t & ~trmask_group;                                          $t = $t & ~trmask_group;
1419                                          $u = $user;                                          $perm = unroll_perm($user,$t,$perm, $one_level);
1420                                          $perm = unroll_perm($u,$t,$user, $perm);                                          unset($tr[$g]);
                                         unset($tr[$u]);  
1421                                  }                                  }
1422                          }                          }
1423                          // then apply use policy                          // then apply user policy
1424                          if (isset($tr[$user])) {                          if (isset($tr[$user])) {
1425                                  $perm = unroll_perm($user,$tr[$user],$user, $perm);                                  $perm = unroll_perm($user,$tr[$user],$perm,$one_level);
1426                                  unset($tr[$user]);                                  unset($tr[$user]);
1427                          }                          }
   
1428                  }                  }
1429    $debug.="d(".display_trustee($perm['deny']).") a(".display_trustee($perm['allow']).") ";
1430    
1431          }          }
1432  #print "<br>user: $user path: $path perm: ";  $debug.="<br>check_trustee: user: $user path: $path==$tmppath perm: ";
1433  #print "d: $perm[deny] (".display_trustee($perm[deny]).") a: $perm[allow] (".display_trustee($perm[allow]).")<Br>\n";  $debug.="d: ".$perm['deny']." (".display_trustee($perm['deny']).") a: ".$perm['allow']." (".display_trustee($perm['allow']).")<Br>\n";
1434          return $perm;          return $perm;
1435  }  }
1436    
# Line 1414  function check_trustee($user,$path) { Line 1438  function check_trustee($user,$path) {
1438    
1439  function check_perm($path,$trperm) {  function check_perm($path,$trperm) {
1440          global $gblLogin,$HAVE_TRUSTEE;          global $gblLogin,$HAVE_TRUSTEE;
1441  print "<br>check_perm: <tt>$path</tt> test perm ".display_trustee($perm)."<br>\n";  
1442            $path = str_replace("//","/",$path);
1443    
1444            global $debug;
1445    $debug.="<br>check_perm: on <tt>$path</tt> for perm ".display_trustee($trperm)."<br>\n";
1446    
1447          $return = ! $HAVE_TRUSTEE;          $return = ! $HAVE_TRUSTEE;
1448          if ($HAVE_TRUSTEE) {          if ($HAVE_TRUSTEE) {
1449                  $perm = check_trustee($gblLogin,$path);                  $perm = check_trustee($gblLogin,$path);
1450  print " d: $perm[deny] (".display_trustee($perm[deny]).") a: $perm[allow] (".display_trustee($perm[allow]).") perm: $trperm";  $debug.=" d: ".$perm['deny']." (".display_trustee($perm['deny']).") a: ".$perm['allow']." (".display_trustee($perm['allow']).") perm to have: $trperm (".display_trustee($trperm).")";
1451                  if ($perm[deny] & $trperm) $return=0;                  if ($perm['deny'] & $trperm) $return=0;
1452                  elseif ($perm[allow] & $trperm) $return=1;                  elseif (($perm['allow'] & $trperm) == $trperm) $return=1;
1453          }          }
1454  print " return: $return<br>\n";  $debug.=" return: $return<br>\n";
1455          return($return);          return($return);
1456  }  }
1457    
1458    //////////////////////////////////////////////////////////////////
1459    
1460    function readMime() {
1461            global $mime_type;
1462    
1463            if (! isset($gblMimeTypes)) {
1464                    $gblMimeTypes = "/etc/mime.types";
1465            }
1466    
1467            $mime = @fopen($gblMimeTypes,"r");
1468    
1469            if (! $mime) Error("Can't read MIME types","<tt>$gblMimeTypes</tt> file not found. You can setup other <tt>mime.types</tt> file using <tt>\$gblMimeTypes</tt> in <tt>$realm_config</tt>");
1470    
1471            while($line = fgets($mime,80)) {
1472                    if (substr($line,0,1) == "#") continue; // skip comment
1473                    $arr = preg_split("/[\s\t]+/",$line);
1474                    $type = array_shift($arr);
1475                    while ($ext = array_shift($arr)) {
1476                            $mime_type[$ext] = $type;
1477                    }
1478            }
1479    
1480            fclose($mime);
1481    }
1482    
1483    //////////////////////////////////////////////////////////////////
1484    
1485    // check for invalid characters in filename and dirname (.. and /)
1486    
1487    function check_dirname($file) {
1488            if (strstr($file,"..")) Error("Security violation","No parent dir <tt>..</tt> allowed in directory name <tt>$file</tt>",1);
1489    }
1490    
1491    function check_filename($file) {
1492            if (strstr($file,"..")) Error("Security violation","No parent dir <tt>..</tt> allowed in file name <tt>$file</tt>",1);
1493            // remove deleted directory (for undelete to work)
1494            $file = str_replace(".del/","",$file);
1495            if (strstr($file,"/")) Error("Security violation","No slashes <tt>/</tt> allowed in file name <tt>$file</tt>",1);
1496    }
1497    
1498    // bla/blo/../foo will return bla/foo
1499    function remove_parent($path) {
1500            while (preg_match(",/[^/]+/\.\./,",$path)) {
1501                    $path = preg_replace(",/[^/]+/\.\./,","",$path);
1502            }
1503            if (substr($path,0,1) != "/") $path = "/".$path;
1504            return $path;
1505    }
1506    
1507    //////////////////////////////////////////////////////////////////
1508    
1509    // functions to move HTTP server variables to global namespace
1510    // [replacement for register_globals in php.ini]
1511    
1512    function HTTP_GET_VAR($var) {
1513            global $HTTP_GET_VARS, ${$var};
1514            if (isset($HTTP_GET_VARS[$var])) {
1515                    $$var = stripSlashes($HTTP_GET_VARS[$var]);
1516                    return $$var;
1517            }
1518    }
1519    
1520    function HTTP_POST_VAR($var) {
1521            global $HTTP_POST_VARS, ${$var};
1522            if (isset($HTTP_POST_VARS[$var])) {
1523                    $$var = $HTTP_POST_VARS[$var];
1524                    return $$var;
1525            }
1526    }
1527    
1528    function HTTP_SERVER_VAR($var) {
1529            global $HTTP_SERVER_VARS, ${$var};
1530            if (isset($HTTP_SERVER_VARS[$var])) {
1531                    $$var = $HTTP_SERVER_VARS[$var];
1532                    return $$var;
1533            }
1534    }
1535    
1536    //////////////////////////////////////////////////////////////////
1537    
1538    function Warn($text) {
1539    }
1540    
1541  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
1542  // MAIN PROGRAM  // MAIN PROGRAM
# Line 1433  print " return: $return<br>\n"; Line 1544  print " return: $return<br>\n";
1544          $gblFilePerms = 0640 ;         // default for new files          $gblFilePerms = 0640 ;         // default for new files
1545          $gblDirPerms  = 0750 ;          // default for new dirs          $gblDirPerms  = 0750 ;          // default for new dirs
1546    
1547          if (isset($STYLE) && $STYLE == "get") {          if (isset($HTTP_GET_VARS["STYLE"]) && $HTTP_GET_VARS["STYLE"] == "get") {
1548                  include("$html/docman.css");                  include("$html/docman.css");
1549                  exit;                  exit;
1550          }          }
# Line 1441  print " return: $return<br>\n"; Line 1552  print " return: $return<br>\n";
1552          // location of master docman configuration file          // location of master docman configuration file
1553          $docman_conf = "/etc/docman.conf";          $docman_conf = "/etc/docman.conf";
1554          if (! file_exists($docman_conf)) {          if (! file_exists($docman_conf)) {
1555                  $error = "Can't find master configuration file $docman_conf. See docman2/doc/upgrade.html#docman_conf for more informations";                  $error = "Can't find master configuration file <tt>$docman_conf</tt>. See <tt>docman2/doc/upgrade.html#docman_conf</tt> for more informations";
1556                                    
1557                  error_log("docman: $error");                  error_log("docman: $error");
1558                  Error("docman not installed completly",$error);                  Error("docman not installed completly",$error);
# Line 1451  print " return: $return<br>\n"; Line 1562  print " return: $return<br>\n";
1562          if (! isset($fsRealmDir)) {          if (! isset($fsRealmDir)) {
1563                  $fsRealmDir = "$gblIncDir/realm";                  $fsRealmDir = "$gblIncDir/realm";
1564          }          }
1565          $realm_config = "$fsRealmDir/$realm.conf";  
1566            // try to add dir to script name to realm var
1567            if (is_dir("$fsRealmDir/$realm/".dirname($HTTP_SERVER_VARS["SCRIPT_NAME"]))) {
1568                    $realm .= dirname($HTTP_SERVER_VARS["SCRIPT_NAME"]);
1569                    $realm_sep = "/";
1570            } else {
1571                    $realm_sep = ".";
1572            }
1573    
1574            $realm_config = $fsRealmDir."/".$realm.$realm_sep."conf";
1575    
1576          // read user-defined configuration          // read user-defined configuration
1577          if (file_exists($realm_config)) {          if (file_exists($realm_config)) {
# Line 1469  print " return: $return<br>\n"; Line 1589  print " return: $return<br>\n";
1589                  Error("Configuration error","Can't find user handling module at <tt>$gblIncDir/htusers/$gblUsers.php</tt> ! Please fix <tt>$realm_config</tt>");                  Error("Configuration error","Can't find user handling module at <tt>$gblIncDir/htusers/$gblUsers.php</tt> ! Please fix <tt>$realm_config</tt>");
1590          }          }
1591    
1592            // take additional login vars
1593            HTTP_GET_VAR("relogin");
1594            HTTP_GET_VAR("force_login");
1595    
1596          // if no password, or empty password logout          // if no password, or empty password logout
1597          if (          if (
1598                  isset($gblLogin) && (                  isset($gblLogin) && (
# Line 1484  print " return: $return<br>\n"; Line 1608  print " return: $return<br>\n";
1608                  exit ;                  exit ;
1609          }          }
1610    
1611            if (!is_dir($gblRepositoryDir)) Error("Repository dir not found","Can't find repository directory <tt>$gblRepositoryDir</tt>. Please fix that in <tt>$realm_config</tt> variable <tt>\$gblRepositoryDir</tt>.",1);
1612    
1613          // trustee (ACL) file configuration          // trustee (ACL) file configuration
1614          $trustee_conf="$gblIncDir/realm/$realm.trustee";          $trustee_conf="$fsRealmDir/$realm".$realm_sep."trustee";
1615          // compiled version of trustee file          // compiled version of trustee file
1616          $trustee_php="$gblRepositoryDir/.trustee.php";          $trustee_php="$gblRepositoryDir/.trustee.php";
1617          // get ACL informations          // get ACL informations
1618          $HAVE_TRUSTEE = init_trustee();          $HAVE_TRUSTEE = init_trustee();
1619    
1620          if (strtolower($gblLogin) == "anonymous" || !isset($gblPasswd)) {          if (strtolower($gblLogin) == "anonymous" || !isset($gblLogin)) {
1621                  $perm = check_trustee($gblLogin,$path);                  $perm = check_trustee("anonymous","/");
1622                  // browsing must be explicitly allowed for root directory                  // browsing must be explicitly allowed for root directory
1623                  // of repository for anonymous user to work!                  // of repository for anonymous user to work!
1624                  if ($perm[allow] & trperm_b) {                  if ($perm['allow'] & trperm_b) {
1625                            $gblLogin = $gblPasswd = "anonymous";
1626                          $secHash = md5($gblLogin.$gblPasswd);                          $secHash = md5($gblLogin.$gblPasswd);
1627                          $gblUserName = "Anonymous user";                          $gblUserName = "Anonymous user";
1628                  }                  }
# Line 1506  print " return: $return<br>\n"; Line 1633  print " return: $return<br>\n";
1633                  isset($relogin) && $secHash == $relogin) {                  isset($relogin) && $secHash == $relogin) {
1634                  header("WWW-authenticate: basic realm=\"$realm\"") ;                  header("WWW-authenticate: basic realm=\"$realm\"") ;
1635                  header("HTTP/1.0 401 Unauthorized") ;                  header("HTTP/1.0 401 Unauthorized") ;
1636                  Error("401 Unauthorized","No trespassing !");                  Error("401 Unauthorized","No trespassing !",0,1);
                 exit ;  
1637          }          }
1638    
         // get current directory relative to $gblFsRoot  
         $relDir = $DIR ;        // from POST  
         if ($relDir == "") {    // not defined in POST ?  
                 $relDir = urldecode($D) ;  // then use GET  
         }        
1639    
1640          $relDir=stripSlashes($relDir);          // read mime.types
1641            readMime();
1642    
1643          if ($relDir == "/") $relDir = "" ;                if (! isset($gblPermNote)) {
1644          // default : website root = ""                  $gblPermNote = trperm_r;
1645            }
1646    
1647          if (strstr($relDir,"..")) Error("No updirs allowed");          HTTP_POST_VAR("FN");
1648    
1649          // full paths contain "fs" or "Fs". Paths realitve to root of          if ($HTTP_SERVER_VARS["REQUEST_METHOD"] == "POST") {
1650          // website contain "rel" or "Rel". The script won't let you                  // take variables from server
1651          // edit anything above directory equal to http://server.com                  if (HTTP_POST_VAR("FN"))
1652          // i.e. below $gblFsRoot.                          check_filename($FN);
1653                    if (HTTP_POST_VAR("DIR")) {
1654                            check_dirname($DIR);
1655                            $relDir = $DIR;
1656                    } else {
1657                            trigger_error("Can't get DIR",E_USER_WARNING);
1658                            $relDir = "/";
1659                    }
1660                    if (HTTP_POST_VAR("RELPATH")) check_dirname($RELPATH);
1661                    HTTP_POST_VAR("T");
1662                    HTTP_POST_VAR("CONFIRM");
1663            } else {
1664                    // get
1665                    HTTP_GET_VAR("A");
1666                    if (HTTP_GET_VAR("D")) {
1667                            check_dirname($D);
1668                            $D=urldecode($D);
1669                            $relDir = $D;
1670                    } else {
1671                            //trigger_error("Can't get D",E_USER_WARNING);
1672                            $relDir = "/";
1673                    }
1674                    if (HTTP_GET_VAR("F")) check_filename($F);
1675            }
1676    
1677          $relScriptDir = dirname($SCRIPT_NAME) ;                  $relScriptDir = dirname($HTTP_SERVER_VARS["SCRIPT_NAME"]) ;    
1678          // i.e. /docman          // i.e. /docman
1679    
1680          // start on server root          // start on server root
1681          $gblFsRoot = $gblRepositoryDir;          $gblFsRoot = $gblRepositoryDir;
1682          // i.e. /home/httpd/html          // i.e. /home/httpd/repository
1683    
1684          $fsDir = $gblFsRoot . $relDir ; // current directory          $fsDir = $gblFsRoot . $relDir ; // current directory
1685          if ( !is_dir($fsDir) ) Error("Dir not found",$relDir) ;          if ( !is_dir($fsDir) ) Error("Dir not found","Can't find <tt>$relDir</tt> which points to <tt>$fsDir</tt>",1) ;
1686    
1687          if (isset($GLOBALS["HTTPS"]) && $GLOBALS["HTTPS"] == "on") {          if ($relDir == "") $relDir="/";
1688    
1689            if (isset($HTTP_SERVER_VARS["HTTPS"]) && $HTTP_SERVER_VARS["HTTPS"] == "on") {
1690                  $webRoot  = "https://";                  $webRoot  = "https://";
1691          } else {          } else {
1692                  $webRoot  = "http://";                  $webRoot  = "http://";
1693          }          }
1694          $webRoot .= $GLOBALS["HTTP_HOST"] . $relScriptDir;          $webRoot .= $HTTP_SERVER_VARS["HTTP_HOST"] . $relScriptDir;
   
         $FN=stripSlashes($FN);  
1695    
1696          switch ($POSTACTION) {          if (HTTP_POST_VAR("POSTACTION")) switch ($POSTACTION) {
1697          case "UPLOAD" :          case "UPLOAD" :
1698                    $FN_name=stripSlashes($HTTP_POST_FILES["FN"]["tmp_name"]);
1699                    $FN=stripSlashes($HTTP_POST_FILES["FN"]["name"]);
1700                  if (!is_writeable($fsDir)) Error("Write denied",$relDir) ;                  if (!is_writeable($fsDir)) Error("Write denied",$relDir) ;
1701                  if (strstr($FN_name,"/"))  
1702                          Error("Non-conforming filename") ;                  $source = $FN_name ;
                 // TODO : should rather check for escapeshellcmds  
                 // but maybe RFC 18xx asserts safe filenames ....  
                 $source = $FN ;  
1703                  if (! file_exists($source)) {                  if (! file_exists($source)) {
1704                          Error("You must select file with browse to upload it!");                          Error("You must select file with browse to upload it!");
1705                  }                  }
1706    
1707                    if (HTTP_POST_VAR("FILENAME")) check_filename($FILENAME);
1708    
1709                  if (! isset($FILENAME)) {       // from update file                  if (! isset($FILENAME)) {       // from update file
1710                          $target = "$fsDir/$FN_name" ;                          $target = "$fsDir/".basename($FN);
1711                  } else {                  } else {
1712                          $target = "$fsDir/$FILENAME";                          $target = "$fsDir/$FILENAME";
1713                  }                  }
1714    
1715                    if (! check_perm("$relDir/".basename($target), trperm_w))
1716                            Error("Access denied","User <tt>$gblLogin</tt> tried to upload <tt>$relDir/".basename($target)."</tt> without valid trustee.",1);
1717    
1718                  // backup old files first                  // backup old files first
1719                  $dir=dirname($target);                  $dir=dirname($target);
1720                  if (! file_exists($dir."/.bak")) {                  if (! file_exists($dir."/.bak")) {
1721                          mkdir($dir."/.bak",0700);                          mkdir($dir."/.bak",0700);
1722                  }                  }
1723                  if (! file_exists($dir."/.bak/$GLOBALS[gblNumBackups]")) {                  if (! file_exists($dir."/.bak/$gblNumBackups")) {
1724                          mkdir($dir."/.bak/$GLOBALS[gblNumBackups]",0700);                          mkdir($dir."/.bak/$gblNumBackups",0700);
1725                  }                  }
1726                  $file=basename($target);                  $file=basename($target);
1727                  for($i=$GLOBALS[gblNumBackups]-1;$i>0;$i--) {                  for($i=$gblNumBackups-1;$i>0;$i--) {
1728                          MoveTo("$dir/.bak/$i/$file","$dir/.bak/".($i+1)."/");                          MoveTo("$dir/.bak/$i/$file","$dir/.bak/".($i+1)."/");
1729                  }                  }
1730                  MoveTo($target,$dir."/.bak/1/");                  MoveTo($target,$dir."/.bak/1/");
# Line 1581  print " return: $return<br>\n"; Line 1732  print " return: $return<br>\n";
1732                  copy($source,$target) ;                  copy($source,$target) ;
1733                  chmod($target,$gblFilePerms) ;                  chmod($target,$gblFilePerms) ;
1734                  clearstatcache() ;                  clearstatcache() ;
                 Logit($target,"uploaded");  
1735                  if (isset($FILENAME)) {                  if (isset($FILENAME)) {
1736                            LogIt($target,"check-in",trperm_r | trperm_w);
1737                          Unlock($target);                          Unlock($target);
1738                    } else {
1739                            LogIt($target,"uploaded",trperm_r | trperm_w);
1740                  }                  }
                 ChangeLog($target,"updated");  
1741                  break ;                  break ;
1742    
1743          case "SAVE" :          case "SAVE" :
1744                  $path = $gblFsRoot . $RELPATH ;                  $path = $gblFsRoot . $RELPATH ;
1745                  $path=stripSlashes($path);                  $path=stripSlashes($path);
1746    
1747                    if (! check_perm("$RELPATH", trperm_w))
1748                            Error("Access denied","User <tt>$gblLogin</tt> tried to save <tt>$RELPATH</tt> without valid trustee.",1);
1749    
1750                  $writable = is_writeable($path) ;                  $writable = is_writeable($path) ;
1751                  $legaldir = is_writeable(dirname($path)) ;                  $legaldir = is_writeable(dirname($path)) ;
1752                  $exists   = (file_exists($path)) ? 1 : 0 ;                  $exists   = (file_exists($path)) ? 1 : 0 ;
1753  // check for legal extension here as well                  // FIX: more verbose error message
1754                  if (!($writable || (!$exists && $legaldir)))                  if (!($writable || (!$exists && $legaldir)))
1755                          Error("Write denied",$RELPATH) ;                          Error("Write denied",$RELPATH) ;
1756                  $fh = fopen($path, "w") ;                  $fh = fopen($path, "w") ;
1757                  $FILEDATA=stripSlashes($FILEDATA);                  HTTP_POST_VAR("FILEDATA");
1758                  fwrite($fh,$FILEDATA) ;                  fwrite($fh,$FILEDATA) ;
1759                  fclose($fh) ;                  fclose($fh) ;
1760                  clearstatcache() ;                  clearstatcache() ;
1761                  Logit($path,"saved changes");                  LogIt($path,"saved changes",trperm_r);
                 ChangeLog($path,"saved changes");  
1762                  break ;                  break ;
1763    
1764          case "CREATE" :          case "CREATE" :
1765                  // we know $fsDir exists                  // we know $fsDir exists
1766                  if ($FN == "") break;           // no filename!                  if (! check_perm($relDir, trperm_w))
1767                  if (!is_writeable($fsDir)) Error("Write denied",$relDir) ;                          Error("Write access denied","You don't have permission to write in <tt>$relDir</tt>");
1768                  $path = $fsDir . "/" . $FN ;  // file or dir to create                  if ($T == "D") $type = "directory";
1769                  $relPath = $relDir . "/" . $FN ;                  else $type ="file";
1770                    if ($FN == "") Error("Can't create $type","You must enter name of $type to create it.");
1771                    if (!is_writeable($fsDir)) Error("Write denied","User <tt>$gblLogin</tt> has trustee to write in <tt>$relDir</tt> but permissions on <tt>$fsDir</tt> are wrong!", 1) ;
1772                    $path = "$fsDir/$FN";           // file or dir to create
1773                    $relPath = "$relDir/$FN";
1774    
1775                    if (file_exists($path))
1776                            Error("Can't create $type","Object <tt>$relPath</tt> allready exists");
1777    
1778                  switch ( $T ) {                  switch ( $T ) {
1779                  case "D" :  // create a directory                  case "D" :  // create a directory
1780                          if ( ! @mkdir($path,$gblDirPerms) )                          if ( ! @mkdir($path,$gblDirPerms) )
1781                                  Error("Mkdir failed",$relPath) ; // eg. if it exists                                  Error("Mkdir failed",$relPath) ; // eg. if it exists
1782                            else
1783                                    LogIt($path."/","dir created",trperm_w);
1784                          clearstatcache() ;                          clearstatcache() ;
1785                          break ;                          break ;
1786                  case "F" :  // create a new file                  case "F" :  // create a new file
# Line 1623  print " return: $return<br>\n"; Line 1788  print " return: $return<br>\n";
1788  // better keep it here altogether  // better keep it here altogether
1789  // chmod perms to $gblFilePerms  // chmod perms to $gblFilePerms
1790                          if ( file_exists($path) && !is_writeable($path) )                          if ( file_exists($path) && !is_writeable($path) )
1791                                  Error("File not writable", $relPath) ;                                  Error("File not writable", "User <tt>$gblLogin</tt> has trustee to write in <tt>$relPath</tt> but permissions on <tt>$path</tt> are wrong!", 1) ;
1792                          $fh = fopen($path, "w+") ;                          $fh = fopen($path, "w+") ;
1793                          if ($fh) {                          if ($fh) {
1794                                  fputs($fh,"\n");                                  fputs($fh,"\n");
1795                                  fclose($fh) ;                                  fclose($fh) ;
1796                                  LogIt($path,"file created");                                  LogIt($path,"file created",trperm_r | trperm_w);
1797                          } else {                          } else {
1798                                  Error("Creation of file $relPath failed -- $path");                                  Error("Creation of file $relPath failed", "User <tt>$gblLogin</tt> has trustee to write in <tt>$relPath</tt> but creation of <tt>$path</tt> failed!", 1) ;
1799                          }                          }
1800                          $tstr = "$PHP_SELF?A=E&D=".urlencode($relDir)."&F=".urlencode($FN) ;                          $tstr = $HTTP_SERVER_VARS["PHP_SELF"]."?A=E&D=".urlencode($relDir)."&F=".urlencode($FN) ;
1801                          header("Location: " . $tstr) ;                          header("Location: " . $tstr) ;
                         ChangeLog($target,"created");  
1802                          exit ;                          exit ;
1803                  }                  }
1804                  break ;                  break ;
1805    
1806          case "DELETE" :            case "DELETE" :  
1807                  if ( $CONFIRM != "on" ) break ;                  if ( $CONFIRM != "on" ) break;
1808    
1809                  $tstr  = "Attempt to delete non-existing object or " ;                  if ( isset($FN) && $FN != "") {
1810                  $tstr .= "insufficient privileges: " ;                          $path=$fsDir."/".$FN;
1811                            $what = "file";
1812                    } elseif (isset($DIR)) {
1813                            $path=$gblFsRoot."/".$DIR;
1814                            $what = "directory";
1815                    } else  {
1816                            Error("Can't delete object","Can't find filename <tt>\$FN</tt> or dirname in <tt>\$DIR</tt>",1);
1817                    }
1818    
1819                  if ( $FN != "") {  // delete file                  if (! check_perm("$relDir/$FN", trperm_w))
1820                          $path =  $fsDir . "/" . $FN ;                          Error("Access denied","User <tt>$gblLogin</tt> tried to erase $what <tt>$relDir/$FN</tt> without valid trustee.",1);
                   
                         $dir=dirname($path);  
                         $file=basename($path);  
                         if (! file_exists("$dir/.del")) {  
                                 mkdir("$dir/.del",0700);  
                         }  
1821    
1822  //                      if ( ! @unlink($path) ) {                  $tstr  = "Attempt to delete non-existing object or insufficient privileges: " ;
1823                          if ( ! rename($path,"$dir/.del/$file") ) {  
1824                                  Error("File delete failed", $tstr . $path) ;                  $dir=dirname($path);
1825                                  Logit($path,"file delete failed");                  $file=basename($path);
1826                                  exit ;  
1827                          } else {                  if (! file_exists("$dir/.del")) {
1828                                  Logit($path,"file deleted");                          mkdir("$dir/.del",0700);
                                 MoveTo("$dir/.log/$file","$dir/.del/.log/");  
                                 MoveTo("$dir/.note/$file","$dir/.del/.note/");  
                                 MoveTo("$dir/.lock/$file","$dir/.del/.lock/");  
                         }  
1829                  }                  }
1830                  else {  // delete directory  
1831                    if ( ! @rrmdir($fsDir) ) {                  if ( ! @rename($path,"$dir/.del/$file") ) {
1832                      Error("Rmdir failed", $tstr . $fsDir) ;                          LogIt($path,"$what delete failed");
1833                    }                          Error("Can't delete $what",$tstr."<tt>".$relDir."/".$FN."</tt>") ;
1834                    else {                  } else {
1835                      $relDir = dirname($relDir) ;  // move up                          LogIt($path,"$what deleted",trperm_w);
1836                    }                          MoveTo("$dir/.log/$file","$dir/.del/.log/");
1837                            MoveTo("$dir/.note/$file","$dir/.del/.note/");
1838                            MoveTo("$dir/.lock/$file","$dir/.del/.lock/");
1839                  }                  }
1840                  break ;                  break ;
1841    
# Line 1682  print " return: $return<br>\n"; Line 1845  print " return: $return<br>\n";
1845                  if (substr($FN,0,4) != ".del") break ;                  if (substr($FN,0,4) != ".del") break ;
1846                  $file=substr($FN,4,strlen($FN)-4);                  $file=substr($FN,4,strlen($FN)-4);
1847    
1848                  Logit("$fsDir/.del/$file","undeleted");                  if (! check_perm("$relDir/$file", trperm_w))
1849                            Error("Access denied","User <tt>$gblLogin</tt> tried to undelete <tt>$relDir/$file</tt> without valid trustee.",1);
1850    
1851                    LogIt("$fsDir/.del/$file","undeleted",trperm_w);
1852                  MoveTo("$fsDir/.del/$file","$fsDir/");                  MoveTo("$fsDir/.del/$file","$fsDir/");
1853                  MoveTo("$fsDir/.del/.log/$file","$fsDir/.log/");                  MoveTo("$fsDir/.del/.log/$file","$fsDir/.log/");
1854                  MoveTo("$fsDir/.del/.note/$file","$fsDir/.note/");                  MoveTo("$fsDir/.del/.note/$file","$fsDir/.note/");
# Line 1693  print " return: $return<br>\n"; Line 1859  print " return: $return<br>\n";
1859          case "RENAME" :            case "RENAME" :  
1860                  if ( $CONFIRM != "on" ) break ;                  if ( $CONFIRM != "on" ) break ;
1861    
1862                  Logit("$fsDir/$FN","renamed $FN to $NEWNAME");                  if (HTTP_POST_VAR("NEWNAME")) {
1863                            $dest = remove_parent($relDir.$NEWNAME);
1864                            if (! check_perm($relDir.$FN, trperm_w) ||
1865                                ! check_perm($dest, trperm_w) )
1866                                    Error("Access denied","User <tt>$gblLogin</tt> tried to rename <tt>$relDir$FN</tt> to <tt>$dest</tt> without valid trustee.",1);
1867                    } else {
1868                            Error("Rename error","Can't find new name in var <tt>\$NEWNAME</tt>",1);
1869                    }
1870                    LogIt("$fsDir/$FN","renamed $FN to $NEWNAME",trperm_r);
1871                  safe_rename($fsDir,$FN,$NEWNAME);                  safe_rename($fsDir,$FN,$NEWNAME);
1872                  break ;                  break ;
1873    
1874          case "NOTE" :            case "NOTE" :
1875                  WriteNote("$fsDir/$FN","$NOTE");                  if (! HTTP_POST_VAR("NOTE"))
1876                            Error("Can't add note to object","Can't find var <tt>\$NOTE</tt>",1);
1877                    if (! check_perm("$relDir/$FN", trperm_w))
1878                            Error("Access denied","User <tt>$gblLogin</tt> tried to add note to <tt>$relDir/$FN</tt> without valid trustee.",1);
1879    
1880                    WriteNote("$fsDir/$FN",$NOTE);
1881                  break ;                  break ;
1882    
1883          case "UNLOCK" :            case "UNLOCK" :  
1884                  if ( $CONFIRM != "on" ) break ;                  if ( $CONFIRM != "on" ) break ;
1885                    if (! check_perm("$relDir/$FN", trperm_w))
1886                            Error("Access denied","User <tt>$gblLogin</tt> tried to unlock <tt>$relDir/$FN</tt> without valid trustee.",1);
1887                  Unlock("$fsDir/$FN");                  Unlock("$fsDir/$FN");
1888                  break ;                  break ;
1889    
# Line 1711  print " return: $return<br>\n"; Line 1892  print " return: $return<br>\n";
1892          }          }
1893    
1894          // common to all POSTs : redirect to directory view ($relDir)          // common to all POSTs : redirect to directory view ($relDir)
1895          if ( $POSTACTION != "" ) {          if (isset($POSTACTION)) {
1896                  $tstr = $PHP_SELF . "?D=" . urlencode($relDir) ;                  $tstr = $HTTP_SERVER_VARS["PHP_SELF"]."?D=".urlencode($relDir);
1897                  header("Location: " . $tstr) ;                    header("Location: ".$tstr) ;  
1898                  exit ;                  exit ;
1899          }          }
1900            
1901          // check for mode.. navigate, code display, upload, or detail?          // check for mode.. navigate, code display, upload, or detail?
1902          // $A=U : upload to path given in $D          // $A=U : upload to path given in $D
1903          // $A=E : display detail of file $D/$F and edit          // $A=E : display detail of file $D/$F and edit
# Line 1724  print " return: $return<br>\n"; Line 1905  print " return: $return<br>\n";
1905          // $A=Co : checkout file $D/$F          // $A=Co : checkout file $D/$F
1906          // $A=Ci : checkin file $D/$F          // $A=Ci : checkin file $D/$F
1907          // $A=V : view file (do nothing except log)          // $A=V : view file (do nothing except log)
1908          // $A=I : include file .$F.php from $gblFsRoot          // $A=I : include file .$F.php from [$gblIncDir|realm]/include_php
1909          // default : display directory $D          // default : display directory $D
1910    
1911          switch ($A) {          if (isset($A)) switch ($A) {
1912          case "U" :          case "U" :
1913                  // upload to $relDir                  // upload to $relDir
1914                    if (! check_perm($relDir, trperm_w))
1915                            Error("Write access denied","You don't have permission to write in <tt>$relDir</tt>");
1916                  if (!is_writeable($gblFsRoot . $relDir))                  if (!is_writeable($gblFsRoot . $relDir))
1917                          Error("Write access denied",$relDir) ;                          Error("Write access denied","User <tt>$gblLogin</tt> has permission on <tt>$relDir</tt>, but directory is not writable",1);
1918                  $text  = "Use this page to upload a single " ;                  $text  = "Use this page to upload a single " ;
1919                  $text .= "file to <B>$HTTP_HOST</B>." ;                  $text .= "file to <B>$realm</B>." ;
1920                  StartHTML("(Upload Page)", $text) ;                  StartHTML("(Upload Page)", $text) ;
1921                  UploadPage($gblFsRoot, $relDir) ;                  UploadPage($gblFsRoot, $relDir) ;
1922                  EndHTML() ;                  EndHTML() ;
1923                  exit ;                  exit ;
1924          case "E" :          case "E" :
                 $F=stripSlashes($F);  
1925                  // detail of $relDir/$F                  // detail of $relDir/$F
1926                  if (is_file("$gblFsRoot/$relDir/$F") || is_dir("$gblFsRoot/$relDir/$F")) DetailPage($gblFsRoot, $relDir, $F) ;                  if (is_file("$gblFsRoot/$relDir/$F") || is_dir("$gblFsRoot/$relDir/$F")) DetailPage($gblFsRoot, $relDir, $F) ;
1927                  exit ;                  exit ;
# Line 1751  print " return: $return<br>\n"; Line 1933  print " return: $return<br>\n";
1933          case "Co" :          case "Co" :
1934                  // checkout                  // checkout
1935                  Lock("$gblFsRoot/$relDir/$F");                  Lock("$gblFsRoot/$relDir/$F");
1936                  Download("$gblFsRoot/$relDir/$F");                  Download("$gblFsRoot/$relDir/$F",1);
1937                  exit;                  exit;
1938          case "Ci" :          case "Ci" :
1939                  $F=stripSlashes($F);                  $F=stripSlashes($F);
# Line 1759  print " return: $return<br>\n"; Line 1941  print " return: $return<br>\n";
1941                  if (!is_writeable($gblFsRoot . $relDir))                  if (!is_writeable($gblFsRoot . $relDir))
1942                          Error("Write access denied",$relDir) ;                          Error("Write access denied",$relDir) ;
1943                  $text  = "Use this page to update a single " ;                  $text  = "Use this page to update a single " ;
1944                  $text .= "file to <B>$HTTP_HOST</B>." ;                  $text .= "file to <B>$realm</B>." ;
1945                  StartHTML("(Update file Page)", $text) ;                  StartHTML("(Update file Page)", $text) ;
1946                  UploadPage($gblFsRoot, $relDir, $F) ;                  UploadPage($gblFsRoot, $relDir, $F) ;
1947                  EndHTML() ;                  EndHTML() ;
# Line 1767  print " return: $return<br>\n"; Line 1949  print " return: $return<br>\n";
1949          case "V" :          case "V" :
1950                  // view                  // view
1951                  LogIt("$gblFsRoot/$relDir/$F","viewed");                  LogIt("$gblFsRoot/$relDir/$F","viewed");
1952                  if ($gblForceDownload) {                  Download("$gblFsRoot/$relDir/$F",$gblForceDownload);
                         Download("$gblFsRoot/$relDir/$F");  
                 } else {  
                         header("Content-Disposition: attachment; filename=$F" );  
                         Header("Location: $webRoot".urlpath("$relDir/$F"));  
                 }  
1953                  exit;                  exit;
1954          case "Ch" :          case "Ch" :
1955                  StartHTML("(File changes)","All changes chronologicaly...");                  StartHTML("(File changes)","All changes chronologicaly...");
# Line 1785  print " return: $return<br>\n"; Line 1962  print " return: $return<br>\n";
1962                  EndHTML() ;                  EndHTML() ;
1963                  exit;                  exit;
1964          case "I" :          case "I" :
1965                  $F=stripSlashes($F);                  if (! isset($F) || $F == "")
1966                  $inc_file="${gblFsRoot}/.${F}.php";                          Error("Can't find file to include","Your request didn't specify file to include which should be in variable <tt>F</tt> like <tt>$HTTP_SERVER_VARS[REQUEST_URI]<b>&F=include_php_file</b></tt>",1);
1967                  if (!isset($F) || $F == "" || !file_exists($inc_file)) Error("Fatal error $inc_file"); // can't find file to include                  $inc_file="$fsRealmDir/$realm".$realm_sep.$F.".php";
1968                    if (! file_exists($inc_file)) {
1969                            Error("Can't find file to include","Can't find include file <tt>$F.php</tt> in <tt>$fsRealmDir/$realm/</tt>. Meybe you should copy <tt>$gblIncDir/include_php/$F.php</tt> to <tt>$inc_file<tt> ?",1);
1970                    }
1971                  if (!is_readable($inc_file))                  if (!is_readable($inc_file))
1972                          Error("Read access to include file denied",".${F}.php");                          Error("Read access to include file denied","Can't read PHP include file <tt>$inc_file</tt>. Fix permissions on it.",1);
1973                  $text  = "Your include file should define \$text variable which holds this text and \$title variable which is page title";                  $text  = "Your include file should define \$text variable which holds this text and \$title variable which is page title";
1974                  $title = "You should define \$title variable with page title";                  $title = "You should define \$title variable with page title";
1975                  include($inc_file);                  include($inc_file);
1976                  StartHTML($title, $text) ;                  StartHTML($title, $text) ;
1977                  print "<p>".GifIcon(up)." Back to <a href=$GLOBALS[PHP_SELF]>front page</a>.</p>";                  print "<p>".GifIcon(up)." Back to <a href=$HTTP_SERVER_VARS[PHP_SELF]>front page</a>.</p>";
1978                  EndHTML() ;                  EndHTML() ;
1979                  exit ;                  exit ;
1980          }          }
# Line 1803  print " return: $return<br>\n"; Line 1983  print " return: $return<br>\n";
1983          Navigate($gblFsRoot,$relDir) ;            Navigate($gblFsRoot,$relDir) ;  
1984          exit ;          exit ;
1985    
1986          Error("Whooah!","By cartesian logic, this never happens") ;          Error("Whooah!","By cartesian logic, this never happens",1) ;
1987  ?>  ?>

Legend:
Removed from v.1.1.1.1  
changed lines
  Added in v.1.32

  ViewVC Help
Powered by ViewVC 1.1.26