/[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.1.1.1 by dpavlin, Sun Jul 21 18:15:47 2002 UTC revision 1.29 by dpavlin, Mon Jul 29 12:34:18 2002 UTC
# Line 20  Line 20 
20  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
21  // CONFIGURATION OPTIONS  // CONFIGURATION OPTIONS
22    
23  //      error_reporting(4) ;            // how verbose ?          error_reporting(E_ALL) ;                // how verbose ?
24    
25          // from where to include auth_*.php modules?          // from where to include auth_*.php modules?
26          $gblIncDir = "/data/docman2";          $gblIncDir = "/data/docman2";
27    
28          // force download (so it won't open in associated application)          // force download on view (so it won't open in associated application)
29          $gblForceDownload = 1;          $gblForceDownload = 0;
30    
31          // date format          // date format
32          $gblDateFmt="Y-m-d";          $gblDateFmt="Y-m-d";
# Line 84  Line 84 
84          LoadLanguage($HTTP_SERVER_VARS["HTTP_ACCEPT_LANGUAGE"]);          LoadLanguage($HTTP_SERVER_VARS["HTTP_ACCEPT_LANGUAGE"]);
85    
86          // for security and configuration          // for security and configuration
87          $realm="$HTTP_HOST";    // FIX          $realm=$HTTP_SERVER_VARS["HTTP_HOST"];
88    
89          $fsDocumentRoot = dirname($HTTP_SERVER_VARS[SCRIPT_FILENAME]);          $fsDocumentRoot = dirname($HTTP_SERVER_VARS["SCRIPT_FILENAME"]);
90          if ($fsDocumentRoot == "") Error("Configuration error","Can't get SCRIPT_FILENAME from your web server. Please set <tt>\$fsDocumentRoot</tt> in <tt>\$</tt>");          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 = $PHP_AUTH_USER;          $gblLogin = HTTP_SERVER_VAR("PHP_AUTH_USER");
94          $gblPasswd = $PHP_AUTH_PW;          $gblPasswd = HTTP_SERVER_VAR("PHP_AUTH_PW");
95    
96  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
97    
# Line 109  function LoadLanguage($lang) { Line 109  function LoadLanguage($lang) {
109    
110  function StartHTML($title,$text="") {  function StartHTML($title,$text="") {
111    
112          global $html,$fsDocumentRoot;          global $html,$fsDocumentRoot,$gblTitle,$HTTP_SERVER_VARS;
113    
114          $title = $gblTitle." ".$title ;          $host  = $HTTP_SERVER_VARS["HTTP_HOST"] ;
115          $host  = $GLOBALS["HTTP_HOST"] ;          $self  = $HTTP_SERVER_VARS["PHP_SELF"] ;
         $self  = $GLOBALS["PHP_SELF"] ;  
116    
117          if (file_exists("$fsDocumentRoot/docman.css")) {          if (file_exists("$fsDocumentRoot/docman.css")) {
118                  $css=dirname($self)."/docman.css";                  $css=dirname($self)."/docman.css";
119          } else {          } else {
120                  $css=$self."?STYLE=get&css=$css";                  $css=$self."?STYLE=get";
121          }          }
122    
123          include("$html/head.html");          include("$html/head.html");
# Line 138  function EndHTML() { Line 137  function EndHTML() {
137          } else {          } else {
138                  $url .= md5($gblLogin.$gblPasswd);                  $url .= md5($gblLogin.$gblPasswd);
139          }          }
140          if (isset($gblLogin) && $gblLogin != "" && ($gblPasswd == "" || !isset($gblPasswd))) {          if ( (  (isset($gblLogin) && $gblLogin != "") ||
141                    (!isset($gblLogin) || $gblLogin == "")
142                 ) && ($gblPasswd == "" || !isset($gblPasswd))) {
143                  $url_title="login";                  $url_title="login";
144                  $url .= "&force_login=1";                  $url .= "&force_login=1";
145          } else {          } else {
146                  $url_title="relogin";                  $url_title="relogin";
147          }          }
148          include("$html/footer.html");          include("$html/footer.html");
149          //phpinfo();  
150            global $debug;
151            if ($debug) print $debug;
152  } // end function EndHTML  } // end function EndHTML
153    
154  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
155    
156  function DetailPage($fsRoot,$relDir,$fn) {  function DetailPage($fsRoot,$relDir,$fn) {
157                    
158          global $gblEditable, $gblImages, $webRoot, $html ;          global $gblEditable, $gblImages,
159          $self = $GLOBALS["PHP_SELF"] ;                  $gblDateFmt, $gblTimeFmt,
160                    $webRoot, $html,
161                    $HTTP_SERVER_VARS ;
162            $self = $HTTP_SERVER_VARS["PHP_SELF"] ;
163    
164          $relPath  = $relDir . "/" . $fn ;          $relPath  = $relDir . "/" . $fn ;
165          $fsPath   = $fsRoot . $relPath ;          $fsPath   = $fsRoot . $relPath ;
# Line 161  function DetailPage($fsRoot,$relDir,$fn) Line 167  function DetailPage($fsRoot,$relDir,$fn)
167    
168          $exists   = file_exists($fsPath) ;          $exists   = file_exists($fsPath) ;
169          $ext      = strtolower(strrchr($relPath,".")) ;          $ext      = strtolower(strrchr($relPath,".")) ;
170          $editable = ( $ext=="" || strstr(join(" ",$gblEditable),$ext)) ;          $editable = ( $ext=="" || strstr(join(" ",$gblEditable),$ext)) &&
171          $writable = is_writeable($fsPath) ;                  check_perm($relPath,trperm_w);
172            $writable = is_writeable($fsPath) && check_perm($relPath,trperm_w) ;
173            $writable_dir = is_writeable($fsDir) && check_perm($relDir,trperm_w) ;
174          $file_lock = CheckLock($fsPath);          $file_lock = CheckLock($fsPath);
175    
176          if (!$editable && !$exists)          if (!$editable && !$exists)
177                  Error(_("Creation unsupported for type"),$relPath) ;                  Error("Creation denied","Can't create <tt>$relPath</tt>") ;
178          if (!exists && !is_writeable($fsDir) )          if (!$exists && !$writable_dir )
179                  Error(_("Creation denied"),$relDir) ;                  Error("Creation denied","Can't write in directory <tt>$relDir</tt> while creating <tt>$relPath</tt>for which user has permissions.",1);
180    
181          $text  = _("Use this page to view, modify or ") ;          $text  = _("Use this page to view, modify or ") ;
182          if (is_dir($fsPath)) {          if (is_dir($fsPath)) {
# Line 180  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 201  function DetailPage($fsRoot,$relDir,$fn) Line 210  function DetailPage($fsRoot,$relDir,$fn)
210                  $fstr = htmlentities( $fstr ) ;                  $fstr = htmlentities( $fstr ) ;
211  ?>  ?>
212    
213  <FORM ACTION="<?= $self ; ?>" METHOD="POST">  <FORM ACTION="<?= $self ?>" METHOD="POST">
214  <SPAN TITLE="Click [SAVE] to store updated contents.">  <SPAN TITLE="Click [SAVE] to store updated contents.">
215          <B>DOCUMENT CONTENTS</B>          <B>DOCUMENT CONTENTS</B>
216  </SPAN><BR>  </SPAN><BR>
# Line 221  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 472  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 561  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 572  function GifIcon($txt) { Line 578  function GifIcon($txt) {
578  function Navigate($fsRoot,$relDir) {  function Navigate($fsRoot,$relDir) {
579    
580          global $gblEditable, $gblIcon, $gblModDays, $webRoot, $gblHide,          global $gblEditable, $gblIcon, $gblModDays, $webRoot, $gblHide,
581                  $HTTP_GET_VARS, $html;                  $gblIgnoreUnknownFileType, $gblRepositoryDir,
582                    $gblLogin, $gblUserName, $gblDateFmt, $gblTimeFmt,
583                    $fsRealmDir, $realm, $realm_sep,
584                    $html, $realm_config,
585                    $HTTP_GET_VARS, $HTTP_SERVER_VARS;
586            
587            $self     = $HTTP_SERVER_VARS["PHP_SELF"] ;
588    
589          $self     = $GLOBALS["PHP_SELF"] ;          $relDir = chopsl($relDir)."/";
590            $fsDir = $fsRoot.$relDir;       // current directory
591    
592          if ($relDir == "") $relDir = "/";          if (!is_dir($fsDir)) Error("Dir not found","Directory <tt>$relDir<tt> not found on filesystem at <tt>$fsDir</tt>",1) ;
593    
594          $fsDir = $fsRoot.$relDir."/";   // current directory          global $debug;
595            $debug .= "[$gblLogin|$relDir] before >";
596    
597          if (!is_dir($fsDir)) Error("Dir not found",$relDir) ;          if (! check_perm($relDir,trperm_b))
598                    Error("Access denied","User <tt>$gblLogin</tt> tried to access <tt>$relDir</tt> without valid trustee.",1);
599            $debug .= "< afeter";
600    
601          $hide_items=",$gblHide,";          $hide_items=",$gblHide,";
602    
603  #display_all_trustee();          $dirList = array();
604  print "-- $fsDir --";          $fileList = array();
605    
606          // read directory contents          // read directory contents
607          if ( !($dir = @opendir($fsDir)) )          if ( !($dir = @opendir($fsDir)) )
608                  Error("Read Access denied",$relDir) ;                  Error("Read Access denied",$relDir,1) ;
609          while ($item = readdir($dir)) {          while ($item = readdir($dir)) {
 print "$item, ";  
610                  if ( substr($item,0,1) == "." || strstr($hide_items,",$item,") ) continue ;                  if ( substr($item,0,1) == "." || strstr($hide_items,",$item,") ) continue ;
611                  if ((is_dir($fsDir.$item) || is_link ($fsDir.$item)) && check_perm($relDir.$item,trperm_b)) {                  if (is_dir($fsDir.$item) || is_link ($fsDir.$item)) {
612                          $dirList[$item] = $item ;                          if (check_perm($relDir.$item,trperm_b)) {
613                          $dirNote[$item] = ReadNote($fsDir.$item);                                  $dirList[$item] = $item ;
614                  } else if ( is_file($fsDir.$item) && check_perm($relDir.$item,trperm_r) ) {                                  $dirNote[$item] = ReadNote($fsDir.$item);
615                          $fileList[$item] = $item ;                                        }
616                          $fileDate[$item] = filemtime($fsDir.$item) ;                  } else if (is_file($fsDir.$item)) {
617                          $fileSize[$item] = filesize($fsDir.$item) ;                          if (check_perm($relDir.$item,trperm_r)) {
618                          $fileNote[$item] = ReadNote($fsDir.$item);                                  $fileList[$item] = $item ;              
619                                    $fileDate[$item] = filemtime($fsDir.$item) ;
620                                    $fileSize[$item] = filesize($fsDir.$item) ;
621                                    $fileNote[$item] = ReadNote($fsDir.$item);
622                            }
623                  } else {                  } else {
624                    // unknown file type                          if (! $gblIgnoreUnknownFileType) Error("File Type Error", "Item <tt>".$fsDir.$item."</tt> is not file, directory or link. If you want to ignore errors like this, set <tt>\$gblIgnoreUnknownFileType = 1</tt> in <tt>$realm_config</tt>.",1);
                   // $text = "Could not determine file type of " ;  
                   // Error("File Error", $text.$relDir."/".$item) ;  
                   // exit ;  
625                  }                  }
626          }          }
627          closedir($dir) ;          closedir($dir) ;
628    
629          // scan deleted files          // scan deleted files
630          if ( $GLOBALS[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 626  print "$item, "; Line 647  print "$item, ";
647    
648          // start navigation page          // start navigation page
649          $text  = "Use this page to add, delete";          $text  = "Use this page to add, delete";
650          if (! isset($show_deleted)) {          if (! isset($HTTP_GET_VARS["show_deleted"])) {
651                  $text .= ", <a href=$self?D=".urlencode($relDir)."&show_deleted=1>undelete</a>";                  $text .= ", <a href=$self?D=".urlencode($relDir)."&show_deleted=1>undelete</a>";
652          }          }
653          $text .= " or revise files on this web site." ;          $text .= " or revise files on this web site." ;
# Line 636  print "$item, "; Line 657  print "$item, ";
657          echo "<TABLE BORDER=0 CELLPADDING=2          echo "<TABLE BORDER=0 CELLPADDING=2
658                  CELLSPACING=3 WIDTH=\"100%\">" ;                  CELLSPACING=3 WIDTH=\"100%\">" ;
659    
660          // updir bar              // updir (parent) bar  
661          if (chopsl($fsDir) != chopsl($fsRoot)) {          if (chopsl($fsDir) != chopsl($fsRoot)) {
662                  $parent = dirname($relDir) ;                  $parent = dirname($relDir) ;
663                  if ($parent == "") $parent = "/" ;                  if ($parent == "") $parent = "/" ;
# Line 652  print "$item, "; Line 673  print "$item, ";
673                  return $out;                  return $out;
674          }          }
675    
676          $dsort = $HTTP_GET_VARS[dsort];          if (! HTTP_GET_VAR("dsort")) $dsort = "name"; // default directory sort
         if (! isset($dsort)) $dsort = "name";   // default directory sort  
677    
678          $dsort_arr = array(          $dsort_arr = array(
679                  "name" => array ("rname", "note"),                  "name" => array ("rname", "note"),
# Line 662  print "$item, "; Line 682  print "$item, ";
682                  "rnote" => array ("name", "note")                  "rnote" => array ("name", "note")
683                  );                  );
684    
685          $fsort = $HTTP_GET_VARS[fsort];          if (! HTTP_GET_VAR("fsort")) $fsort = "name"; // default directory sort
         if (! isset($fsort)) $fsort = "name";   // default directory sort  
686    
687          $fsort_arr = array(          $fsort_arr = array(
688                  "name" => array ("rname", "note", "date", "size"),                  "name" => array ("rname", "note", "date", "size"),
# Line 679  print "$item, "; Line 698  print "$item, ";
698          $D="D=".urlencode($relDir);          $D="D=".urlencode($relDir);
699    
700          function self_args($arr = array()) {          function self_args($arr = array()) {
701                    global $self;
702                  $arg = implode("&",$arr);                  $arg = implode("&",$arr);
703                  if ($arg) {                  if ($arg) {
704                          return $self."?".$arg;                          return $self."?".$arg;
# Line 715  print "$item, "; Line 735  print "$item, ";
735    
736                          $dir = $dirList[$key];                          $dir = $dirList[$key];
737    
738                          $info_url=self_args(array("A" => "A=E", "F" => "F=".urlencode($dir)));                          $info_url=self_args(array("A"=>"A=E", "F"=>"F=".urlencode($dir), "D"=>$D));
739                          $dir_url=$self."?D=".urlencode($relDir.$dir);                          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);
747                          include("$html/Navigate-dirEntry.html");                          include("$html/Navigate-dirEntry.html");
748    
749                  }  // iterate over dirs                  }  // iterate over dirs
# Line 788  print "$item, "; Line 815  print "$item, ";
815    
816                  $file_lock=CheckLock($path);                  $file_lock=CheckLock($path);
817    
818                  $file_url_html="<A HREF=\"$self?A=V&F=".urlencode($file);                  $file_url_html="<A HREF=\"$self?A=V&D=".urlencode($relDir)."&F=".urlencode($file);
                 $file_url_html.="&D=".urlencode($relDir);  
819                  $file_url_html.="\" TITLE=\"View file\">" ;                  $file_url_html.="\" TITLE=\"View file\">" ;
820    
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 803  print "$item, "; Line 829  print "$item, ";
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&F=".urlencode($file);                                  $b.="<A HREF=\"$self?A=Ci&D=".urlencode($relDir)."&F=".urlencode($file);
                                 $b.="&D=".urlencode($relDir);  
834                                  $b.="\" TITLE=\"Checkin (update) file on server\">" ;                                  $b.="\" TITLE=\"Checkin (update) file on server\">" ;
835                                  $file_url_html=$b;                                  $file_url_html=$b;
836                                  $b.=$gblIcon("checkin")."</A>" ;                                  $b.=$gblIcon("checkin")."</A>" ;
# Line 819  print "$item, "; Line 844  print "$item, ";
844                                  $file_url_html = "$file $a";                                  $file_url_html = "$file $a";
845                          }                          }
846                  } else {                  } else {
847                          $b.="<A HREF=\"$self?A=Co&F=".urlencode($file);                          $b.="<A HREF=\"$self?A=Co&D=".urlencode($relDir)."&F=".urlencode($file);
                         $b.="&D=".urlencode($relDir);  
848                          $b.="\" TITLE=\"Checkout file for edit\">" ;                          $b.="\" TITLE=\"Checkout file for edit\">" ;
849                          $b.=$gblIcon("checkout")."</A>" ;                          $b.=$gblIcon("checkout")."</A>";
850    
851                          if ( $ext=="" || strstr(join(" ",$gblEditable),$ext) ) {                            if ( $ext=="" || strstr(join(" ",$gblEditable),$ext) ) {  
852                                  $b.="<A HREF=\"$self?A=C&F=".urlencode($file);                                  $b.="<A HREF=\"$self?A=C&D=".urlencode($relDir)."&F=".urlencode($file);
                                 $b.="&D=".urlencode($relDir);  
853                                  $b.="\" TITLE=\"List contents\">" ;                                  $b.="\" TITLE=\"List contents\">" ;
854                                  $b.=$gblIcon("view")."</A>" ;                                  $b.=$gblIcon("view")."</A>" ;
855                          } else {                          } else {
# Line 834  print "$item, "; Line 857  print "$item, ";
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 866  print "$item, "; Line 889  print "$item, ";
889  <TR><TD></TD><TD COLSPAN=5><HR></TD></TR>  <TR><TD></TD><TD COLSPAN=5><HR></TD></TR>
890    
891  <?  <?
892  if (file_exists(".info.inc")) {  
893    if (file_exists("$fsRealmDir/$realm".$realm_sep."info.inc")) {
894          print "<TR><TD></TD><TD COLSPAN=5>";          print "<TR><TD></TD><TD COLSPAN=5>";
895          include(".info.inc");          include("$fsRealmDir/$realm".$realm_sep."info.inc");
896          print "</TD></TR>          print "</TD></TR><TR><TD></TD><TD COLSPAN=5><HR></TD></TR>";
897          <TR><TD></TD><TD COLSPAN=5><HR></TD></TR>";  } elseif (file_exists("$gblRepositoryDir/.info.inc")) {
898            print "<TR><TD></TD><TD COLSPAN=5>";
899            include("$gblRepositoryDir/.info.inc");
900            print "</TD></TR><TR><TD></TD><TD COLSPAN=5><HR></TD></TR>";
901  }  }
902    
903    
904  ?>  ?>
905    
906  <FORM METHOD="POST" ACTION="<?= $self ?>">  <FORM METHOD="POST" ACTION="<?= $self ?>">
# Line 896  if (file_exists(".info.inc")) { Line 925  if (file_exists(".info.inc")) {
925    
926  function UploadPage($fsRoot, $relDir, $filename="") {  function UploadPage($fsRoot, $relDir, $filename="") {
927    
928          $self = $GLOBALS["PHP_SELF"] ;          global $html, $HTTP_SERVER_VARS;
         if ($relDir == "") $relDir = "/" ;  
 ?>  
929    
930  <P><TABLE BORDER=0 CELLPADDING=5><TR><TD WIDTH=5></TD><TD CLASS=BAR>          $self = $HTTP_SERVER_VARS["PHP_SELF"] ;
931  <FORM ENCTYPE="multipart/form-data" METHOD="POST"          include("$html/UploadPage.html");
  ACTION="<?= $self ?>">  
 DESTINATION DIRECTORY:<B><?= " " . $relDir ?></B>  
 <? if (isset($filename) && $filename!="") { ?>  
 <br>DESTINATION FILE:<B><?= " " . $filename ?></B>  
 <INPUT TYPE="HIDDEN" NAME="FILENAME" VALUE="<?= $filename ?>">  
 <? } ?>  
 <P>PATHNAME OF LOCAL FILE<BR>  
 <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ?>">  
 <INPUT TYPE="HIDDEN" NAME="POSTACTION" VALUE="UPLOAD">  
 <INPUT SIZE=30 TYPE="FILE" NAME="FN"></P>  
 <P><INPUT TYPE="SUBMIT" VALUE="UPLOAD"></P>  
 <P>If the <B>[BROWSE...]</B> button is not displayed,<BR>  
 you must upgrade to an RFC1867-compliant browser.</P>  
 <P>Your browser:<BR><?= $GLOBALS["HTTP_USER_AGENT"] ?></P>  
 </FORM>  
 </TD></TR>  
 <TR><TD></TD><TD>  
 <FORM METHOD="POST" ACTION="<?= $self ?>">  
 <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ?>"><BR>  
 <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="CANCEL">  
 </FORM>  
 </TD></TR></TABLE></P>  
932    
 <?php    
933  } // end function UploadPage  } // end function UploadPage
934    
935  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
936    
937  function Error($title,$text="") {  // Error with sysadmin flag are reported to error_log or hidden from
938          StartHTML("(".$title.")",$text) ;  // users
939          echo "<P ALIGN=center>Hit your Browser's Back Button.</P>" ;  
940          EndHTML() ;  function Error($title,$text="",$sysadmin=0,$no_404=0) {
941            global $gblSeparateAdminMessages,
942                    $gblMailAdminMessages,$realm,
943                    $HTTP_SERVER_VARS;
944            if (! headers_sent() && ! $no_404) header("HTTP/1.0 404 Not Found");
945            if ($sysadmin) {
946                    if ($gblSeparateAdminMessages) {
947                            $user="Your administrator ";
948                            if ($gblMailAdminMessages) {
949                                    mail($HTTP_SERVER_VARS["SERVER_ADMIN"], "docman $realm error message: $title", strip_tags($text));
950                                    $user.="<tt>".$HTTP_SERVER_VARS["SERVER_ADMIN"]."</tt> ";
951                            }
952                            $user.="has been notified about error" ;
953                            StartHTML("($title)",$user);
954                            echo "<P ALIGN=center>Hit your Browser's Back Button.</P>" ;
955                            EndHTML();
956                            error_log("docman $realm: ".strip_tags($text));
957                    } else {
958                            StartHTML("ADMIN: ".$title,$text) ;
959                            echo "<P ALIGN=center>Hit your Browser's Back Button.</P>" ;
960                            EndHTML();
961                    }
962            } else {
963                    StartHTML("(".$title.")",$text) ;
964                    echo "<P ALIGN=center>Hit your Browser's Back Button.</P>" ;
965                    EndHTML() ;
966            }
967          exit ;          exit ;
968  } // end function Error  } // end function Error
969    
970  //////////////////////////////////////////////////////////////////  function LogIt($target,$msg, $changelog=0) {
971    
972  function LogIt($target,$msg) {          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>");                  if (! @mkdir($dir."/.log",0700)) Error("docman installation problem","can't create log directory <tt>$dir/.log</tt>",1);
977          }          }
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;
986    
987            $log=fopen("$gblFsRoot/.changelog","a+");
988            if (substr($target,0,strlen($gblFsRoot)) == $gblFsRoot)
989                    $target=substr($target,strlen($gblFsRoot),strlen($target)-strlen($gblFsRoot));
990            $msg=str_replace("\t"," ",$msg);
991            fputs($log,time()."\t$target\t$gblUserName\t$msg\n");
992            fclose($log);
993    
994            // FIX: implement e-mail notification based on $changelog
995            // permission
996  }  }
997    
998    
# Line 970  function WriteNote($target,$msg) { Line 1011  function WriteNote($target,$msg) {
1011          fputs($note,"$msg\n");          fputs($note,"$msg\n");
1012          fclose($note);          fclose($note);
1013    
1014          Logit($target,"added note $msg");          LogIt($target,"added note $msg");
1015    
1016  }  }
1017    
# Line 1007  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 1015  function Lock($target) { Line 1058  function Lock($target) {
1058          $file=basename($target);          $file=basename($target);
1059    
1060          if (file_exists("$dir/.lock/$file")) {          if (file_exists("$dir/.lock/$file")) {
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");
1068          }          }
1069    
1070  }  }
# Line 1048  function Unlock($target) { Line 1091  function Unlock($target) {
1091          $file=basename($target);          $file=basename($target);
1092          if (file_exists($dir."/.lock/$file")) {          if (file_exists($dir."/.lock/$file")) {
1093                  unlink("$dir/.lock/$file");                  unlink("$dir/.lock/$file");
1094                  Logit($target,"file unlocked");                  LogIt($target,"file unlocked");
1095          } else {          } else {
1096                  Logit($target,"attempt to unlocked non-locked file!");                  LogIt($target,"attempt to unlocked non-locked file!");
1097          }          }
1098    
1099  }  }
# Line 1067  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))) {
1119                          rename($from,$to);                          return rename($from,$to);
1120                    } else {
1121                            return 0;
1122                  }                  }
1123          }          }
1124    
1125          function try_dir($todir) {          function try_dir($todir) {
1126                  if (! file_exists($todir)) {                  if (! file_exists($todir)) {
1127                          mkdir($todir,0700);                          @mkdir($todir,0700);
1128                  }                  }
1129          }          }
1130    
# Line 1086  function safe_rename($fromdir,$fromfile, Line 1134  function safe_rename($fromdir,$fromfile,
1134    
1135  #       print "<pre>$fromdir / $fromfile -> $todir / $tofile\n\n";  #       print "<pre>$fromdir / $fromfile -> $todir / $tofile\n\n";
1136    
1137          try_rename("$fromdir/$fromfile","$todir/$tofile");          if (! try_rename("$fromdir/$fromfile","$todir/$tofile")) Error("Rename error","Can't rename file <tt>$fromfile</tt> to <tt>$tofile</tt>",1);
1138          try_dir("$todir/.log");          try_dir("$todir/.log");
1139          try_rename("$fromdir/.log/$fromfile","$todir/.log/$tofile");          try_rename("$fromdir/.log/$fromfile","$todir/.log/$tofile");
1140          try_dir("$todir/.note");          try_dir("$todir/.note");
# Line 1094  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 1120  function rrmdir($dir) { Line 1168  function rrmdir($dir) {
1168    
1169  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
1170    
1171  function ChangeLog($target,$msg) {  function DisplayChangeLog($day) {
   
         global $gblFsRoot;  
         $log=fopen("$gblFsRoot/.changelog","a+");  
         if (substr($target,0,strlen($gblFsRoot)) == $gblFsRoot)  
                 $target=substr($target,strlen($gblFsRoot),strlen($target)-strlen($gblFsRoot));  
         $msg=str_replace("\t"," ",$msg);  
         fputs($log,time()."\t$target\t$GLOBALS[gblUserName]\t$msg\n");  
         fclose($log);  
1172    
1173  }          global $gblFsRoot, $gblDateFmt, $gblTimeFmt,
1174                    $HTTP_SERVER_VARS;
1175    
1176  function DisplayChangeLog($day) {          $self  = $HTTP_SERVER_VARS["PHP_SELF"];
1177    
         global $gblFsRoot;  
1178          if (!file_exists("$gblFsRoot/.changelog")) return;          if (!file_exists("$gblFsRoot/.changelog")) return;
1179          $log=fopen("$gblFsRoot/.changelog","r");          $log=fopen("$gblFsRoot/.changelog","r");
1180          $logarr = array();          $logarr = array();
# Line 1152  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=\"$GLOBALS[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=$GLOBALS[PHP_SELF]>front page</a>.</p>";          print "<p>".GifIcon("up")." Back to <a href=\"$self\">front page</a>.</p>";
1203  }  }
1204    
1205  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
1206    
1207  function Download($path) {  function Download($path,$force=0) {
1208          global $HTTP_USER_AGENT;          global $HTTP_SERVER_VARS,$mime_type;
1209          $file=basename($path);  
1210            // default transfer-encoding
1211            $encoding = "binary";
1212    
1213            // known transfer encodings
1214            $encoding_ext = array(
1215                    "gz" => "x-gzip",
1216                    "Z" => "x-compress",
1217            );
1218    
1219            $file = basename($path);
1220          $size = filesize($path);          $size = filesize($path);
1221          //header("Content-Type: application/octet-stream");  
1222          header("Content-Type: application/force-download");          $ext_arr = explode(".",$file);
1223          header("Content-Length: $size");          $ext = array_pop($ext_arr);
1224            if (isset($encoding_ext[$ext])) {
1225                    $encoding = $encoding_ext[$ext];
1226                    $ext = array_pop($ext_arr);
1227            }
1228    
1229            if ($force || !isset($mime_type[$ext])) {
1230                    header("Content-Type: application/force-download");
1231            } else {
1232                    header("Content-Type: $mime_type[$ext]");
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_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");
1240          }          }
1241          header("Content-Transfer-Encoding: binary");  
1242            header("Content-Transfer-Encoding: $encoding");
1243          $fh = fopen($path, "r");          $fh = fopen($path, "r");
1244          fpassthru($fh);          fpassthru($fh);
1245  }  }
# Line 1186  function Download($path) { Line 1248  function Download($path) {
1248  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
1249    
1250  function chopsl($path) {  function chopsl($path) {
         if (substr($path,strlen($path)-1,1) == "/") $path=substr($path,0,strlen($path)-1);  
1251          $path=str_replace("//","/",$path);          $path=str_replace("//","/",$path);
1252            if (substr($path,strlen($path)-1,1) == "/") $path=substr($path,0,strlen($path)-1);
1253          return $path;          return $path;
1254  }  }
1255    
# Line 1201  function chopsl($path) { Line 1263  function chopsl($path) {
1263          by Vyacheslav Zavadsky <zavadsky@braysystems.com>          by Vyacheslav Zavadsky <zavadsky@braysystems.com>
1264  */  */
1265    
1266  define(trmask_not,1 << 0);  define('trmask_not',1 << 0);
1267  define(trmask_clear,1 << 1);  define('trmask_clear',1 << 1);
1268  define(trmask_deny,1 << 2);  define('trmask_deny',1 << 2);
1269  define(trmask_one_level,1 << 3);  define('trmask_one_level',1 << 3);
1270  define(trmask_group,1 << 4);  define('trmask_group',1 << 4);
1271    
1272  define(trperm_r,1 << 5);  define('trperm_r',1 << 5);
1273  define(trperm_w,1 << 6);  define('trperm_w',1 << 6);
1274  define(trperm_b,1 << 7);  define('trperm_b',1 << 7);
1275  define(trperm_n,1 << 8);  define('trperm_n',1 << 8);
1276    
1277  $trustee_a2n = array(  $trustee_a2n = array(
1278          '!' => trmask_not,          '!' => trmask_not,
# Line 1258  if (! file_exists($trustee_conf)) { Line 1320  if (! file_exists($trustee_conf)) {
1320          $error="<tt>".dirname($trustee_php)."</tt> must be writable by web server user";          $error="<tt>".dirname($trustee_php)."</tt> must be writable by web server user";
1321  } elseif (file_exists($trustee_php) && !is_writable($trustee_php)) {  } elseif (file_exists($trustee_php) && !is_writable($trustee_php)) {
1322          $error="trustees cache file <tt>$trustee_php</tt> exists, but is not writable by web server";          $error="trustees cache file <tt>$trustee_php</tt> exists, but is not writable by web server";
1323  } elseif (1 || filemtime($trustee_conf) >= filemtime($trustee_php)) {  } elseif (@filemtime($trustee_conf) >= @filemtime($trustee_php)) {
1324          $fp_php=@fopen($trustee_php,"w");          $fp_php=@fopen($trustee_php,"w");
1325          fputs($fp_php,"<?php // don't edit by hand!\n");          fputs($fp_php,"<?php // don't edit by hand!\n");
1326    
# Line 1267  if (! file_exists($trustee_conf)) { Line 1329  if (! file_exists($trustee_conf)) {
1329          $groups_arr = array();          $groups_arr = array();
1330          $perm_arr = array();          $perm_arr = array();
1331    
         $error=0;  
   
1332          $tr_arr = array();          $tr_arr = array();
1333    
1334          while (! feof($fp_conf)) {          while (! feof($fp_conf)) {
# Line 1296  if (! file_exists($trustee_conf)) { Line 1356  if (! file_exists($trustee_conf)) {
1356                                                  $error.="trustee error in line '$l' [Unknown modifier '$ch']<br>\n";                                                  $error.="trustee error in line '$l' [Unknown modifier '$ch']<br>\n";
1357                                          }                                          }
1358                                  }                                  }
1359                                  $tr_arr[$path][$user] |= $perm;                                  if (isset($tr_arr[$path][$user])) {
1360                                            $tr_arr[$path][$user] |= $perm;
1361                                    } else {
1362                                            $tr_arr[$path][$user] = $perm;
1363                                    }
1364                          }                          }
1365                  }                  }
1366          }          }
# Line 1335  if (! file_exists($trustee_conf)) { Line 1399  if (! file_exists($trustee_conf)) {
1399          fclose($fp_php);          fclose($fp_php);
1400  }  }
1401    
1402  if ($error) {  if (isset($error)) {
1403          Error("Trustee error",$error);          Error("Trustee error",$error,1);
1404  } else {  } else {
1405          include("$trustee_php");          include_once("$trustee_php");
1406  }  }
1407    
1408  return 1;  return 1;
# Line 1346  return 1; Line 1410  return 1;
1410  }//init_trustee  }//init_trustee
1411    
1412  function in_group($user,$group) {  function in_group($user,$group) {
1413          return in_array($groups[$group],$user);          global $groups;
1414            return in_array($user,$groups[$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          // check user  
1420          if ($t & trmask_not && ($u==$user)) continue;          if ($t & trmask_one_level && !$one_level) return $perm;
         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) {
1424                          $perm[deny] &= ~$t;                          $perm['deny'] &= ~$t;
1425                  } else {                  } else {
1426                          $perm[deny] |= $t;                          $perm['deny'] |= $t;
1427                  }                  }
1428          } elseif ($t & trmask_clear) {          } elseif ($t & trmask_clear) {
1429                  $perm[allow] &= ~$t;                  $perm['allow'] &= ~$t;
1430          } else {          } else {
1431                  $perm[allow] |= $t;                  $perm['allow'] |= $t;
1432          }          }
1433          return $perm;          return $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            // 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;
1447    $debug .= "<br>check_trustee $path ... ";
1448    
1449          $path_arr=explode("/",$path);          $path_arr=explode("/",$path);
1450          $path = "/";          $tmppath = "/";
1451          while (count($path_arr)) {          while (count($path_arr)) {
1452                  if (substr($path,strlen($path)-1,1) != "/") $path.="/";                  $tmppath.=array_shift($path_arr);
1453                  $path.=array_shift($path_arr);  $debug.= ">> $tmppath ";
1454                  $tr = $trustees[$path];  
1455                    if (! isset($trustees[$tmppath])) continue;
1456                    $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 $u=>$t) {                          foreach ($tr as $g=>$t) {
1469                                  if ($t & trmask_group && in_group($user,$u)) {                                  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                                          $u = $user;                                          $perm = unroll_perm($user,$t,$perm, $one_level);
1478                                          $perm = unroll_perm($u,$t,$user, $perm);                                          unset($tr[$g]);
                                         unset($tr[$u]);  
1479                                  }                                  }
1480                          }                          }
1481                          // then apply use 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                  }                  }
1487    $debug.="d(".display_trustee($perm['deny']).") a(".display_trustee($perm['allow']).") ";
1488    
1489          }          }
1490  #print "<br>user: $user path: $path perm: ";  $debug.="<br>check_trustee: user: $user path: $path==$tmppath perm: ";
1491  #print "d: $perm[deny] (".display_trustee($perm[deny]).") a: $perm[allow] (".display_trustee($perm[allow]).")<Br>\n";  $debug.="d: ".$perm['deny']." (".display_trustee($perm['deny']).") a: ".$perm['allow']." (".display_trustee($perm['allow']).")<Br>\n";
1492          return $perm;          return $perm;
1493  }  }
1494    
# Line 1414  function check_trustee($user,$path) { Line 1496  function check_trustee($user,$path) {
1496    
1497  function check_perm($path,$trperm) {  function check_perm($path,$trperm) {
1498          global $gblLogin,$HAVE_TRUSTEE;          global $gblLogin,$HAVE_TRUSTEE;
1499  print "<br>check_perm: <tt>$path</tt> test perm ".display_trustee($perm)."<br>\n";  
1500            $path = str_replace("//","/",$path);
1501    
1502            global $debug;
1503    $debug.="<br>check_perm: on <tt>$path</tt> for perm ".display_trustee($trperm)."<br>\n";
1504    
1505          $return = ! $HAVE_TRUSTEE;          $return = ! $HAVE_TRUSTEE;
1506          if ($HAVE_TRUSTEE) {          if ($HAVE_TRUSTEE) {
1507                  $perm = check_trustee($gblLogin,$path);                  $perm = check_trustee($gblLogin,$path);
1508  print " d: $perm[deny] (".display_trustee($perm[deny]).") a: $perm[allow] (".display_trustee($perm[allow]).") perm: $trperm";  $debug.=" d: ".$perm['deny']." (".display_trustee($perm['deny']).") a: ".$perm['allow']." (".display_trustee($perm['allow']).") perm to have: $trperm (".display_trustee($trperm).")";
1509                  if ($perm[deny] & $trperm) $return=0;                  if ($perm['deny'] & $trperm) $return=0;
1510                  elseif ($perm[allow] & $trperm) $return=1;                  elseif (($perm['allow'] & $trperm) == $trperm) $return=1;
1511          }          }
1512  print " return: $return<br>\n";  $debug.=" return: $return<br>\n";
1513          return($return);          return($return);
1514  }  }
1515    
1516    //////////////////////////////////////////////////////////////////
1517    
1518    function readMime() {
1519            global $mime_type;
1520    
1521            if (! isset($gblMimeTypes)) {
1522                    $gblMimeTypes = "/etc/mime.types";
1523            }
1524    
1525            $mime = @fopen($gblMimeTypes,"r");
1526    
1527            if (! $mime) Error("Can't read MIME types","<tt>$gblMimeTypes</tt> file not found. You can setup other <tt>mime.types</tt> file using <tt>\$gblMimeTypes</tt> in <tt>$realm_config</tt>");
1528    
1529            while($line = fgets($mime,80)) {
1530                    if (substr($line,0,1) == "#") continue; // skip comment
1531                    $arr = preg_split("/[\s\t]+/",$line);
1532                    $type = array_shift($arr);
1533                    while ($ext = array_shift($arr)) {
1534                            $mime_type[$ext] = $type;
1535                    }
1536            }
1537    
1538            fclose($mime);
1539    }
1540    
1541    //////////////////////////////////////////////////////////////////
1542    
1543    // check for invalid characters in filename and dirname (.. and /)
1544    
1545    function check_dirname($file) {
1546            if (strstr($file,"..")) Error("Security violation","No parent dir <tt>..</tt> allowed in directory name <tt>$file</tt>",1);
1547    }
1548    
1549    function check_filename($file) {
1550            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);
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
1568    // [replacement for register_globals in php.ini]
1569    
1570    function HTTP_GET_VAR($var) {
1571            global $HTTP_GET_VARS, ${$var};
1572            if (isset($HTTP_GET_VARS[$var])) {
1573                    $$var = stripSlashes($HTTP_GET_VARS[$var]);
1574                    return $$var;
1575            }
1576    }
1577    
1578    function HTTP_POST_VAR($var) {
1579            global $HTTP_POST_VARS, ${$var};
1580            if (isset($HTTP_POST_VARS[$var])) {
1581                    $$var = $HTTP_POST_VARS[$var];
1582                    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    
1594    //////////////////////////////////////////////////////////////////
1595    
1596    function Warn($text) {
1597    }
1598    
1599  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
1600  // MAIN PROGRAM  // MAIN PROGRAM
# Line 1433  print " return: $return<br>\n"; Line 1602  print " return: $return<br>\n";
1602          $gblFilePerms = 0640 ;         // default for new files          $gblFilePerms = 0640 ;         // default for new files
1603          $gblDirPerms  = 0750 ;          // default for new dirs          $gblDirPerms  = 0750 ;          // default for new dirs
1604    
1605          if (isset($STYLE) && $STYLE == "get") {          if (isset($HTTP_GET_VARS["STYLE"]) && $HTTP_GET_VARS["STYLE"] == "get") {
1606                  include("$html/docman.css");                  include("$html/docman.css");
1607                  exit;                  exit;
1608          }          }
# Line 1441  print " return: $return<br>\n"; Line 1610  print " return: $return<br>\n";
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 1451  print " return: $return<br>\n"; Line 1620  print " return: $return<br>\n";
1620          if (! isset($fsRealmDir)) {          if (! isset($fsRealmDir)) {
1621                  $fsRealmDir = "$gblIncDir/realm";                  $fsRealmDir = "$gblIncDir/realm";
1622          }          }
1623          $realm_config = "$fsRealmDir/$realm.conf";  
1624            // try to add dir to script name to realm var
1625            if (is_dir("$fsRealmDir/$realm/".dirname($HTTP_SERVER_VARS["SCRIPT_NAME"]))) {
1626                    $realm .= dirname($HTTP_SERVER_VARS["SCRIPT_NAME"]);
1627                    $realm_sep = "/";
1628            } else {
1629                    $realm_sep = ".";
1630            }
1631    
1632            $realm_config = $fsRealmDir."/".$realm.$realm_sep."conf";
1633    
1634          // read user-defined configuration          // read user-defined configuration
1635          if (file_exists($realm_config)) {          if (file_exists($realm_config)) {
# Line 1469  print " return: $return<br>\n"; Line 1647  print " return: $return<br>\n";
1647                  Error("Configuration error","Can't find user handling module at <tt>$gblIncDir/htusers/$gblUsers.php</tt> ! Please fix <tt>$realm_config</tt>");                  Error("Configuration error","Can't find user handling module at <tt>$gblIncDir/htusers/$gblUsers.php</tt> ! Please fix <tt>$realm_config</tt>");
1648          }          }
1649    
1650            // take additional login vars
1651            HTTP_GET_VAR("relogin");
1652            HTTP_GET_VAR("force_login");
1653    
1654          // if no password, or empty password logout          // if no password, or empty password logout
1655          if (          if (
1656                  isset($gblLogin) && (                  isset($gblLogin) && (
# Line 1484  print " return: $return<br>\n"; Line 1666  print " return: $return<br>\n";
1666                  exit ;                  exit ;
1667          }          }
1668    
1669            if (!is_dir($gblRepositoryDir)) Error("Repository dir not found","Can't find repository directory <tt>$gblRepositoryDir</tt>. Please fix that in <tt>$realm_config</tt> variable <tt>\$gblRepositoryDir</tt>.",1);
1670    
1671          // trustee (ACL) file configuration          // trustee (ACL) file configuration
1672          $trustee_conf="$gblIncDir/realm/$realm.trustee";          $trustee_conf="$fsRealmDir/$realm".$realm_sep."trustee";
1673          // compiled version of trustee file          // compiled version of trustee file
1674          $trustee_php="$gblRepositoryDir/.trustee.php";          $trustee_php="$gblRepositoryDir/.trustee.php";
1675          // get ACL informations          // get ACL informations
1676          $HAVE_TRUSTEE = init_trustee();          $HAVE_TRUSTEE = init_trustee();
1677    
1678          if (strtolower($gblLogin) == "anonymous" || !isset($gblPasswd)) {          if (strtolower($gblLogin) == "anonymous" || !isset($gblLogin)) {
1679                  $perm = check_trustee($gblLogin,$path);                  $perm = check_trustee("anonymous","/");
1680                  // browsing must be explicitly allowed for root directory                  // browsing must be explicitly allowed for root directory
1681                  // of repository for anonymous user to work!                  // of repository for anonymous user to work!
1682                  if ($perm[allow] & trperm_b) {                  if ($perm['allow'] & trperm_b) {
1683                            $gblLogin = $gblPasswd = "anonymous";
1684                          $secHash = md5($gblLogin.$gblPasswd);                          $secHash = md5($gblLogin.$gblPasswd);
1685                          $gblUserName = "Anonymous user";                          $gblUserName = "Anonymous user";
1686                  }                  }
# Line 1506  print " return: $return<br>\n"; Line 1691  print " return: $return<br>\n";
1691                  isset($relogin) && $secHash == $relogin) {                  isset($relogin) && $secHash == $relogin) {
1692                  header("WWW-authenticate: basic realm=\"$realm\"") ;                  header("WWW-authenticate: basic realm=\"$realm\"") ;
1693                  header("HTTP/1.0 401 Unauthorized") ;                  header("HTTP/1.0 401 Unauthorized") ;
1694                  Error("401 Unauthorized","No trespassing !");                  Error("401 Unauthorized","No trespassing !",0,1);
                 exit ;  
1695          }          }
1696    
         // get current directory relative to $gblFsRoot  
         $relDir = $DIR ;        // from POST  
         if ($relDir == "") {    // not defined in POST ?  
                 $relDir = urldecode($D) ;  // then use GET  
         }        
1697    
1698          $relDir=stripSlashes($relDir);          // read mime.types
1699            readMime();
1700    
1701          if ($relDir == "/") $relDir = "" ;        HTTP_POST_VAR("FN");
         // default : website root = ""  
1702    
1703          if (strstr($relDir,"..")) Error("No updirs allowed");          if ($HTTP_SERVER_VARS["REQUEST_METHOD"] == "POST") {
1704                    // take variables from server
1705          // full paths contain "fs" or "Fs". Paths realitve to root of                  if (HTTP_POST_VAR("FN"))
1706          // website contain "rel" or "Rel". The script won't let you                          check_filename($FN);
1707          // edit anything above directory equal to http://server.com                  if (HTTP_POST_VAR("DIR")) {
1708          // i.e. below $gblFsRoot.                          check_dirname($DIR);
1709                            $relDir = $DIR;
1710                    } else {
1711                            trigger_error("Can't get DIR",E_USER_WARNING);
1712                            $relDir = "/";
1713                    }
1714                    if (HTTP_POST_VAR("RELPATH")) check_dirname($RELPATH);
1715                    HTTP_POST_VAR("T");
1716                    HTTP_POST_VAR("CONFIRM");
1717            } else {
1718                    // get
1719                    HTTP_GET_VAR("A");
1720                    if (HTTP_GET_VAR("D")) {
1721                            check_dirname($D);
1722                            $D=urldecode($D);
1723                            $relDir = $D;
1724                    } else {
1725                            //trigger_error("Can't get D",E_USER_WARNING);
1726                            $relDir = "/";
1727                    }
1728                    if (HTTP_GET_VAR("F")) check_filename($F);
1729            }
1730    
1731          $relScriptDir = dirname($SCRIPT_NAME) ;                  $relScriptDir = dirname($HTTP_SERVER_VARS["SCRIPT_NAME"]) ;    
1732          // i.e. /docman          // i.e. /docman
1733    
1734          // start on server root          // start on server root
1735          $gblFsRoot = $gblRepositoryDir;          $gblFsRoot = $gblRepositoryDir;
1736          // i.e. /home/httpd/html          // i.e. /home/httpd/repository
1737    
1738          $fsDir = $gblFsRoot . $relDir ; // current directory          $fsDir = $gblFsRoot . $relDir ; // current directory
1739          if ( !is_dir($fsDir) ) Error("Dir not found",$relDir) ;          if ( !is_dir($fsDir) ) Error("Dir not found","Can't find <tt>$relDir</tt> which points to <tt>$fsDir</tt>",1) ;
1740    
1741            if ($relDir == "") $relDir="/";
1742    
1743          if (isset($GLOBALS["HTTPS"]) && $GLOBALS["HTTPS"] == "on") {          if (isset($HTTP_SERVER_VARS["HTTPS"]) && $HTTP_SERVER_VARS["HTTPS"] == "on") {
1744                  $webRoot  = "https://";                  $webRoot  = "https://";
1745          } else {          } else {
1746                  $webRoot  = "http://";                  $webRoot  = "http://";
1747          }          }
1748          $webRoot .= $GLOBALS["HTTP_HOST"] . $relScriptDir;          $webRoot .= $HTTP_SERVER_VARS["HTTP_HOST"] . $relScriptDir;
1749    
1750          $FN=stripSlashes($FN);          if (HTTP_POST_VAR("POSTACTION")) switch ($POSTACTION) {
   
         switch ($POSTACTION) {  
1751          case "UPLOAD" :          case "UPLOAD" :
1752                    $FN_name=stripSlashes($HTTP_POST_FILES["FN"]["tmp_name"]);
1753                    $FN=stripSlashes($HTTP_POST_FILES["FN"]["name"]);
1754                  if (!is_writeable($fsDir)) Error("Write denied",$relDir) ;                  if (!is_writeable($fsDir)) Error("Write denied",$relDir) ;
1755                  if (strstr($FN_name,"/"))  
1756                          Error("Non-conforming filename") ;                  $source = $FN_name ;
                 // TODO : should rather check for escapeshellcmds  
                 // but maybe RFC 18xx asserts safe filenames ....  
                 $source = $FN ;  
1757                  if (! file_exists($source)) {                  if (! file_exists($source)) {
1758                          Error("You must select file with browse to upload it!");                          Error("You must select file with browse to upload it!");
1759                  }                  }
1760    
1761                    if (HTTP_POST_VAR("FILENAME")) check_filename($FILENAME);
1762    
1763                  if (! isset($FILENAME)) {       // from update file                  if (! isset($FILENAME)) {       // from update file
1764                          $target = "$fsDir/$FN_name" ;                          $target = "$fsDir/".basename($FN);
1765                  } else {                  } else {
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 1581  print " return: $return<br>\n"; Line 1786  print " return: $return<br>\n";
1786                  copy($source,$target) ;                  copy($source,$target) ;
1787                  chmod($target,$gblFilePerms) ;                  chmod($target,$gblFilePerms) ;
1788                  clearstatcache() ;                  clearstatcache() ;
                 Logit($target,"uploaded");  
1789                  if (isset($FILENAME)) {                  if (isset($FILENAME)) {
1790                            LogIt($target,"check-in",trperm_r | trperm_w);
1791                          Unlock($target);                          Unlock($target);
1792                    } else {
1793                            LogIt($target,"uploaded",trperm_r | trperm_w);
1794                  }                  }
                 ChangeLog($target,"updated");  
1795                  break ;                  break ;
1796    
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() ;
1815                  Logit($path,"saved changes");                  LogIt($path,"saved changes",trperm_r);
                 ChangeLog($path,"saved changes");  
1816                  break ;                  break ;
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) )
1835                                  Error("Mkdir failed",$relPath) ; // eg. if it exists                                  Error("Mkdir failed",$relPath) ; // eg. if it exists
1836                            else
1837                                    LogIt($path."/","dir created",trperm_w);
1838                          clearstatcache() ;                          clearstatcache() ;
1839                          break ;                          break ;
1840                  case "F" :  // create a new file                  case "F" :  // create a new file
# Line 1623  print " return: $return<br>\n"; Line 1842  print " return: $return<br>\n";
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");                                  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) ;
                         ChangeLog($target,"created");  
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                                  Error("File delete failed", $tstr . $path) ;                  $dir=dirname($path);
1879                                  Logit($path,"file delete failed");                  $file=basename($path);
1880                                  exit ;  
1881                          } else {                  if (! file_exists("$dir/.del")) {
1882                                  Logit($path,"file deleted");                          mkdir("$dir/.del",0700);
                                 MoveTo("$dir/.log/$file","$dir/.del/.log/");  
                                 MoveTo("$dir/.note/$file","$dir/.del/.note/");  
                                 MoveTo("$dir/.lock/$file","$dir/.del/.lock/");  
                         }  
1883                  }                  }
1884                  else {  // delete directory  
1885                    if ( ! @rrmdir($fsDir) ) {                  if ( ! @rename($path,"$dir/.del/$file") ) {
1886                      Error("Rmdir failed", $tstr . $fsDir) ;                          LogIt($path,"$what delete failed");
1887                    }                          Error("Can't delete $what",$tstr."<tt>".$relDir."/".$FN."</tt>") ;
1888                    else {                  } else {
1889                      $relDir = dirname($relDir) ;  // move up                          LogIt($path,"$what deleted",trperm_w);
1890                    }                          MoveTo("$dir/.log/$file","$dir/.del/.log/");
1891                            MoveTo("$dir/.note/$file","$dir/.del/.note/");
1892                            MoveTo("$dir/.lock/$file","$dir/.del/.lock/");
1893                  }                  }
1894                  break ;                  break ;
1895    
# Line 1682  print " return: $return<br>\n"; Line 1899  print " return: $return<br>\n";
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                  Logit("$fsDir/.del/$file","undeleted");                  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);
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/");
1908                  MoveTo("$fsDir/.del/.note/$file","$fsDir/.note/");                  MoveTo("$fsDir/.del/.note/$file","$fsDir/.note/");
# Line 1693  print " return: $return<br>\n"; Line 1913  print " return: $return<br>\n";
1913          case "RENAME" :            case "RENAME" :  
1914                  if ( $CONFIRM != "on" ) break ;                  if ( $CONFIRM != "on" ) break ;
1915    
1916                  Logit("$fsDir/$FN","renamed $FN to $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);
1925                  safe_rename($fsDir,$FN,$NEWNAME);                  safe_rename($fsDir,$FN,$NEWNAME);
1926                  break ;                  break ;
1927    
1928          case "NOTE" :            case "NOTE" :  
1929                    $NOTE=stripSlashes($HTTP_POST_VARS["NOTE"]);
1930                  WriteNote("$fsDir/$FN","$NOTE");                  WriteNote("$fsDir/$FN","$NOTE");
1931                  break ;                  break ;
1932    
# Line 1711  print " return: $return<br>\n"; Line 1940  print " return: $return<br>\n";
1940          }          }
1941    
1942          // common to all POSTs : redirect to directory view ($relDir)          // common to all POSTs : redirect to directory view ($relDir)
1943          if ( $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                    
# Line 1724  print " return: $return<br>\n"; Line 1953  print " return: $return<br>\n";
1953          // $A=Co : checkout file $D/$F          // $A=Co : checkout file $D/$F
1954          // $A=Ci : checkin file $D/$F          // $A=Ci : checkin file $D/$F
1955          // $A=V : view file (do nothing except log)          // $A=V : view file (do nothing except log)
1956          // $A=I : include file .$F.php from $gblFsRoot          // $A=I : include file .$F.php from [$gblIncDir|realm]/include_php
1957          // default : display directory $D          // default : display directory $D
1958    
1959          switch ($A) {          if (isset($A)) switch ($A) {
1960          case "U" :          case "U" :
1961                  // upload to $relDir                  // upload to $relDir
1962                    if (! check_perm($relDir, trperm_w))
1963                            Error("Write access denied","You don't have permission to write in <tt>$relDir</tt>");
1964                  if (!is_writeable($gblFsRoot . $relDir))                  if (!is_writeable($gblFsRoot . $relDir))
1965                          Error("Write access denied",$relDir) ;                          Error("Write access denied","User <tt>$gblLogin</tt> has permission on <tt>$relDir</tt>, but directory is not writable",1);
1966                  $text  = "Use this page to upload a single " ;                  $text  = "Use this page to upload a single " ;
1967                  $text .= "file to <B>$HTTP_HOST</B>." ;                  $text .= "file to <B>$realm</B>." ;
1968                  StartHTML("(Upload Page)", $text) ;                  StartHTML("(Upload Page)", $text) ;
1969                  UploadPage($gblFsRoot, $relDir) ;                  UploadPage($gblFsRoot, $relDir) ;
1970                  EndHTML() ;                  EndHTML() ;
1971                  exit ;                  exit ;
1972          case "E" :          case "E" :
                 $F=stripSlashes($F);  
1973                  // detail of $relDir/$F                  // detail of $relDir/$F
1974                  if (is_file("$gblFsRoot/$relDir/$F") || is_dir("$gblFsRoot/$relDir/$F")) DetailPage($gblFsRoot, $relDir, $F) ;                  if (is_file("$gblFsRoot/$relDir/$F") || is_dir("$gblFsRoot/$relDir/$F")) DetailPage($gblFsRoot, $relDir, $F) ;
1975                  exit ;                  exit ;
# Line 1751  print " return: $return<br>\n"; Line 1981  print " return: $return<br>\n";
1981          case "Co" :          case "Co" :
1982                  // checkout                  // checkout
1983                  Lock("$gblFsRoot/$relDir/$F");                  Lock("$gblFsRoot/$relDir/$F");
1984                  Download("$gblFsRoot/$relDir/$F");                  Download("$gblFsRoot/$relDir/$F",1);
1985                  exit;                  exit;
1986          case "Ci" :          case "Ci" :
1987                  $F=stripSlashes($F);                  $F=stripSlashes($F);
# Line 1759  print " return: $return<br>\n"; Line 1989  print " return: $return<br>\n";
1989                  if (!is_writeable($gblFsRoot . $relDir))                  if (!is_writeable($gblFsRoot . $relDir))
1990                          Error("Write access denied",$relDir) ;                          Error("Write access denied",$relDir) ;
1991                  $text  = "Use this page to update a single " ;                  $text  = "Use this page to update a single " ;
1992                  $text .= "file to <B>$HTTP_HOST</B>." ;                  $text .= "file to <B>$realm</B>." ;
1993                  StartHTML("(Update file Page)", $text) ;                  StartHTML("(Update file Page)", $text) ;
1994                  UploadPage($gblFsRoot, $relDir, $F) ;                  UploadPage($gblFsRoot, $relDir, $F) ;
1995                  EndHTML() ;                  EndHTML() ;
# Line 1767  print " return: $return<br>\n"; Line 1997  print " return: $return<br>\n";
1997          case "V" :          case "V" :
1998                  // view                  // view
1999                  LogIt("$gblFsRoot/$relDir/$F","viewed");                  LogIt("$gblFsRoot/$relDir/$F","viewed");
2000                  if ($gblForceDownload) {                  Download("$gblFsRoot/$relDir/$F",$gblForceDownload);
                         Download("$gblFsRoot/$relDir/$F");  
                 } else {  
                         header("Content-Disposition: attachment; filename=$F" );  
                         Header("Location: $webRoot".urlpath("$relDir/$F"));  
                 }  
2001                  exit;                  exit;
2002          case "Ch" :          case "Ch" :
2003                  StartHTML("(File changes)","All changes chronologicaly...");                  StartHTML("(File changes)","All changes chronologicaly...");
# Line 1785  print " return: $return<br>\n"; Line 2010  print " return: $return<br>\n";
2010                  EndHTML() ;                  EndHTML() ;
2011                  exit;                  exit;
2012          case "I" :          case "I" :
2013                  $F=stripSlashes($F);                  if (! isset($F) || $F == "")
2014                  $inc_file="${gblFsRoot}/.${F}.php";                          Error("Can't find file to include","Your request didn't specify file to include which should be in variable <tt>F</tt> like <tt>$HTTP_SERVER_VARS[REQUEST_URI]<b>&F=include_php_file</b></tt>",1);
2015                  if (!isset($F) || $F == "" || !file_exists($inc_file)) Error("Fatal error $inc_file"); // can't find file to include                  $inc_file="$fsRealmDir/$realm".$realm_sep.$F.".php";
2016                    if (! file_exists($inc_file)) {
2017                            Error("Can't find file to include","Can't find include file <tt>$F.php</tt> in <tt>$fsRealmDir/$realm/</tt>. Meybe you should copy <tt>$gblIncDir/include_php/$F.php</tt> to <tt>$inc_file<tt> ?",1);
2018                    }
2019                  if (!is_readable($inc_file))                  if (!is_readable($inc_file))
2020                          Error("Read access to include file denied",".${F}.php");                          Error("Read access to include file denied","Can't read PHP include file <tt>$inc_file</tt>. Fix permissions on it.",1);
2021                  $text  = "Your include file should define \$text variable which holds this text and \$title variable which is page title";                  $text  = "Your include file should define \$text variable which holds this text and \$title variable which is page title";
2022                  $title = "You should define \$title variable with page title";                  $title = "You should define \$title variable with page title";
2023                  include($inc_file);                  include($inc_file);
2024                  StartHTML($title, $text) ;                  StartHTML($title, $text) ;
2025                  print "<p>".GifIcon(up)." Back to <a href=$GLOBALS[PHP_SELF]>front page</a>.</p>";                  print "<p>".GifIcon(up)." Back to <a href=$HTTP_SERVER_VARS[PHP_SELF]>front page</a>.</p>";
2026                  EndHTML() ;                  EndHTML() ;
2027                  exit ;                  exit ;
2028          }          }
# Line 1803  print " return: $return<br>\n"; Line 2031  print " return: $return<br>\n";
2031          Navigate($gblFsRoot,$relDir) ;            Navigate($gblFsRoot,$relDir) ;  
2032          exit ;          exit ;
2033    
2034          Error("Whooah!","By cartesian logic, this never happens") ;          Error("Whooah!","By cartesian logic, this never happens",1) ;
2035  ?>  ?>

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

  ViewVC Help
Powered by ViewVC 1.1.26