/[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.29 by dpavlin, Mon Jul 29 12:34:18 2002 UTC
# Line 188  function DetailPage($fsRoot,$relDir,$fn) Line 188  function DetailPage($fsRoot,$relDir,$fn)
188          $title = "("._("Detail Page").")" ;          $title = "("._("Detail Page").")" ;
189          StartHTML($title, $text) ;          StartHTML($title, $text) ;
190    
191          echo "<H3>" . $relDir . "/" . $fn . "</H3>" ;          print "<H3>".$relDir.$fn."</H3>";
192    
193          if ($exists) {  // get file info          if ($exists) {  // get file info
194                  $fsize = filesize($fsPath) ;                  $fsize = filesize($fsPath) ;
195                  $fmodified = date("$gblDateFmt $gblTimeFmt", filemtime($fsPath)) ;                  $fmodified = date("$gblDateFmt $gblTimeFmt", filemtime($fsPath)) ;
# Line 229  echo($fstr) ; ?></TEXTAREA> Line 230  echo($fstr) ; ?></TEXTAREA>
230          }          }
231          if ( !$file_lock && $ext!="" && strstr(join(' ',$gblImages),$ext) ) {            if ( !$file_lock && $ext!="" && strstr(join(' ',$gblImages),$ext) ) {  
232                  $info  = getimagesize($fsPath) ;                  $info  = getimagesize($fsPath) ;
233                  $tstr = "<IMG SRC=\"$webRoot".urlpath($relPath)."\" BORDER=0 " ;                  $tstr = "<IMG SRC=\"$self?A=V&D=".urlpath(dirname($relPath))."&F=".urlpath(basename($relPath))."\" BORDER=0 " ;
234                  $tstr .= $info[3] . " ALT=\"" . $fn . " - " ;                  $tstr .= $info[3] . " ALT=\"" . $fn . " - " ;
235                  $tstr .= (int)(($fsize+1023)/1024) . "Kb\">" ;                  $tstr .= (int)(($fsize+1023)/1024) . "Kb\">" ;
236  //              echo htmlentities($tstr) . "<BR><BR>" . $tstr ;  //              echo htmlentities($tstr) . "<BR><BR>" . $tstr ;
# Line 480  function MockIcon($txt) { Line 481  function MockIcon($txt) {
481    
482  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
483    
484  function GifIcon($txt) {  function GifIcon($txt = "") {
485          global $gblIconLocation ;          global $gblIconLocation, $gblImages ;
486    
487          switch (strtolower($txt)) {          switch (strtolower($txt)) {
         case ".bmp" :  
         case ".gif" :  
         case ".jpg" :  
         case ".jpeg":  
         case ".tif" :  
         case ".tiff":  
                 $d = "image2.gif" ;  
                 break ;  
488          case ".doc" :          case ".doc" :
489                  $d = "layout.gif" ;                  $d = "layout.gif" ;
490                  break ;                  break ;
# Line 569  function GifIcon($txt) { Line 562  function GifIcon($txt) {
562                  $d = "quill.gif";                  $d = "quill.gif";
563                  break;                  break;
564          default :          default :
565                  $d = "generic.gif" ;                  if (in_array(strtolower($txt),$gblImages)) {
566                            $d = "image2.gif" ;
567                    } else {
568                            $d = "generic.gif" ;
569                    }
570          }          }
571    
572    
573          return "<IMG SRC=\"$gblIconLocation" . $d . "\" BORDER=0>" ;          return "<IMG SRC=\"$gblIconLocation" . $d . "\" BORDER=0>" ;
574  } // end function GifIcon  } // end function GifIcon
575    
# Line 632  function Navigate($fsRoot,$relDir) { Line 630  function Navigate($fsRoot,$relDir) {
630          if ( HTTP_GET_VAR("show_deleted") == 1 && ($dir = @opendir("$fsDir/.del")) ) {          if ( HTTP_GET_VAR("show_deleted") == 1 && ($dir = @opendir("$fsDir/.del")) ) {
631                  while ($item = readdir($dir)) {                  while ($item = readdir($dir)) {
632                          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 ;
633                          $fileList[$item] = ".del/$item" ;                                        if (is_file($fsDir.".del/$item")) {
634                          $fileDate[$item] = filemtime($fsDir.".del/$path") ;                                  $fileList[$item] = ".del/$item" ;              
635                          $fileSize[$item] = filesize($fsDir.".del/$path") ;                                  $fileDate[$item] = filemtime($fsDir.".del/$item") ;
636                          $fileNote[$item] = ReadNote($fsDir.".del/$item");                                  $fileSize[$item] = filesize($fsDir.".del/$item") ;
637                                    $fileNote[$item] = ReadNote($fsDir.".del/$item");
638                            } else {
639                                    $dirList[$item] = ".del/$item" ;                
640                                    $dirNote[$item] = ReadNote($fsDir.".del/$item");
641                            }
642                  }                  }
643                  closedir($dir) ;                  closedir($dir) ;
644          }          }
# Line 733  function Navigate($fsRoot,$relDir) { Line 736  function Navigate($fsRoot,$relDir) {
736                          $dir = $dirList[$key];                          $dir = $dirList[$key];
737    
738                          $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));
739                            if (substr($dir,0,5) == ".del/") {
740                                    $dir = substr($dir,5,strlen($dir)-5);
741                                    $deleted = " <a href=\"$info_url#undelete\"><SPAN CLASS=deleted TITLE=\"deleted\">deleted</span></a>";
742                            } else {
743                                    $deleted = "";
744                            }
745            
746                          $dir_url=$self."?D=".urlencode(chopsl($relDir)."/".$dir);                          $dir_url=$self."?D=".urlencode(chopsl($relDir)."/".$dir);
747                          include("$html/Navigate-dirEntry.html");                          include("$html/Navigate-dirEntry.html");
748    
# Line 811  function Navigate($fsRoot,$relDir) { Line 821  function Navigate($fsRoot,$relDir) {
821                  if (substr($file,0,5) != ".del/") {                  if (substr($file,0,5) != ".del/") {
822                          $file_url_html .= $file . "</A>" . $a ;                          $file_url_html .= $file . "</A>" . $a ;
823                  } else {                  } else {
824                          $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>";
825                  }                  }
826    
827                  $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 1211  function Download($path,$force=0) { Line 1221  function Download($path,$force=0) {
1221    
1222          $ext_arr = explode(".",$file);          $ext_arr = explode(".",$file);
1223          $ext = array_pop($ext_arr);          $ext = array_pop($ext_arr);
1224          if ($encoding_ext[$ext]) {          if (isset($encoding_ext[$ext])) {
1225                  $encoding = $encoding_ext[$ext];                  $encoding = $encoding_ext[$ext];
1226                  $ext = array_pop($ext_arr);                  $ext = array_pop($ext_arr);
1227          }          }
# Line 1223  function Download($path,$force=0) { Line 1233  function Download($path,$force=0) {
1233          }          }
1234    
1235          // IE5.5 just downloads index.php if we don't do this          // IE5.5 just downloads index.php if we don't do this
1236          if(preg_match("/MSIE 5.5/", $HTTP_SERVER_VARS[HTTP_USER_AGENT])) {          if(preg_match("/MSIE 5.5/", $HTTP_SERVER_VARS["HTTP_USER_AGENT"])) {
1237                  header("Content-Disposition: filename=$file");                  header("Content-Disposition: filename=$file");
1238          } else {          } else {
1239                  header("Content-Disposition: attachment; filename=$file");                  header("Content-Disposition: attachment; filename=$file");
# Line 1424  function unroll_perm($u,$t,$perm,$one_le Line 1434  function unroll_perm($u,$t,$perm,$one_le
1434  }// end of helper function  }// end of helper function
1435    
1436  function check_trustee($user,$path) {  function check_trustee($user,$path) {
1437          global $trustees;          global $trustees,$HAVE_TRUSTEE;
1438          $perm['allow'] = 0;          $perm['allow'] = 0;
1439          $perm['deny'] = 0;          $perm['deny'] = 0;
1440    
1441          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?
1442            if (! $HAVE_TRUSTEE) return $perm;
1443    
1444            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);
1445    
1446  global $debug;  global $debug;
1447  $debug .= "<br>check_trustee $path ... ";  $debug .= "<br>check_trustee $path ... ";
# Line 1447  $debug.=" O($one_level) "; Line 1460  $debug.=" O($one_level) ";
1460    
1461                  if (isset($tr)) {                  if (isset($tr)) {
1462                          // first apply trustee for all                          // first apply trustee for all
1463                          if (isset($tr['*'])) {                          if (isset($tr['*']) && $user!="anonymous") {
1464                                  $perm = unroll_perm($user,$tr['*'],$perm, $one_level);                                  $perm = unroll_perm($user,$tr['*'],$perm, $one_level);
1465                                  unset($tr['*']);                                  unset($tr['*']);
1466                          }                          }
# Line 1484  $debug.="d: ".$perm['deny']." (".display Line 1497  $debug.="d: ".$perm['deny']." (".display
1497  function check_perm($path,$trperm) {  function check_perm($path,$trperm) {
1498          global $gblLogin,$HAVE_TRUSTEE;          global $gblLogin,$HAVE_TRUSTEE;
1499    
1500            $path = str_replace("//","/",$path);
1501    
1502          global $debug;          global $debug;
1503  $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";
1504    
# Line 1533  function check_dirname($file) { Line 1548  function check_dirname($file) {
1548    
1549  function check_filename($file) {  function check_filename($file) {
1550          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);
1551            // remove deleted directory (for undelete to work)
1552            $file = str_replace(".del/","",$file);
1553          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);
1554  }  }
1555    
1556    // bla/blo/../foo will return bla/foo
1557    function remove_parent($path) {
1558            while (preg_match(",/[^/]+/\.\./,",$path)) {
1559                    $path = preg_replace(",/[^/]+/\.\./,","",$path);
1560            }
1561            if (substr($path,0,1) != "/") $path = "/".$path;
1562            return $path;
1563    }
1564    
1565  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
1566    
1567  // functions to move HTTP server variables to global namespace  // functions to move HTTP server variables to global namespace
# Line 1584  function Warn($text) { Line 1610  function Warn($text) {
1610          // location of master docman configuration file          // location of master docman configuration file
1611          $docman_conf = "/etc/docman.conf";          $docman_conf = "/etc/docman.conf";
1612          if (! file_exists($docman_conf)) {          if (! file_exists($docman_conf)) {
1613                  $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";
1614                                    
1615                  error_log("docman: $error");                  error_log("docman: $error");
1616                  Error("docman not installed completly",$error);                  Error("docman not installed completly",$error);
# Line 1740  HTTP_POST_VAR("FN"); Line 1766  HTTP_POST_VAR("FN");
1766                          $target = "$fsDir/$FILENAME";                          $target = "$fsDir/$FILENAME";
1767                  }                  }
1768    
1769                    if (! check_perm("$relDir/".basename($target), trperm_w))
1770                            Error("Access denied","User <tt>$gblLogin</tt> tried to upload <tt>$relDir/".basename($target)."</tt> without valid trustee.",1);
1771    
1772                  // backup old files first                  // backup old files first
1773                  $dir=dirname($target);                  $dir=dirname($target);
1774                  if (! file_exists($dir."/.bak")) {                  if (! file_exists($dir."/.bak")) {
# Line 1768  HTTP_POST_VAR("FN"); Line 1797  HTTP_POST_VAR("FN");
1797          case "SAVE" :          case "SAVE" :
1798                  $path = $gblFsRoot . $RELPATH ;                  $path = $gblFsRoot . $RELPATH ;
1799                  $path=stripSlashes($path);                  $path=stripSlashes($path);
1800    
1801                    if (! check_perm("$RELPATH", trperm_w))
1802                            Error("Access denied","User <tt>$gblLogin</tt> tried to save <tt>$RELPATH</tt> without valid trustee.",1);
1803    
1804                  $writable = is_writeable($path) ;                  $writable = is_writeable($path) ;
1805                  $legaldir = is_writeable(dirname($path)) ;                  $legaldir = is_writeable(dirname($path)) ;
1806                  $exists   = (file_exists($path)) ? 1 : 0 ;                  $exists   = (file_exists($path)) ? 1 : 0 ;
1807  // check for legal extension here as well                  // FIX: more verbose error message
1808                  if (!($writable || (!$exists && $legaldir)))                  if (!($writable || (!$exists && $legaldir)))
1809                          Error("Write denied",$RELPATH) ;                          Error("Write denied",$RELPATH) ;
1810                  $fh = fopen($path, "w") ;                  $fh = fopen($path, "w") ;
# Line 1789  HTTP_POST_VAR("FN"); Line 1822  HTTP_POST_VAR("FN");
1822                  if ($T == "D") $type = "directory";                  if ($T == "D") $type = "directory";
1823                  else $type ="file";                  else $type ="file";
1824                  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.");
1825                  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) ;
1826                  $path = $fsDir . "/" . $FN ;  // file or dir to create                  $path = "$fsDir/$FN";           // file or dir to create
1827                  $relPath = $relDir . "/" . $FN ;                  $relPath = "$relDir/$FN";
1828    
1829                    if (file_exists($path))
1830                            Error("Can't create $type","Object <tt>$relPath</tt> allready exists");
1831    
1832                  switch ( $T ) {                  switch ( $T ) {
1833                  case "D" :  // create a directory                  case "D" :  // create a directory
1834                          if ( ! @mkdir($path,$gblDirPerms) )                          if ( ! @mkdir($path,$gblDirPerms) )
# Line 1805  HTTP_POST_VAR("FN"); Line 1842  HTTP_POST_VAR("FN");
1842  // better keep it here altogether  // better keep it here altogether
1843  // chmod perms to $gblFilePerms  // chmod perms to $gblFilePerms
1844                          if ( file_exists($path) && !is_writeable($path) )                          if ( file_exists($path) && !is_writeable($path) )
1845                                  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) ;
1846                          $fh = fopen($path, "w+") ;                          $fh = fopen($path, "w+") ;
1847                          if ($fh) {                          if ($fh) {
1848                                  fputs($fh,"\n");                                  fputs($fh,"\n");
1849                                  fclose($fh) ;                                  fclose($fh) ;
1850                                  LogIt($path,"file created",trperm_r | trperm_w);                                  LogIt($path,"file created",trperm_r | trperm_w);
1851                          } else {                          } else {
1852                                  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) ;
1853                          }                          }
1854                          $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) ;
1855                          header("Location: " . $tstr) ;                          header("Location: " . $tstr) ;
# Line 1821  HTTP_POST_VAR("FN"); Line 1858  HTTP_POST_VAR("FN");
1858                  break ;                  break ;
1859    
1860          case "DELETE" :            case "DELETE" :  
1861                  if ( $CONFIRM != "on" ) break ;                  if ( $CONFIRM != "on" ) break;
1862    
1863                  $tstr  = "Attempt to delete non-existing object or " ;                  if ( isset($FN) && $FN != "") {
1864                  $tstr .= "insufficient privileges: " ;                          $path=$fsDir."/".$FN;
1865                            $what = "file";
1866                    } elseif (isset($DIR)) {
1867                            $path=$gblFsRoot."/".$DIR;
1868                            $what = "directory";
1869                    } else  {
1870                            Error("Can't delete object","Can't find filename <tt>\$FN</tt> or dirname in <tt>\$DIR</tt>",1);
1871                    }
1872    
1873                  if ( $FN != "") {  // delete file                  if (! check_perm("$relDir/$FN", trperm_w))
1874                          $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);  
                         }  
1875    
1876  //                      if ( ! @unlink($path) ) {                  $tstr  = "Attempt to delete non-existing object or insufficient privileges: " ;
1877                          if ( ! rename($path,"$dir/.del/$file") ) {  
1878                                  LogIt($path,"file delete failed");                  $dir=dirname($path);
1879                                  Error("File delete failed", $tstr . $path) ;                  $file=basename($path);
1880                          } else {  
1881                                  LogIt($path,"file deleted",trperm_w);                  if (! file_exists("$dir/.del")) {
1882                                  MoveTo("$dir/.log/$file","$dir/.del/.log/");                          mkdir("$dir/.del",0700);
1883                                  MoveTo("$dir/.note/$file","$dir/.del/.note/");                  }
1884                                  MoveTo("$dir/.lock/$file","$dir/.del/.lock/");  
1885                          }                  if ( ! @rename($path,"$dir/.del/$file") ) {
1886                  } else {  // delete directory                          LogIt($path,"$what delete failed");
1887                          if ( ! @rrmdir($fsDir) ) {                          Error("Can't delete $what",$tstr."<tt>".$relDir."/".$FN."</tt>") ;
1888                                  Error("Rmdir failed", $tstr . $fsDir) ;                  } else {
1889                          } else {                          LogIt($path,"$what deleted",trperm_w);
1890                                  LogIt($path,"dir deleted",trperm_w);                          MoveTo("$dir/.log/$file","$dir/.del/.log/");
1891                                  $relDir = dirname($relDir) ;  // move up                          MoveTo("$dir/.note/$file","$dir/.del/.note/");
1892                          }                          MoveTo("$dir/.lock/$file","$dir/.del/.lock/");
1893                  }                  }
1894                  break ;                  break ;
1895    
# Line 1861  HTTP_POST_VAR("FN"); Line 1899  HTTP_POST_VAR("FN");
1899                  if (substr($FN,0,4) != ".del") break ;                  if (substr($FN,0,4) != ".del") break ;
1900                  $file=substr($FN,4,strlen($FN)-4);                  $file=substr($FN,4,strlen($FN)-4);
1901    
1902                    if (! check_perm("$relDir/$file", trperm_w))
1903                            Error("Access denied","User <tt>$gblLogin</tt> tried to undelete <tt>$relDir/$file</tt> without valid trustee.",1);
1904    
1905                  LogIt("$fsDir/.del/$file","undeleted",trperm_w);                  LogIt("$fsDir/.del/$file","undeleted",trperm_w);
1906                  MoveTo("$fsDir/.del/$file","$fsDir/");                  MoveTo("$fsDir/.del/$file","$fsDir/");
1907                  MoveTo("$fsDir/.del/.log/$file","$fsDir/.log/");                  MoveTo("$fsDir/.del/.log/$file","$fsDir/.log/");
# Line 1872  HTTP_POST_VAR("FN"); Line 1913  HTTP_POST_VAR("FN");
1913          case "RENAME" :            case "RENAME" :  
1914                  if ( $CONFIRM != "on" ) break ;                  if ( $CONFIRM != "on" ) break ;
1915    
1916                  $NEWNAME=stripSlashes($HTTP_POST_VARS["NEWNAME"]);                  if (HTTP_POST_VAR("NEWNAME")) {
1917                            $dest = remove_parent($relDir.$NEWNAME);
1918                            if (! check_perm($relDir.$FN, trperm_w) ||
1919                                ! check_perm($dest, trperm_w) )
1920                                    Error("Access denied","User <tt>$gblLogin</tt> tried to rename <tt>$relDir$FN</tt> to <tt>$dest</tt> without valid trustee.",1);
1921                    } else {
1922                            Error("Rename error","Can't find new name in var <tt>\$NEWNAME</tt>",1);
1923                    }
1924                  LogIt("$fsDir/$FN","renamed $FN to $NEWNAME",trperm_r);                  LogIt("$fsDir/$FN","renamed $FN to $NEWNAME",trperm_r);
1925                  safe_rename($fsDir,$FN,$NEWNAME);                  safe_rename($fsDir,$FN,$NEWNAME);
1926                  break ;                  break ;

Legend:
Removed from v.1.23  
changed lines
  Added in v.1.29

  ViewVC Help
Powered by ViewVC 1.1.26