/[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.26 by dpavlin, Mon Jul 29 10:29:04 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 572  function GifIcon($txt) { Line 581  function GifIcon($txt) {
581  function Navigate($fsRoot,$relDir) {  function Navigate($fsRoot,$relDir) {
582    
583          global $gblEditable, $gblIcon, $gblModDays, $webRoot, $gblHide,          global $gblEditable, $gblIcon, $gblModDays, $webRoot, $gblHide,
584                  $HTTP_GET_VARS, $html;                  $gblIgnoreUnknownFileType, $gblRepositoryDir,
585                    $gblLogin, $gblUserName, $gblDateFmt, $gblTimeFmt,
586                    $fsRealmDir, $realm, $realm_sep,
587                    $html, $realm_config,
588                    $HTTP_GET_VARS, $HTTP_SERVER_VARS;
589            
590            $self     = $HTTP_SERVER_VARS["PHP_SELF"] ;
591    
592          $self     = $GLOBALS["PHP_SELF"] ;          $relDir = chopsl($relDir)."/";
593            $fsDir = $fsRoot.$relDir;       // current directory
594    
595          if ($relDir == "") $relDir = "/";          if (!is_dir($fsDir)) Error("Dir not found","Directory <tt>$relDir<tt> not found on filesystem at <tt>$fsDir</tt>",1) ;
596    
597          $fsDir = $fsRoot.$relDir."/";   // current directory          global $debug;
598            $debug .= "[$gblLogin|$relDir] before >";
599    
600          if (!is_dir($fsDir)) Error("Dir not found",$relDir) ;          if (! check_perm($relDir,trperm_b))
601                    Error("Access denied","User <tt>$gblLogin</tt> tried to access <tt>$relDir</tt> without valid trustee.",1);
602            $debug .= "< afeter";
603    
604          $hide_items=",$gblHide,";          $hide_items=",$gblHide,";
605    
606  #display_all_trustee();          $dirList = array();
607  print "-- $fsDir --";          $fileList = array();
608    
609          // read directory contents          // read directory contents
610          if ( !($dir = @opendir($fsDir)) )          if ( !($dir = @opendir($fsDir)) )
611                  Error("Read Access denied",$relDir) ;                  Error("Read Access denied",$relDir,1) ;
612          while ($item = readdir($dir)) {          while ($item = readdir($dir)) {
 print "$item, ";  
613                  if ( substr($item,0,1) == "." || strstr($hide_items,",$item,") ) continue ;                  if ( substr($item,0,1) == "." || strstr($hide_items,",$item,") ) continue ;
614                  if ((is_dir($fsDir.$item) || is_link ($fsDir.$item)) && check_perm($relDir.$item,trperm_b)) {                  if (is_dir($fsDir.$item) || is_link ($fsDir.$item)) {
615                          $dirList[$item] = $item ;                          if (check_perm($relDir.$item,trperm_b)) {
616                          $dirNote[$item] = ReadNote($fsDir.$item);                                  $dirList[$item] = $item ;
617                  } else if ( is_file($fsDir.$item) && check_perm($relDir.$item,trperm_r) ) {                                  $dirNote[$item] = ReadNote($fsDir.$item);
618                          $fileList[$item] = $item ;                                        }
619                          $fileDate[$item] = filemtime($fsDir.$item) ;                  } else if (is_file($fsDir.$item)) {
620                          $fileSize[$item] = filesize($fsDir.$item) ;                          if (check_perm($relDir.$item,trperm_r)) {
621                          $fileNote[$item] = ReadNote($fsDir.$item);                                  $fileList[$item] = $item ;              
622                                    $fileDate[$item] = filemtime($fsDir.$item) ;
623                                    $fileSize[$item] = filesize($fsDir.$item) ;
624                                    $fileNote[$item] = ReadNote($fsDir.$item);
625                            }
626                  } else {                  } else {
627                    // 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 ;  
628                  }                  }
629          }          }
630          closedir($dir) ;          closedir($dir) ;
631    
632          // scan deleted files          // scan deleted files
633          if ( $GLOBALS[show_deleted] == 1 && ($dir = @opendir("$fsDir/.del")) ) {          if ( HTTP_GET_VAR("show_deleted") == 1 && ($dir = @opendir("$fsDir/.del")) ) {
634                  while ($item = readdir($dir)) {                  while ($item = readdir($dir)) {
635                          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 ;
636                          $fileList[$item] = ".del/$item" ;                                        if (is_file($fsDir.".del/$item")) {
637                          $fileDate[$item] = filemtime($fsDir.".del/$path") ;                                  $fileList[$item] = ".del/$item" ;              
638                          $fileSize[$item] = filesize($fsDir.".del/$path") ;                                  $fileDate[$item] = filemtime($fsDir.".del/$item") ;
639                          $fileNote[$item] = ReadNote($fsDir.".del/$item");                                  $fileSize[$item] = filesize($fsDir.".del/$item") ;
640                                    $fileNote[$item] = ReadNote($fsDir.".del/$item");
641                            } else {
642                                    $dirList[$item] = ".del/$item" ;                
643                                    $dirNote[$item] = ReadNote($fsDir.".del/$item");
644                            }
645                  }                  }
646                  closedir($dir) ;                  closedir($dir) ;
647          }          }
# Line 626  print "$item, "; Line 650  print "$item, ";
650    
651          // start navigation page          // start navigation page
652          $text  = "Use this page to add, delete";          $text  = "Use this page to add, delete";
653          if (! isset($show_deleted)) {          if (! isset($HTTP_GET_VARS["show_deleted"])) {
654                  $text .= ", <a href=$self?D=".urlencode($relDir)."&show_deleted=1>undelete</a>";                  $text .= ", <a href=$self?D=".urlencode($relDir)."&show_deleted=1>undelete</a>";
655          }          }
656          $text .= " or revise files on this web site." ;          $text .= " or revise files on this web site." ;
# Line 636  print "$item, "; Line 660  print "$item, ";
660          echo "<TABLE BORDER=0 CELLPADDING=2          echo "<TABLE BORDER=0 CELLPADDING=2
661                  CELLSPACING=3 WIDTH=\"100%\">" ;                  CELLSPACING=3 WIDTH=\"100%\">" ;
662    
663          // updir bar              // updir (parent) bar  
664          if (chopsl($fsDir) != chopsl($fsRoot)) {          if (chopsl($fsDir) != chopsl($fsRoot)) {
665                  $parent = dirname($relDir) ;                  $parent = dirname($relDir) ;
666                  if ($parent == "") $parent = "/" ;                  if ($parent == "") $parent = "/" ;
# Line 652  print "$item, "; Line 676  print "$item, ";
676                  return $out;                  return $out;
677          }          }
678    
679          $dsort = $HTTP_GET_VARS[dsort];          if (! HTTP_GET_VAR("dsort")) $dsort = "name"; // default directory sort
         if (! isset($dsort)) $dsort = "name";   // default directory sort  
680    
681          $dsort_arr = array(          $dsort_arr = array(
682                  "name" => array ("rname", "note"),                  "name" => array ("rname", "note"),
# Line 662  print "$item, "; Line 685  print "$item, ";
685                  "rnote" => array ("name", "note")                  "rnote" => array ("name", "note")
686                  );                  );
687    
688          $fsort = $HTTP_GET_VARS[fsort];          if (! HTTP_GET_VAR("fsort")) $fsort = "name"; // default directory sort
         if (! isset($fsort)) $fsort = "name";   // default directory sort  
689    
690          $fsort_arr = array(          $fsort_arr = array(
691                  "name" => array ("rname", "note", "date", "size"),                  "name" => array ("rname", "note", "date", "size"),
# Line 679  print "$item, "; Line 701  print "$item, ";
701          $D="D=".urlencode($relDir);          $D="D=".urlencode($relDir);
702    
703          function self_args($arr = array()) {          function self_args($arr = array()) {
704                    global $self;
705                  $arg = implode("&",$arr);                  $arg = implode("&",$arr);
706                  if ($arg) {                  if ($arg) {
707                          return $self."?".$arg;                          return $self."?".$arg;
# Line 715  print "$item, "; Line 738  print "$item, ";
738    
739                          $dir = $dirList[$key];                          $dir = $dirList[$key];
740    
741                          $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));
742                          $dir_url=$self."?D=".urlencode($relDir.$dir);                          if (substr($dir,0,5) == ".del/") {
743                                    $dir = substr($dir,5,strlen($dir)-5);
744                                    $deleted = " <a href=\"$info_url#undelete\"><SPAN CLASS=deleted TITLE=\"deleted\">deleted</span></a>";
745                            } else {
746                                    $deleted = "";
747                            }
748            
749                            $dir_url=$self."?D=".urlencode(chopsl($relDir)."/".$dir);
750                          include("$html/Navigate-dirEntry.html");                          include("$html/Navigate-dirEntry.html");
751    
752                  }  // iterate over dirs                  }  // iterate over dirs
# Line 788  print "$item, "; Line 818  print "$item, ";
818    
819                  $file_lock=CheckLock($path);                  $file_lock=CheckLock($path);
820    
821                  $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);  
822                  $file_url_html.="\" TITLE=\"View file\">" ;                  $file_url_html.="\" TITLE=\"View file\">" ;
823    
824                  if (substr($file,0,5) != ".del/") {                  if (substr($file,0,5) != ".del/") {
825                          $file_url_html .= $file . "</A>" . $a ;                          $file_url_html .= $file . "</A>" . $a ;
826                  } else {                  } else {
827                          $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>";
828                  }                  }
829    
830                  $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 832  print "$item, ";
832                  $ext = strtolower(strrchr($file,".")) ;                  $ext = strtolower(strrchr($file,".")) ;
833    
834                  if ($file_lock) {                  if ($file_lock) {
835                          if ($file_lock == $GLOBALS[gblUserName]) {                          if ($file_lock == $gblUserName) {
836                                  $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);  
837                                  $b.="\" TITLE=\"Checkin (update) file on server\">" ;                                  $b.="\" TITLE=\"Checkin (update) file on server\">" ;
838                                  $file_url_html=$b;                                  $file_url_html=$b;
839                                  $b.=$gblIcon("checkin")."</A>" ;                                  $b.=$gblIcon("checkin")."</A>" ;
# Line 819  print "$item, "; Line 847  print "$item, ";
847                                  $file_url_html = "$file $a";                                  $file_url_html = "$file $a";
848                          }                          }
849                  } else {                  } else {
850                          $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);  
851                          $b.="\" TITLE=\"Checkout file for edit\">" ;                          $b.="\" TITLE=\"Checkout file for edit\">" ;
852                          $b.=$gblIcon("checkout")."</A>" ;                          $b.=$gblIcon("checkout")."</A>";
853    
854                          if ( $ext=="" || strstr(join(" ",$gblEditable),$ext) ) {                            if ( $ext=="" || strstr(join(" ",$gblEditable),$ext) ) {  
855                                  $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);  
856                                  $b.="\" TITLE=\"List contents\">" ;                                  $b.="\" TITLE=\"List contents\">" ;
857                                  $b.=$gblIcon("view")."</A>" ;                                  $b.=$gblIcon("view")."</A>" ;
858                          } else {                          } else {
# Line 834  print "$item, "; Line 860  print "$item, ";
860                          }                          }
861                  }                  }
862    
863                  $mod = date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]",$mod);                  $mod = date("$gblDateFmt $gblTimeFmt",$mod);
864    
865                  include("$html/Navigate-fileEntry.html");                  include("$html/Navigate-fileEntry.html");
866    
# Line 866  print "$item, "; Line 892  print "$item, ";
892  <TR><TD></TD><TD COLSPAN=5><HR></TD></TR>  <TR><TD></TD><TD COLSPAN=5><HR></TD></TR>
893    
894  <?  <?
895  if (file_exists(".info.inc")) {  
896    if (file_exists("$fsRealmDir/$realm".$realm_sep."info.inc")) {
897          print "<TR><TD></TD><TD COLSPAN=5>";          print "<TR><TD></TD><TD COLSPAN=5>";
898          include(".info.inc");          include("$fsRealmDir/$realm".$realm_sep."info.inc");
899          print "</TD></TR>          print "</TD></TR><TR><TD></TD><TD COLSPAN=5><HR></TD></TR>";
900          <TR><TD></TD><TD COLSPAN=5><HR></TD></TR>";  } elseif (file_exists("$gblRepositoryDir/.info.inc")) {
901            print "<TR><TD></TD><TD COLSPAN=5>";
902            include("$gblRepositoryDir/.info.inc");
903            print "</TD></TR><TR><TD></TD><TD COLSPAN=5><HR></TD></TR>";
904  }  }
905    
906    
907  ?>  ?>
908    
909  <FORM METHOD="POST" ACTION="<?= $self ?>">  <FORM METHOD="POST" ACTION="<?= $self ?>">
# Line 896  if (file_exists(".info.inc")) { Line 928  if (file_exists(".info.inc")) {
928    
929  function UploadPage($fsRoot, $relDir, $filename="") {  function UploadPage($fsRoot, $relDir, $filename="") {
930    
931          $self = $GLOBALS["PHP_SELF"] ;          global $html, $HTTP_SERVER_VARS;
         if ($relDir == "") $relDir = "/" ;  
 ?>  
932    
933  <P><TABLE BORDER=0 CELLPADDING=5><TR><TD WIDTH=5></TD><TD CLASS=BAR>          $self = $HTTP_SERVER_VARS["PHP_SELF"] ;
934  <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>  
935    
 <?php    
936  } // end function UploadPage  } // end function UploadPage
937    
938  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
939    
940  function Error($title,$text="") {  // Error with sysadmin flag are reported to error_log or hidden from
941          StartHTML("(".$title.")",$text) ;  // users
942          echo "<P ALIGN=center>Hit your Browser's Back Button.</P>" ;  
943          EndHTML() ;  function Error($title,$text="",$sysadmin=0,$no_404=0) {
944            global $gblSeparateAdminMessages,
945                    $gblMailAdminMessages,$realm,
946                    $HTTP_SERVER_VARS;
947            if (! headers_sent() && ! $no_404) header("HTTP/1.0 404 Not Found");
948            if ($sysadmin) {
949                    if ($gblSeparateAdminMessages) {
950                            $user="Your administrator ";
951                            if ($gblMailAdminMessages) {
952                                    mail($HTTP_SERVER_VARS["SERVER_ADMIN"], "docman $realm error message: $title", strip_tags($text));
953                                    $user.="<tt>".$HTTP_SERVER_VARS["SERVER_ADMIN"]."</tt> ";
954                            }
955                            $user.="has been notified about error" ;
956                            StartHTML("($title)",$user);
957                            echo "<P ALIGN=center>Hit your Browser's Back Button.</P>" ;
958                            EndHTML();
959                            error_log("docman $realm: ".strip_tags($text));
960                    } else {
961                            StartHTML("ADMIN: ".$title,$text) ;
962                            echo "<P ALIGN=center>Hit your Browser's Back Button.</P>" ;
963                            EndHTML();
964                    }
965            } else {
966                    StartHTML("(".$title.")",$text) ;
967                    echo "<P ALIGN=center>Hit your Browser's Back Button.</P>" ;
968                    EndHTML() ;
969            }
970          exit ;          exit ;
971  } // end function Error  } // end function Error
972    
973  //////////////////////////////////////////////////////////////////  function LogIt($target,$msg, $changelog=0) {
974    
975  function LogIt($target,$msg) {          global $gblDateFmt, $gblTimeFmt, $gblUserName, $gblFsRoot;
976    
977          $dir=dirname($target);          $dir=dirname($target);
978          if (! file_exists($dir."/.log")) {          if (! file_exists($dir."/.log")) {
979                  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);
980          }          }
981          $file=basename($target);          $file=basename($target);
982    
983          $log=fopen("$dir/.log/$file","a+");          $log=fopen("$dir/.log/$file","a+");
984          fputs($log,date("$GLOBALS[gblDateFmt]\t$GLOBALS[gblTimeFmt]").          fputs($log,date("$gblDateFmt\t$gblTimeFmt").
985                  "\t$GLOBALS[gblUserName]\t$msg\n");                  "\t$gblUserName\t$msg\n");
986          fclose($log);          fclose($log);
987    
988            if (! $changelog) return;
989    
990            $log=fopen("$gblFsRoot/.changelog","a+");
991            if (substr($target,0,strlen($gblFsRoot)) == $gblFsRoot)
992                    $target=substr($target,strlen($gblFsRoot),strlen($target)-strlen($gblFsRoot));
993            $msg=str_replace("\t"," ",$msg);
994            fputs($log,time()."\t$target\t$gblUserName\t$msg\n");
995            fclose($log);
996    
997            // FIX: implement e-mail notification based on $changelog
998            // permission
999  }  }
1000    
1001    
# Line 970  function WriteNote($target,$msg) { Line 1014  function WriteNote($target,$msg) {
1014          fputs($note,"$msg\n");          fputs($note,"$msg\n");
1015          fclose($note);          fclose($note);
1016    
1017          Logit($target,"added note $msg");          LogIt($target,"added note $msg");
1018    
1019  }  }
1020    
# Line 1007  function MoveTo($source,$folder) { Line 1051  function MoveTo($source,$folder) {
1051    
1052  function Lock($target) {  function Lock($target) {
1053    
1054            global $gblUserName;
1055    
1056          $target=stripSlashes($target);          $target=stripSlashes($target);
1057          $dir=dirname($target);          $dir=dirname($target);
1058          if (! file_exists($dir."/.lock")) {          if (! file_exists($dir."/.lock")) {
# Line 1015  function Lock($target) { Line 1061  function Lock($target) {
1061          $file=basename($target);          $file=basename($target);
1062    
1063          if (file_exists("$dir/.lock/$file")) {          if (file_exists("$dir/.lock/$file")) {
1064                  Logit($target,"attempt to locked allready locked file!");                  LogIt($target,"attempt to locked allready locked file!");
1065          } else {          } else {
1066                  $lock=fopen("$dir/.lock/$file","w");                  $lock=fopen("$dir/.lock/$file","w");
1067                  fputs($lock,"$GLOBALS[gblUserName]\n");                  fputs($lock,"$gblUserName\n");
1068                  fclose($lock);                  fclose($lock);
1069    
1070                  Logit($target,"file locked");                  LogIt($target,"file locked");
1071          }          }
1072    
1073  }  }
# Line 1048  function Unlock($target) { Line 1094  function Unlock($target) {
1094          $file=basename($target);          $file=basename($target);
1095          if (file_exists($dir."/.lock/$file")) {          if (file_exists($dir."/.lock/$file")) {
1096                  unlink("$dir/.lock/$file");                  unlink("$dir/.lock/$file");
1097                  Logit($target,"file unlocked");                  LogIt($target,"file unlocked");
1098          } else {          } else {
1099                  Logit($target,"attempt to unlocked non-locked file!");                  LogIt($target,"attempt to unlocked non-locked file!");
1100          }          }
1101    
1102  }  }
# Line 1067  function urlpath($url) { Line 1113  function urlpath($url) {
1113  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
1114    
1115  function safe_rename($fromdir,$fromfile,$tofile) {  function safe_rename($fromdir,$fromfile,$tofile) {
1116    
1117            global $gblNumBackups;
1118    
1119          function try_rename($from,$to) {          function try_rename($from,$to) {
1120  #               print "$from -> $to\n";  #               print "$from -> $to\n";
1121                  if (file_exists($from) && is_writeable(dirname($to))) {                  if (file_exists($from) && is_writeable(dirname($to))) {
1122                          rename($from,$to);                          return rename($from,$to);
1123                    } else {
1124                            return 0;
1125                  }                  }
1126          }          }
1127    
1128          function try_dir($todir) {          function try_dir($todir) {
1129                  if (! file_exists($todir)) {                  if (! file_exists($todir)) {
1130                          mkdir($todir,0700);                          @mkdir($todir,0700);
1131                  }                  }
1132          }          }
1133    
# Line 1086  function safe_rename($fromdir,$fromfile, Line 1137  function safe_rename($fromdir,$fromfile,
1137    
1138  #       print "<pre>$fromdir / $fromfile -> $todir / $tofile\n\n";  #       print "<pre>$fromdir / $fromfile -> $todir / $tofile\n\n";
1139    
1140          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);
1141          try_dir("$todir/.log");          try_dir("$todir/.log");
1142          try_rename("$fromdir/.log/$fromfile","$todir/.log/$tofile");          try_rename("$fromdir/.log/$fromfile","$todir/.log/$tofile");
1143          try_dir("$todir/.note");          try_dir("$todir/.note");
# Line 1094  function safe_rename($fromdir,$fromfile, Line 1145  function safe_rename($fromdir,$fromfile,
1145          try_dir("$todir/.lock");          try_dir("$todir/.lock");
1146          try_rename("$fromdir/.lock/$fromfile","$todir/.lock/$tofile");          try_rename("$fromdir/.lock/$fromfile","$todir/.lock/$tofile");
1147          try_dir("$todir/.bak");          try_dir("$todir/.bak");
1148          for($i=0;$i<=$GLOBALS[gblNumBackups];$i++) {          for($i=0;$i<=$gblNumBackups;$i++) {
1149                  try_rename("$fromdir/.bak/$i/$fromfile","$todir/.bak/$i/$tofile");                  try_rename("$fromdir/.bak/$i/$fromfile","$todir/.bak/$i/$tofile");
1150          }          }
1151  }  }
# Line 1120  function rrmdir($dir) { Line 1171  function rrmdir($dir) {
1171    
1172  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
1173    
1174  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);  
1175    
1176  }          global $gblFsRoot, $gblDateFmt, $gblTimeFmt,
1177                    $HTTP_SERVER_VARS;
1178    
1179  function DisplayChangeLog($day) {          $self  = $HTTP_SERVER_VARS["PHP_SELF"];
1180    
         global $gblFsRoot;  
1181          if (!file_exists("$gblFsRoot/.changelog")) return;          if (!file_exists("$gblFsRoot/.changelog")) return;
1182          $log=fopen("$gblFsRoot/.changelog","r");          $log=fopen("$gblFsRoot/.changelog","r");
1183          $logarr = array();          $logarr = array();
# Line 1152  function DisplayChangeLog($day) { Line 1195  function DisplayChangeLog($day) {
1195          print "<table border=0 width=100%>\n";          print "<table border=0 width=100%>\n";
1196          while ($e = array_shift($logarr)) {          while ($e = array_shift($logarr)) {
1197                  $cl=$cl1; $cl1=$cl2; $cl2=$cl;                  $cl=$cl1; $cl1=$cl2; $cl2=$cl;
1198                  $date = date("$GLOBALS[gblDateFmt]", $e[0]);                  $date = date($gblDateFmt, $e[0]);
1199                  $time = date("$GLOBALS[gblTimeFmt]", $e[0]);                  $time = date($gblTimeFmt, $e[0]);
1200                  $dir = dirname($e[1]);                  $dir = dirname($e[1]);
1201                  $file = basename($e[1]);                  $file = basename($e[1]);
1202                  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";
1203          }          }
1204          print "</table>";          print "</table>";
1205          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>";
1206  }  }
1207    
1208  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
1209    
1210  function Download($path) {  function Download($path,$force=0) {
1211          global $HTTP_USER_AGENT;          global $HTTP_SERVER_VARS,$mime_type;
1212          $file=basename($path);  
1213            // default transfer-encoding
1214            $encoding = "binary";
1215    
1216            // known transfer encodings
1217            $encoding_ext = array(
1218                    "gz" => "x-gzip",
1219                    "Z" => "x-compress",
1220            );
1221    
1222            $file = basename($path);
1223          $size = filesize($path);          $size = filesize($path);
1224          //header("Content-Type: application/octet-stream");  
1225          header("Content-Type: application/force-download");          $ext_arr = explode(".",$file);
1226          header("Content-Length: $size");          $ext = array_pop($ext_arr);
1227            if (isset($encoding_ext[$ext])) {
1228                    $encoding = $encoding_ext[$ext];
1229                    $ext = array_pop($ext_arr);
1230            }
1231    
1232            if ($force || !isset($mime_type[$ext])) {
1233                    header("Content-Type: application/force-download");
1234            } else {
1235                    header("Content-Type: $mime_type[$ext]");
1236            }
1237    
1238          // IE5.5 just downloads index.php if we don't do this          // IE5.5 just downloads index.php if we don't do this
1239          if(preg_match("/MSIE 5.5/", $HTTP_USER_AGENT)) {          if(preg_match("/MSIE 5.5/", $HTTP_SERVER_VARS["HTTP_USER_AGENT"])) {
1240                  header("Content-Disposition: filename=$file");                  header("Content-Disposition: filename=$file");
1241          } else {          } else {
1242                  header("Content-Disposition: attachment; filename=$file");                  header("Content-Disposition: attachment; filename=$file");
1243          }          }
1244          header("Content-Transfer-Encoding: binary");  
1245            header("Content-Transfer-Encoding: $encoding");
1246          $fh = fopen($path, "r");          $fh = fopen($path, "r");
1247          fpassthru($fh);          fpassthru($fh);
1248  }  }
# Line 1186  function Download($path) { Line 1251  function Download($path) {
1251  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
1252    
1253  function chopsl($path) {  function chopsl($path) {
         if (substr($path,strlen($path)-1,1) == "/") $path=substr($path,0,strlen($path)-1);  
1254          $path=str_replace("//","/",$path);          $path=str_replace("//","/",$path);
1255            if (substr($path,strlen($path)-1,1) == "/") $path=substr($path,0,strlen($path)-1);
1256          return $path;          return $path;
1257  }  }
1258    
# Line 1201  function chopsl($path) { Line 1266  function chopsl($path) {
1266          by Vyacheslav Zavadsky <zavadsky@braysystems.com>          by Vyacheslav Zavadsky <zavadsky@braysystems.com>
1267  */  */
1268    
1269  define(trmask_not,1 << 0);  define('trmask_not',1 << 0);
1270  define(trmask_clear,1 << 1);  define('trmask_clear',1 << 1);
1271  define(trmask_deny,1 << 2);  define('trmask_deny',1 << 2);
1272  define(trmask_one_level,1 << 3);  define('trmask_one_level',1 << 3);
1273  define(trmask_group,1 << 4);  define('trmask_group',1 << 4);
1274    
1275  define(trperm_r,1 << 5);  define('trperm_r',1 << 5);
1276  define(trperm_w,1 << 6);  define('trperm_w',1 << 6);
1277  define(trperm_b,1 << 7);  define('trperm_b',1 << 7);
1278  define(trperm_n,1 << 8);  define('trperm_n',1 << 8);
1279    
1280  $trustee_a2n = array(  $trustee_a2n = array(
1281          '!' => trmask_not,          '!' => trmask_not,
# Line 1258  if (! file_exists($trustee_conf)) { Line 1323  if (! file_exists($trustee_conf)) {
1323          $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";
1324  } elseif (file_exists($trustee_php) && !is_writable($trustee_php)) {  } elseif (file_exists($trustee_php) && !is_writable($trustee_php)) {
1325          $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";
1326  } elseif (1 || filemtime($trustee_conf) >= filemtime($trustee_php)) {  } elseif (@filemtime($trustee_conf) >= @filemtime($trustee_php)) {
1327          $fp_php=@fopen($trustee_php,"w");          $fp_php=@fopen($trustee_php,"w");
1328          fputs($fp_php,"<?php // don't edit by hand!\n");          fputs($fp_php,"<?php // don't edit by hand!\n");
1329    
# Line 1267  if (! file_exists($trustee_conf)) { Line 1332  if (! file_exists($trustee_conf)) {
1332          $groups_arr = array();          $groups_arr = array();
1333          $perm_arr = array();          $perm_arr = array();
1334    
         $error=0;  
   
1335          $tr_arr = array();          $tr_arr = array();
1336    
1337          while (! feof($fp_conf)) {          while (! feof($fp_conf)) {
# Line 1296  if (! file_exists($trustee_conf)) { Line 1359  if (! file_exists($trustee_conf)) {
1359                                                  $error.="trustee error in line '$l' [Unknown modifier '$ch']<br>\n";                                                  $error.="trustee error in line '$l' [Unknown modifier '$ch']<br>\n";
1360                                          }                                          }
1361                                  }                                  }
1362                                  $tr_arr[$path][$user] |= $perm;                                  if (isset($tr_arr[$path][$user])) {
1363                                            $tr_arr[$path][$user] |= $perm;
1364                                    } else {
1365                                            $tr_arr[$path][$user] = $perm;
1366                                    }
1367                          }                          }
1368                  }                  }
1369          }          }
# Line 1335  if (! file_exists($trustee_conf)) { Line 1402  if (! file_exists($trustee_conf)) {
1402          fclose($fp_php);          fclose($fp_php);
1403  }  }
1404    
1405  if ($error) {  if (isset($error)) {
1406          Error("Trustee error",$error);          Error("Trustee error",$error,1);
1407  } else {  } else {
1408          include("$trustee_php");          include_once("$trustee_php");
1409  }  }
1410    
1411  return 1;  return 1;
# Line 1346  return 1; Line 1413  return 1;
1413  }//init_trustee  }//init_trustee
1414    
1415  function in_group($user,$group) {  function in_group($user,$group) {
1416          return in_array($groups[$group],$user);          global $groups;
1417            return in_array($user,$groups[$group]);
1418  }  }
1419    
1420  // helper function  // helper function
1421  function unroll_perm($u,$t,$user,$perm) {  function unroll_perm($u,$t,$perm,$one_level) {
1422          // check user  
1423          if ($t & trmask_not && ($u==$user)) continue;          if ($t & trmask_one_level && !$one_level) return $perm;
         if (!($t & trmask_not) && ($u!=$user)) continue;  
1424    
1425          if ($t & trmask_deny) {          if ($t & trmask_deny) {
1426                  if ($t & trmask_clear) {                  if ($t & trmask_clear) {
1427                          $perm[deny] &= ~$t;                          $perm['deny'] &= ~$t;
1428                  } else {                  } else {
1429                          $perm[deny] |= $t;                          $perm['deny'] |= $t;
1430                  }                  }
1431          } elseif ($t & trmask_clear) {          } elseif ($t & trmask_clear) {
1432                  $perm[allow] &= ~$t;                  $perm['allow'] &= ~$t;
1433          } else {          } else {
1434                  $perm[allow] |= $t;                  $perm['allow'] |= $t;
1435          }          }
1436          return $perm;          return $perm;
1437  }// end of helper function  }// end of helper function
1438    
1439  function check_trustee($user,$path) {  function check_trustee($user,$path) {
1440          global $trustees;          global $trustees,$HAVE_TRUSTEE;
1441          $perm[allow] = 0;          $perm['allow'] = 0;
1442          $perm[deny] = 0;          $perm['deny'] = 0;
1443    
1444            // do we use trustees?
1445            if (! $HAVE_TRUSTEE) return $perm;
1446    
1447            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);
1448    
1449    global $debug;
1450    $debug .= "<br>check_trustee $path ... ";
1451    
1452          $path_arr=explode("/",$path);          $path_arr=explode("/",$path);
1453          $path = "/";          $tmppath = "/";
1454          while (count($path_arr)) {          while (count($path_arr)) {
1455                  if (substr($path,strlen($path)-1,1) != "/") $path.="/";                  $tmppath.=array_shift($path_arr);
1456                  $path.=array_shift($path_arr);  $debug.= ">> $tmppath ";
1457                  $tr = $trustees[$path];  
1458                    if (! isset($trustees[$tmppath])) continue;
1459                    $tr = $trustees[$tmppath];
1460    
1461                    $one_level = (!count($path_arr));
1462    $debug.=" O($one_level) ";
1463    
1464                  if (isset($tr)) {                  if (isset($tr)) {
1465                          // first apply trustee for all                          // first apply trustee for all
1466                          if (isset($tr['*'])) {                          if (isset($tr['*']) && $user!="anonymous") {
1467                                  $perm = unroll_perm($user,$tr['*'],$user, $perm);                                  $perm = unroll_perm($user,$tr['*'],$perm, $one_level);
1468                                  unset($tr['*']);                                  unset($tr['*']);
1469                          }                          }
1470                          // then apply group policies                          // then apply not and group policies
1471                          foreach ($tr as $u=>$t) {                          foreach ($tr as $g=>$t) {
1472                                  if ($t & trmask_group && in_group($user,$u)) {                                  if ($t & trmask_not && $g != $user) {
1473                                            $t = $t & ~trmask_not;
1474                                            $perm = unroll_perm($user,$t,$perm, $one_level);
1475                                            unset($tr[$g]);
1476    
1477                                    } elseif ($t & trmask_group && in_group($user,$g)) {
1478                                          // resolv user                                          // resolv user
1479                                          $t = $t & ~trmask_group;                                          $t = $t & ~trmask_group;
1480                                          $u = $user;                                          $perm = unroll_perm($user,$t,$perm, $one_level);
1481                                          $perm = unroll_perm($u,$t,$user, $perm);                                          unset($tr[$g]);
                                         unset($tr[$u]);  
1482                                  }                                  }
1483                          }                          }
1484                          // then apply use policy                          // then apply user policy
1485                          if (isset($tr[$user])) {                          if (isset($tr[$user])) {
1486                                  $perm = unroll_perm($user,$tr[$user],$user, $perm);                                  $perm = unroll_perm($user,$tr[$user],$perm,$one_level);
1487                                  unset($tr[$user]);                                  unset($tr[$user]);
1488                          }                          }
   
1489                  }                  }
1490    $debug.="d(".display_trustee($perm['deny']).") a(".display_trustee($perm['allow']).") ";
1491    
1492          }          }
1493  #print "<br>user: $user path: $path perm: ";  $debug.="<br>check_trustee: user: $user path: $path==$tmppath perm: ";
1494  #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";
1495          return $perm;          return $perm;
1496  }  }
1497    
# Line 1414  function check_trustee($user,$path) { Line 1499  function check_trustee($user,$path) {
1499    
1500  function check_perm($path,$trperm) {  function check_perm($path,$trperm) {
1501          global $gblLogin,$HAVE_TRUSTEE;          global $gblLogin,$HAVE_TRUSTEE;
1502  print "<br>check_perm: <tt>$path</tt> test perm ".display_trustee($perm)."<br>\n";  
1503            global $debug;
1504    $debug.="<br>check_perm: on <tt>$path</tt> for perm ".display_trustee($trperm)."<br>\n";
1505    
1506          $return = ! $HAVE_TRUSTEE;          $return = ! $HAVE_TRUSTEE;
1507          if ($HAVE_TRUSTEE) {          if ($HAVE_TRUSTEE) {
1508                  $perm = check_trustee($gblLogin,$path);                  $perm = check_trustee($gblLogin,$path);
1509  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).")";
1510                  if ($perm[deny] & $trperm) $return=0;                  if ($perm['deny'] & $trperm) $return=0;
1511                  elseif ($perm[allow] & $trperm) $return=1;                  elseif (($perm['allow'] & $trperm) == $trperm) $return=1;
1512          }          }
1513  print " return: $return<br>\n";  $debug.=" return: $return<br>\n";
1514          return($return);          return($return);
1515  }  }
1516    
1517    //////////////////////////////////////////////////////////////////
1518    
1519    function readMime() {
1520            global $mime_type;
1521    
1522            if (! isset($gblMimeTypes)) {
1523                    $gblMimeTypes = "/etc/mime.types";
1524            }
1525    
1526            $mime = @fopen($gblMimeTypes,"r");
1527    
1528            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>");
1529    
1530            while($line = fgets($mime,80)) {
1531                    if (substr($line,0,1) == "#") continue; // skip comment
1532                    $arr = preg_split("/[\s\t]+/",$line);
1533                    $type = array_shift($arr);
1534                    while ($ext = array_shift($arr)) {
1535                            $mime_type[$ext] = $type;
1536                    }
1537            }
1538    
1539            fclose($mime);
1540    }
1541    
1542    //////////////////////////////////////////////////////////////////
1543    
1544    // check for invalid characters in filename and dirname (.. and /)
1545    
1546    function check_dirname($file) {
1547            if (strstr($file,"..")) Error("Security violation","No parent dir <tt>..</tt> allowed in directory name <tt>$file</tt>",1);
1548    }
1549    
1550    function check_filename($file) {
1551            if (strstr($file,"..")) Error("Security violation","No parent dir <tt>..</tt> allowed in file name <tt>$file</tt>",1);
1552            // remove deleted directory (for undelete to work)
1553            $file = str_replace(".del/","",$file);
1554            if (strstr($file,"/")) Error("Security violation","No slashes <tt>/</tt> allowed in file name <tt>$file</tt>",1);
1555    }
1556    
1557    //////////////////////////////////////////////////////////////////
1558    
1559    // functions to move HTTP server variables to global namespace
1560    // [replacement for register_globals in php.ini]
1561    
1562    function HTTP_GET_VAR($var) {
1563            global $HTTP_GET_VARS, ${$var};
1564            if (isset($HTTP_GET_VARS[$var])) {
1565                    $$var = stripSlashes($HTTP_GET_VARS[$var]);
1566                    return $$var;
1567            }
1568    }
1569    
1570    function HTTP_POST_VAR($var) {
1571            global $HTTP_POST_VARS, ${$var};
1572            if (isset($HTTP_POST_VARS[$var])) {
1573                    $$var = $HTTP_POST_VARS[$var];
1574                    return $$var;
1575            }
1576    }
1577    
1578    function HTTP_SERVER_VAR($var) {
1579            global $HTTP_SERVER_VARS, ${$var};
1580            if (isset($HTTP_SERVER_VARS[$var])) {
1581                    $$var = $HTTP_SERVER_VARS[$var];
1582                    return $$var;
1583            }
1584    }
1585    
1586    //////////////////////////////////////////////////////////////////
1587    
1588    function Warn($text) {
1589    }
1590    
1591  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
1592  // MAIN PROGRAM  // MAIN PROGRAM
# Line 1433  print " return: $return<br>\n"; Line 1594  print " return: $return<br>\n";
1594          $gblFilePerms = 0640 ;         // default for new files          $gblFilePerms = 0640 ;         // default for new files
1595          $gblDirPerms  = 0750 ;          // default for new dirs          $gblDirPerms  = 0750 ;          // default for new dirs
1596    
1597          if (isset($STYLE) && $STYLE == "get") {          if (isset($HTTP_GET_VARS["STYLE"]) && $HTTP_GET_VARS["STYLE"] == "get") {
1598                  include("$html/docman.css");                  include("$html/docman.css");
1599                  exit;                  exit;
1600          }          }
# Line 1441  print " return: $return<br>\n"; Line 1602  print " return: $return<br>\n";
1602          // location of master docman configuration file          // location of master docman configuration file
1603          $docman_conf = "/etc/docman.conf";          $docman_conf = "/etc/docman.conf";
1604          if (! file_exists($docman_conf)) {          if (! file_exists($docman_conf)) {
1605                  $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";
1606                                    
1607                  error_log("docman: $error");                  error_log("docman: $error");
1608                  Error("docman not installed completly",$error);                  Error("docman not installed completly",$error);
# Line 1451  print " return: $return<br>\n"; Line 1612  print " return: $return<br>\n";
1612          if (! isset($fsRealmDir)) {          if (! isset($fsRealmDir)) {
1613                  $fsRealmDir = "$gblIncDir/realm";                  $fsRealmDir = "$gblIncDir/realm";
1614          }          }
1615          $realm_config = "$fsRealmDir/$realm.conf";  
1616            // try to add dir to script name to realm var
1617            if (is_dir("$fsRealmDir/$realm/".dirname($HTTP_SERVER_VARS["SCRIPT_NAME"]))) {
1618                    $realm .= dirname($HTTP_SERVER_VARS["SCRIPT_NAME"]);
1619                    $realm_sep = "/";
1620            } else {
1621                    $realm_sep = ".";
1622            }
1623    
1624            $realm_config = $fsRealmDir."/".$realm.$realm_sep."conf";
1625    
1626          // read user-defined configuration          // read user-defined configuration
1627          if (file_exists($realm_config)) {          if (file_exists($realm_config)) {
# Line 1469  print " return: $return<br>\n"; Line 1639  print " return: $return<br>\n";
1639                  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>");
1640          }          }
1641    
1642            // take additional login vars
1643            HTTP_GET_VAR("relogin");
1644            HTTP_GET_VAR("force_login");
1645    
1646          // if no password, or empty password logout          // if no password, or empty password logout
1647          if (          if (
1648                  isset($gblLogin) && (                  isset($gblLogin) && (
# Line 1484  print " return: $return<br>\n"; Line 1658  print " return: $return<br>\n";
1658                  exit ;                  exit ;
1659          }          }
1660    
1661            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);
1662    
1663          // trustee (ACL) file configuration          // trustee (ACL) file configuration
1664          $trustee_conf="$gblIncDir/realm/$realm.trustee";          $trustee_conf="$fsRealmDir/$realm".$realm_sep."trustee";
1665          // compiled version of trustee file          // compiled version of trustee file
1666          $trustee_php="$gblRepositoryDir/.trustee.php";          $trustee_php="$gblRepositoryDir/.trustee.php";
1667          // get ACL informations          // get ACL informations
1668          $HAVE_TRUSTEE = init_trustee();          $HAVE_TRUSTEE = init_trustee();
1669    
1670          if (strtolower($gblLogin) == "anonymous" || !isset($gblPasswd)) {          if (strtolower($gblLogin) == "anonymous" || !isset($gblLogin)) {
1671                  $perm = check_trustee($gblLogin,$path);                  $perm = check_trustee("anonymous","/");
1672                  // browsing must be explicitly allowed for root directory                  // browsing must be explicitly allowed for root directory
1673                  // of repository for anonymous user to work!                  // of repository for anonymous user to work!
1674                  if ($perm[allow] & trperm_b) {                  if ($perm['allow'] & trperm_b) {
1675                            $gblLogin = $gblPasswd = "anonymous";
1676                          $secHash = md5($gblLogin.$gblPasswd);                          $secHash = md5($gblLogin.$gblPasswd);
1677                          $gblUserName = "Anonymous user";                          $gblUserName = "Anonymous user";
1678                  }                  }
# Line 1506  print " return: $return<br>\n"; Line 1683  print " return: $return<br>\n";
1683                  isset($relogin) && $secHash == $relogin) {                  isset($relogin) && $secHash == $relogin) {
1684                  header("WWW-authenticate: basic realm=\"$realm\"") ;                  header("WWW-authenticate: basic realm=\"$realm\"") ;
1685                  header("HTTP/1.0 401 Unauthorized") ;                  header("HTTP/1.0 401 Unauthorized") ;
1686                  Error("401 Unauthorized","No trespassing !");                  Error("401 Unauthorized","No trespassing !",0,1);
                 exit ;  
1687          }          }
1688    
         // get current directory relative to $gblFsRoot  
         $relDir = $DIR ;        // from POST  
         if ($relDir == "") {    // not defined in POST ?  
                 $relDir = urldecode($D) ;  // then use GET  
         }        
1689    
1690          $relDir=stripSlashes($relDir);          // read mime.types
1691            readMime();
1692    
1693          if ($relDir == "/") $relDir = "" ;        HTTP_POST_VAR("FN");
         // default : website root = ""  
1694    
1695          if (strstr($relDir,"..")) Error("No updirs allowed");          if ($HTTP_SERVER_VARS["REQUEST_METHOD"] == "POST") {
1696                    // take variables from server
1697          // full paths contain "fs" or "Fs". Paths realitve to root of                  if (HTTP_POST_VAR("FN"))
1698          // website contain "rel" or "Rel". The script won't let you                          check_filename($FN);
1699          // edit anything above directory equal to http://server.com                  if (HTTP_POST_VAR("DIR")) {
1700          // i.e. below $gblFsRoot.                          check_dirname($DIR);
1701                            $relDir = $DIR;
1702                    } else {
1703                            trigger_error("Can't get DIR",E_USER_WARNING);
1704                            $relDir = "/";
1705                    }
1706                    if (HTTP_POST_VAR("RELPATH")) check_dirname($RELPATH);
1707                    HTTP_POST_VAR("T");
1708                    HTTP_POST_VAR("CONFIRM");
1709            } else {
1710                    // get
1711                    HTTP_GET_VAR("A");
1712                    if (HTTP_GET_VAR("D")) {
1713                            check_dirname($D);
1714                            $D=urldecode($D);
1715                            $relDir = $D;
1716                    } else {
1717                            //trigger_error("Can't get D",E_USER_WARNING);
1718                            $relDir = "/";
1719                    }
1720                    if (HTTP_GET_VAR("F")) check_filename($F);
1721            }
1722    
1723          $relScriptDir = dirname($SCRIPT_NAME) ;                  $relScriptDir = dirname($HTTP_SERVER_VARS["SCRIPT_NAME"]) ;    
1724          // i.e. /docman          // i.e. /docman
1725    
1726          // start on server root          // start on server root
1727          $gblFsRoot = $gblRepositoryDir;          $gblFsRoot = $gblRepositoryDir;
1728          // i.e. /home/httpd/html          // i.e. /home/httpd/repository
1729    
1730          $fsDir = $gblFsRoot . $relDir ; // current directory          $fsDir = $gblFsRoot . $relDir ; // current directory
1731          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) ;
1732    
1733          if (isset($GLOBALS["HTTPS"]) && $GLOBALS["HTTPS"] == "on") {          if ($relDir == "") $relDir="/";
1734    
1735            if (isset($HTTP_SERVER_VARS["HTTPS"]) && $HTTP_SERVER_VARS["HTTPS"] == "on") {
1736                  $webRoot  = "https://";                  $webRoot  = "https://";
1737          } else {          } else {
1738                  $webRoot  = "http://";                  $webRoot  = "http://";
1739          }          }
1740          $webRoot .= $GLOBALS["HTTP_HOST"] . $relScriptDir;          $webRoot .= $HTTP_SERVER_VARS["HTTP_HOST"] . $relScriptDir;
   
         $FN=stripSlashes($FN);  
1741    
1742          switch ($POSTACTION) {          if (HTTP_POST_VAR("POSTACTION")) switch ($POSTACTION) {
1743          case "UPLOAD" :          case "UPLOAD" :
1744                    $FN_name=stripSlashes($HTTP_POST_FILES["FN"]["tmp_name"]);
1745                    $FN=stripSlashes($HTTP_POST_FILES["FN"]["name"]);
1746                  if (!is_writeable($fsDir)) Error("Write denied",$relDir) ;                  if (!is_writeable($fsDir)) Error("Write denied",$relDir) ;
1747                  if (strstr($FN_name,"/"))  
1748                          Error("Non-conforming filename") ;                  $source = $FN_name ;
                 // TODO : should rather check for escapeshellcmds  
                 // but maybe RFC 18xx asserts safe filenames ....  
                 $source = $FN ;  
1749                  if (! file_exists($source)) {                  if (! file_exists($source)) {
1750                          Error("You must select file with browse to upload it!");                          Error("You must select file with browse to upload it!");
1751                  }                  }
1752    
1753                    if (HTTP_POST_VAR("FILENAME")) check_filename($FILENAME);
1754    
1755                  if (! isset($FILENAME)) {       // from update file                  if (! isset($FILENAME)) {       // from update file
1756                          $target = "$fsDir/$FN_name" ;                          $target = "$fsDir/".basename($FN);
1757                  } else {                  } else {
1758                          $target = "$fsDir/$FILENAME";                          $target = "$fsDir/$FILENAME";
1759                  }                  }
# Line 1569  print " return: $return<br>\n"; Line 1763  print " return: $return<br>\n";
1763                  if (! file_exists($dir."/.bak")) {                  if (! file_exists($dir."/.bak")) {
1764                          mkdir($dir."/.bak",0700);                          mkdir($dir."/.bak",0700);
1765                  }                  }
1766                  if (! file_exists($dir."/.bak/$GLOBALS[gblNumBackups]")) {                  if (! file_exists($dir."/.bak/$gblNumBackups")) {
1767                          mkdir($dir."/.bak/$GLOBALS[gblNumBackups]",0700);                          mkdir($dir."/.bak/$gblNumBackups",0700);
1768                  }                  }
1769                  $file=basename($target);                  $file=basename($target);
1770                  for($i=$GLOBALS[gblNumBackups]-1;$i>0;$i--) {                  for($i=$gblNumBackups-1;$i>0;$i--) {
1771                          MoveTo("$dir/.bak/$i/$file","$dir/.bak/".($i+1)."/");                          MoveTo("$dir/.bak/$i/$file","$dir/.bak/".($i+1)."/");
1772                  }                  }
1773                  MoveTo($target,$dir."/.bak/1/");                  MoveTo($target,$dir."/.bak/1/");
# Line 1581  print " return: $return<br>\n"; Line 1775  print " return: $return<br>\n";
1775                  copy($source,$target) ;                  copy($source,$target) ;
1776                  chmod($target,$gblFilePerms) ;                  chmod($target,$gblFilePerms) ;
1777                  clearstatcache() ;                  clearstatcache() ;
                 Logit($target,"uploaded");  
1778                  if (isset($FILENAME)) {                  if (isset($FILENAME)) {
1779                            LogIt($target,"check-in",trperm_r | trperm_w);
1780                          Unlock($target);                          Unlock($target);
1781                    } else {
1782                            LogIt($target,"uploaded",trperm_r | trperm_w);
1783                  }                  }
                 ChangeLog($target,"updated");  
1784                  break ;                  break ;
1785    
1786          case "SAVE" :          case "SAVE" :
# Line 1598  print " return: $return<br>\n"; Line 1793  print " return: $return<br>\n";
1793                  if (!($writable || (!$exists && $legaldir)))                  if (!($writable || (!$exists && $legaldir)))
1794                          Error("Write denied",$RELPATH) ;                          Error("Write denied",$RELPATH) ;
1795                  $fh = fopen($path, "w") ;                  $fh = fopen($path, "w") ;
1796                  $FILEDATA=stripSlashes($FILEDATA);                  HTTP_POST_VAR("FILEDATA");
1797                  fwrite($fh,$FILEDATA) ;                  fwrite($fh,$FILEDATA) ;
1798                  fclose($fh) ;                  fclose($fh) ;
1799                  clearstatcache() ;                  clearstatcache() ;
1800                  Logit($path,"saved changes");                  LogIt($path,"saved changes",trperm_r);
                 ChangeLog($path,"saved changes");  
1801                  break ;                  break ;
1802    
1803          case "CREATE" :          case "CREATE" :
1804                  // we know $fsDir exists                  // we know $fsDir exists
1805                  if ($FN == "") break;           // no filename!                  if (! check_perm($relDir, trperm_w))
1806                            Error("Write access denied","You don't have permission to write in <tt>$relDir</tt>");
1807                    if ($T == "D") $type = "directory";
1808                    else $type ="file";
1809                    if ($FN == "") Error("Can't create $type","You must enter name of $type to create it.");
1810                  if (!is_writeable($fsDir)) Error("Write denied",$relDir) ;                  if (!is_writeable($fsDir)) Error("Write denied",$relDir) ;
1811                  $path = $fsDir . "/" . $FN ;  // file or dir to create                  $path = $fsDir . "/" . $FN ;  // file or dir to create
1812                  $relPath = $relDir . "/" . $FN ;                  $relPath = $relDir . "/" . $FN ;
# Line 1616  print " return: $return<br>\n"; Line 1814  print " return: $return<br>\n";
1814                  case "D" :  // create a directory                  case "D" :  // create a directory
1815                          if ( ! @mkdir($path,$gblDirPerms) )                          if ( ! @mkdir($path,$gblDirPerms) )
1816                                  Error("Mkdir failed",$relPath) ; // eg. if it exists                                  Error("Mkdir failed",$relPath) ; // eg. if it exists
1817                            else
1818                                    LogIt($path."/","dir created",trperm_w);
1819                          clearstatcache() ;                          clearstatcache() ;
1820                          break ;                          break ;
1821                  case "F" :  // create a new file                  case "F" :  // create a new file
# Line 1628  print " return: $return<br>\n"; Line 1828  print " return: $return<br>\n";
1828                          if ($fh) {                          if ($fh) {
1829                                  fputs($fh,"\n");                                  fputs($fh,"\n");
1830                                  fclose($fh) ;                                  fclose($fh) ;
1831                                  LogIt($path,"file created");                                  LogIt($path,"file created",trperm_r | trperm_w);
1832                          } else {                          } else {
1833                                  Error("Creation of file $relPath failed -- $path");                                  Error("Creation of file $relPath failed -- $path");
1834                          }                          }
1835                          $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) ;
1836                          header("Location: " . $tstr) ;                          header("Location: " . $tstr) ;
                         ChangeLog($target,"created");  
1837                          exit ;                          exit ;
1838                  }                  }
1839                  break ;                  break ;
1840    
1841          case "DELETE" :            case "DELETE" :  
1842                  if ( $CONFIRM != "on" ) break ;                  if ( $CONFIRM != "on" ) break;
1843    
1844                  $tstr  = "Attempt to delete non-existing object or " ;                  if ( isset($FN) && $FN != "") {
1845                  $tstr .= "insufficient privileges: " ;                          $path=$fsDir."/".$FN;
1846    
1847                            $what = "file";
1848                            if (is_dir($path)) {
1849                                    $what = "dir";
1850                            }
1851    
1852                            if (! check_perm($relDir."/".$FN, trperm_w))
1853                                    Error("Access denied","User <tt>$gblLogin</tt> tried to erase $what <tt>$relDir/$FN</tt> without valid trustee.",1);
1854    
1855                            $tstr  = "Attempt to delete non-existing object or " ;
1856                            $tstr .= "insufficient privileges: " ;
1857    
                 if ( $FN != "") {  // delete file  
                         $path =  $fsDir . "/" . $FN ;  
                   
1858                          $dir=dirname($path);                          $dir=dirname($path);
1859                          $file=basename($path);                          $file=basename($path);
1860                          if (! file_exists("$dir/.del")) {                          if (! file_exists("$dir/.del")) {
# Line 1655  print " return: $return<br>\n"; Line 1862  print " return: $return<br>\n";
1862                          }                          }
1863    
1864  //                      if ( ! @unlink($path) ) {  //                      if ( ! @unlink($path) ) {
1865                          if ( ! rename($path,"$dir/.del/$file") ) {                          if ( ! @rename($path,"$dir/.del/$file") ) {
1866                                  Error("File delete failed", $tstr . $path) ;                                  LogIt($path,"$what delete failed");
1867                                  Logit($path,"file delete failed");                                  Error("Can't delete $what",$tstr.$relDir."/".$FN) ;
                                 exit ;  
1868                          } else {                          } else {
1869                                  Logit($path,"file deleted");                                  LogIt($path,"$what deleted",trperm_w);
1870                                  MoveTo("$dir/.log/$file","$dir/.del/.log/");                                  MoveTo("$dir/.log/$file","$dir/.del/.log/");
1871                                  MoveTo("$dir/.note/$file","$dir/.del/.note/");                                  MoveTo("$dir/.note/$file","$dir/.del/.note/");
1872                                  MoveTo("$dir/.lock/$file","$dir/.del/.lock/");                                  MoveTo("$dir/.lock/$file","$dir/.del/.lock/");
1873                          }                          }
1874                  }                  } else {
1875                  else {  // delete directory                          Error("Rmdir failed", $tstr . $fsDir) ;
                   if ( ! @rrmdir($fsDir) ) {  
                     Error("Rmdir failed", $tstr . $fsDir) ;  
                   }  
                   else {  
                     $relDir = dirname($relDir) ;  // move up  
                   }  
1876                  }                  }
1877                  break ;                  break ;
1878    
# Line 1682  print " return: $return<br>\n"; Line 1882  print " return: $return<br>\n";
1882                  if (substr($FN,0,4) != ".del") break ;                  if (substr($FN,0,4) != ".del") break ;
1883                  $file=substr($FN,4,strlen($FN)-4);                  $file=substr($FN,4,strlen($FN)-4);
1884    
1885                  Logit("$fsDir/.del/$file","undeleted");                  LogIt("$fsDir/.del/$file","undeleted",trperm_w);
1886                  MoveTo("$fsDir/.del/$file","$fsDir/");                  MoveTo("$fsDir/.del/$file","$fsDir/");
1887                  MoveTo("$fsDir/.del/.log/$file","$fsDir/.log/");                  MoveTo("$fsDir/.del/.log/$file","$fsDir/.log/");
1888                  MoveTo("$fsDir/.del/.note/$file","$fsDir/.note/");                  MoveTo("$fsDir/.del/.note/$file","$fsDir/.note/");
# Line 1693  print " return: $return<br>\n"; Line 1893  print " return: $return<br>\n";
1893          case "RENAME" :            case "RENAME" :  
1894                  if ( $CONFIRM != "on" ) break ;                  if ( $CONFIRM != "on" ) break ;
1895    
1896                  Logit("$fsDir/$FN","renamed $FN to $NEWNAME");                  $NEWNAME=stripSlashes($HTTP_POST_VARS["NEWNAME"]);
1897                    LogIt("$fsDir/$FN","renamed $FN to $NEWNAME",trperm_r);
1898                  safe_rename($fsDir,$FN,$NEWNAME);                  safe_rename($fsDir,$FN,$NEWNAME);
1899                  break ;                  break ;
1900    
1901          case "NOTE" :            case "NOTE" :  
1902                    $NOTE=stripSlashes($HTTP_POST_VARS["NOTE"]);
1903                  WriteNote("$fsDir/$FN","$NOTE");                  WriteNote("$fsDir/$FN","$NOTE");
1904                  break ;                  break ;
1905    
# Line 1711  print " return: $return<br>\n"; Line 1913  print " return: $return<br>\n";
1913          }          }
1914    
1915          // common to all POSTs : redirect to directory view ($relDir)          // common to all POSTs : redirect to directory view ($relDir)
1916          if ( $POSTACTION != "" ) {          if (isset($POSTACTION)) {
1917                  $tstr = $PHP_SELF . "?D=" . urlencode($relDir) ;                  $tstr = $HTTP_SERVER_VARS["PHP_SELF"]."?D=".urlencode($relDir);
1918                  header("Location: " . $tstr) ;                    header("Location: ".$tstr) ;  
1919                  exit ;                  exit ;
1920          }          }
1921                    
# Line 1724  print " return: $return<br>\n"; Line 1926  print " return: $return<br>\n";
1926          // $A=Co : checkout file $D/$F          // $A=Co : checkout file $D/$F
1927          // $A=Ci : checkin file $D/$F          // $A=Ci : checkin file $D/$F
1928          // $A=V : view file (do nothing except log)          // $A=V : view file (do nothing except log)
1929          // $A=I : include file .$F.php from $gblFsRoot          // $A=I : include file .$F.php from [$gblIncDir|realm]/include_php
1930          // default : display directory $D          // default : display directory $D
1931    
1932          switch ($A) {          if (isset($A)) switch ($A) {
1933          case "U" :          case "U" :
1934                  // upload to $relDir                  // upload to $relDir
1935                    if (! check_perm($relDir, trperm_w))
1936                            Error("Write access denied","You don't have permission to write in <tt>$relDir</tt>");
1937                  if (!is_writeable($gblFsRoot . $relDir))                  if (!is_writeable($gblFsRoot . $relDir))
1938                          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);
1939                  $text  = "Use this page to upload a single " ;                  $text  = "Use this page to upload a single " ;
1940                  $text .= "file to <B>$HTTP_HOST</B>." ;                  $text .= "file to <B>$realm</B>." ;
1941                  StartHTML("(Upload Page)", $text) ;                  StartHTML("(Upload Page)", $text) ;
1942                  UploadPage($gblFsRoot, $relDir) ;                  UploadPage($gblFsRoot, $relDir) ;
1943                  EndHTML() ;                  EndHTML() ;
1944                  exit ;                  exit ;
1945          case "E" :          case "E" :
                 $F=stripSlashes($F);  
1946                  // detail of $relDir/$F                  // detail of $relDir/$F
1947                  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) ;
1948                  exit ;                  exit ;
# Line 1751  print " return: $return<br>\n"; Line 1954  print " return: $return<br>\n";
1954          case "Co" :          case "Co" :
1955                  // checkout                  // checkout
1956                  Lock("$gblFsRoot/$relDir/$F");                  Lock("$gblFsRoot/$relDir/$F");
1957                  Download("$gblFsRoot/$relDir/$F");                  Download("$gblFsRoot/$relDir/$F",1);
1958                  exit;                  exit;
1959          case "Ci" :          case "Ci" :
1960                  $F=stripSlashes($F);                  $F=stripSlashes($F);
# Line 1759  print " return: $return<br>\n"; Line 1962  print " return: $return<br>\n";
1962                  if (!is_writeable($gblFsRoot . $relDir))                  if (!is_writeable($gblFsRoot . $relDir))
1963                          Error("Write access denied",$relDir) ;                          Error("Write access denied",$relDir) ;
1964                  $text  = "Use this page to update a single " ;                  $text  = "Use this page to update a single " ;
1965                  $text .= "file to <B>$HTTP_HOST</B>." ;                  $text .= "file to <B>$realm</B>." ;
1966                  StartHTML("(Update file Page)", $text) ;                  StartHTML("(Update file Page)", $text) ;
1967                  UploadPage($gblFsRoot, $relDir, $F) ;                  UploadPage($gblFsRoot, $relDir, $F) ;
1968                  EndHTML() ;                  EndHTML() ;
# Line 1767  print " return: $return<br>\n"; Line 1970  print " return: $return<br>\n";
1970          case "V" :          case "V" :
1971                  // view                  // view
1972                  LogIt("$gblFsRoot/$relDir/$F","viewed");                  LogIt("$gblFsRoot/$relDir/$F","viewed");
1973                  if ($gblForceDownload) {                  Download("$gblFsRoot/$relDir/$F",$gblForceDownload);
                         Download("$gblFsRoot/$relDir/$F");  
                 } else {  
                         header("Content-Disposition: attachment; filename=$F" );  
                         Header("Location: $webRoot".urlpath("$relDir/$F"));  
                 }  
