/[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.26 by dpavlin, Mon Jul 29 10:29:04 2002 UTC revision 1.27 by dpavlin, Mon Jul 29 12:04:43 2002 UTC
# Line 1500  $debug.="d: ".$perm['deny']." (".display Line 1500  $debug.="d: ".$perm['deny']." (".display
1500  function check_perm($path,$trperm) {  function check_perm($path,$trperm) {
1501          global $gblLogin,$HAVE_TRUSTEE;          global $gblLogin,$HAVE_TRUSTEE;
1502    
1503            $path = str_replace("//","/",$path);
1504    
1505          global $debug;          global $debug;
1506  $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";
1507    
# Line 1554  function check_filename($file) { Line 1556  function check_filename($file) {
1556          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);
1557  }  }
1558    
1559    // bla/blo/../foo will return bla/foo
1560    function remove_parent($path) {
1561            while (preg_match(",/[^/]+/\.\./,",$path)) {
1562                    $path = preg_replace(",/[^/]+/\.\./,","",$path);
1563            }
1564            if (substr($path,0,1) != "/") $path = "/".$path;
1565            return $path;
1566    }
1567    
1568  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
1569    
1570  // functions to move HTTP server variables to global namespace  // functions to move HTTP server variables to global namespace
# Line 1807  HTTP_POST_VAR("FN"); Line 1818  HTTP_POST_VAR("FN");
1818                  if ($T == "D") $type = "directory";                  if ($T == "D") $type = "directory";
1819                  else $type ="file";                  else $type ="file";
1820                  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.");
1821                  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) ;
1822                  $path = $fsDir . "/" . $FN ;  // file or dir to create                  $path = "$fsDir/$FN";           // file or dir to create
1823                  $relPath = $relDir . "/" . $FN ;                  $relPath = "$relDir/$FN";
1824    
1825                    if (file_exists($path))
1826                            Error("Can't create $type","Object <tt>$relPath</tt> allready exists");
1827    
1828                  switch ( $T ) {                  switch ( $T ) {
1829                  case "D" :  // create a directory                  case "D" :  // create a directory
1830                          if ( ! @mkdir($path,$gblDirPerms) )                          if ( ! @mkdir($path,$gblDirPerms) )
# Line 1823  HTTP_POST_VAR("FN"); Line 1838  HTTP_POST_VAR("FN");
1838  // better keep it here altogether  // better keep it here altogether
1839  // chmod perms to $gblFilePerms  // chmod perms to $gblFilePerms
1840                          if ( file_exists($path) && !is_writeable($path) )                          if ( file_exists($path) && !is_writeable($path) )
1841                                  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) ;
1842                          $fh = fopen($path, "w+") ;                          $fh = fopen($path, "w+") ;
1843                          if ($fh) {                          if ($fh) {
1844                                  fputs($fh,"\n");                                  fputs($fh,"\n");
1845                                  fclose($fh) ;                                  fclose($fh) ;
1846                                  LogIt($path,"file created",trperm_r | trperm_w);                                  LogIt($path,"file created",trperm_r | trperm_w);
1847                          } else {                          } else {
1848                                  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) ;
1849                          }                          }
1850                          $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) ;
1851                          header("Location: " . $tstr) ;                          header("Location: " . $tstr) ;
# Line 1843  HTTP_POST_VAR("FN"); Line 1858  HTTP_POST_VAR("FN");
1858    
1859                  if ( isset($FN) && $FN != "") {                  if ( isset($FN) && $FN != "") {
1860                          $path=$fsDir."/".$FN;                          $path=$fsDir."/".$FN;
   
1861                          $what = "file";                          $what = "file";
1862                          if (is_dir($path)) {                  } elseif (isset($DIR)) {
1863                                  $what = "dir";                          $path=$gblFsRoot."/".$DIR;
1864                          }                          $what = "directory";
1865                    } else  {
1866                            Error("Can't delete object","Can't find filename <tt>\$FN</tt> or dirname in <tt>\$DIR</tt>",1);
1867                    }
1868    
1869                          if (! check_perm($relDir."/".$FN, trperm_w))                  if (! check_perm("$relDir/$FN", trperm_w))
1870                                  Error("Access denied","User <tt>$gblLogin</tt> tried to erase $what <tt>$relDir/$FN</tt> without valid trustee.",1);                          Error("Access denied","User <tt>$gblLogin</tt> tried to erase $what <tt>$relDir/$FN</tt> without valid trustee.",1);
1871    
1872                          $tstr  = "Attempt to delete non-existing object or " ;                  $tstr  = "Attempt to delete non-existing object or insufficient privileges: " ;
                         $tstr .= "insufficient privileges: " ;  
1873    
1874                          $dir=dirname($path);                  $dir=dirname($path);
1875                          $file=basename($path);                  $file=basename($path);
                         if (! file_exists("$dir/.del")) {  
                                 mkdir("$dir/.del",0700);  
                         }  
1876    
1877  //                      if ( ! @unlink($path) ) {                  if (! file_exists("$dir/.del")) {
1878                          if ( ! @rename($path,"$dir/.del/$file") ) {                          mkdir("$dir/.del",0700);
1879                                  LogIt($path,"$what delete failed");                  }
1880                                  Error("Can't delete $what",$tstr.$relDir."/".$FN) ;  
1881                          } else {                  if ( ! @rename($path,"$dir/.del/$file") ) {
1882                                  LogIt($path,"$what deleted",trperm_w);                          LogIt($path,"$what delete failed");
1883                                  MoveTo("$dir/.log/$file","$dir/.del/.log/");                          Error("Can't delete $what",$tstr."<tt>".$relDir."/".$FN."</tt>") ;
                                 MoveTo("$dir/.note/$file","$dir/.del/.note/");  
                                 MoveTo("$dir/.lock/$file","$dir/.del/.lock/");  
                         }  
1884                  } else {                  } else {
1885                          Error("Rmdir failed", $tstr . $fsDir) ;                          LogIt($path,"$what deleted",trperm_w);
1886                            MoveTo("$dir/.log/$file","$dir/.del/.log/");
1887                            MoveTo("$dir/.note/$file","$dir/.del/.note/");
1888                            MoveTo("$dir/.lock/$file","$dir/.del/.lock/");
1889                  }                  }
1890                  break ;                  break ;
1891    
# Line 1893  HTTP_POST_VAR("FN"); Line 1906  HTTP_POST_VAR("FN");
1906          case "RENAME" :            case "RENAME" :  
1907                  if ( $CONFIRM != "on" ) break ;                  if ( $CONFIRM != "on" ) break ;
1908    
1909                  $NEWNAME=stripSlashes($HTTP_POST_VARS["NEWNAME"]);                  if (HTTP_POST_VAR("NEWNAME")) {
1910                            $dest = remove_parent($relDir.$NEWNAME);
1911                            if (! check_perm($relDir.$FN, trperm_w) ||
1912                                ! check_perm($dest, trperm_w) )
1913                                    Error("Access denied","User <tt>$gblLogin</tt> tried to rename <tt>$relDir$FN</tt> to <tt>$dest</tt> without valid trustee.",1);
1914                    } else {
1915                            Error("Rename error","Can't find new name in var <tt>\$NEWNAME</tt>",1);
1916                    }
1917                  LogIt("$fsDir/$FN","renamed $FN to $NEWNAME",trperm_r);                  LogIt("$fsDir/$FN","renamed $FN to $NEWNAME",trperm_r);
1918                  safe_rename($fsDir,$FN,$NEWNAME);                  safe_rename($fsDir,$FN,$NEWNAME);
1919                  break ;                  break ;

Legend:
Removed from v.1.26  
changed lines
  Added in v.1.27

  ViewVC Help
Powered by ViewVC 1.1.26