/[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.19 by dpavlin, Sun Jul 28 17:31:03 2002 UTC revision 1.32 by dpavlin, Mon Jul 29 14:17:05 2002 UTC
# Line 90  Line 90 
90          if ($fsDocumentRoot == "") Error("Configuration error","Can't get SCRIPT_FILENAME from your web server. Please set <tt>\$fsDocumentRoot</tt> in <tt>\$</tt>",1);          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 = $HTTP_SERVER_VARS["PHP_AUTH_USER"];          $gblLogin = HTTP_SERVER_VAR("PHP_AUTH_USER");
94          $gblPasswd = $HTTP_SERVER_VARS["PHP_AUTH_PW"];          $gblPasswd = HTTP_SERVER_VAR("PHP_AUTH_PW");
95    
96  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
97    
# Line 155  function EndHTML() { Line 155  function EndHTML() {
155    
156  function DetailPage($fsRoot,$relDir,$fn) {  function DetailPage($fsRoot,$relDir,$fn) {
157                    
158          global $gblEditable, $gblImages, $webRoot, $html, $HTTP_SERVER_VARS ;          global $gblEditable, $gblImages,
159                    $gblDateFmt, $gblTimeFmt,
160                    $gblPermNote,
161                    $webRoot, $html,
162                    $HTTP_SERVER_VARS ;
163          $self = $HTTP_SERVER_VARS["PHP_SELF"] ;          $self = $HTTP_SERVER_VARS["PHP_SELF"] ;
164    
165          $relPath  = $relDir . "/" . $fn ;          $relPath  = $relDir . "/" . $fn ;
# Line 185  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 204  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 ) ;
 ?>  
   
 <FORM ACTION="<?= $self ?>" METHOD="POST">  
 <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>  
212    
213  <?php                  include("$html/DetailPage-edit.html");
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    
 ?>  
224    
225  <FORM ACTION="<?= $self ; ?>" METHOD="POST">          print '<FORM ACTION="'.$self.'" METHOD="POST">
226  <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ; ?>">                  <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="'.$relDir.'">
227  <INPUT TYPE="HIDDEN" NAME="FN" VALUE="<?= $fn ; ?>">                  <INPUT TYPE="HIDDEN" NAME="FN" VALUE="'.$fn.'">
228  <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="CANCEL"><BR>                  <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="CANCEL"><BR>
229                    ';
230  <?php  
231            if ($file_lock && check_perm($relDir.$fn,trperm_w)) {
232          if ($file_lock) {                  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 261  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");
246    
247  <HR>          }
248  <a name="undelete">          
249  <SPAN TITLE="Check OK and click [<?= $action ?>] to <?= $desc ?>.">          if (check_perm($relDir.$fn,$gblPermNote)) {
250  <B>OK TO <?= $action ?> "<?= $fn ; ?>"? </B></SPAN>                  include("$html/DetailPage-note.html");
251  <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">  
   
 <?php  
         }       // exists && writable  
 ?>  
 <HR>  
 <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 477  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 566  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 578  function Navigate($fsRoot,$relDir) { Line 534  function Navigate($fsRoot,$relDir) {
534    
535          global $gblEditable, $gblIcon, $gblModDays, $webRoot, $gblHide,          global $gblEditable, $gblIcon, $gblModDays, $webRoot, $gblHide,
536                  $gblIgnoreUnknownFileType, $gblRepositoryDir,                  $gblIgnoreUnknownFileType, $gblRepositoryDir,
537                  $gblLogin,                  $gblLogin, $gblUserName, $gblDateFmt, $gblTimeFmt,
538                    $gblPermNote,
539                  $fsRealmDir, $realm, $realm_sep,                  $fsRealmDir, $realm, $realm_sep,
540                  $html, $realm_config,                  $html, $realm_config,
541                  $HTTP_GET_VARS, $HTTP_SERVER_VARS;                  $HTTP_GET_VARS, $HTTP_SERVER_VARS;
# Line 593  function Navigate($fsRoot,$relDir) { Line 550  function Navigate($fsRoot,$relDir) {
550          global $debug;          global $debug;
551          $debug .= "[$gblLogin|$relDir] before >";          $debug .= "[$gblLogin|$relDir] before >";
552    
553          if (! check_perm($relDir,(trperm_b | trperm_r)))          if (! check_perm($relDir,trperm_b))
554                  Error("Access denied","User <tt>$gblLogin</tt> tried to access <tt>$relDir</tt> without valid trustee.",1);                  Error("Access denied","User <tt>$gblLogin</tt> tried to access <tt>$relDir</tt> without valid trustee.",1);
555          $debug .= "< afeter";          $debug .= "< afeter";
556    
# Line 629  function Navigate($fsRoot,$relDir) { Line 586  function Navigate($fsRoot,$relDir) {
586          if ( HTTP_GET_VAR("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 648  function Navigate($fsRoot,$relDir) { Line 610  function Navigate($fsRoot,$relDir) {
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 (parent) bar            // updir (parent) bar  
616          if (chopsl($fsDir) != chopsl($fsRoot)) {          if (chopsl($fsDir) != chopsl($fsRoot)) {
# Line 667  function Navigate($fsRoot,$relDir) { Line 628  function Navigate($fsRoot,$relDir) {
628                  return $out;                  return $out;
629          }          }
630    
631          if (! HTTP_GET_VAR("dsort")) $dsort = "name"; // default directory sort          $dsort = HTTP_GET_VAR("dsort");
632            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 676  function Navigate($fsRoot,$relDir) { Line 638  function Navigate($fsRoot,$relDir) {
638                  "rnote" => array ("name", "note")                  "rnote" => array ("name", "note")
639                  );                  );
640    
641          if (! HTTP_GET_VAR("fsort")) $fsort = "name"; // default directory sort          $fsort = HTTP_GET_VAR("fsort");
642            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 730  function Navigate($fsRoot,$relDir) { Line 693  function Navigate($fsRoot,$relDir) {
693                          $dir = $dirList[$key];                          $dir = $dirList[$key];
694    
695                          $info_url=self_args(array("A"=>"A=E", "F"=>"F=".urlencode($dir), "D"=>$D));                          $info_url=self_args(array("A"=>"A=E", "F"=>"F=".urlencode($dir), "D"=>$D));
696                            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);                          $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 808  function Navigate($fsRoot,$relDir) { Line 784  function Navigate($fsRoot,$relDir) {
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&D=".urlencode($relDir)."&F=".urlencode($file);                                  $b.="<A HREF=\"$self?A=Ci&D=".urlencode($relDir)."&F=".urlencode($file);
801                                  $b.="\" TITLE=\"Checkin (update) file on server\">" ;                                  $b.="\" TITLE=\"Checkin (update) file on server\">" ;
802                                  $file_url_html=$b;                                  $file_url_html=$b;
# Line 831  function Navigate($fsRoot,$relDir) { Line 811  function Navigate($fsRoot,$relDir) {
811                                  $file_url_html = "$file $a";                                  $file_url_html = "$file $a";
812                          }                          }
813                  } else {                  } else {
814                          $b.="<A HREF=\"$self?A=Co&D=".urlencode($relDir)."&F=".urlencode($file);                          if (check_perm($relDir.$file,trperm_w)) {
815                          $b.="\" TITLE=\"Checkout file for edit\">" ;                                  $b.="<A HREF=\"$self?A=Co&D=".urlencode($relDir)."&F=".urlencode($file);
816                          $b.=$gblIcon("checkout")."</A>";                                  $b.="\" TITLE=\"Checkout file for edit\">" ;
817                                    $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&D=".urlencode($relDir)."&F=".urlencode($file);                                  $b.="<A HREF=\"$self?A=C&D=".urlencode($relDir)."&F=".urlencode($file);
# Line 844  function Navigate($fsRoot,$relDir) { Line 826  function Navigate($fsRoot,$relDir) {
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
 ?>  
   
 <TR><TD></TD><TD COLSPAN=5><HR></TD></TR>  
841    
842  <?          include("$html/Navigate-hr.html");      
843    
844  if (file_exists("$fsRealmDir/$realm".$realm_sep."info.inc")) {          if (file_exists("$fsRealmDir/$realm".$realm_sep."info.inc")) {
845          print "<TR><TD></TD><TD COLSPAN=5>";                  print "<TR><TD></TD><TD COLSPAN=5>";
846          include("$fsRealmDir/$realm".$realm_sep."info.inc");                  include("$fsRealmDir/$realm".$realm_sep."info.inc");
847          print "</TD></TR><TR><TD></TD><TD COLSPAN=5><HR></TD></TR>";                  print "</TD></TR>";
848  } elseif (file_exists("$gblRepositoryDir/.info.inc")) {                  include("$html/Navigate-hr.html");      
849          print "<TR><TD></TD><TD COLSPAN=5>";          } elseif (file_exists("$gblRepositoryDir/.info.inc")) {
850          include("$gblRepositoryDir/.info.inc");                  print "<TR><TD></TD><TD COLSPAN=5>";
851          print "</TD></TR><TR><TD></TD><TD COLSPAN=5><HR></TD></TR>";                  include("$gblRepositoryDir/.info.inc");
852  }                  print "</TD></TR>";
853                    include("$html/Navigate-hr.html");      
854            }
855    
856            include("$html/Navigate-createNew.html");
857    
858  ?>          print "</TABLE>";
   
 <FORM METHOD="POST" ACTION="<?= $self ?>">  
 <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 956  function Error($title,$text="",$sysadmin Line 908  function Error($title,$text="",$sysadmin
908    
909  function LogIt($target,$msg, $changelog=0) {  function LogIt($target,$msg, $changelog=0) {
910    
911            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>",1);                  if (! @mkdir($dir."/.log",0700)) Error("docman installation problem","can't create log directory <tt>$dir/.log</tt>",1);
# Line 963  function LogIt($target,$msg, $changelog= Line 917  function LogIt($target,$msg, $changelog=
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);          fclose($log);
923    
924          if (! $changelog) return;          if (! $changelog) return;
925    
         global $gblFsRoot;  
926          $log=fopen("$gblFsRoot/.changelog","a+");          $log=fopen("$gblFsRoot/.changelog","a+");
927          if (substr($target,0,strlen($gblFsRoot)) == $gblFsRoot)          if (substr($target,0,strlen($gblFsRoot)) == $gblFsRoot)
928                  $target=substr($target,strlen($gblFsRoot),strlen($target)-strlen($gblFsRoot));                  $target=substr($target,strlen($gblFsRoot),strlen($target)-strlen($gblFsRoot));
929          $msg=str_replace("\t"," ",$msg);          $msg=str_replace("\t"," ",$msg);
930          fputs($log,time()."\t$target\t$GLOBALS[gblUserName]\t$msg\n");          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          // FIX: implement e-mail notification based on $changelog
# Line 994  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    
# Line 1034  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 1045  function Lock($target) { Line 1003  function Lock($target) {
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");
# Line 1094  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))) {
# Line 1123  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 1151  function rrmdir($dir) { Line 1112  function rrmdir($dir) {
1112    
1113  function DisplayChangeLog($day) {  function DisplayChangeLog($day) {
1114    
1115          global $gblFsRoot,$HTTP_SERVER_VARS;          global $gblFsRoot, $gblDateFmt, $gblTimeFmt,
1116                    $HTTP_SERVER_VARS;
1117    
1118            $self  = $HTTP_SERVER_VARS["PHP_SELF"];
1119    
1120          if (!file_exists("$gblFsRoot/.changelog")) return;          if (!file_exists("$gblFsRoot/.changelog")) return;
1121          $log=fopen("$gblFsRoot/.changelog","r");          $log=fopen("$gblFsRoot/.changelog","r");
# Line 1170  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=\"$HTTP_SERVER_VARS[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=$HTTP_SERVER_VARS[PHP_SELF]>front page</a>.</p>";          print "<p>".GifIcon("up")." Back to <a href=\"$self\">front page</a>.</p>";
1145  }  }
1146    
1147  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
# Line 1199  function Download($path,$force=0) { Line 1163  function Download($path,$force=0) {
1163    
1164          $ext_arr = explode(".",$file);          $ext_arr = explode(".",$file);
1165          $ext = array_pop($ext_arr);          $ext = array_pop($ext_arr);
1166          if ($encoding_ext[$ext]) {          if (isset($encoding_ext[$ext])) {
1167                  $encoding = $encoding_ext[$ext];                  $encoding = $encoding_ext[$ext];
1168                  $ext = array_pop($ext_arr);                  $ext = array_pop($ext_arr);
1169          }          }
# Line 1211  function Download($path,$force=0) { Line 1175  function Download($path,$force=0) {
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_SERVER_VARS[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");
# Line 1393  function in_group($user,$group) { Line 1357  function in_group($user,$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    
1362          // check user FIX          if ($t & trmask_one_level && !$one_level) return $perm;
         if ($t & trmask_not && ($u==$user)) continue;  
         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) {
# Line 1414  function unroll_perm($u,$t,$user,$perm) Line 1376  function unroll_perm($u,$t,$user,$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          if (! isset($trustees)) Error("Trustees not found","Can't find in-memory trustee structure \$trustees. Probably bug in code. Contact <tt>dpavlin@rot13.org</tt>",1);          // 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;  global $debug;
1389  $debug .= "<br>check_trustee $path ... ";  $debug .= "<br>check_trustee $path ... ";
# Line 1429  $debug .= "<br>check_trustee $path ... " Line 1394  $debug .= "<br>check_trustee $path ... "
1394                  $tmppath.=array_shift($path_arr);                  $tmppath.=array_shift($path_arr);
1395  $debug.= ">> $tmppath ";  $debug.= ">> $tmppath ";
1396    
                 # clear one level flag  
                 $perm['allow'] &= ~trmask_one_level;  
                 $perm['deny'] &= ~trmask_one_level;  
   
1397                  if (! isset($trustees[$tmppath])) continue;                  if (! isset($trustees[$tmppath])) continue;
1398                  $tr = $trustees[$tmppath];                  $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 $g=>$t) {                          foreach ($tr as $g=>$t) {
1411                                  if ($t & trmask_group && in_group($user,$g)) {                                  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                                          $perm = unroll_perm($user,$t,$user, $perm);                                          $perm = unroll_perm($user,$t,$perm, $one_level);
1420                                          unset($tr[$g]);                                          unset($tr[$g]);
1421                                  }                                  }
1422                          }                          }
1423                          // then apply user 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                  }                  }
# Line 1470  $debug.="d: ".$perm['deny']." (".display Line 1439  $debug.="d: ".$perm['deny']." (".display
1439  function check_perm($path,$trperm) {  function check_perm($path,$trperm) {
1440          global $gblLogin,$HAVE_TRUSTEE;          global $gblLogin,$HAVE_TRUSTEE;
1441    
1442            $path = str_replace("//","/",$path);
1443    
1444          global $debug;          global $debug;
1445  $debug.="<br>check_perm: on <tt>$path</tt> for perm ".display_trustee($trperm)."<br>\n";  $debug.="<br>check_perm: on <tt>$path</tt> for perm ".display_trustee($trperm)."<br>\n";
1446    
# Line 1519  function check_dirname($file) { Line 1490  function check_dirname($file) {
1490    
1491  function check_filename($file) {  function check_filename($file) {
1492          if (strstr($file,"..")) Error("Security violation","No parent dir <tt>..</tt> allowed in file name <tt>$file</tt>",1);          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);          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  // functions to move HTTP server variables to global namespace
1510  // [replacement for register_globals in php.ini]  // [replacement for register_globals in php.ini]
1511    
1512  function HTTP_GET_VAR($var) {  function HTTP_GET_VAR($var) {
1513          global $HTTP_GET_VARS, $GLOBALS;          global $HTTP_GET_VARS, ${$var};
1514          if (isset($HTTP_GET_VARS[$var])) {          if (isset($HTTP_GET_VARS[$var])) {
1515                  $GLOBALS[$var] = stripSlashes($HTTP_GET_VARS[$var]);                  $$var = stripSlashes($HTTP_GET_VARS[$var]);
1516                  return $GLOBALS[$var];                  return $$var;
1517          }          }
1518  }  }
1519    
1520  function HTTP_POST_VAR($var) {  function HTTP_POST_VAR($var) {
1521          global $HTTP_GET_VARS, $GLOBALS;          global $HTTP_POST_VARS, ${$var};
1522          if (isset($HTTP_GET_VARS[$var])) {          if (isset($HTTP_POST_VARS[$var])) {
1523                  $GLOBALS[$var] = stripSlashes($HTTP_GET_VARS[$var]);                  $$var = $HTTP_POST_VARS[$var];
1524                  return $GLOBALS[$var];                  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    
# Line 1562  function Warn($text) { Line 1552  function Warn($text) {
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 1650  function Warn($text) { Line 1640  function Warn($text) {
1640          // read mime.types          // read mime.types
1641          readMime();          readMime();
1642    
1643            if (! isset($gblPermNote)) {
1644                    $gblPermNote = trperm_r;
1645            }
1646    
1647            HTTP_POST_VAR("FN");
1648    
1649          if ($HTTP_SERVER_VARS["REQUEST_METHOD"] == "POST") {          if ($HTTP_SERVER_VARS["REQUEST_METHOD"] == "POST") {
1650                  // take variables from server                  // take variables from server
1651                  if (HTTP_POST_VAR("FN")) check_filename($FN);                  if (HTTP_POST_VAR("FN"))
1652                            check_filename($FN);
1653                  if (HTTP_POST_VAR("DIR")) {                  if (HTTP_POST_VAR("DIR")) {
1654                          check_dirname($DIR);                          check_dirname($DIR);
1655                          $relDir = $DIR;                          $relDir = $DIR;
1656                  } else {                  } else {
1657                          trigger_error("Can't get DIR",E_USER_WARNING);                          trigger_error("Can't get DIR",E_USER_WARNING);
1658                            $relDir = "/";
1659                  }                  }
1660                  if (HTTP_POST_VAR("RELPATH")) check_dirname($RELPATH);                  if (HTTP_POST_VAR("RELPATH")) check_dirname($RELPATH);
1661                  HTTP_POST_VAR("T");                  HTTP_POST_VAR("T");
1662                  HTTP_POST_VAR("CONFIRM");                  HTTP_POST_VAR("CONFIRM");
   
1663          } else {          } else {
1664                  // get                  // get
1665                  HTTP_GET_VAR("A");                  HTTP_GET_VAR("A");
# Line 1707  function Warn($text) { Line 1704  function Warn($text) {
1704                          Error("You must select file with browse to upload it!");                          Error("You must select file with browse to upload it!");
1705                  }                  }
1706    
1707                  $FILENAME = $HTTP_POST_VARS["FILENAME"];                  if (HTTP_POST_VAR("FILENAME")) check_filename($FILENAME);
                 check_filename($FILENAME);  
1708    
1709                  if (! isset($FILENAME)) {       // from update file                  if (! isset($FILENAME)) {       // from update file
1710                          $target = "$fsDir/".basename($FN);                          $target = "$fsDir/".basename($FN);
# Line 1716  function Warn($text) { Line 1712  function Warn($text) {
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 1744  function Warn($text) { Line 1743  function Warn($text) {
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() ;
# Line 1760  function Warn($text) { Line 1763  function Warn($text) {
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) )
# Line 1777  function Warn($text) { Line 1788  function Warn($text) {
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",trperm_r | trperm_w);                                  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) ;
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                                  LogIt($path,"file delete failed");                  $dir=dirname($path);
1825                                  Error("File delete failed", $tstr . $path) ;                  $file=basename($path);
1826                          } else {  
1827                                  LogIt($path,"file deleted",trperm_w);                  if (! file_exists("$dir/.del")) {
1828                                  MoveTo("$dir/.log/$file","$dir/.del/.log/");                          mkdir("$dir/.del",0700);
1829                                  MoveTo("$dir/.note/$file","$dir/.del/.note/");                  }
1830                                  MoveTo("$dir/.lock/$file","$dir/.del/.lock/");  
1831                          }                  if ( ! @rename($path,"$dir/.del/$file") ) {
1832                  } else {  // delete directory                          LogIt($path,"$what delete failed");
1833                          if ( ! @rrmdir($fsDir) ) {                          Error("Can't delete $what",$tstr."<tt>".$relDir."/".$FN."</tt>") ;
1834                                  Error("Rmdir failed", $tstr . $fsDir) ;                  } else {
1835                          } else {                          LogIt($path,"$what deleted",trperm_w);
1836                                  LogIt($path,"dir deleted",trperm_w);                          MoveTo("$dir/.log/$file","$dir/.del/.log/");
1837                                  $relDir = dirname($relDir) ;  // move up                          MoveTo("$dir/.note/$file","$dir/.del/.note/");
1838                          }                          MoveTo("$dir/.lock/$file","$dir/.del/.lock/");
1839                  }                  }
1840                  break ;                  break ;
1841    
# Line 1833  function Warn($text) { Line 1845  function Warn($text) {
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                    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);                  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/");
# Line 1844  function Warn($text) { Line 1859  function Warn($text) {
1859          case "RENAME" :            case "RENAME" :  
1860                  if ( $CONFIRM != "on" ) break ;                  if ( $CONFIRM != "on" ) break ;
1861    
1862                  $NEWNAME=stripSlashes($HTTP_POST_VARS["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);                  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                  $NOTE=stripSlashes($HTTP_POST_VARS["NOTE"]);                  if (! HTTP_POST_VAR("NOTE"))
1876                  WriteNote("$fsDir/$FN","$NOTE");                          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 1865  function Warn($text) { Line 1893  function Warn($text) {
1893    
1894          // common to all POSTs : redirect to directory view ($relDir)          // common to all POSTs : redirect to directory view ($relDir)
1895          if (isset($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

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

  ViewVC Help
Powered by ViewVC 1.1.26