/[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.29 by dpavlin, Mon Jul 29 12:34:18 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                    $webRoot, $html,
161                    $HTTP_SERVER_VARS ;
162          $self = $HTTP_SERVER_VARS["PHP_SELF"] ;          $self = $HTTP_SERVER_VARS["PHP_SELF"] ;
163    
164          $relPath  = $relDir . "/" . $fn ;          $relPath  = $relDir . "/" . $fn ;
# Line 185  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("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]", filemtime($fsPath)) ;                  $fmodified = date("$gblDateFmt $gblTimeFmt", filemtime($fsPath)) ;
196                  $faccessed = date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]", fileatime($fsPath)) ;                  $faccessed = date("$gblDateFmt $gblTimeFmt", fileatime($fsPath)) ;
197                  $fuid=fileowner($fsPath);                  $fuid=fileowner($fsPath);
198                  $fgid=filegroup($fsPath);                  $fgid=filegroup($fsPath);
199                  $userinfo = posix_getpwuid($fuid);                  $userinfo = posix_getpwuid($fuid);
# Line 226  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 477  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 566  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 578  function Navigate($fsRoot,$relDir) { Line 579  function Navigate($fsRoot,$relDir) {
579    
580          global $gblEditable, $gblIcon, $gblModDays, $webRoot, $gblHide,          global $gblEditable, $gblIcon, $gblModDays, $webRoot, $gblHide,
581                  $gblIgnoreUnknownFileType, $gblRepositoryDir,                  $gblIgnoreUnknownFileType, $gblRepositoryDir,
582                  $gblLogin,                  $gblLogin, $gblUserName, $gblDateFmt, $gblTimeFmt,
583                  $fsRealmDir, $realm, $realm_sep,                  $fsRealmDir, $realm, $realm_sep,
584                  $html, $realm_config,                  $html, $realm_config,
585                  $HTTP_GET_VARS, $HTTP_SERVER_VARS;                  $HTTP_GET_VARS, $HTTP_SERVER_VARS;
# Line 593  function Navigate($fsRoot,$relDir) { Line 594  function Navigate($fsRoot,$relDir) {
594          global $debug;          global $debug;
595          $debug .= "[$gblLogin|$relDir] before >";          $debug .= "[$gblLogin|$relDir] before >";
596    
597          if (! check_perm($relDir,(trperm_b | trperm_r)))          if (! check_perm($relDir,trperm_b))
598                  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);
599          $debug .= "< afeter";          $debug .= "< afeter";
600    
# Line 629  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 730  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 808  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 816  function Navigate($fsRoot,$relDir) { Line 829  function Navigate($fsRoot,$relDir) {
829                  $ext = strtolower(strrchr($file,".")) ;                  $ext = strtolower(strrchr($file,".")) ;
830    
831                  if ($file_lock) {                  if ($file_lock) {
832                          if ($file_lock == $GLOBALS[gblUserName]) {                          if ($file_lock == $gblUserName) {
833                                  $b.="<A HREF=\"$self?A=Ci&D=".urlencode($relDir)."&F=".urlencode($file);                                  $b.="<A HREF=\"$self?A=Ci&D=".urlencode($relDir)."&F=".urlencode($file);
834                                  $b.="\" TITLE=\"Checkin (update) file on server\">" ;                                  $b.="\" TITLE=\"Checkin (update) file on server\">" ;
835                                  $file_url_html=$b;                                  $file_url_html=$b;
# Line 844  function Navigate($fsRoot,$relDir) { Line 857  function Navigate($fsRoot,$relDir) {
857                          }                          }
858                  }                  }
859    
860                  $mod = date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]",$mod);                  $mod = date("$gblDateFmt $gblTimeFmt",$mod);
861    
862                  include("$html/Navigate-fileEntry.html");                  include("$html/Navigate-fileEntry.html");
863    
# Line 956  function Error($title,$text="",$sysadmin Line 969  function Error($title,$text="",$sysadmin
969    
970  function LogIt($target,$msg, $changelog=0) {  function LogIt($target,$msg, $changelog=0) {
971    
972            global $gblDateFmt, $gblTimeFmt, $gblUserName, $gblFsRoot;
973    
974          $dir=dirname($target);          $dir=dirname($target);
975          if (! file_exists($dir."/.log")) {          if (! file_exists($dir."/.log")) {
976                  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 978  function LogIt($target,$msg, $changelog=
978          $file=basename($target);          $file=basename($target);
979    
980          $log=fopen("$dir/.log/$file","a+");          $log=fopen("$dir/.log/$file","a+");
981          fputs($log,date("$GLOBALS[gblDateFmt]\t$GLOBALS[gblTimeFmt]").          fputs($log,date("$gblDateFmt\t$gblTimeFmt").
982                  "\t$GLOBALS[gblUserName]\t$msg\n");                  "\t$gblUserName\t$msg\n");
983          fclose($log);          fclose($log);
984    
985          if (! $changelog) return;          if (! $changelog) return;
986    
         global $gblFsRoot;  
987          $log=fopen("$gblFsRoot/.changelog","a+");          $log=fopen("$gblFsRoot/.changelog","a+");
988          if (substr($target,0,strlen($gblFsRoot)) == $gblFsRoot)          if (substr($target,0,strlen($gblFsRoot)) == $gblFsRoot)
989                  $target=substr($target,strlen($gblFsRoot),strlen($target)-strlen($gblFsRoot));                  $target=substr($target,strlen($gblFsRoot),strlen($target)-strlen($gblFsRoot));
990          $msg=str_replace("\t"," ",$msg);          $msg=str_replace("\t"," ",$msg);
991          fputs($log,time()."\t$target\t$GLOBALS[gblUserName]\t$msg\n");          fputs($log,time()."\t$target\t$gblUserName\t$msg\n");
992          fclose($log);          fclose($log);
993    
994          // FIX: implement e-mail notification based on $changelog          // FIX: implement e-mail notification based on $changelog
# Line 1034  function MoveTo($source,$folder) { Line 1048  function MoveTo($source,$folder) {
1048    
1049  function Lock($target) {  function Lock($target) {
1050    
1051            global $gblUserName;
1052    
1053          $target=stripSlashes($target);          $target=stripSlashes($target);
1054          $dir=dirname($target);          $dir=dirname($target);
1055          if (! file_exists($dir."/.lock")) {          if (! file_exists($dir."/.lock")) {
# Line 1045  function Lock($target) { Line 1061  function Lock($target) {
1061                  LogIt($target,"attempt to locked allready locked file!");                  LogIt($target,"attempt to locked allready locked file!");
1062          } else {          } else {
1063                  $lock=fopen("$dir/.lock/$file","w");                  $lock=fopen("$dir/.lock/$file","w");
1064                  fputs($lock,"$GLOBALS[gblUserName]\n");                  fputs($lock,"$gblUserName\n");
1065                  fclose($lock);                  fclose($lock);
1066    
1067                  LogIt($target,"file locked");                  LogIt($target,"file locked");
# Line 1094  function urlpath($url) { Line 1110  function urlpath($url) {
1110  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
1111    
1112  function safe_rename($fromdir,$fromfile,$tofile) {  function safe_rename($fromdir,$fromfile,$tofile) {
1113    
1114            global $gblNumBackups;
1115    
1116          function try_rename($from,$to) {          function try_rename($from,$to) {
1117  #               print "$from -> $to\n";  #               print "$from -> $to\n";
1118                  if (file_exists($from) && is_writeable(dirname($to))) {                  if (file_exists($from) && is_writeable(dirname($to))) {
# Line 1123  function safe_rename($fromdir,$fromfile, Line 1142  function safe_rename($fromdir,$fromfile,
1142          try_dir("$todir/.lock");          try_dir("$todir/.lock");
1143          try_rename("$fromdir/.lock/$fromfile","$todir/.lock/$tofile");          try_rename("$fromdir/.lock/$fromfile","$todir/.lock/$tofile");
1144          try_dir("$todir/.bak");          try_dir("$todir/.bak");
1145          for($i=0;$i<=$GLOBALS[gblNumBackups];$i++) {          for($i=0;$i<=$gblNumBackups;$i++) {
1146                  try_rename("$fromdir/.bak/$i/$fromfile","$todir/.bak/$i/$tofile");                  try_rename("$fromdir/.bak/$i/$fromfile","$todir/.bak/$i/$tofile");
1147          }          }
1148  }  }
# Line 1151  function rrmdir($dir) { Line 1170  function rrmdir($dir) {
1170    
1171  function DisplayChangeLog($day) {  function DisplayChangeLog($day) {
1172    
1173          global $gblFsRoot,$HTTP_SERVER_VARS;          global $gblFsRoot, $gblDateFmt, $gblTimeFmt,
1174                    $HTTP_SERVER_VARS;
1175    
1176            $self  = $HTTP_SERVER_VARS["PHP_SELF"];
1177    
1178          if (!file_exists("$gblFsRoot/.changelog")) return;          if (!file_exists("$gblFsRoot/.changelog")) return;
1179          $log=fopen("$gblFsRoot/.changelog","r");          $log=fopen("$gblFsRoot/.changelog","r");
# Line 1170  function DisplayChangeLog($day) { Line 1192  function DisplayChangeLog($day) {
1192          print "<table border=0 width=100%>\n";          print "<table border=0 width=100%>\n";
1193          while ($e = array_shift($logarr)) {          while ($e = array_shift($logarr)) {
1194                  $cl=$cl1; $cl1=$cl2; $cl2=$cl;                  $cl=$cl1; $cl1=$cl2; $cl2=$cl;
1195                  $date = date("$GLOBALS[gblDateFmt]", $e[0]);                  $date = date($gblDateFmt, $e[0]);
1196                  $time = date("$GLOBALS[gblTimeFmt]", $e[0]);                  $time = date($gblTimeFmt, $e[0]);
1197                  $dir = dirname($e[1]);                  $dir = dirname($e[1]);
1198                  $file = basename($e[1]);                  $file = basename($e[1]);
1199                  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";
1200          }          }
1201          print "</table>";          print "</table>";
1202          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>";
1203  }  }
1204    
1205  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
# Line 1199  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 1211  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 1393  function in_group($user,$group) { Line 1415  function in_group($user,$group) {
1415  }  }
1416    
1417  // helper function  // helper function
1418  function unroll_perm($u,$t,$user,$perm) {  function unroll_perm($u,$t,$perm,$one_level) {
1419    
1420          // 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;  
1421    
1422          if ($t & trmask_deny) {          if ($t & trmask_deny) {
1423                  if ($t & trmask_clear) {                  if ($t & trmask_clear) {
# Line 1414  function unroll_perm($u,$t,$user,$perm) Line 1434  function unroll_perm($u,$t,$user,$perm)
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 1429  $debug .= "<br>check_trustee $path ... " Line 1452  $debug .= "<br>check_trustee $path ... "
1452                  $tmppath.=array_shift($path_arr);                  $tmppath.=array_shift($path_arr);
1453  $debug.= ">> $tmppath ";  $debug.= ">> $tmppath ";
1454    
                 # clear one level flag  
                 $perm['allow'] &= ~trmask_one_level;  
                 $perm['deny'] &= ~trmask_one_level;  
   
1455                  if (! isset($trustees[$tmppath])) continue;                  if (! isset($trustees[$tmppath])) continue;
1456                  $tr = $trustees[$tmppath];                  $tr = $trustees[$tmppath];
1457    
1458                    $one_level = (!count($path_arr));
1459    $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['*'],$user, $perm);                                  $perm = unroll_perm($user,$tr['*'],$perm, $one_level);
1465                                  unset($tr['*']);                                  unset($tr['*']);
1466                          }                          }
1467                          // then apply group policies                          // then apply not and group policies
1468                          foreach ($tr as $g=>$t) {                          foreach ($tr as $g=>$t) {
1469                                  if ($t & trmask_group && in_group($user,$g)) {                                  if ($t & trmask_not && $g != $user) {
1470                                            $t = $t & ~trmask_not;
1471                                            $perm = unroll_perm($user,$t,$perm, $one_level);
1472                                            unset($tr[$g]);
1473    
1474                                    } elseif ($t & trmask_group && in_group($user,$g)) {
1475                                          // resolv user                                          // resolv user
1476                                          $t = $t & ~trmask_group;                                          $t = $t & ~trmask_group;
1477                                          $perm = unroll_perm($user,$t,$user, $perm);                                          $perm = unroll_perm($user,$t,$perm, $one_level);
1478                                          unset($tr[$g]);                                          unset($tr[$g]);
1479                                  }                                  }
1480                          }                          }
1481                          // then apply user policy                          // then apply user policy
1482                          if (isset($tr[$user])) {                          if (isset($tr[$user])) {
1483                                  $perm = unroll_perm($user,$tr[$user],$user, $perm);                                  $perm = unroll_perm($user,$tr[$user],$perm,$one_level);
1484                                  unset($tr[$user]);                                  unset($tr[$user]);
1485                          }                          }
1486                  }                  }
# Line 1470  $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 1519  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
1568  // [replacement for register_globals in php.ini]  // [replacement for register_globals in php.ini]
1569    
1570  function HTTP_GET_VAR($var) {  function HTTP_GET_VAR($var) {
1571          global $HTTP_GET_VARS, $GLOBALS;          global $HTTP_GET_VARS, ${$var};
1572          if (isset($HTTP_GET_VARS[$var])) {          if (isset($HTTP_GET_VARS[$var])) {
1573                  $GLOBALS[$var] = stripSlashes($HTTP_GET_VARS[$var]);                  $$var = stripSlashes($HTTP_GET_VARS[$var]);
1574                  return $GLOBALS[$var];                  return $$var;
1575          }          }
1576  }  }
1577    
1578  function HTTP_POST_VAR($var) {  function HTTP_POST_VAR($var) {
1579          global $HTTP_GET_VARS, $GLOBALS;          global $HTTP_POST_VARS, ${$var};
1580          if (isset($HTTP_GET_VARS[$var])) {          if (isset($HTTP_POST_VARS[$var])) {
1581                  $GLOBALS[$var] = stripSlashes($HTTP_GET_VARS[$var]);                  $$var = $HTTP_POST_VARS[$var];
1582                  return $GLOBALS[$var];                  return $$var;
1583            }
1584    }
1585    
1586    function HTTP_SERVER_VAR($var) {
1587            global $HTTP_SERVER_VARS, ${$var};
1588            if (isset($HTTP_SERVER_VARS[$var])) {
1589                    $$var = $HTTP_SERVER_VARS[$var];
1590                    return $$var;
1591          }          }
1592  }  }
1593    
# Line 1562  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 1650  function Warn($text) { Line 1698  function Warn($text) {
1698          // read mime.types          // read mime.types
1699          readMime();          readMime();
1700    
1701    HTTP_POST_VAR("FN");
1702    
1703          if ($HTTP_SERVER_VARS["REQUEST_METHOD"] == "POST") {          if ($HTTP_SERVER_VARS["REQUEST_METHOD"] == "POST") {
1704                  // take variables from server                  // take variables from server
1705                  if (HTTP_POST_VAR("FN")) check_filename($FN);                  if (HTTP_POST_VAR("FN"))
1706                            check_filename($FN);
1707                  if (HTTP_POST_VAR("DIR")) {                  if (HTTP_POST_VAR("DIR")) {
1708                          check_dirname($DIR);                          check_dirname($DIR);
1709                          $relDir = $DIR;                          $relDir = $DIR;
1710                  } else {                  } else {
1711                          trigger_error("Can't get DIR",E_USER_WARNING);                          trigger_error("Can't get DIR",E_USER_WARNING);
1712                            $relDir = "/";
1713                  }                  }
1714                  if (HTTP_POST_VAR("RELPATH")) check_dirname($RELPATH);                  if (HTTP_POST_VAR("RELPATH")) check_dirname($RELPATH);
1715                  HTTP_POST_VAR("T");                  HTTP_POST_VAR("T");
1716                  HTTP_POST_VAR("CONFIRM");                  HTTP_POST_VAR("CONFIRM");
   
1717          } else {          } else {
1718                  // get                  // get
1719                  HTTP_GET_VAR("A");                  HTTP_GET_VAR("A");
# Line 1707  function Warn($text) { Line 1758  function Warn($text) {
1758                          Error("You must select file with browse to upload it!");                          Error("You must select file with browse to upload it!");
1759                  }                  }
1760    
1761                  $FILENAME = $HTTP_POST_VARS["FILENAME"];                  if (HTTP_POST_VAR("FILENAME")) check_filename($FILENAME);
                 check_filename($FILENAME);  
1762    
1763                  if (! isset($FILENAME)) {       // from update file                  if (! isset($FILENAME)) {       // from update file
1764                          $target = "$fsDir/".basename($FN);                          $target = "$fsDir/".basename($FN);
# Line 1716  function Warn($text) { Line 1766  function Warn($text) {
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")) {
1775                          mkdir($dir."/.bak",0700);                          mkdir($dir."/.bak",0700);
1776                  }                  }
1777                  if (! file_exists($dir."/.bak/$GLOBALS[gblNumBackups]")) {                  if (! file_exists($dir."/.bak/$gblNumBackups")) {
1778                          mkdir($dir."/.bak/$GLOBALS[gblNumBackups]",0700);                          mkdir($dir."/.bak/$gblNumBackups",0700);
1779                  }                  }
1780                  $file=basename($target);                  $file=basename($target);
1781                  for($i=$GLOBALS[gblNumBackups]-1;$i>0;$i--) {                  for($i=$gblNumBackups-1;$i>0;$i--) {
1782                          MoveTo("$dir/.bak/$i/$file","$dir/.bak/".($i+1)."/");                          MoveTo("$dir/.bak/$i/$file","$dir/.bak/".($i+1)."/");
1783                  }                  }
1784                  MoveTo($target,$dir."/.bak/1/");                  MoveTo($target,$dir."/.bak/1/");
# Line 1744  function Warn($text) { Line 1797  function Warn($text) {
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") ;
1811                  $FILEDATA=stripSlashes($FILEDATA);                  HTTP_POST_VAR("FILEDATA");
1812                  fwrite($fh,$FILEDATA) ;                  fwrite($fh,$FILEDATA) ;
1813                  fclose($fh) ;                  fclose($fh) ;
1814                  clearstatcache() ;                  clearstatcache() ;
# Line 1760  function Warn($text) { Line 1817  function Warn($text) {
1817    
1818          case "CREATE" :          case "CREATE" :
1819                  // we know $fsDir exists                  // we know $fsDir exists
1820                  if ($FN == "") break;           // no filename!                  if (! check_perm($relDir, trperm_w))
1821                  if (!is_writeable($fsDir)) Error("Write denied",$relDir) ;                          Error("Write access denied","You don't have permission to write in <tt>$relDir</tt>");
1822                  $path = $fsDir . "/" . $FN ;  // file or dir to create                  if ($T == "D") $type = "directory";
1823                  $relPath = $relDir . "/" . $FN ;                  else $type ="file";
1824                    if ($FN == "") Error("Can't create $type","You must enter name of $type to create it.");
1825                    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
1827                    $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 1777  function Warn($text) { Line 1842  function Warn($text) {
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 = "$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) ;
1856                          exit ;                          exit ;
1857                  }                  }
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 1833  function Warn($text) { Line 1899  function Warn($text) {
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 1844  function Warn($text) { Line 1913  function Warn($text) {
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 ;
# Line 1865  function Warn($text) { Line 1941  function Warn($text) {
1941    
1942          // common to all POSTs : redirect to directory view ($relDir)          // common to all POSTs : redirect to directory view ($relDir)
1943          if (isset($POSTACTION)) {          if (isset($POSTACTION)) {
1944                  $tstr = $PHP_SELF . "?D=" . urlencode($relDir) ;                  $tstr = $HTTP_SERVER_VARS["PHP_SELF"]."?D=".urlencode($relDir);
1945                  header("Location: " . $tstr) ;                    header("Location: ".$tstr) ;  
1946                  exit ;                  exit ;
1947          }          }
1948                    

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

  ViewVC Help
Powered by ViewVC 1.1.26