1974                  exit;                  exit;
1975          case "Ch" :          case "Ch" :
1976                  StartHTML("(File changes)","All changes chronologicaly...");                  StartHTML("(File changes)","All changes chronologicaly...");
# Line 1785  print " return: $return<br>\n"; Line 1983  print " return: $return<br>\n";
1983                  EndHTML() ;                  EndHTML() ;
1984                  exit;                  exit;
1985          case "I" :          case "I" :
1986                  $F=stripSlashes($F);                  if (! isset($F) || $F == "")
1987                  $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);
1988                  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";
1989                    if (! file_exists($inc_file)) {
1990                            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);
1991                    }
1992                  if (!is_readable($inc_file))                  if (!is_readable($inc_file))
1993                          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);
1994                  $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";
1995                  $title = "You should define \$title variable with page title";                  $title = "You should define \$title variable with page title";
1996                  include($inc_file);                  include($inc_file);
1997                  StartHTML($title, $text) ;                  StartHTML($title, $text) ;
1998                  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>";
1999                  EndHTML() ;                  EndHTML() ;
2000                  exit ;                  exit ;
2001          }          }
# Line 1803  print " return: $return<br>\n"; Line 2004  print " return: $return<br>\n";
2004          Navigate($gblFsRoot,$relDir) ;            Navigate($gblFsRoot,$relDir) ;  
2005          exit ;          exit ;
2006    
2007          Error("Whooah!","By cartesian logic, this never happens") ;          Error("Whooah!","By cartesian logic, this never happens",1) ;
2008  ?>  ?>

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

  ViewVC Help
Powered by ViewVC 1.1.26