/[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.12 by dpavlin, Sat Jul 27 22:26:30 2002 UTC revision 1.31 by dpavlin, Mon Jul 29 13:53:56 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";
# 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_SERVER_VARS[HTTP_HOST];          $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>",1);          if ($fsDocumentRoot == "") Error("Configuration error","Can't get SCRIPT_FILENAME from your web server. Please set <tt>\$fsDocumentRoot</tt> in <tt>\$</tt>",1);
91    
92          // globals for later          // globals for later
93          $gblLogin = $HTTP_SERVER_VARS[PHP_AUTH_USER];          $gblLogin = HTTP_SERVER_VAR("PHP_AUTH_USER");
94          $gblPasswd = $HTTP_SERVER_VARS[PHP_AUTH_PW];          $gblPasswd = HTTP_SERVER_VAR("PHP_AUTH_PW");
95    
96  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
97    
# Line 109  function LoadLanguage($lang) { Line 109  function LoadLanguage($lang) {
109    
110  function StartHTML($title,$text="") {  function StartHTML($title,$text="") {
111    
112          global $html,$fsDocumentRoot,$HTTP_SERVER_VARS;          global $html,$fsDocumentRoot,$gblTitle,$HTTP_SERVER_VARS;
113    
         $title = $gblTitle." ".$title ;  
114          $host  = $HTTP_SERVER_VARS["HTTP_HOST"] ;          $host  = $HTTP_SERVER_VARS["HTTP_HOST"] ;
115          $self  = $HTTP_SERVER_VARS["PHP_SELF"] ;          $self  = $HTTP_SERVER_VARS["PHP_SELF"] ;
116    
# 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    
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, $HTTP_SERVER_VARS ;          global $gblEditable, $gblImages,
159                    $gblDateFmt, $gblTimeFmt,
160                    $gblPermNote,
161                    $webRoot, $html,
162                    $HTTP_SERVER_VARS ;
163          $self = $HTTP_SERVER_VARS["PHP_SELF"] ;          $self = $HTTP_SERVER_VARS["PHP_SELF"] ;
164    
165          $relPath  = $relDir . "/" . $fn ;          $relPath  = $relDir . "/" . $fn ;
# Line 160  function DetailPage($fsRoot,$relDir,$fn) Line 168  function DetailPage($fsRoot,$relDir,$fn)
168    
169          $exists   = file_exists($fsPath) ;          $exists   = file_exists($fsPath) ;
170          $ext      = strtolower(strrchr($relPath,".")) ;          $ext      = strtolower(strrchr($relPath,".")) ;
171          $editable = ( $ext=="" || strstr(join(" ",$gblEditable),$ext)) ;          $editable = ( $ext=="" || strstr(join(" ",$gblEditable),$ext)) &&
172          $writable = is_writeable($fsPath) ;                  check_perm($relPath,trperm_w);
173            $writable = is_writeable($fsPath) && check_perm($relPath,trperm_w) ;
174            $writable_dir = is_writeable($fsDir) && check_perm($relDir,trperm_w) ;
175          $file_lock = CheckLock($fsPath);          $file_lock = CheckLock($fsPath);
176    
177          if (!$editable && !$exists)          if (!$editable && !$exists)
178                  Error("Creation unsupported for type",$relPath) ;                  Error("Creation denied","Can't create <tt>$relPath</tt>") ;
179          if (!exists && !is_writeable($fsDir) )          if (!$exists && !$writable_dir )
180                  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);
181    
182          $text  = _("Use this page to view, modify or ") ;          $text  = _("Use this page to view, modify or ") ;
183          if (is_dir($fsPath)) {          if (is_dir($fsPath)) {
# Line 179  function DetailPage($fsRoot,$relDir,$fn) Line 189  function DetailPage($fsRoot,$relDir,$fn)
189          $title = "("._("Detail Page").")" ;          $title = "("._("Detail Page").")" ;
190          StartHTML($title, $text) ;          StartHTML($title, $text) ;
191    
192          echo "<H3>" . $relDir . "/" . $fn . "</H3>" ;          print "<H3>".$relDir.$fn."</H3>";
193    
194          if ($exists) {  // get file info          if ($exists) {  // get file info
195                  $fsize = filesize($fsPath) ;                  $fsize = filesize($fsPath) ;
196                  $fmodified = date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]", filemtime($fsPath)) ;                  $fmodified = date("$gblDateFmt $gblTimeFmt", filemtime($fsPath)) ;
197                  $faccessed = date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]", fileatime($fsPath)) ;                  $faccessed = date("$gblDateFmt $gblTimeFmt", fileatime($fsPath)) ;
198                  $fuid=fileowner($fsPath);                  $fuid=fileowner($fsPath);
199                  $fgid=filegroup($fsPath);                  $fgid=filegroup($fsPath);
200                  $userinfo = posix_getpwuid($fuid);                  $userinfo = posix_getpwuid($fuid);
# Line 198  function DetailPage($fsRoot,$relDir,$fn) Line 209  function DetailPage($fsRoot,$relDir,$fn)
209                  $fstr = fread($fh,filesize($fsPath)) ;                  $fstr = fread($fh,filesize($fsPath)) ;
210                  fclose($fh) ;                  fclose($fh) ;
211                  $fstr = htmlentities( $fstr ) ;                  $fstr = htmlentities( $fstr ) ;
 ?>  
   
 <FORM ACTION="<?= $self ; ?>" METHOD="POST">  
 <SPAN TITLE="Click [SAVE] to store updated contents.">  
         <B>DOCUMENT CONTENTS</B>  
 </SPAN><BR>  
 <TEXTAREA NAME="FILEDATA" ROWS=18 COLS=70 WRAP="OFF"><?php  
 echo($fstr) ; ?></TEXTAREA>  
 <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ; ?>">  
 <INPUT TYPE="HIDDEN" NAME="FN" VALUE="<?= $fn ; ?>">  
 <INPUT TYPE="HIDDEN" NAME="POSTACTION" VALUE="SAVE">  
 <INPUT TYPE="HIDDEN" SIZE=48 MAXLENGTH=255 NAME="RELPATH"  
         VALUE="<?= $relPath ; ?>">  
 <br>  
 <INPUT TYPE="RESET" VALUE="UNDO ALL CHANGES">  
 <INPUT TYPE="SUBMIT" VALUE="SAVE">  
 </FORM>  
212    
213  <?php                  include("$html/DetailPage-edit.html");
214          }          }
215          if ( !$file_lock && $ext!="" && strstr(join(' ',$gblImages),$ext) ) {            if ( !$file_lock && $ext!="" && strstr(join(' ',$gblImages),$ext) ) {  
216                  $info  = getimagesize($fsPath) ;                  $info  = getimagesize($fsPath) ;
217                  $tstr = "<IMG SRC=\"$webRoot".urlpath($relPath)."\" BORDER=0 " ;                  $tstr = "<IMG SRC=\"$self?A=V&D=".urlpath(dirname($relPath))."&F=".urlpath(basename($relPath))."\" BORDER=0 " ;
218                  $tstr .= $info[3] . " ALT=\"" . $fn . " - " ;                  $tstr .= $info[3] . " ALT=\"" . $fn . " - " ;
219                  $tstr .= (int)(($fsize+1023)/1024) . "Kb\">" ;                  $tstr .= (int)(($fsize+1023)/1024) . "Kb\">" ;
220  //              echo htmlentities($tstr) . "<BR><BR>" . $tstr ;  //              echo htmlentities($tstr) . "<BR><BR>" . $tstr ;
221                  echo $tstr ;                  echo $tstr ;
222          }          }
223    
 ?>  
   
 <FORM ACTION="<?= $self ; ?>" METHOD="POST">  
 <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ; ?>">  
 <INPUT TYPE="HIDDEN" NAME="FN" VALUE="<?= $fn ; ?>">  
 <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="CANCEL"><BR>  
224    
225  <?php          print '<FORM ACTION="'.$self.'" METHOD="POST">
226                    <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="'.$relDir.'">
227                    <INPUT TYPE="HIDDEN" NAME="FN" VALUE="'.$fn.'">
228                    <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="CANCEL"><BR>
229                    ';
230    
231          if ($file_lock) {          if ($file_lock && check_perm($relDir.$fn,trperm_w)) {
232  ?>                  include("$html/DetailPage-unlock.html");
 <hr>  
 <SPAN TITLE="Check OK and click UNLOCK to remove lock on file.">  
 <B>OK TO FORCE LOCK REMOVAL ON "<?= $fn ; ?>" HELD BY <?= $file_lock ?>? </B></SPAN>  
 <INPUT TYPE="CHECKBOX" NAME="CONFIRM">  
 <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="UNLOCK">  
 <?  
233          } // file_lock          } // file_lock
234    
235          if (substr($fn,0,4) == ".del") {          if (substr($fn,0,4) == ".del") {
# Line 255  echo($fstr) ; ?></TEXTAREA> Line 241  echo($fstr) ; ?></TEXTAREA>
241          }          }
242    
243          if ($exists && $writable) {          if ($exists && $writable) {
244  ?>                  include("$html/DetailPage-undelete.html");
245                    include("$html/DetailPage-rename.html");
 <HR>  
 <a name="undelete">  
 <SPAN TITLE="Check OK and click [<?= $action ?>] to <?= $desc ?>.">  
 <B>OK TO <?= $action ?> "<?= $fn ; ?>"? </B></SPAN>  
 <INPUT TYPE="CHECKBOX" NAME="CONFIRM">  
 <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="<?= $action ?>">  
   
 <HR>  
 <a name="rename">  
 <SPAN TITLE="Check OK and click [RENAME] to rename.">  
 <B>OK TO RENAME "<?= $fn ; ?>" TO  
 <INPUT TYPE="TEXT" SIZE=24 MAXLENGTH=255 NAME="NEWNAME" VALUE="<?= $fn ?>">  
 ? </B></SPAN>  
 <INPUT TYPE="CHECKBOX" NAME="CONFIRM">  
 <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="RENAME">  
246    
247  <?php          } elseif (check_perm($relDir.$fn,$gblPermNote)) {
248          }       // exists && writable                          include("$html/DetailPage-note.html");
249  ?>          }
 <HR>  
 <a name="note">  
 <B>NOTE FOR "<?= $fn ; ?>":  
 <INPUT TYPE="TEXT" SIZE=50 MAXLENGTH=255 NAME="NOTE" VALUE="<?= ReadNote($fsPath) ?>">  
 </B></SPAN>  
 <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="NOTE">  
   
 </FORM>  
250    
251  <?php          print "</FORM>";
252    
253          $name=basename("$fsDir/$fn");          $name=basename("$fsDir/$fn");
254          $logname=dirname("$fsDir/$fn")."/.log/$name";          $logname=dirname("$fsDir/$fn")."/.log/$name";
# Line 471  function MockIcon($txt) { Line 434  function MockIcon($txt) {
434    
435  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
436    
437  function GifIcon($txt) {  function GifIcon($txt = "") {
438          global $gblIconLocation ;          global $gblIconLocation, $gblImages ;
439    
440          switch (strtolower($txt)) {          switch (strtolower($txt)) {
         case ".bmp" :  
         case ".gif" :  
         case ".jpg" :  
         case ".jpeg":  
         case ".tif" :  
         case ".tiff":  
                 $d = "image2.gif" ;  
                 break ;  
441          case ".doc" :          case ".doc" :
442                  $d = "layout.gif" ;                  $d = "layout.gif" ;
443                  break ;                  break ;
# Line 560  function GifIcon($txt) { Line 515  function GifIcon($txt) {
515                  $d = "quill.gif";                  $d = "quill.gif";
516                  break;                  break;
517          default :          default :
518                  $d = "generic.gif" ;                  if (in_array(strtolower($txt),$gblImages)) {
519                            $d = "image2.gif" ;
520                    } else {
521                            $d = "generic.gif" ;
522                    }
523          }          }
524    
525    
526          return "<IMG SRC=\"$gblIconLocation" . $d . "\" BORDER=0>" ;          return "<IMG SRC=\"$gblIconLocation" . $d . "\" BORDER=0>" ;
527  } // end function GifIcon  } // end function GifIcon
528    
# Line 572  function Navigate($fsRoot,$relDir) { Line 532  function Navigate($fsRoot,$relDir) {
532    
533          global $gblEditable, $gblIcon, $gblModDays, $webRoot, $gblHide,          global $gblEditable, $gblIcon, $gblModDays, $webRoot, $gblHide,
534                  $gblIgnoreUnknownFileType, $gblRepositoryDir,                  $gblIgnoreUnknownFileType, $gblRepositoryDir,
535                    $gblLogin, $gblUserName, $gblDateFmt, $gblTimeFmt,
536                  $fsRealmDir, $realm, $realm_sep,                  $fsRealmDir, $realm, $realm_sep,
537                  $HTTP_GET_VARS, $html, $realm_config;                  $html, $realm_config,
538                    $HTTP_GET_VARS, $HTTP_SERVER_VARS;
539            
540          $self     = $HTTP_SERVER_VARS["PHP_SELF"] ;          $self     = $HTTP_SERVER_VARS["PHP_SELF"] ;
541    
542          if ($relDir == "") $relDir = "/";          $relDir = chopsl($relDir)."/";
543            $fsDir = $fsRoot.$relDir;       // current directory
544    
545            if (!is_dir($fsDir)) Error("Dir not found","Directory <tt>$relDir<tt> not found on filesystem at <tt>$fsDir</tt>",1) ;
546    
547          $fsDir = $fsRoot.$relDir."/";   // current directory          global $debug;
548            $debug .= "[$gblLogin|$relDir] before >";
549    
550          if (!is_dir($fsDir)) Error("Dir not found",$relDir) ;          if (! check_perm($relDir,trperm_b))
551                    Error("Access denied","User <tt>$gblLogin</tt> tried to access <tt>$relDir</tt> without valid trustee.",1);
552            $debug .= "< afeter";
553    
554          $hide_items=",$gblHide,";          $hide_items=",$gblHide,";
555    
556            $dirList = array();
557            $fileList = array();
558    
559          // read directory contents          // read directory contents
560          if ( !($dir = @opendir($fsDir)) )          if ( !($dir = @opendir($fsDir)) )
561                  Error("Read Access denied",$relDir,1) ;                  Error("Read Access denied",$relDir,1) ;
# Line 609  function Navigate($fsRoot,$relDir) { Line 580  function Navigate($fsRoot,$relDir) {
580          closedir($dir) ;          closedir($dir) ;
581    
582          // scan deleted files          // scan deleted files
583          if ( $HTTP_GET_VARS["show_deleted"] == 1 && ($dir = @opendir("$fsDir/.del")) ) {          if ( HTTP_GET_VAR("show_deleted") == 1 && ($dir = @opendir("$fsDir/.del")) ) {
584                  while ($item = readdir($dir)) {                  while ($item = readdir($dir)) {
585                          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 ;
586                          $fileList[$item] = ".del/$item" ;                                        if (is_file($fsDir.".del/$item")) {
587                          $fileDate[$item] = filemtime($fsDir.".del/$path") ;                                  $fileList[$item] = ".del/$item" ;              
588                          $fileSize[$item] = filesize($fsDir.".del/$path") ;                                  $fileDate[$item] = filemtime($fsDir.".del/$item") ;
589                          $fileNote[$item] = ReadNote($fsDir.".del/$item");                                  $fileSize[$item] = filesize($fsDir.".del/$item") ;
590                                    $fileNote[$item] = ReadNote($fsDir.".del/$item");
591                            } else {
592                                    $dirList[$item] = ".del/$item" ;                
593                                    $dirNote[$item] = ReadNote($fsDir.".del/$item");
594                            }
595                  }                  }
596                  closedir($dir) ;                  closedir($dir) ;
597          }          }
# Line 624  function Navigate($fsRoot,$relDir) { Line 600  function Navigate($fsRoot,$relDir) {
600    
601          // start navigation page          // start navigation page
602          $text  = "Use this page to add, delete";          $text  = "Use this page to add, delete";
603          if (! isset($HTTP_GET_VARS[show_deleted])) {          if (! isset($HTTP_GET_VARS["show_deleted"])) {
604                  $text .= ", <a href=$self?D=".urlencode($relDir)."&show_deleted=1>undelete</a>";                  $text .= ", <a href=$self?D=".urlencode($relDir)."&show_deleted=1>undelete</a>";
605          }          }
606          $text .= " or revise files on this web site." ;          $text .= " or revise files on this web site." ;
# Line 634  function Navigate($fsRoot,$relDir) { Line 610  function Navigate($fsRoot,$relDir) {
610          echo "<TABLE BORDER=0 CELLPADDING=2          echo "<TABLE BORDER=0 CELLPADDING=2
611                  CELLSPACING=3 WIDTH=\"100%\">" ;                  CELLSPACING=3 WIDTH=\"100%\">" ;
612    
613          // updir bar              // updir (parent) bar  
614          if (chopsl($fsDir) != chopsl($fsRoot)) {          if (chopsl($fsDir) != chopsl($fsRoot)) {
615                  $parent = dirname($relDir) ;                  $parent = dirname($relDir) ;
616                  if ($parent == "") $parent = "/" ;                  if ($parent == "") $parent = "/" ;
# Line 650  function Navigate($fsRoot,$relDir) { Line 626  function Navigate($fsRoot,$relDir) {
626                  return $out;                  return $out;
627          }          }
628    
629          $dsort = $HTTP_GET_VARS[dsort];          if (! HTTP_GET_VAR("dsort")) $dsort = "name"; // default directory sort
         if (! isset($dsort)) $dsort = "name";   // default directory sort  
630    
631          $dsort_arr = array(          $dsort_arr = array(
632                  "name" => array ("rname", "note"),                  "name" => array ("rname", "note"),
# Line 660  function Navigate($fsRoot,$relDir) { Line 635  function Navigate($fsRoot,$relDir) {
635                  "rnote" => array ("name", "note")                  "rnote" => array ("name", "note")
636                  );                  );
637    
638          $fsort = $HTTP_GET_VARS[fsort];          if (! HTTP_GET_VAR("fsort")) $fsort = "name"; // default directory sort
         if (! isset($fsort)) $fsort = "name";   // default directory sort  
639    
640          $fsort_arr = array(          $fsort_arr = array(
641                  "name" => array ("rname", "note", "date", "size"),                  "name" => array ("rname", "note", "date", "size"),
# Line 677  function Navigate($fsRoot,$relDir) { Line 651  function Navigate($fsRoot,$relDir) {
651          $D="D=".urlencode($relDir);          $D="D=".urlencode($relDir);
652    
653          function self_args($arr = array()) {          function self_args($arr = array()) {
654                    global $self;
655                  $arg = implode("&",$arr);                  $arg = implode("&",$arr);
656                  if ($arg) {                  if ($arg) {
657                          return $self."?".$arg;                          return $self."?".$arg;
# Line 714  function Navigate($fsRoot,$relDir) { Line 689  function Navigate($fsRoot,$relDir) {
689                          $dir = $dirList[$key];                          $dir = $dirList[$key];
690    
691                          $info_url=self_args(array("A"=>"A=E", "F"=>"F=".urlencode($dir), "D"=>$D));                          $info_url=self_args(array("A"=>"A=E", "F"=>"F=".urlencode($dir), "D"=>$D));
692                          $dir_url=$self."?D=".urlencode($relDir."/".$dir);                          if (substr($dir,0,5) == ".del/") {
693                                    $dir = substr($dir,5,strlen($dir)-5);
694                                    $deleted = " <a href=\"$info_url#undelete\"><SPAN CLASS=deleted TITLE=\"deleted\">deleted</span></a>";
695                            } else {
696                                    $deleted = "";
697                            }
698            
699                            $dir_url=$self."?D=".urlencode(chopsl($relDir)."/".$dir);
700                          include("$html/Navigate-dirEntry.html");                          include("$html/Navigate-dirEntry.html");
701    
702                  }  // iterate over dirs                  }  // iterate over dirs
# Line 792  function Navigate($fsRoot,$relDir) { Line 774  function Navigate($fsRoot,$relDir) {
774                  if (substr($file,0,5) != ".del/") {                  if (substr($file,0,5) != ".del/") {
775                          $file_url_html .= $file . "</A>" . $a ;                          $file_url_html .= $file . "</A>" . $a ;
776                  } else {                  } else {
777                          $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>";
778                  }                  }
779    
780                  $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 800  function Navigate($fsRoot,$relDir) { Line 782  function Navigate($fsRoot,$relDir) {
782                  $ext = strtolower(strrchr($file,".")) ;                  $ext = strtolower(strrchr($file,".")) ;
783    
784                  if ($file_lock) {                  if ($file_lock) {
785                          if ($file_lock == $GLOBALS[gblUserName]) {                          if ($file_lock == $gblUserName) {
786                                  $b.="<A HREF=\"$self?A=Ci&D=".urlencode($relDir)."&F=".urlencode($file);                                  $b.="<A HREF=\"$self?A=Ci&D=".urlencode($relDir)."&F=".urlencode($file);
787                                  $b.="\" TITLE=\"Checkin (update) file on server\">" ;                                  $b.="\" TITLE=\"Checkin (update) file on server\">" ;
788                                  $file_url_html=$b;                                  $file_url_html=$b;
# Line 815  function Navigate($fsRoot,$relDir) { Line 797  function Navigate($fsRoot,$relDir) {
797                                  $file_url_html = "$file $a";                                  $file_url_html = "$file $a";
798                          }                          }
799                  } else {                  } else {
800                          $b.="<A HREF=\"$self?A=Co&D=".urlencode($relDir)."&F=".urlencode($file);                          if (check_perm($relDir.$file,trperm_w)) {
801                          $b.="\" TITLE=\"Checkout file for edit\">" ;                                  $b.="<A HREF=\"$self?A=Co&D=".urlencode($relDir)."&F=".urlencode($file);
802                          $b.=$gblIcon("checkout")."</A>";                                  $b.="\" TITLE=\"Checkout file for edit\">" ;
803                                    $b.=$gblIcon("checkout")."</A>";
804                            }
805    
806                          if ( $ext=="" || strstr(join(" ",$gblEditable),$ext) ) {                            if ( $ext=="" || strstr(join(" ",$gblEditable),$ext) ) {  
807                                  $b.="<A HREF=\"$self?A=C&D=".urlencode($relDir)."&F=".urlencode($file);                                  $b.="<A HREF=\"$self?A=C&D=".urlencode($relDir)."&F=".urlencode($file);
# Line 828  function Navigate($fsRoot,$relDir) { Line 812  function Navigate($fsRoot,$relDir) {
812                          }                          }
813                  }                  }
814    
815                  $mod = date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]",$mod);                  $mod = date("$gblDateFmt $gblTimeFmt",$mod);
816    
817                  include("$html/Navigate-fileEntry.html");                  include("$html/Navigate-fileEntry.html");
818    
# Line 899  function UploadPage($fsRoot, $relDir, $f Line 883  function UploadPage($fsRoot, $relDir, $f
883          global $html, $HTTP_SERVER_VARS;          global $html, $HTTP_SERVER_VARS;
884    
885          $self = $HTTP_SERVER_VARS["PHP_SELF"] ;          $self = $HTTP_SERVER_VARS["PHP_SELF"] ;
         if ($relDir == "") $relDir = "/" ;  
   
886          include("$html/UploadPage.html");          include("$html/UploadPage.html");
887    
888  } // end function UploadPage  } // end function UploadPage
# Line 942  function Error($title,$text="",$sysadmin Line 924  function Error($title,$text="",$sysadmin
924    
925  function LogIt($target,$msg, $changelog=0) {  function LogIt($target,$msg, $changelog=0) {
926    
927            global $gblDateFmt, $gblTimeFmt, $gblUserName, $gblFsRoot;
928    
929          $dir=dirname($target);          $dir=dirname($target);
930          if (! file_exists($dir."/.log")) {          if (! file_exists($dir."/.log")) {
931                  if (! @mkdir($dir."/.log",0700)) Error("docman installation problem","can't create log directory <tt>$dir/.log</tt>",1);                  if (! @mkdir($dir."/.log",0700)) Error("docman installation problem","can't create log directory <tt>$dir/.log</tt>",1);
# Line 949  function LogIt($target,$msg, $changelog= Line 933  function LogIt($target,$msg, $changelog=
933          $file=basename($target);          $file=basename($target);
934    
935          $log=fopen("$dir/.log/$file","a+");          $log=fopen("$dir/.log/$file","a+");
936          fputs($log,date("$GLOBALS[gblDateFmt]\t$GLOBALS[gblTimeFmt]").          fputs($log,date("$gblDateFmt\t$gblTimeFmt").
937                  "\t$GLOBALS[gblUserName]\t$msg\n");                  "\t$gblUserName\t$msg\n");
938          fclose($log);          fclose($log);
939    
940          if (! $changelog) return;          if (! $changelog) return;
941    
         global $gblFsRoot;  
942          $log=fopen("$gblFsRoot/.changelog","a+");          $log=fopen("$gblFsRoot/.changelog","a+");
943          if (substr($target,0,strlen($gblFsRoot)) == $gblFsRoot)          if (substr($target,0,strlen($gblFsRoot)) == $gblFsRoot)
944                  $target=substr($target,strlen($gblFsRoot),strlen($target)-strlen($gblFsRoot));                  $target=substr($target,strlen($gblFsRoot),strlen($target)-strlen($gblFsRoot));
945          $msg=str_replace("\t"," ",$msg);          $msg=str_replace("\t"," ",$msg);
946          fputs($log,time()."\t$target\t$GLOBALS[gblUserName]\t$msg\n");          fputs($log,time()."\t$target\t$gblUserName\t$msg\n");
947          fclose($log);          fclose($log);
948    
949          // FIX: implement e-mail notification based on $changelog          // FIX: implement e-mail notification based on $changelog
# Line 980  function WriteNote($target,$msg) { Line 963  function WriteNote($target,$msg) {
963          $file=basename($target);          $file=basename($target);
964    
965          $note=fopen("$dir/.note/$file","w");          $note=fopen("$dir/.note/$file","w");
966            if (! $note) {
967                    Error("Error writing note","Can't open note file <tt>$dir/.note/$file</tt> for writing",1);
968            }
969          fputs($note,"$msg\n");          fputs($note,"$msg\n");
970          fclose($note);          fclose($note);
971    
# Line 1020  function MoveTo($source,$folder) { Line 1006  function MoveTo($source,$folder) {
1006    
1007  function Lock($target) {  function Lock($target) {
1008    
1009            global $gblUserName;
1010    
1011          $target=stripSlashes($target);          $target=stripSlashes($target);
1012          $dir=dirname($target);          $dir=dirname($target);
1013          if (! file_exists($dir."/.lock")) {          if (! file_exists($dir."/.lock")) {
# Line 1031  function Lock($target) { Line 1019  function Lock($target) {
1019                  LogIt($target,"attempt to locked allready locked file!");                  LogIt($target,"attempt to locked allready locked file!");
1020          } else {          } else {
1021                  $lock=fopen("$dir/.lock/$file","w");                  $lock=fopen("$dir/.lock/$file","w");
1022                  fputs($lock,"$GLOBALS[gblUserName]\n");                  fputs($lock,"$gblUserName\n");
1023                  fclose($lock);                  fclose($lock);
1024    
1025                  LogIt($target,"file locked");                  LogIt($target,"file locked");
# Line 1080  function urlpath($url) { Line 1068  function urlpath($url) {
1068  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
1069    
1070  function safe_rename($fromdir,$fromfile,$tofile) {  function safe_rename($fromdir,$fromfile,$tofile) {
1071    
1072            global $gblNumBackups;
1073    
1074          function try_rename($from,$to) {          function try_rename($from,$to) {
1075  #               print "$from -> $to\n";  #               print "$from -> $to\n";
1076                  if (file_exists($from) && is_writeable(dirname($to))) {                  if (file_exists($from) && is_writeable(dirname($to))) {
# Line 1109  function safe_rename($fromdir,$fromfile, Line 1100  function safe_rename($fromdir,$fromfile,
1100          try_dir("$todir/.lock");          try_dir("$todir/.lock");
1101          try_rename("$fromdir/.lock/$fromfile","$todir/.lock/$tofile");          try_rename("$fromdir/.lock/$fromfile","$todir/.lock/$tofile");
1102          try_dir("$todir/.bak");          try_dir("$todir/.bak");
1103          for($i=0;$i<=$GLOBALS[gblNumBackups];$i++) {          for($i=0;$i<=$gblNumBackups;$i++) {
1104                  try_rename("$fromdir/.bak/$i/$fromfile","$todir/.bak/$i/$tofile");                  try_rename("$fromdir/.bak/$i/$fromfile","$todir/.bak/$i/$tofile");
1105          }          }
1106  }  }
# Line 1137  function rrmdir($dir) { Line 1128  function rrmdir($dir) {
1128    
1129  function DisplayChangeLog($day) {  function DisplayChangeLog($day) {
1130    
1131          global $gblFsRoot,$HTTP_SERVER_VARS;          global $gblFsRoot, $gblDateFmt, $gblTimeFmt,
1132                    $HTTP_SERVER_VARS;
1133    
1134            $self  = $HTTP_SERVER_VARS["PHP_SELF"];
1135    
1136          if (!file_exists("$gblFsRoot/.changelog")) return;          if (!file_exists("$gblFsRoot/.changelog")) return;
1137          $log=fopen("$gblFsRoot/.changelog","r");          $log=fopen("$gblFsRoot/.changelog","r");
# Line 1156  function DisplayChangeLog($day) { Line 1150  function DisplayChangeLog($day) {
1150          print "<table border=0 width=100%>\n";          print "<table border=0 width=100%>\n";
1151          while ($e = array_shift($logarr)) {          while ($e = array_shift($logarr)) {
1152                  $cl=$cl1; $cl1=$cl2; $cl2=$cl;                  $cl=$cl1; $cl1=$cl2; $cl2=$cl;
1153                  $date = date("$GLOBALS[gblDateFmt]", $e[0]);                  $date = date($gblDateFmt, $e[0]);
1154                  $time = date("$GLOBALS[gblTimeFmt]", $e[0]);                  $time = date($gblTimeFmt, $e[0]);
1155                  $dir = dirname($e[1]);                  $dir = dirname($e[1]);
1156                  $file = basename($e[1]);                  $file = basename($e[1]);
1157                  print "<tr><td$cl>$date</td><td$cl>$time</td><td$cl><a href=\"$HTTP_SERVER_VARS[PHP_SELF]?D=".urlencode($dir)."\">$dir</a>/$file</td><td$cl>$e[2]</td><td$cl>$e[3]</td></tr>\n";                  print "<tr><td$cl>$date</td><td$cl>$time</td><td$cl><a href=\"$HTTP_SERVER_VARS[PHP_SELF]?D=".urlencode($dir)."\">$dir</a>/$file</td><td$cl>$e[2]</td><td$cl>$e[3]</td></tr>\n";
1158          }          }
1159          print "</table>";          print "</table>";
1160          print "<p>".GifIcon(up)." Back to <a href=$HTTP_SERVER_VARS[PHP_SELF]>front page</a>.</p>";          print "<p>".GifIcon("up")." Back to <a href=\"$self\">front page</a>.</p>";
1161  }  }
1162    
1163  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
# Line 1185  function Download($path,$force=0) { Line 1179  function Download($path,$force=0) {
1179    
1180          $ext_arr = explode(".",$file);          $ext_arr = explode(".",$file);
1181          $ext = array_pop($ext_arr);          $ext = array_pop($ext_arr);
1182          if ($encoding_ext[$ext]) {          if (isset($encoding_ext[$ext])) {
1183                  $encoding = $encoding_ext[$ext];                  $encoding = $encoding_ext[$ext];
1184                  $ext = array_pop($ext_arr);                  $ext = array_pop($ext_arr);
1185          }          }
# Line 1197  function Download($path,$force=0) { Line 1191  function Download($path,$force=0) {
1191          }          }
1192    
1193          // IE5.5 just downloads index.php if we don't do this          // IE5.5 just downloads index.php if we don't do this
1194          if(preg_match("/MSIE 5.5/", $HTTP_SERVER_VARS[HTTP_USER_AGENT])) {          if(preg_match("/MSIE 5.5/", $HTTP_SERVER_VARS["HTTP_USER_AGENT"])) {
1195                  header("Content-Disposition: filename=$file");                  header("Content-Disposition: filename=$file");
1196          } else {          } else {
1197                  header("Content-Disposition: attachment; filename=$file");                  header("Content-Disposition: attachment; filename=$file");
# Line 1212  function Download($path,$force=0) { Line 1206  function Download($path,$force=0) {
1206  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
1207    
1208  function chopsl($path) {  function chopsl($path) {
         if (substr($path,strlen($path)-1,1) == "/") $path=substr($path,0,strlen($path)-1);  
1209          $path=str_replace("//","/",$path);          $path=str_replace("//","/",$path);
1210            if (substr($path,strlen($path)-1,1) == "/") $path=substr($path,0,strlen($path)-1);
1211          return $path;          return $path;
1212  }  }
1213    
# Line 1227  function chopsl($path) { Line 1221  function chopsl($path) {
1221          by Vyacheslav Zavadsky <zavadsky@braysystems.com>          by Vyacheslav Zavadsky <zavadsky@braysystems.com>
1222  */  */
1223    
1224  define(trmask_not,1 << 0);  define('trmask_not',1 << 0);
1225  define(trmask_clear,1 << 1);  define('trmask_clear',1 << 1);
1226  define(trmask_deny,1 << 2);  define('trmask_deny',1 << 2);
1227  define(trmask_one_level,1 << 3);  define('trmask_one_level',1 << 3);
1228  define(trmask_group,1 << 4);  define('trmask_group',1 << 4);
1229    
1230  define(trperm_r,1 << 5);  define('trperm_r',1 << 5);
1231  define(trperm_w,1 << 6);  define('trperm_w',1 << 6);
1232  define(trperm_b,1 << 7);  define('trperm_b',1 << 7);
1233  define(trperm_n,1 << 8);  define('trperm_n',1 << 8);
1234    
1235  $trustee_a2n = array(  $trustee_a2n = array(
1236          '!' => trmask_not,          '!' => trmask_not,
# Line 1284  if (! file_exists($trustee_conf)) { Line 1278  if (! file_exists($trustee_conf)) {
1278          $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";
1279  } elseif (file_exists($trustee_php) && !is_writable($trustee_php)) {  } elseif (file_exists($trustee_php) && !is_writable($trustee_php)) {
1280          $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";
1281  } elseif (1 || filemtime($trustee_conf) >= filemtime($trustee_php)) {  } elseif (@filemtime($trustee_conf) >= @filemtime($trustee_php)) {
1282          $fp_php=@fopen($trustee_php,"w");          $fp_php=@fopen($trustee_php,"w");
1283          fputs($fp_php,"<?php // don't edit by hand!\n");          fputs($fp_php,"<?php // don't edit by hand!\n");
1284    
# Line 1320  if (! file_exists($trustee_conf)) { Line 1314  if (! file_exists($trustee_conf)) {
1314                                                  $error.="trustee error in line '$l' [Unknown modifier '$ch']<br>\n";                                                  $error.="trustee error in line '$l' [Unknown modifier '$ch']<br>\n";
1315                                          }                                          }
1316                                  }                                  }
1317                                  $tr_arr[$path][$user] |= $perm;                                  if (isset($tr_arr[$path][$user])) {
1318                                            $tr_arr[$path][$user] |= $perm;
1319                                    } else {
1320                                            $tr_arr[$path][$user] = $perm;
1321                                    }
1322                          }                          }
1323                  }                  }
1324          }          }
# Line 1359  if (! file_exists($trustee_conf)) { Line 1357  if (! file_exists($trustee_conf)) {
1357          fclose($fp_php);          fclose($fp_php);
1358  }  }
1359    
1360  if ($error) {  if (isset($error)) {
1361          Error("Trustee error",$error,1);          Error("Trustee error",$error,1);
1362  } else {  } else {
1363          include("$trustee_php");          include_once("$trustee_php");
1364  }  }
1365    
1366  return 1;  return 1;
# Line 1370  return 1; Line 1368  return 1;
1368  }//init_trustee  }//init_trustee
1369    
1370  function in_group($user,$group) {  function in_group($user,$group) {
1371          return in_array($groups[$group],$user);          global $groups;
1372            return in_array($user,$groups[$group]);
1373  }  }
1374    
1375  // helper function  // helper function
1376  function unroll_perm($u,$t,$user,$perm) {  function unroll_perm($u,$t,$perm,$one_level) {
1377          // check user  
1378          if ($t & trmask_not && ($u==$user)) continue;          if ($t & trmask_one_level && !$one_level) return $perm;
         if (!($t & trmask_not) && ($u!=$user)) continue;  
1379    
1380          if ($t & trmask_deny) {          if ($t & trmask_deny) {
1381                  if ($t & trmask_clear) {                  if ($t & trmask_clear) {
1382                          $perm[deny] &= ~$t;                          $perm['deny'] &= ~$t;
1383                  } else {                  } else {
1384                          $perm[deny] |= $t;                          $perm['deny'] |= $t;
1385                  }                  }
1386          } elseif ($t & trmask_clear) {          } elseif ($t & trmask_clear) {
1387                  $perm[allow] &= ~$t;                  $perm['allow'] &= ~$t;
1388          } else {          } else {
1389                  $perm[allow] |= $t;                  $perm['allow'] |= $t;
1390          }          }
1391          return $perm;          return $perm;
1392  }// end of helper function  }// end of helper function
1393    
1394  function check_trustee($user,$path) {  function check_trustee($user,$path) {
1395          global $trustees;          global $trustees,$HAVE_TRUSTEE;
1396          $perm[allow] = 0;          $perm['allow'] = 0;
1397          $perm[deny] = 0;          $perm['deny'] = 0;
1398    
1399            // do we use trustees?
1400            if (! $HAVE_TRUSTEE) return $perm;
1401    
1402            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);
1403    
1404    global $debug;
1405    $debug .= "<br>check_trustee $path ... ";
1406    
1407          $path_arr=explode("/",$path);          $path_arr=explode("/",$path);
1408          $path = "/";          $tmppath = "/";
1409          while (count($path_arr)) {          while (count($path_arr)) {
1410                  if (substr($path,strlen($path)-1,1) != "/") $path.="/";                  $tmppath.=array_shift($path_arr);
1411                  $path.=array_shift($path_arr);  $debug.= ">> $tmppath ";
1412                  $tr = $trustees[$path];  
1413                    if (! isset($trustees[$tmppath])) continue;
1414                    $tr = $trustees[$tmppath];
1415    
1416                    $one_level = (!count($path_arr));
1417    $debug.=" O($one_level) ";
1418    
1419                  if (isset($tr)) {                  if (isset($tr)) {
1420                          // first apply trustee for all                          // first apply trustee for all
1421                          if (isset($tr['*'])) {                          if (isset($tr['*']) && $user!="anonymous") {
1422                                  $perm = unroll_perm($user,$tr['*'],$user, $perm);                                  $perm = unroll_perm($user,$tr['*'],$perm, $one_level);
1423                                  unset($tr['*']);                                  unset($tr['*']);
1424                          }                          }
1425                          // then apply group policies                          // then apply not and group policies
1426                          foreach ($tr as $u=>$t) {                          foreach ($tr as $g=>$t) {
1427                                  if ($t & trmask_group && in_group($user,$u)) {                                  if ($t & trmask_not && $g != $user) {
1428                                            $t = $t & ~trmask_not;
1429                                            $perm = unroll_perm($user,$t,$perm, $one_level);
1430                                            unset($tr[$g]);
1431    
1432                                    } elseif ($t & trmask_group && in_group($user,$g)) {
1433                                          // resolv user                                          // resolv user
1434                                          $t = $t & ~trmask_group;                                          $t = $t & ~trmask_group;
1435                                          $u = $user;                                          $perm = unroll_perm($user,$t,$perm, $one_level);
1436                                          $perm = unroll_perm($u,$t,$user, $perm);                                          unset($tr[$g]);
                                         unset($tr[$u]);  
1437                                  }                                  }
1438                          }                          }
1439                          // then apply use policy                          // then apply user policy
1440                          if (isset($tr[$user])) {                          if (isset($tr[$user])) {
1441                                  $perm = unroll_perm($user,$tr[$user],$user, $perm);                                  $perm = unroll_perm($user,$tr[$user],$perm,$one_level);
1442                                  unset($tr[$user]);                                  unset($tr[$user]);
1443                          }                          }
   
1444                  }                  }
1445    $debug.="d(".display_trustee($perm['deny']).") a(".display_trustee($perm['allow']).") ";
1446    
1447          }          }
1448  #print "<br>user: $user path: $path perm: ";  $debug.="<br>check_trustee: user: $user path: $path==$tmppath perm: ";
1449  #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";
1450          return $perm;          return $perm;
1451  }  }
1452    
# Line 1438  function check_trustee($user,$path) { Line 1454  function check_trustee($user,$path) {
1454    
1455  function check_perm($path,$trperm) {  function check_perm($path,$trperm) {
1456          global $gblLogin,$HAVE_TRUSTEE;          global $gblLogin,$HAVE_TRUSTEE;
1457  print "<br>check_perm: <tt>$path</tt> test perm ".display_trustee($perm)."<br>\n";  
1458            $path = str_replace("//","/",$path);
1459    
1460            global $debug;
1461    $debug.="<br>check_perm: on <tt>$path</tt> for perm ".display_trustee($trperm)."<br>\n";
1462    
1463          $return = ! $HAVE_TRUSTEE;          $return = ! $HAVE_TRUSTEE;
1464          if ($HAVE_TRUSTEE) {          if ($HAVE_TRUSTEE) {
1465                  $perm = check_trustee($gblLogin,$path);                  $perm = check_trustee($gblLogin,$path);
1466  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).")";
1467                  if ($perm[deny] & $trperm) $return=0;                  if ($perm['deny'] & $trperm) $return=0;
1468                  elseif ($perm[allow] & $trperm) $return=1;                  elseif (($perm['allow'] & $trperm) == $trperm) $return=1;
1469          }          }
1470  print " return: $return<br>\n";  $debug.=" return: $return<br>\n";
1471          return($return);          return($return);
1472  }  }
1473    
# Line 1476  function readMime() { Line 1497  function readMime() {
1497  }  }
1498    
1499  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
1500    
1501    // check for invalid characters in filename and dirname (.. and /)
1502    
1503    function check_dirname($file) {
1504            if (strstr($file,"..")) Error("Security violation","No parent dir <tt>..</tt> allowed in directory name <tt>$file</tt>",1);
1505    }
1506    
1507    function check_filename($file) {
1508            if (strstr($file,"..")) Error("Security violation","No parent dir <tt>..</tt> allowed in file name <tt>$file</tt>",1);
1509            // remove deleted directory (for undelete to work)
1510            $file = str_replace(".del/","",$file);
1511            if (strstr($file,"/")) Error("Security violation","No slashes <tt>/</tt> allowed in file name <tt>$file</tt>",1);
1512    }
1513    
1514    // bla/blo/../foo will return bla/foo
1515    function remove_parent($path) {
1516            while (preg_match(",/[^/]+/\.\./,",$path)) {
1517                    $path = preg_replace(",/[^/]+/\.\./,","",$path);
1518            }
1519            if (substr($path,0,1) != "/") $path = "/".$path;
1520            return $path;
1521    }
1522    
1523    //////////////////////////////////////////////////////////////////
1524    
1525    // functions to move HTTP server variables to global namespace
1526    // [replacement for register_globals in php.ini]
1527    
1528    function HTTP_GET_VAR($var) {
1529            global $HTTP_GET_VARS, ${$var};
1530            if (isset($HTTP_GET_VARS[$var])) {
1531                    $$var = stripSlashes($HTTP_GET_VARS[$var]);
1532                    return $$var;
1533            }
1534    }
1535    
1536    function HTTP_POST_VAR($var) {
1537            global $HTTP_POST_VARS, ${$var};
1538            if (isset($HTTP_POST_VARS[$var])) {
1539                    $$var = $HTTP_POST_VARS[$var];
1540                    return $$var;
1541            }
1542    }
1543    
1544    function HTTP_SERVER_VAR($var) {
1545            global $HTTP_SERVER_VARS, ${$var};
1546            if (isset($HTTP_SERVER_VARS[$var])) {
1547                    $$var = $HTTP_SERVER_VARS[$var];
1548                    return $$var;
1549            }
1550    }
1551    
1552    //////////////////////////////////////////////////////////////////
1553    
1554    function Warn($text) {
1555    }
1556    
1557    //////////////////////////////////////////////////////////////////
1558  // MAIN PROGRAM  // MAIN PROGRAM
1559    
1560          $gblFilePerms = 0640 ;         // default for new files          $gblFilePerms = 0640 ;         // default for new files
1561          $gblDirPerms  = 0750 ;          // default for new dirs          $gblDirPerms  = 0750 ;          // default for new dirs
1562    
1563          $STYLE = $HTTP_GET_VARS[STYLE];          if (isset($HTTP_GET_VARS["STYLE"]) && $HTTP_GET_VARS["STYLE"] == "get") {
         if (isset($STYLE) && $STYLE == "get") {  
1564                  include("$html/docman.css");                  include("$html/docman.css");
1565                  exit;                  exit;
1566          }          }
# Line 1490  function readMime() { Line 1568  function readMime() {
1568          // location of master docman configuration file          // location of master docman configuration file
1569          $docman_conf = "/etc/docman.conf";          $docman_conf = "/etc/docman.conf";
1570          if (! file_exists($docman_conf)) {          if (! file_exists($docman_conf)) {
1571                  $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";
1572                                    
1573                  error_log("docman: $error");                  error_log("docman: $error");
1574                  Error("docman not installed completly",$error);                  Error("docman not installed completly",$error);
# Line 1502  function readMime() { Line 1580  function readMime() {
1580          }          }
1581    
1582          // try to add dir to script name to realm var          // try to add dir to script name to realm var
1583          if (is_dir("$fsRealmDir/$realm/".dirname($HTTP_SERVER_VARS[SCRIPT_NAME]))) {          if (is_dir("$fsRealmDir/$realm/".dirname($HTTP_SERVER_VARS["SCRIPT_NAME"]))) {
1584                  $realm .= "/".dirname($HTTP_SERVER_VARS[SCRIPT_NAME]);                  $realm .= dirname($HTTP_SERVER_VARS["SCRIPT_NAME"]);
1585                  $realm_sep = "/";                  $realm_sep = "/";
1586          } else {          } else {
1587                  $realm_sep = ".";                  $realm_sep = ".";
# Line 1527  function readMime() { Line 1605  function readMime() {
1605                  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>");
1606          }          }
1607    
1608            // take additional login vars
1609            HTTP_GET_VAR("relogin");
1610            HTTP_GET_VAR("force_login");
1611    
1612          // if no password, or empty password logout          // if no password, or empty password logout
1613          if (          if (
1614                  isset($gblLogin) && (                  isset($gblLogin) && (
# Line 1551  function readMime() { Line 1633  function readMime() {
1633          // get ACL informations          // get ACL informations
1634          $HAVE_TRUSTEE = init_trustee();          $HAVE_TRUSTEE = init_trustee();
1635    
1636          if (strtolower($gblLogin) == "anonymous" || !isset($gblPasswd)) {          if (strtolower($gblLogin) == "anonymous" || !isset($gblLogin)) {
1637                  $perm = check_trustee($gblLogin,$path);                  $perm = check_trustee("anonymous","/");
1638                  // browsing must be explicitly allowed for root directory                  // browsing must be explicitly allowed for root directory
1639                  // of repository for anonymous user to work!                  // of repository for anonymous user to work!
1640                  if ($perm[allow] & trperm_b) {                  if ($perm['allow'] & trperm_b) {
1641                            $gblLogin = $gblPasswd = "anonymous";
1642                          $secHash = md5($gblLogin.$gblPasswd);                          $secHash = md5($gblLogin.$gblPasswd);
1643                          $gblUserName = "Anonymous user";                          $gblUserName = "Anonymous user";
1644                  }                  }
# Line 1569  function readMime() { Line 1652  function readMime() {
1652                  Error("401 Unauthorized","No trespassing !",0,1);                  Error("401 Unauthorized","No trespassing !",0,1);
1653          }          }
1654    
1655    
1656          // read mime.types          // read mime.types
1657          readMime();          readMime();
1658    
1659          // get current directory relative to $gblFsRoot          if (! isset($gblPermNote)) {
1660          $relDir = $DIR ;        // from POST                  $gblPermNote = trperm_r;
1661          if ($relDir == "") {    // not defined in POST ?          }
                 $relDir = urldecode($D) ;  // then use GET  
         }        
   
         $relDir=stripSlashes($relDir);  
   
         if ($relDir == "/") $relDir = "" ;        
         // default : website root = ""  
1662    
1663          if (strstr($relDir,"..")) Error("No updirs allowed");          HTTP_POST_VAR("FN");
1664    
1665          // full paths contain "fs" or "Fs". Paths realitve to root of          if ($HTTP_SERVER_VARS["REQUEST_METHOD"] == "POST") {
1666          // website contain "rel" or "Rel". The script won't let you                  // take variables from server
1667          // edit anything above directory equal to http://server.com                  if (HTTP_POST_VAR("FN"))
1668          // i.e. below $gblFsRoot.                          check_filename($FN);
1669                    if (HTTP_POST_VAR("DIR")) {
1670                            check_dirname($DIR);
1671                            $relDir = $DIR;
1672                    } else {
1673                            trigger_error("Can't get DIR",E_USER_WARNING);
1674                            $relDir = "/";
1675                    }
1676                    if (HTTP_POST_VAR("RELPATH")) check_dirname($RELPATH);
1677                    HTTP_POST_VAR("T");
1678                    HTTP_POST_VAR("CONFIRM");
1679            } else {
1680                    // get
1681                    HTTP_GET_VAR("A");
1682                    if (HTTP_GET_VAR("D")) {
1683                            check_dirname($D);
1684                            $D=urldecode($D);
1685                            $relDir = $D;
1686                    } else {
1687                            //trigger_error("Can't get D",E_USER_WARNING);
1688                            $relDir = "/";
1689                    }
1690                    if (HTTP_GET_VAR("F")) check_filename($F);
1691            }
1692    
1693          $relScriptDir = dirname($SCRIPT_NAME) ;                  $relScriptDir = dirname($HTTP_SERVER_VARS["SCRIPT_NAME"]) ;    
1694          // i.e. /docman          // i.e. /docman
1695    
1696          // start on server root          // start on server root
1697          $gblFsRoot = $gblRepositoryDir;          $gblFsRoot = $gblRepositoryDir;
1698          // i.e. /home/httpd/html          // i.e. /home/httpd/repository
1699    
1700          $fsDir = $gblFsRoot . $relDir ; // current directory          $fsDir = $gblFsRoot . $relDir ; // current directory
1701          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) ;
1702    
1703            if ($relDir == "") $relDir="/";
1704    
1705          if (isset($HTTP_SERVER_VARS["HTTPS"]) && $HTTP_SERVER_VARS["HTTPS"] == "on") {          if (isset($HTTP_SERVER_VARS["HTTPS"]) && $HTTP_SERVER_VARS["HTTPS"] == "on") {
1706                  $webRoot  = "https://";                  $webRoot  = "https://";
# Line 1607  function readMime() { Line 1709  function readMime() {
1709          }          }
1710          $webRoot .= $HTTP_SERVER_VARS["HTTP_HOST"] . $relScriptDir;          $webRoot .= $HTTP_SERVER_VARS["HTTP_HOST"] . $relScriptDir;
1711    
1712          // take variables from server          if (HTTP_POST_VAR("POSTACTION")) switch ($POSTACTION) {
         $FN=stripSlashes($HTTP_POST_VARS["FN"]);  
         $DIR=stripSlashes($HTTP_POST_VARS["DIR"]);  
         $RELPATH=stripSlashes($HTTP_POST_VARS["RELPATH"]);  
         $T=stripSlashes($HTTP_POST_VARS["T"]);  
         $CONFIRM=stripSlashes($HTTP_POST_VARS["CONFIRM"]);  
   
         // get  
         $A=stripSlashes($HTTP_GET_VARS["A"]);  
         $D=stripSlashes($HTTP_GET_VARS["D"]);  
   
 //      if (isset($F)) Error("Document manager system error","variable $F shouldn't be set here (re-check old code)",1);  
 //      $F=stripSlashes($HTTP_SERVER_VARS["PATH_INFO"]);  
         $F=stripSlashes($HTTP_GET_VARS["F"]);  
   
         switch ($HTTP_POST_VARS["POSTACTION"]) {  
1713          case "UPLOAD" :          case "UPLOAD" :
1714                  $FN_name=stripSlashes($HTTP_POST_FILES["FN"]["tmp_name"]);                  $FN_name=stripSlashes($HTTP_POST_FILES["FN"]["tmp_name"]);
1715                  $FN=stripSlashes($HTTP_POST_FILES["FN"]["name"]);                  $FN=stripSlashes($HTTP_POST_FILES["FN"]["name"]);
# Line 1633  function readMime() { Line 1720  function readMime() {
1720                          Error("You must select file with browse to upload it!");                          Error("You must select file with browse to upload it!");
1721                  }                  }
1722    
1723                  $FILENAME = $HTTP_POST_VARS["FILENAME"];                  if (HTTP_POST_VAR("FILENAME")) check_filename($FILENAME);
1724                  if (strstr($FILENAME,"/"))  
                         Error("Upload error","Non-conforming filename. Filename <tt>$FILENAME</tt> has slashes (<tt>/</tt>) in it.") ;  
1725                  if (! isset($FILENAME)) {       // from update file                  if (! isset($FILENAME)) {       // from update file
1726                          $target = "$fsDir/".basename($FN);                          $target = "$fsDir/".basename($FN);
1727                  } else {                  } else {
1728                          $target = "$fsDir/$FILENAME";                          $target = "$fsDir/$FILENAME";
1729                  }                  }
1730    
1731                    if (! check_perm("$relDir/".basename($target), trperm_w))
1732                            Error("Access denied","User <tt>$gblLogin</tt> tried to upload <tt>$relDir/".basename($target)."</tt> without valid trustee.",1);
1733    
1734                  // backup old files first                  // backup old files first
1735                  $dir=dirname($target);                  $dir=dirname($target);
1736                  if (! file_exists($dir."/.bak")) {                  if (! file_exists($dir."/.bak")) {
1737                          mkdir($dir."/.bak",0700);                          mkdir($dir."/.bak",0700);
1738                  }                  }
1739                  if (! file_exists($dir."/.bak/$GLOBALS[gblNumBackups]")) {                  if (! file_exists($dir."/.bak/$gblNumBackups")) {
1740                          mkdir($dir."/.bak/$GLOBALS[gblNumBackups]",0700);                          mkdir($dir."/.bak/$gblNumBackups",0700);
1741                  }                  }
1742                  $file=basename($target);                  $file=basename($target);
1743                  for($i=$GLOBALS[gblNumBackups]-1;$i>0;$i--) {                  for($i=$gblNumBackups-1;$i>0;$i--) {
1744                          MoveTo("$dir/.bak/$i/$file","$dir/.bak/".($i+1)."/");                          MoveTo("$dir/.bak/$i/$file","$dir/.bak/".($i+1)."/");
1745                  }                  }
1746                  MoveTo($target,$dir."/.bak/1/");                  MoveTo($target,$dir."/.bak/1/");
# Line 1670  function readMime() { Line 1759  function readMime() {
1759          case "SAVE" :          case "SAVE" :
1760                  $path = $gblFsRoot . $RELPATH ;                  $path = $gblFsRoot . $RELPATH ;
1761                  $path=stripSlashes($path);                  $path=stripSlashes($path);
1762    
1763                    if (! check_perm("$RELPATH", trperm_w))
1764                            Error("Access denied","User <tt>$gblLogin</tt> tried to save <tt>$RELPATH</tt> without valid trustee.",1);
1765    
1766                  $writable = is_writeable($path) ;                  $writable = is_writeable($path) ;
1767                  $legaldir = is_writeable(dirname($path)) ;                  $legaldir = is_writeable(dirname($path)) ;
1768                  $exists   = (file_exists($path)) ? 1 : 0 ;                  $exists   = (file_exists($path)) ? 1 : 0 ;
1769  // check for legal extension here as well                  // FIX: more verbose error message
1770                  if (!($writable || (!$exists && $legaldir)))                  if (!($writable || (!$exists && $legaldir)))
1771                          Error("Write denied",$RELPATH) ;                          Error("Write denied",$RELPATH) ;
1772                  $fh = fopen($path, "w") ;                  $fh = fopen($path, "w") ;
1773                  $FILEDATA=stripSlashes($FILEDATA);                  HTTP_POST_VAR("FILEDATA");
1774                  fwrite($fh,$FILEDATA) ;                  fwrite($fh,$FILEDATA) ;
1775                  fclose($fh) ;                  fclose($fh) ;
1776                  clearstatcache() ;                  clearstatcache() ;
# Line 1686  function readMime() { Line 1779  function readMime() {
1779    
1780          case "CREATE" :          case "CREATE" :
1781                  // we know $fsDir exists                  // we know $fsDir exists
1782                  if ($FN == "") break;           // no filename!                  if (! check_perm($relDir, trperm_w))
1783                  if (!is_writeable($fsDir)) Error("Write denied",$relDir) ;                          Error("Write access denied","You don't have permission to write in <tt>$relDir</tt>");
1784                  $path = $fsDir . "/" . $FN ;  // file or dir to create                  if ($T == "D") $type = "directory";
1785                  $relPath = $relDir . "/" . $FN ;                  else $type ="file";
1786                    if ($FN == "") Error("Can't create $type","You must enter name of $type to create it.");
1787                    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) ;
1788                    $path = "$fsDir/$FN";           // file or dir to create
1789                    $relPath = "$relDir/$FN";
1790    
1791                    if (file_exists($path))
1792                            Error("Can't create $type","Object <tt>$relPath</tt> allready exists");
1793    
1794                  switch ( $T ) {                  switch ( $T ) {
1795                  case "D" :  // create a directory                  case "D" :  // create a directory
1796                          if ( ! @mkdir($path,$gblDirPerms) )                          if ( ! @mkdir($path,$gblDirPerms) )
# Line 1703  function readMime() { Line 1804  function readMime() {
1804  // better keep it here altogether  // better keep it here altogether
1805  // chmod perms to $gblFilePerms  // chmod perms to $gblFilePerms
1806                          if ( file_exists($path) && !is_writeable($path) )                          if ( file_exists($path) && !is_writeable($path) )
1807                                  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) ;
1808                          $fh = fopen($path, "w+") ;                          $fh = fopen($path, "w+") ;
1809                          if ($fh) {                          if ($fh) {
1810                                  fputs($fh,"\n");                                  fputs($fh,"\n");
1811                                  fclose($fh) ;                                  fclose($fh) ;
1812                                  LogIt($path,"file created",trperm_r | trperm_w);                                  LogIt($path,"file created",trperm_r | trperm_w);
1813                          } else {                          } else {
1814                                  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) ;
1815                          }                          }
1816                          $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) ;
1817                          header("Location: " . $tstr) ;                          header("Location: " . $tstr) ;
1818                          exit ;                          exit ;
1819                  }                  }
1820                  break ;                  break ;
1821    
1822          case "DELETE" :            case "DELETE" :  
1823                  if ( $CONFIRM != "on" ) break ;                  if ( $CONFIRM != "on" ) break;
1824    
1825                  $tstr  = "Attempt to delete non-existing object or " ;                  if ( isset($FN) && $FN != "") {
1826                  $tstr .= "insufficient privileges: " ;                          $path=$fsDir."/".$FN;
1827                            $what = "file";
1828                    } elseif (isset($DIR)) {
1829                            $path=$gblFsRoot."/".$DIR;
1830                            $what = "directory";
1831                    } else  {
1832                            Error("Can't delete object","Can't find filename <tt>\$FN</tt> or dirname in <tt>\$DIR</tt>",1);
1833                    }
1834    
1835                  if ( $FN != "") {  // delete file                  if (! check_perm("$relDir/$FN", trperm_w))
1836                          $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);  
                         }  
1837    
1838  //                      if ( ! @unlink($path) ) {                  $tstr  = "Attempt to delete non-existing object or insufficient privileges: " ;
1839                          if ( ! rename($path,"$dir/.del/$file") ) {  
1840                                  LogIt($path,"file delete failed");                  $dir=dirname($path);
1841                                  Error("File delete failed", $tstr . $path) ;                  $file=basename($path);
1842                          } else {  
1843                                  LogIt($path,"file deleted",trperm_w);                  if (! file_exists("$dir/.del")) {
1844                                  MoveTo("$dir/.log/$file","$dir/.del/.log/");                          mkdir("$dir/.del",0700);
1845                                  MoveTo("$dir/.note/$file","$dir/.del/.note/");                  }
1846                                  MoveTo("$dir/.lock/$file","$dir/.del/.lock/");  
1847                          }                  if ( ! @rename($path,"$dir/.del/$file") ) {
1848                  } else {  // delete directory                          LogIt($path,"$what delete failed");
1849                          if ( ! @rrmdir($fsDir) ) {                          Error("Can't delete $what",$tstr."<tt>".$relDir."/".$FN."</tt>") ;
1850                                  Error("Rmdir failed", $tstr . $fsDir) ;                  } else {
1851                          } else {                          LogIt($path,"$what deleted",trperm_w);
1852                                  LogIt($path,"dir deleted",trperm_w);                          MoveTo("$dir/.log/$file","$dir/.del/.log/");
1853                                  $relDir = dirname($relDir) ;  // move up                          MoveTo("$dir/.note/$file","$dir/.del/.note/");
1854                          }                          MoveTo("$dir/.lock/$file","$dir/.del/.lock/");
1855                  }                  }
1856                  break ;                  break ;
1857    
# Line 1759  function readMime() { Line 1861  function readMime() {
1861                  if (substr($FN,0,4) != ".del") break ;                  if (substr($FN,0,4) != ".del") break ;
1862                  $file=substr($FN,4,strlen($FN)-4);                  $file=substr($FN,4,strlen($FN)-4);
1863    
1864                    if (! check_perm("$relDir/$file", trperm_w))
1865                            Error("Access denied","User <tt>$gblLogin</tt> tried to undelete <tt>$relDir/$file</tt> without valid trustee.",1);
1866    
1867                  LogIt("$fsDir/.del/$file","undeleted",trperm_w);                  LogIt("$fsDir/.del/$file","undeleted",trperm_w);
1868                  MoveTo("$fsDir/.del/$file","$fsDir/");                  MoveTo("$fsDir/.del/$file","$fsDir/");
1869                  MoveTo("$fsDir/.del/.log/$file","$fsDir/.log/");                  MoveTo("$fsDir/.del/.log/$file","$fsDir/.log/");
# Line 1770  function readMime() { Line 1875  function readMime() {
1875          case "RENAME" :            case "RENAME" :  
1876                  if ( $CONFIRM != "on" ) break ;                  if ( $CONFIRM != "on" ) break ;
1877    
1878                  $NEWNAME=stripSlashes($HTTP_POST_VARS["NEWNAME"]);                  if (HTTP_POST_VAR("NEWNAME")) {
1879                            $dest = remove_parent($relDir.$NEWNAME);
1880                            if (! check_perm($relDir.$FN, trperm_w) ||
1881                                ! check_perm($dest, trperm_w) )
1882                                    Error("Access denied","User <tt>$gblLogin</tt> tried to rename <tt>$relDir$FN</tt> to <tt>$dest</tt> without valid trustee.",1);
1883                    } else {
1884                            Error("Rename error","Can't find new name in var <tt>\$NEWNAME</tt>",1);
1885                    }
1886                  LogIt("$fsDir/$FN","renamed $FN to $NEWNAME",trperm_r);                  LogIt("$fsDir/$FN","renamed $FN to $NEWNAME",trperm_r);
1887                  safe_rename($fsDir,$FN,$NEWNAME);                  safe_rename($fsDir,$FN,$NEWNAME);
1888                  break ;                  break ;
1889    
1890          case "NOTE" :            case "NOTE" :
1891                  $NOTE=stripSlashes($HTTP_POST_VARS["NOTE"]);                  if (! HTTP_POST_VAR("NOTE"))
1892                  WriteNote("$fsDir/$FN","$NOTE");                          Error("Can't add note to object","Can't find var <tt>\$NOTE</tt>",1);
1893                    if (! check_perm("$relDir/$FN", trperm_w))
1894                            Error("Access denied","User <tt>$gblLogin</tt> tried to add note to <tt>$relDir/$FN</tt> without valid trustee.",1);
1895    
1896                    WriteNote("$fsDir/$FN",$NOTE);
1897                  break ;                  break ;
1898    
1899          case "UNLOCK" :            case "UNLOCK" :  
1900                  if ( $CONFIRM != "on" ) break ;                  if ( $CONFIRM != "on" ) break ;
1901                    if (! check_perm("$relDir/$FN", trperm_w))
1902                            Error("Access denied","User <tt>$gblLogin</tt> tried to unlock <tt>$relDir/$FN</tt> without valid trustee.",1);
1903                  Unlock("$fsDir/$FN");                  Unlock("$fsDir/$FN");
1904                  break ;                  break ;
1905    
# Line 1790  function readMime() { Line 1908  function readMime() {
1908          }          }
1909    
1910          // common to all POSTs : redirect to directory view ($relDir)          // common to all POSTs : redirect to directory view ($relDir)
1911          if ( $POSTACTION != "" ) {          if (isset($POSTACTION)) {
1912                  $tstr = $PHP_SELF . "?D=" . urlencode($relDir) ;                  $tstr = $HTTP_SERVER_VARS["PHP_SELF"]."?D=".urlencode($relDir);
1913                  header("Location: " . $tstr) ;                    header("Location: ".$tstr) ;  
1914                  exit ;                  exit ;
1915          }          }
1916            
1917          // check for mode.. navigate, code display, upload, or detail?          // check for mode.. navigate, code display, upload, or detail?
1918          // $A=U : upload to path given in $D          // $A=U : upload to path given in $D
1919          // $A=E : display detail of file $D/$F and edit          // $A=E : display detail of file $D/$F and edit
# Line 1803  function readMime() { Line 1921  function readMime() {
1921          // $A=Co : checkout file $D/$F          // $A=Co : checkout file $D/$F
1922          // $A=Ci : checkin file $D/$F          // $A=Ci : checkin file $D/$F
1923          // $A=V : view file (do nothing except log)          // $A=V : view file (do nothing except log)
1924          // $A=I : include file .$F.php from $gblFsRoot          // $A=I : include file .$F.php from [$gblIncDir|realm]/include_php
1925          // default : display directory $D          // default : display directory $D
1926    
1927          switch ($A) {          if (isset($A)) switch ($A) {
1928          case "U" :          case "U" :
1929                  // upload to $relDir                  // upload to $relDir
1930                    if (! check_perm($relDir, trperm_w))
1931                            Error("Write access denied","You don't have permission to write in <tt>$relDir</tt>");
1932                  if (!is_writeable($gblFsRoot . $relDir))                  if (!is_writeable($gblFsRoot . $relDir))
1933                          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);
1934                  $text  = "Use this page to upload a single " ;                  $text  = "Use this page to upload a single " ;
1935                  $text .= "file to <B>$realm</B>." ;                  $text .= "file to <B>$realm</B>." ;
1936                  StartHTML("(Upload Page)", $text) ;                  StartHTML("(Upload Page)", $text) ;
# Line 1858  function readMime() { Line 1978  function readMime() {
1978                  EndHTML() ;                  EndHTML() ;
1979                  exit;                  exit;
1980          case "I" :          case "I" :
1981                  $F=stripSlashes($F);                  if (! isset($F) || $F == "")
1982                  $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);
1983                  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";
1984                    if (! file_exists($inc_file)) {
1985                            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);
1986                    }
1987                  if (!is_readable($inc_file))                  if (!is_readable($inc_file))
1988                          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);
1989                  $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";
1990                  $title = "You should define \$title variable with page title";                  $title = "You should define \$title variable with page title";
1991                  include($inc_file);                  include($inc_file);

Legend:
Removed from v.1.12  
changed lines
  Added in v.1.31

  ViewVC Help
Powered by ViewVC 1.1.26