/[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.23 by dpavlin, Sun Jul 28 19:52:11 2002 UTC revision 1.31 by dpavlin, Mon Jul 29 13:53:56 2002 UTC
# Line 157  function DetailPage($fsRoot,$relDir,$fn) Line 157  function DetailPage($fsRoot,$relDir,$fn)
157                    
158          global $gblEditable, $gblImages,          global $gblEditable, $gblImages,
159                  $gblDateFmt, $gblTimeFmt,                  $gblDateFmt, $gblTimeFmt,
160                    $gblPermNote,
161                  $webRoot, $html,                  $webRoot, $html,
162                  $HTTP_SERVER_VARS ;                  $HTTP_SERVER_VARS ;
163          $self = $HTTP_SERVER_VARS["PHP_SELF"] ;          $self = $HTTP_SERVER_VARS["PHP_SELF"] ;
# Line 188  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("$gblDateFmt $gblTimeFmt", filemtime($fsPath)) ;                  $fmodified = date("$gblDateFmt $gblTimeFmt", filemtime($fsPath)) ;
# Line 207  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 264  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          } elseif (check_perm($relDir.$fn,$gblPermNote)) {
248          }       // exists && writable                          include("$html/DetailPage-note.html");
249  ?>          }
 <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>  
250    
251  <?php          print "</FORM>";
252    
253          $name=basename("$fsDir/$fn");          $name=basename("$fsDir/$fn");
254          $logname=dirname("$fsDir/$fn")."/.log/$name";          $logname=dirname("$fsDir/$fn")."/.log/$name";
# Line 480  function MockIcon($txt) { Line 434  function MockIcon($txt) {
434    
435  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
436    
437  function GifIcon($txt) {  function GifIcon($txt = "") {
438          global $gblIconLocation ;          global $gblIconLocation, $gblImages ;
439    
440          switch (strtolower($txt)) {          switch (strtolower($txt)) {
         case ".bmp" :  
         case ".gif" :  
         case ".jpg" :  
         case ".jpeg":  
         case ".tif" :  
         case ".tiff":  
                 $d = "image2.gif" ;  
                 break ;  
441          case ".doc" :          case ".doc" :
442                  $d = "layout.gif" ;                  $d = "layout.gif" ;
443                  break ;                  break ;
# Line 569  function GifIcon($txt) { Line 515  function GifIcon($txt) {
515                  $d = "quill.gif";                  $d = "quill.gif";
516                  break;                  break;
517          default :          default :
518                  $d = "generic.gif" ;                  if (in_array(strtolower($txt),$gblImages)) {
519                            $d = "image2.gif" ;
520                    } else {
521                            $d = "generic.gif" ;
522                    }
523          }          }
524    
525    
526          return "<IMG SRC=\"$gblIconLocation" . $d . "\" BORDER=0>" ;          return "<IMG SRC=\"$gblIconLocation" . $d . "\" BORDER=0>" ;
527  } // end function GifIcon  } // end function GifIcon
528    
# Line 632  function Navigate($fsRoot,$relDir) { Line 583  function Navigate($fsRoot,$relDir) {
583          if ( HTTP_GET_VAR("show_deleted") == 1 && ($dir = @opendir("$fsDir/.del")) ) {          if ( HTTP_GET_VAR("show_deleted") == 1 && ($dir = @opendir("$fsDir/.del")) ) {
584                  while ($item = readdir($dir)) {                  while ($item = readdir($dir)) {
585                          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 ;
586                          $fileList[$item] = ".del/$item" ;                                        if (is_file($fsDir.".del/$item")) {
587                          $fileDate[$item] = filemtime($fsDir.".del/$path") ;                                  $fileList[$item] = ".del/$item" ;              
588                          $fileSize[$item] = filesize($fsDir.".del/$path") ;                                  $fileDate[$item] = filemtime($fsDir.".del/$item") ;
589                          $fileNote[$item] = ReadNote($fsDir.".del/$item");                                  $fileSize[$item] = filesize($fsDir.".del/$item") ;
590                                    $fileNote[$item] = ReadNote($fsDir.".del/$item");
591                            } else {
592                                    $dirList[$item] = ".del/$item" ;                
593                                    $dirNote[$item] = ReadNote($fsDir.".del/$item");
594                            }
595                  }                  }
596                  closedir($dir) ;                  closedir($dir) ;
597          }          }
# Line 733  function Navigate($fsRoot,$relDir) { Line 689  function Navigate($fsRoot,$relDir) {
689                          $dir = $dirList[$key];                          $dir = $dirList[$key];
690    
691                          $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));
692                            if (substr($dir,0,5) == ".del/") {
693                                    $dir = substr($dir,5,strlen($dir)-5);
694                                    $deleted = " <a href=\"$info_url#undelete\"><SPAN CLASS=deleted TITLE=\"deleted\">deleted</span></a>";
695                            } else {
696                                    $deleted = "";
697                            }
698            
699                          $dir_url=$self."?D=".urlencode(chopsl($relDir)."/".$dir);                          $dir_url=$self."?D=".urlencode(chopsl($relDir)."/".$dir);
700                          include("$html/Navigate-dirEntry.html");                          include("$html/Navigate-dirEntry.html");
701    
# Line 811  function Navigate($fsRoot,$relDir) { Line 774  function Navigate($fsRoot,$relDir) {
774                  if (substr($file,0,5) != ".del/") {                  if (substr($file,0,5) != ".del/") {
775                          $file_url_html .= $file . "</A>" . $a ;                          $file_url_html .= $file . "</A>" . $a ;
776                  } else {                  } else {
777                          $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>";
778                  }                  }
779    
780                  $note_html="<a href=\"$info_url#note\">".$gblIcon("note")."</a>".ReadNote($path);                  $note_html="<a href=\"$info_url#note\">".$gblIcon("note")."</a>".ReadNote($path);
# Line 834  function Navigate($fsRoot,$relDir) { Line 797  function Navigate($fsRoot,$relDir) {
797                                  $file_url_html = "$file $a";                                  $file_url_html = "$file $a";
798                          }                          }
799                  } else {                  } else {
800                          $b.="<A HREF=\"$self?A=Co&D=".urlencode($relDir)."&F=".urlencode($file);                          if (check_perm($relDir.$file,trperm_w)) {
801                          $b.="\" TITLE=\"Checkout file for edit\">" ;                                  $b.="<A HREF=\"$self?A=Co&D=".urlencode($relDir)."&F=".urlencode($file);
802                          $b.=$gblIcon("checkout")."</A>";                                  $b.="\" TITLE=\"Checkout file for edit\">" ;
803                                    $b.=$gblIcon("checkout")."</A>";
804                            }
805    
806                          if ( $ext=="" || strstr(join(" ",$gblEditable),$ext) ) {                            if ( $ext=="" || strstr(join(" ",$gblEditable),$ext) ) {  
807                                  $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 998  function WriteNote($target,$msg) { Line 963  function WriteNote($target,$msg) {
963          $file=basename($target);          $file=basename($target);
964    
965          $note=fopen("$dir/.note/$file","w");          $note=fopen("$dir/.note/$file","w");
966            if (! $note) {
967                    Error("Error writing note","Can't open note file <tt>$dir/.note/$file</tt> for writing",1);
968            }
969          fputs($note,"$msg\n");          fputs($note,"$msg\n");
970          fclose($note);          fclose($note);
971    
# Line 1211  function Download($path,$force=0) { Line 1179  function Download($path,$force=0) {
1179    
1180          $ext_arr = explode(".",$file);          $ext_arr = explode(".",$file);
1181          $ext = array_pop($ext_arr);          $ext = array_pop($ext_arr);
1182          if ($encoding_ext[$ext]) {          if (isset($encoding_ext[$ext])) {
1183                  $encoding = $encoding_ext[$ext];                  $encoding = $encoding_ext[$ext];
1184                  $ext = array_pop($ext_arr);                  $ext = array_pop($ext_arr);
1185          }          }
# Line 1223  function Download($path,$force=0) { Line 1191  function Download($path,$force=0) {
1191          }          }
1192    
1193          // IE5.5 just downloads index.php if we don't do this          // IE5.5 just downloads index.php if we don't do this
1194          if(preg_match("/MSIE 5.5/", $HTTP_SERVER_VARS[HTTP_USER_AGENT])) {          if(preg_match("/MSIE 5.5/", $HTTP_SERVER_VARS["HTTP_USER_AGENT"])) {
1195                  header("Content-Disposition: filename=$file");                  header("Content-Disposition: filename=$file");
1196          } else {          } else {
1197                  header("Content-Disposition: attachment; filename=$file");                  header("Content-Disposition: attachment; filename=$file");
# Line 1424  function unroll_perm($u,$t,$perm,$one_le Line 1392  function unroll_perm($u,$t,$perm,$one_le
1392  }// end of helper function  }// end of helper function
1393    
1394  function check_trustee($user,$path) {  function check_trustee($user,$path) {
1395          global $trustees;          global $trustees,$HAVE_TRUSTEE;
1396          $perm['allow'] = 0;          $perm['allow'] = 0;
1397          $perm['deny'] = 0;          $perm['deny'] = 0;
1398    
1399          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?
1400            if (! $HAVE_TRUSTEE) return $perm;
1401    
1402            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);
1403    
1404  global $debug;  global $debug;
1405  $debug .= "<br>check_trustee $path ... ";  $debug .= "<br>check_trustee $path ... ";
# Line 1447  $debug.=" O($one_level) "; Line 1418  $debug.=" O($one_level) ";
1418    
1419                  if (isset($tr)) {                  if (isset($tr)) {
1420                          // first apply trustee for all                          // first apply trustee for all
1421                          if (isset($tr['*'])) {                          if (isset($tr['*']) && $user!="anonymous") {
1422                                  $perm = unroll_perm($user,$tr['*'],$perm, $one_level);                                  $perm = unroll_perm($user,$tr['*'],$perm, $one_level);
1423                                  unset($tr['*']);                                  unset($tr['*']);
1424                          }                          }
# Line 1484  $debug.="d: ".$perm['deny']." (".display Line 1455  $debug.="d: ".$perm['deny']." (".display
1455  function check_perm($path,$trperm) {  function check_perm($path,$trperm) {
1456          global $gblLogin,$HAVE_TRUSTEE;          global $gblLogin,$HAVE_TRUSTEE;
1457    
1458            $path = str_replace("//","/",$path);
1459    
1460          global $debug;          global $debug;
1461  $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";
1462    
# Line 1533  function check_dirname($file) { Line 1506  function check_dirname($file) {
1506    
1507  function check_filename($file) {  function check_filename($file) {
1508          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);
1509            // remove deleted directory (for undelete to work)
1510            $file = str_replace(".del/","",$file);
1511          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);
1512  }  }
1513    
1514    // bla/blo/../foo will return bla/foo
1515    function remove_parent($path) {
1516            while (preg_match(",/[^/]+/\.\./,",$path)) {
1517                    $path = preg_replace(",/[^/]+/\.\./,","",$path);
1518            }
1519            if (substr($path,0,1) != "/") $path = "/".$path;
1520            return $path;
1521    }
1522    
1523  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
1524    
1525  // functions to move HTTP server variables to global namespace  // functions to move HTTP server variables to global namespace
# Line 1584  function Warn($text) { Line 1568  function Warn($text) {
1568          // location of master docman configuration file          // location of master docman configuration file
1569          $docman_conf = "/etc/docman.conf";          $docman_conf = "/etc/docman.conf";
1570          if (! file_exists($docman_conf)) {          if (! file_exists($docman_conf)) {
1571                  $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";
1572                                    
1573                  error_log("docman: $error");                  error_log("docman: $error");
1574                  Error("docman not installed completly",$error);                  Error("docman not installed completly",$error);
# Line 1672  function Warn($text) { Line 1656  function Warn($text) {
1656          // read mime.types          // read mime.types
1657          readMime();          readMime();
1658    
1659  HTTP_POST_VAR("FN");          if (! isset($gblPermNote)) {
1660                    $gblPermNote = trperm_r;
1661            }
1662    
1663            HTTP_POST_VAR("FN");
1664    
1665          if ($HTTP_SERVER_VARS["REQUEST_METHOD"] == "POST") {          if ($HTTP_SERVER_VARS["REQUEST_METHOD"] == "POST") {
1666                  // take variables from server                  // take variables from server
# Line 1740  HTTP_POST_VAR("FN"); Line 1728  HTTP_POST_VAR("FN");
1728                          $target = "$fsDir/$FILENAME";                          $target = "$fsDir/$FILENAME";
1729                  }                  }
1730    
1731                    if (! check_perm("$relDir/".basename($target), trperm_w))
1732                            Error("Access denied","User <tt>$gblLogin</tt> tried to upload <tt>$relDir/".basename($target)."</tt> without valid trustee.",1);
1733    
1734                  // backup old files first                  // backup old files first
1735                  $dir=dirname($target);                  $dir=dirname($target);
1736                  if (! file_exists($dir."/.bak")) {                  if (! file_exists($dir."/.bak")) {
# Line 1768  HTTP_POST_VAR("FN"); Line 1759  HTTP_POST_VAR("FN");
1759          case "SAVE" :          case "SAVE" :
1760                  $path = $gblFsRoot . $RELPATH ;                  $path = $gblFsRoot . $RELPATH ;
1761                  $path=stripSlashes($path);                  $path=stripSlashes($path);
1762    
1763                    if (! check_perm("$RELPATH", trperm_w))
1764                            Error("Access denied","User <tt>$gblLogin</tt> tried to save <tt>$RELPATH</tt> without valid trustee.",1);
1765    
1766                  $writable = is_writeable($path) ;                  $writable = is_writeable($path) ;
1767                  $legaldir = is_writeable(dirname($path)) ;                  $legaldir = is_writeable(dirname($path)) ;
1768                  $exists   = (file_exists($path)) ? 1 : 0 ;                  $exists   = (file_exists($path)) ? 1 : 0 ;
1769  // check for legal extension here as well                  // FIX: more verbose error message
1770                  if (!($writable || (!$exists && $legaldir)))                  if (!($writable || (!$exists && $legaldir)))
1771                          Error("Write denied",$RELPATH) ;                          Error("Write denied",$RELPATH) ;
1772                  $fh = fopen($path, "w") ;                  $fh = fopen($path, "w") ;
# Line 1789  HTTP_POST_VAR("FN"); Line 1784  HTTP_POST_VAR("FN");
1784                  if ($T == "D") $type = "directory";                  if ($T == "D") $type = "directory";
1785                  else $type ="file";                  else $type ="file";
1786                  if ($FN == "") Error("Can't create $type","You must enter name of $type to create it.");                  if ($FN == "") Error("Can't create $type","You must enter name of $type to create it.");
1787                  if (!is_writeable($fsDir)) Error("Write denied",$relDir) ;                  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) ;
1788                  $path = $fsDir . "/" . $FN ;  // file or dir to create                  $path = "$fsDir/$FN";           // file or dir to create
1789                  $relPath = $relDir . "/" . $FN ;                  $relPath = "$relDir/$FN";
1790    
1791                    if (file_exists($path))
1792                            Error("Can't create $type","Object <tt>$relPath</tt> allready exists");
1793    
1794                  switch ( $T ) {                  switch ( $T ) {
1795                  case "D" :  // create a directory                  case "D" :  // create a directory
1796                          if ( ! @mkdir($path,$gblDirPerms) )                          if ( ! @mkdir($path,$gblDirPerms) )
# Line 1805  HTTP_POST_VAR("FN"); Line 1804  HTTP_POST_VAR("FN");
1804  // better keep it here altogether  // better keep it here altogether
1805  // chmod perms to $gblFilePerms  // chmod perms to $gblFilePerms
1806                          if ( file_exists($path) && !is_writeable($path) )                          if ( file_exists($path) && !is_writeable($path) )
1807                                  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) ;
1808                          $fh = fopen($path, "w+") ;                          $fh = fopen($path, "w+") ;
1809                          if ($fh) {                          if ($fh) {
1810                                  fputs($fh,"\n");                                  fputs($fh,"\n");
1811                                  fclose($fh) ;                                  fclose($fh) ;
1812                                  LogIt($path,"file created",trperm_r | trperm_w);                                  LogIt($path,"file created",trperm_r | trperm_w);
1813                          } else {                          } else {
1814                                  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) ;
1815                          }                          }
1816                          $tstr = $HTTP_SERVER_VARS["PHP_SELF"]."?A=E&D=".urlencode($relDir)."&F=".urlencode($FN) ;                          $tstr = $HTTP_SERVER_VARS["PHP_SELF"]."?A=E&D=".urlencode($relDir)."&F=".urlencode($FN) ;
1817                          header("Location: " . $tstr) ;                          header("Location: " . $tstr) ;
# Line 1821  HTTP_POST_VAR("FN"); Line 1820  HTTP_POST_VAR("FN");
1820                  break ;                  break ;
1821    
1822          case "DELETE" :            case "DELETE" :  
1823                  if ( $CONFIRM != "on" ) break ;                  if ( $CONFIRM != "on" ) break;
1824    
1825                    if ( isset($FN) && $FN != "") {
1826                            $path=$fsDir."/".$FN;
1827                            $what = "file";
1828                    } elseif (isset($DIR)) {
1829                            $path=$gblFsRoot."/".$DIR;
1830                            $what = "directory";
1831                    } else  {
1832                            Error("Can't delete object","Can't find filename <tt>\$FN</tt> or dirname in <tt>\$DIR</tt>",1);
1833                    }
1834    
1835                  $tstr  = "Attempt to delete non-existing object or " ;                  if (! check_perm("$relDir/$FN", trperm_w))
1836                  $tstr .= "insufficient privileges: " ;                          Error("Access denied","User <tt>$gblLogin</tt> tried to erase $what <tt>$relDir/$FN</tt> without valid trustee.",1);
1837    
1838                  if ( $FN != "") {  // delete file                  $tstr  = "Attempt to delete non-existing object or insufficient privileges: " ;
                         $path =  $fsDir . "/" . $FN ;  
                   
                         $dir=dirname($path);  
                         $file=basename($path);  
                         if (! file_exists("$dir/.del")) {  
                                 mkdir("$dir/.del",0700);  
                         }  
1839    
1840  //                      if ( ! @unlink($path) ) {                  $dir=dirname($path);
1841                          if ( ! rename($path,"$dir/.del/$file") ) {                  $file=basename($path);
1842                                  LogIt($path,"file delete failed");  
1843                                  Error("File delete failed", $tstr . $path) ;                  if (! file_exists("$dir/.del")) {
1844                          } else {                          mkdir("$dir/.del",0700);
1845                                  LogIt($path,"file deleted",trperm_w);                  }
1846                                  MoveTo("$dir/.log/$file","$dir/.del/.log/");  
1847                                  MoveTo("$dir/.note/$file","$dir/.del/.note/");                  if ( ! @rename($path,"$dir/.del/$file") ) {
1848                                  MoveTo("$dir/.lock/$file","$dir/.del/.lock/");                          LogIt($path,"$what delete failed");
1849                          }                          Error("Can't delete $what",$tstr."<tt>".$relDir."/".$FN."</tt>") ;
1850                  } else {  // delete directory                  } else {
1851                          if ( ! @rrmdir($fsDir) ) {                          LogIt($path,"$what deleted",trperm_w);
1852                                  Error("Rmdir failed", $tstr . $fsDir) ;                          MoveTo("$dir/.log/$file","$dir/.del/.log/");
1853                          } else {                          MoveTo("$dir/.note/$file","$dir/.del/.note/");
1854                                  LogIt($path,"dir deleted",trperm_w);                          MoveTo("$dir/.lock/$file","$dir/.del/.lock/");
                                 $relDir = dirname($relDir) ;  // move up  
                         }  
1855                  }                  }
1856                  break ;                  break ;
1857    
# Line 1861  HTTP_POST_VAR("FN"); Line 1861  HTTP_POST_VAR("FN");
1861                  if (substr($FN,0,4) != ".del") break ;                  if (substr($FN,0,4) != ".del") break ;
1862                  $file=substr($FN,4,strlen($FN)-4);                  $file=substr($FN,4,strlen($FN)-4);
1863    
1864                    if (! check_perm("$relDir/$file", trperm_w))
1865                            Error("Access denied","User <tt>$gblLogin</tt> tried to undelete <tt>$relDir/$file</tt> without valid trustee.",1);
1866    
1867                  LogIt("$fsDir/.del/$file","undeleted",trperm_w);                  LogIt("$fsDir/.del/$file","undeleted",trperm_w);
1868                  MoveTo("$fsDir/.del/$file","$fsDir/");                  MoveTo("$fsDir/.del/$file","$fsDir/");
1869                  MoveTo("$fsDir/.del/.log/$file","$fsDir/.log/");                  MoveTo("$fsDir/.del/.log/$file","$fsDir/.log/");
# Line 1872  HTTP_POST_VAR("FN"); Line 1875  HTTP_POST_VAR("FN");
1875          case "RENAME" :            case "RENAME" :  
1876                  if ( $CONFIRM != "on" ) break ;                  if ( $CONFIRM != "on" ) break ;
1877    
1878                  $NEWNAME=stripSlashes($HTTP_POST_VARS["NEWNAME"]);                  if (HTTP_POST_VAR("NEWNAME")) {
1879                            $dest = remove_parent($relDir.$NEWNAME);
1880                            if (! check_perm($relDir.$FN, trperm_w) ||
1881                                ! check_perm($dest, trperm_w) )
1882                                    Error("Access denied","User <tt>$gblLogin</tt> tried to rename <tt>$relDir$FN</tt> to <tt>$dest</tt> without valid trustee.",1);
1883                    } else {
1884                            Error("Rename error","Can't find new name in var <tt>\$NEWNAME</tt>",1);
1885                    }
1886                  LogIt("$fsDir/$FN","renamed $FN to $NEWNAME",trperm_r);                  LogIt("$fsDir/$FN","renamed $FN to $NEWNAME",trperm_r);
1887                  safe_rename($fsDir,$FN,$NEWNAME);                  safe_rename($fsDir,$FN,$NEWNAME);
1888                  break ;                  break ;
1889    
1890          case "NOTE" :            case "NOTE" :
1891                  $NOTE=stripSlashes($HTTP_POST_VARS["NOTE"]);                  if (! HTTP_POST_VAR("NOTE"))
1892                  WriteNote("$fsDir/$FN","$NOTE");                          Error("Can't add note to object","Can't find var <tt>\$NOTE</tt>",1);
1893                    if (! check_perm("$relDir/$FN", trperm_w))
1894                            Error("Access denied","User <tt>$gblLogin</tt> tried to add note to <tt>$relDir/$FN</tt> without valid trustee.",1);
1895    
1896                    WriteNote("$fsDir/$FN",$NOTE);
1897                  break ;                  break ;
1898    
1899          case "UNLOCK" :            case "UNLOCK" :  
1900                  if ( $CONFIRM != "on" ) break ;                  if ( $CONFIRM != "on" ) break ;
1901                    if (! check_perm("$relDir/$FN", trperm_w))
1902                            Error("Access denied","User <tt>$gblLogin</tt> tried to unlock <tt>$relDir/$FN</tt> without valid trustee.",1);
1903                  Unlock("$fsDir/$FN");                  Unlock("$fsDir/$FN");
1904                  break ;                  break ;
1905    
# Line 1897  HTTP_POST_VAR("FN"); Line 1913  HTTP_POST_VAR("FN");
1913                  header("Location: ".$tstr) ;                    header("Location: ".$tstr) ;  
1914                  exit ;                  exit ;
1915          }          }
1916            
1917          // check for mode.. navigate, code display, upload, or detail?          // check for mode.. navigate, code display, upload, or detail?
1918          // $A=U : upload to path given in $D          // $A=U : upload to path given in $D
1919          // $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.23  
changed lines
  Added in v.1.31

  ViewVC Help
Powered by ViewVC 1.1.26