/[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.18 by dpavlin, Sun Jul 28 16:24:54 2002 UTC revision 1.37 by dpavlin, Mon May 5 15:28:02 2003 UTC
# Line 1  Line 1 
1  <?php  <?php
2    
3  /*  /*
4   *      Document Manager ][   *      Document Manager ][
5   *   *
6   *      Dobrica Pavlinusic <dpavlin@rot13.org>   *      Dobrica Pavlinusic <dpavlin@rot13.org>
7   *   *
8   *      License: GPL2   *      License: GPL2
9   *   *
10   *      Document Manager 1.x was based on   *      Document Manager 1.x was based on
11   *      Copyright 1999 by John Martin d/b/a www.ANYPORTAL.com   *      Copyright 1999 by John Martin d/b/a www.ANYPORTAL.com
12   *      PHP version Copyright 2000 by Stefan@Wiesendanger.org   *      PHP version Copyright 2000 by Stefan@Wiesendanger.org
13   *   *
14   *      For more info, please see web pages at   *      For more info, please see web pages at
15   *      http://www.rot13.org/~dpavlin/docman.html   *      http://www.rot13.org/~dpavlin/docman.html
16   *   *
17   */   */
18    
19    
20  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
21  // CONFIGURATION OPTIONS  // CONFIGURATION OPTIONS
22    
23          error_reporting(E_ALL) ;                // 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 on view (so it won't open in associated application)          // force download on view (so it won't open in associated application)
29          $gblForceDownload = 0;          $gblForceDownload = 0;
30    
31          // date format          // date format
32          $gblDateFmt="Y-m-d";          $gblDateFmt="Y-m-d";
33  //      $gblDateFmt="D, F d, Y";  //      $gblDateFmt="D, F d, Y";
34    
35          // time format          // time format
36          $gblTimeFmt="H:i:s";          $gblTimeFmt="H:i:s";
37  //      $gblTimeFmt="g:i:sA";  //      $gblTimeFmt="g:i:sA";
38    
39          // Number of backup files to keep          // Number of backup files to keep
40          $gblNumBackups=3;          $gblNumBackups=3;
41    
42          // show red star if newer than ... days          // show red star if newer than ... days
43          $gblModDays=1;          $gblModDays=1;
44    
45          // choose GifIcon below unless you have the M$          // choose GifIcon below unless you have the M$
46          // WingDings font installed on your system          // WingDings font installed on your system
47    
48          $gblIcon="GifIcon";             // MockIcon or GifIcon          $gblIcon="GifIcon";             // MockIcon or GifIcon
49    
50          // the directory below should be /icons/ or /icons/small/          // the directory below should be /icons/ or /icons/small/
51          // on Apache; a set of icons is included in the distribution          // on Apache; a set of icons is included in the distribution
52    
53          $gblIconLocation="/icons/";          $gblIconLocation="/icons/";
54    
55          // files you want to be able to edit in text mode          // files you want to be able to edit in text mode
56          // and view with (primitive) syntax highlighting          // and view with (primitive) syntax highlighting
57    
58          $gblEditable = array( ".txt",".asa",".asp",".htm",".html",          $gblEditable = array( ".txt",".asa",".asp",".htm",".html",
59                                ".cfm",".php3",".php",".phtml",                                ".cfm",".php3",".php",".phtml",
60                                ".shtml",".css" ) ;                                ".shtml",".css" ) ;
61    
62          // files that will display as images on the detail page          // files that will display as images on the detail page
63          // (useless if your browser doesn't support them)          // (useless if your browser doesn't support them)
64    
65          $gblImages   = array( ".jpg",".jpeg",".gif",".png",".ico",          $gblImages   = array( ".jpg",".jpeg",".gif",".png",".ico",
66                                ".bmp",".xbm") ;                                ".bmp",".xbm") ;
67    
68          // which files to hide (separated by ,)          // which files to hide (separated by ,)
69          $gblHide = "";          $gblHide = "";
70    
71          // Where are users? (by default in .htusers file)          // Where are users? (by default in .htusers file)
72          $gblUsers = "file";          $gblUsers = "file";
73    
74  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
75    
76          $gblTitle = "Document Manager";          $gblTitle = "Document Manager";
77          $gblVersion = "2.0-pre1";          $gblVersion = "2.0-pre2";
78    
79          $secHash    = "";          $secHash    = "";
80    
81          // location of html files          // location of html files
82          $html = $gblIncDir."/html";          $html = $gblIncDir."/html";
83    
84          LoadLanguage($HTTP_SERVER_VARS["HTTP_ACCEPT_LANGUAGE"]);          // load language
85            if (isset($HTTP_SERVER_VARS["HTTP_ACCEPT_LANGUAGE"])) {
86          // for security and configuration                  LoadLanguage($HTTP_SERVER_VARS["HTTP_ACCEPT_LANGUAGE"]);
87          $realm=$HTTP_SERVER_VARS["HTTP_HOST"];          }
88    
89          $fsDocumentRoot = dirname($HTTP_SERVER_VARS[SCRIPT_FILENAME]);          // does gettext locale function exits?
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 (! function_exists("_")) {
91                    function _($str) { return $str; }
92          // globals for later          }
93          $gblLogin = $HTTP_SERVER_VARS[PHP_AUTH_USER];  
94          $gblPasswd = $HTTP_SERVER_VARS[PHP_AUTH_PW];          // for security and configuration
95            $realm=$HTTP_SERVER_VARS["HTTP_HOST"];
96  //////////////////////////////////////////////////////////////////  
97            $fsDocumentRoot = dirname($HTTP_SERVER_VARS["SCRIPT_FILENAME"]);
98  function LoadLanguage($lang) {          if ($fsDocumentRoot == "") Error("Configuration error","Can't get SCRIPT_FILENAME from your web server. Please set <tt>\$fsDocumentRoot</tt> in <tt>\$</tt>",1);
99    
100          global $gblIncDir,$html;          // globals for later
101            $gblLogin = HTTP_SERVER_VAR("PHP_AUTH_USER");
102          if (file_exists($gblIncDir."/lang/$lang.php")) {          $gblPasswd = HTTP_SERVER_VAR("PHP_AUTH_PW");
103                  include($gblIncDir."/lang/$lang.php");  
104                  $html .= "-$lang";  //////////////////////////////////////////////////////////////////
105          } else {  
106                  include($gblIncDir."/lang/default.php");  function LoadLanguage($lang) {
107          }  
108  }          global $gblIncDir,$html;
109    
110  function StartHTML($title,$text="") {          if (file_exists($gblIncDir."/lang/$lang.php")) {
111                    include($gblIncDir."/lang/$lang.php");
112          global $html,$fsDocumentRoot,$HTTP_SERVER_VARS;                  $html .= "-$lang";
113            } else {
114          $title = $gblTitle." ".$title ;                  include($gblIncDir."/lang/default.php");
115          $host  = $HTTP_SERVER_VARS["HTTP_HOST"] ;          }
116          $self  = $HTTP_SERVER_VARS["PHP_SELF"] ;  }
117    
118          if (file_exists("$fsDocumentRoot/docman.css")) {  function StartHTML($title,$text="") {
119                  $css=dirname($self)."/docman.css";  
120          } else {          global $html,$fsDocumentRoot,$gblTitle,$HTTP_SERVER_VARS;
121                  $css=$self."?STYLE=get";  
122          }          $host  = $HTTP_SERVER_VARS["HTTP_HOST"] ;
123            $self  = $HTTP_SERVER_VARS["PHP_SELF"] ;
124          include("$html/head.html");  
125  }          if (file_exists("$fsDocumentRoot/docman.css")) {
126                    $css=dirname($self)."/docman.css";
127  //////////////////////////////////////////////////////////////////          } else {
128                    $css=$self."?STYLE=get";
129  function EndHTML() {          }
130    
131          global $gblDateFmt, $gblTimeFmt, $gblUserName, $PHP_SELF,          include("$html/head.html");
132                  $secHash, $gblVersion, $html,  }
133                  $gblLogin,$gblPasswd;  
134    //////////////////////////////////////////////////////////////////
135          $url = $PHP_SELF."?relogin=";  
136          if (isset($secHash) && $secHash != "") {  function EndHTML() {
137                  $url .= $secHash;  
138          } else {          global $gblDateFmt, $gblTimeFmt, $gblUserName, $PHP_SELF,
139                  $url .= md5($gblLogin.$gblPasswd);                  $secHash, $gblVersion, $html,
140          }                  $gblLogin,$gblPasswd;
141          if ( (  (isset($gblLogin) && $gblLogin != "") ||  
142                  (!isset($gblLogin) || $gblLogin == "")          $url = $PHP_SELF."?relogin=";
143               ) && ($gblPasswd == "" || !isset($gblPasswd))) {          if (isset($secHash) && $secHash != "") {
144                  $url_title="login";                  $url .= $secHash;
145                  $url .= "&force_login=1";          } else {
146          } else {                  $url .= md5($gblLogin.$gblPasswd);
147                  $url_title="relogin";          }
148          }          if ( (  (isset($gblLogin) && $gblLogin != "") ||
149          include("$html/footer.html");                  (!isset($gblLogin) || $gblLogin == "")
150                 ) && ($gblPasswd == "" || !isset($gblPasswd))) {
151          global $debug;                  $url_title="login";
152          if ($debug) print $debug;                  $url .= "&force_login=1";
153  } // end function EndHTML          } else {
154                    $url_title="relogin";
155  //////////////////////////////////////////////////////////////////          }
156            include("$html/footer.html");
157  function DetailPage($fsRoot,$relDir,$fn) {  
158            #       global $debug;
159          global $gblEditable, $gblImages, $webRoot, $html, $HTTP_SERVER_VARS ;  #       if ($debug) print $debug;
160          $self = $HTTP_SERVER_VARS["PHP_SELF"] ;  } // end function EndHTML
161    
162          $relPath  = $relDir . "/" . $fn ;  //////////////////////////////////////////////////////////////////
163          $fsPath   = $fsRoot . $relPath ;  
164          $fsDir    = $fsRoot . $relDir ;  function DetailPage($fsRoot,$relDir,$fn) {
165            
166          $exists   = file_exists($fsPath) ;          global $gblEditable, $gblImages,
167          $ext      = strtolower(strrchr($relPath,".")) ;                  $gblDateFmt, $gblTimeFmt,
168          $editable = ( $ext=="" || strstr(join(" ",$gblEditable),$ext)) &&                  $gblPermNote,
169                  check_perm($relPath,trperm_w);                  $webRoot, $html,
170          $writable = is_writeable($fsPath) && check_perm($relPath,trperm_w) ;                  $HTTP_SERVER_VARS ;
171          $writable_dir = is_writeable($fsDir) && check_perm($relDir,trperm_w) ;          $self = $HTTP_SERVER_VARS["PHP_SELF"] ;
172          $file_lock = CheckLock($fsPath);  
173            $relPath  = $relDir . "/" . $fn ;
174          if (!$editable && !$exists)          $fsPath   = $fsRoot . $relPath ;
175                  Error("Creation denied","Can't create <tt>$relPath</tt>") ;          $fsDir    = $fsRoot . $relDir ;
176          if (!$exists && !$writable_dir )  
177                  Error("Creation denied","Can't write in directory <tt>$relDir</tt> while creating <tt>$relPath</tt>for which user has permissions.",1);          $exists   = file_exists($fsPath) ;
178            $ext      = strtolower(strrchr($relPath,".")) ;
179          $text  = _("Use this page to view, modify or ") ;          $editable = ( $ext=="" || strstr(join(" ",$gblEditable),$ext)) &&
180          if (is_dir($fsPath)) {                  check_perm($relPath,trperm_w);
181                  $text .=_("delete a directory on this ") ;          $writable = is_writeable($fsPath) && check_perm($relPath,trperm_w) ;
182          } else {          $writable_dir = is_writeable($fsDir) && check_perm($relDir,trperm_w) ;
183                  $text .= _("delete a single document on this ") ;          $file_lock = CheckLock($fsPath);
184          };  
185          $text .= _("web site.") ;                if (!$editable && !$exists)
186          $title = "("._("Detail Page").")" ;                  Error("Creation denied","Can't create <tt>$relPath</tt>") ;
187          StartHTML($title, $text) ;          if (!$exists && !$writable_dir )
188                    Error("Creation denied","Can't write in directory <tt>$relDir</tt> while creating <tt>$relPath</tt>for which user has permissions.",1);
189          echo "<H3>" . $relDir . "/" . $fn . "</H3>" ;  
190          if ($exists) {  // get file info          $text  = _("Use this page to view, modify or ") ;
191                  $fsize = filesize($fsPath) ;          if (is_dir($fsPath)) {
192                  $fmodified = date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]", filemtime($fsPath)) ;                  $text .=_("delete a directory on this ") ;
193                  $faccessed = date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]", fileatime($fsPath)) ;          } else {
194                  $fuid=fileowner($fsPath);                  $text .= _("delete a single document on this ") ;
195                  $fgid=filegroup($fsPath);          };
196                  $userinfo = posix_getpwuid($fuid);          $text .= _("web site.") ;      
197                  $grpinfo = posix_getgrgid($fgid);          $title = "("._("Detail Page").")" ;
198            StartHTML($title, $text) ;
199                  include("$html/DetailPage-file.html");  
200          }          print "<H3>".$relDir.$fn."</H3>";
201    
202          if ( !is_dir($fsPath) && $editable && ($writable || !$exists) && !$file_lock ) {          if ($exists) {  // get file info
203                  $fh = fopen($fsPath,"a+") ;                  $fsize = filesize($fsPath) ;
204                  rewind($fh) ;                  $fmodified = date("$gblDateFmt $gblTimeFmt", filemtime($fsPath)) ;
205                  $fstr = fread($fh,filesize($fsPath)) ;                  $faccessed = date("$gblDateFmt $gblTimeFmt", fileatime($fsPath)) ;
206                  fclose($fh) ;                  $fuid=fileowner($fsPath);
207                  $fstr = htmlentities( $fstr ) ;                  $fgid=filegroup($fsPath);
208  ?>                  $userinfo = posix_getpwuid($fuid);
209                    $grpinfo = posix_getgrgid($fgid);
210  <FORM ACTION="<?= $self ?>" METHOD="POST">  
211  <SPAN TITLE="Click [SAVE] to store updated contents.">                  include("$html/DetailPage-file.html");
212          <B>DOCUMENT CONTENTS</B>          }
213  </SPAN><BR>  
214  <TEXTAREA NAME="FILEDATA" ROWS=18 COLS=70 WRAP="OFF"><?php          if ( !is_dir($fsPath) && $editable && ($writable || !$exists) && !$file_lock ) {
215  echo($fstr) ; ?></TEXTAREA>                  $fh = fopen($fsPath,"a+") ;
216  <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ; ?>">                  rewind($fh) ;
217  <INPUT TYPE="HIDDEN" NAME="FN" VALUE="<?= $fn ; ?>">                  $fstr = fread($fh,filesize($fsPath)) ;
218  <INPUT TYPE="HIDDEN" NAME="POSTACTION" VALUE="SAVE">                  fclose($fh) ;
219  <INPUT TYPE="HIDDEN" SIZE=48 MAXLENGTH=255 NAME="RELPATH"                  $fstr = htmlentities( $fstr ) ;
220          VALUE="<?= $relPath ; ?>">  
221  <br>                  include("$html/DetailPage-edit.html");
222  <INPUT TYPE="RESET" VALUE="UNDO ALL CHANGES">          }
223  <INPUT TYPE="SUBMIT" VALUE="SAVE">          if ( !$file_lock && $ext!="" && strstr(join(' ',$gblImages),$ext) ) {  
224  </FORM>                  $info  = getimagesize($fsPath) ;
225                    $tstr = "<IMG SRC=\"$self?A=V&D=".urlpath(dirname($relPath))."&F=".urlpath(basename($relPath))."\" BORDER=0 " ;
226  <?php                  $tstr .= $info[3] . " ALT=\"" . $fn . " - " ;
227          }                  $tstr .= (int)(($fsize+1023)/1024) . "Kb\">" ;
228          if ( !$file_lock && $ext!="" && strstr(join(' ',$gblImages),$ext) ) {    //              echo htmlentities($tstr) . "<BR><BR>" . $tstr ;
229                  $info  = getimagesize($fsPath) ;                  echo $tstr ;
230                  $tstr = "<IMG SRC=\"$webRoot".urlpath($relPath)."\" BORDER=0 " ;          }
231                  $tstr .= $info[3] . " ALT=\"" . $fn . " - " ;  
232                  $tstr .= (int)(($fsize+1023)/1024) . "Kb\">" ;  
233  //              echo htmlentities($tstr) . "<BR><BR>" . $tstr ;          print '<FORM ACTION="'.$self.'" METHOD="POST">
234                  echo $tstr ;                  <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="'.$relDir.'">
235          }                  <INPUT TYPE="HIDDEN" NAME="FN" VALUE="'.$fn.'">
236                    <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="CANCEL"><BR>
237  ?>                  ';
238    
239  <FORM ACTION="<?= $self ; ?>" METHOD="POST">          if ($file_lock && check_perm($relDir.$fn,trperm_w)) {
240  <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ; ?>">                  include("$html/DetailPage-unlock.html");
241  <INPUT TYPE="HIDDEN" NAME="FN" VALUE="<?= $fn ; ?>">          } // file_lock
242  <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="CANCEL"><BR>  
243            if (substr($fn,0,4) == ".del") {
244  <?php                  $action="UNDELETE";
245                    $desc="undelete previously deleted file";
246          if ($file_lock) {          } else {
247  ?>                  $action="DELETE";
248  <hr>                  $desc="delete";
249  <SPAN TITLE="Check OK and click UNLOCK to remove lock on file.">          }
250  <B>OK TO FORCE LOCK REMOVAL ON "<?= $fn ; ?>" HELD BY <?= $file_lock ?>? </B></SPAN>  
251  <INPUT TYPE="CHECKBOX" NAME="CONFIRM">          if ($exists && $writable) {
252  <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="UNLOCK">                  include("$html/DetailPage-undelete.html");
253  <?                  include("$html/DetailPage-rename.html");
254          } // file_lock  
255            }
256          if (substr($fn,0,4) == ".del") {          
257                  $action="UNDELETE";          if (check_perm($relDir.$fn,$gblPermNote)) {
258                  $desc="undelete previously deleted file";                  include("$html/DetailPage-note.html");
259          } else {          }
260                  $action="DELETE";  
261                  $desc="delete";          print "</FORM>";
262          }  
263            $name=basename("$fsDir/$fn");
264          if ($exists && $writable) {          $logname=dirname("$fsDir/$fn")."/.log/$name";
265  ?>          $bakdir=dirname("$fsDir/$fn")."/.bak";
266            if (file_exists($logname)) {
267  <HR>                  $log=fopen($logname,"r");
268  <a name="undelete">                  $cl1=" class=LST"; $cl2="";
269  <SPAN TITLE="Check OK and click [<?= $action ?>] to <?= $desc ?>.">                  $logarr = array();
270  <B>OK TO <?= $action ?> "<?= $fn ; ?>"? </B></SPAN>                  while($line = fgetcsv($log,512,"\t")) {
271  <INPUT TYPE="CHECKBOX" NAME="CONFIRM">                          $cl=$cl1; $cl1=$cl2; $cl2=$cl;
272  <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="<?= $action ?>">                          array_unshift($logarr,array($cl,$line[0],$line[1],$line[2],$line[3]));
273                    }
274  <HR>                  fclose($log);
275  <a name="rename">                  if (is_dir("$fsDir/$fn")) {
276  <SPAN TITLE="Check OK and click [RENAME] to rename.">                          $whatis="DIRECTORY";
277  <B>OK TO RENAME "<?= $fn ; ?>" TO                  } else {
278  <INPUT TYPE="TEXT" SIZE=24 MAXLENGTH=255 NAME="NEWNAME" VALUE="<?= $fn ?>">                          $whatis="FILE";
279  ? </B></SPAN>                  }
280  <INPUT TYPE="CHECKBOX" NAME="CONFIRM">                  print "<hr><br><b>CHANGES TO THIS $whatis</b><br><table border=0 width=100%>\n";
281  <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="RENAME">                  $bakcount = 0;  // start from 0, skip fist backup (it's current)
282                    while ($e = array_shift($logarr)) {
283  <?php                          if (strstr($e[4],"upload")) {
284          }       // exists && writable                                  if (file_exists("$bakdir/$bakcount/$name")) {
285  ?>                                          $e[4]="<a href=\"$webRoot".urlpath(dirname($relPath)."/.bak/$bakcount/$name")."\">$e[4]</a>";
286  <HR>                                  }
287  <a name="note">                                  $bakcount++;
288  <B>NOTE FOR "<?= $fn ; ?>":                          }
289  <INPUT TYPE="TEXT" SIZE=50 MAXLENGTH=255 NAME="NOTE" VALUE="<?= ReadNote($fsPath) ?>">                          print "<tr><td$e[0]>$e[1]</td><td$e[0]>$e[2]</td><td$e[0]>$e[3]</td><td$e[0]>$e[4]</td></tr>\n";
290  </B></SPAN>                  }
291  <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="NOTE">                  print "</table>";
292            }
293  </FORM>  
294            EndHTML() ;
295  <?php  
296    } // end function DetailPage
297          $name=basename("$fsDir/$fn");  
298          $logname=dirname("$fsDir/$fn")."/.log/$name";  //////////////////////////////////////////////////////////////////
299          $bakdir=dirname("$fsDir/$fn")."/.bak";  
300          if (file_exists($logname)) {  function DisplayCode($fsRoot,$relDir,$fn) {
301                  $log=fopen($logname,"r");  
302                  $cl1=" class=LST"; $cl2="";          $path = $fsRoot . $relDir . "/" . $fn ;
303                  $logarr = array();  
304                  while($line = fgetcsv($log,512,"\t")) {          if (!file_exists($path)) Error("File not found",$path) ;
305                          $cl=$cl1; $cl1=$cl2; $cl2=$cl;  
306                          array_unshift($logarr,array($cl,$line[0],$line[1],$line[2],$line[3]));          StartHTML("(".$relDir."/".$fn.")","");
307                  }  
308                  fclose($log);          $tstr = join("",file($path)) ;
309                  if (is_dir("$fsDir/$fn")) {          $tstr = htmlentities($tstr) ;
310                          $whatis="DIRECTORY";  
311                  } else {          // Tabs
312                          $whatis="FILE";          $tstr = str_replace(chr(9),"   ",$tstr) ;  
313                  }  
314                  print "<hr><br><b>CHANGES TO THIS $whatis</b><br><table border=0 width=100%>\n";          // ASP tags & XML/PHP tags
315                  $bakcount = 0;  // start from 0, skip fist backup (it's current)          $aspbeg = "<SPAN CLASS=XML>&lt;%</SPAN><SPAN CLASS=BLK>" ;
316                  while ($e = array_shift($logarr)) {          $aspend = "</SPAN><SPAN CLASS=XML>%&gt;</SPAN>" ;
317                          if (strstr($e[4],"upload")) {          $tstr = str_replace("&lt;%",$aspbeg,$tstr) ;
318                                  if (file_exists("$bakdir/$bakcount/$name")) {          $tstr = str_replace("%&gt;",$aspend,$tstr) ;    
319                                          $e[4]="<a href=\"$webRoot".urlpath(dirname($relPath)."/.bak/$bakcount/$name")."\">$e[4]</a>";  
320                                  }          $xmlbeg = "<SPAN CLASS=XML>&lt;?</SPAN><SPAN CLASS=BLK>" ;
321                                  $bakcount++;          $xmlend = "</SPAN><SPAN CLASS=XML>?&gt;</SPAN>" ;
322                          }          $tstr = str_replace("&lt;?",$xmlbeg,$tstr) ;
323                          print "<tr><td$e[0]>$e[1]</td><td$e[0]>$e[2]</td><td$e[0]>$e[3]</td><td$e[0]>$e[4]</td></tr>\n";          $tstr = str_replace("?&gt;",$xmlend,$tstr) ;    
324                  }  
325                  print "</table>";          // C style comment
326          }          $tstr = str_replace("/*","<SPAN CLASS=REM>/*",$tstr) ;  
327            $tstr = str_replace("*/","*/</SPAN>",$tstr) ;                  
328          EndHTML() ;  
329            // HTML comments
330  } // end function DetailPage          $tstr = str_replace("&lt;!--","<I CLASS=RED>&lt;!--",$tstr) ;  
331            $tstr = str_replace("--&gt;","--&gt;</I>",$tstr) ;  
332  //////////////////////////////////////////////////////////////////  
333            echo "<PRE>" ;  
334  function DisplayCode($fsRoot,$relDir,$fn) {  
335            $tstr = split("\n",$tstr) ;
336          $path = $fsRoot . $relDir . "/" . $fn ;          for ($i = 0 ; $i < sizeof($tstr) ; ++$i) {
337                    // add line numbers
338          if (!file_exists($path)) Error("File not found",$path) ;                  echo "<BR><EM>" ;
339                    echo substr(("000" . ($i+1)), -4) . ":</EM> " ;
340          StartHTML("(".$relDir."/".$fn.")","");                  $line = $tstr[$i] ;
341                    // C++ style comments
342          $tstr = join("",file($path)) ;                  $pos = strpos($line,"//") ;
343          $tstr = htmlentities($tstr) ;                  // exceptions: two slashes aren't a script comment
344                    if (strstr($line,"//") &&
345          // Tabs                      ! ($pos>0 && substr($line,$pos-1,1)==":") &&
346          $tstr = str_replace(chr(9),"   ",$tstr) ;                        ! (substr($line,$pos,8) == "//--&gt;") &&
347                        ! (substr($line,$pos,9) == "// --&gt;")) {
348          // ASP tags & XML/PHP tags                   $beg = substr($line,0,strpos($line,"//")) ;
349          $aspbeg = "<SPAN CLASS=XML>&lt;%</SPAN><SPAN CLASS=BLK>" ;                   $end = strstr($line,"//") ;
350          $aspend = "</SPAN><SPAN CLASS=XML>%&gt;</SPAN>" ;                   $line = $beg."<SPAN CLASS=REM>".$end."</SPAN>";
351          $tstr = str_replace("&lt;%",$aspbeg,$tstr) ;                  }
352          $tstr = str_replace("%&gt;",$aspend,$tstr) ;                      // shell & asp style comments
353                    $first = substr(ltrim($line),0,1) ;
354          $xmlbeg = "<SPAN CLASS=XML>&lt;?</SPAN><SPAN CLASS=BLK>" ;                  if ($first == "#" || $first == "'") {
355          $xmlend = "</SPAN><SPAN CLASS=XML>?&gt;</SPAN>" ;                   $line = "<SPAN CLASS=REM>".$line."</SPAN>";
356          $tstr = str_replace("&lt;?",$xmlbeg,$tstr) ;                  }
357          $tstr = str_replace("?&gt;",$xmlend,$tstr) ;                      print($line) ;
358            } // next i
359          // C style comment  
360          $tstr = str_replace("/*","<SPAN CLASS=REM>/*",$tstr) ;            echo "</PRE>" ;
361          $tstr = str_replace("*/","*/</SPAN>",$tstr) ;                                    
362            EndHTML() ;
363          // HTML comments  
364          $tstr = str_replace("&lt;!--","<I CLASS=RED>&lt;!--",$tstr) ;    } // end function DisplayCode
365          $tstr = str_replace("--&gt;","--&gt;</I>",$tstr) ;    
366    //////////////////////////////////////////////////////////////////
367          echo "<PRE>" ;    
368    function MockIcon($txt) {
369          $tstr = split("\n",$tstr) ;          $tstr = "<SPAN CLASS=MCK>" ;
370          for ($i = 0 ; $i < sizeof($tstr) ; ++$i) {  
371                  // add line numbers          switch (strtolower($txt)) {
372                  echo "<BR><EM>" ;          case ".bmp" :
373                  echo substr(("000" . ($i+1)), -4) . ":</EM> " ;          case ".gif" :
374                  $line = $tstr[$i] ;          case ".jpg" :
375                  // C++ style comments          case ".jpeg":
376                  $pos = strpos($line,"//") ;          case ".tif" :
377                  // exceptions: two slashes aren't a script comment          case ".tiff":
378                  if (strstr($line,"//") &&                  $d = 176 ;
379                      ! ($pos>0 && substr($line,$pos-1,1)==":") &&                  break ;
380                      ! (substr($line,$pos,8) == "//--&gt;") &&          case ".doc" :
381                      ! (substr($line,$pos,9) == "// --&gt;")) {                  $d = 50 ;
382                   $beg = substr($line,0,strpos($line,"//")) ;                  break ;
383                   $end = strstr($line,"//") ;          case ".exe" :
384                   $line = $beg."<SPAN CLASS=REM>".$end."</SPAN>";          case ".bat" :
385                  }                  $d = 255 ;
386                  // shell & asp style comments                  break ;
387                  $first = substr(ltrim($line),0,1) ;          case ".bas" :
388                  if ($first == "#" || $first == "'") {          case ".c"   :
389                   $line = "<SPAN CLASS=REM>".$line."</SPAN>";          case ".cc"  :
390                  }          case ".src" :
391                  print($line) ;                  $d = 255 ;
392          } // next i                  break ;
393            case "file" :
394          echo "</PRE>" ;                  $d = 51 ;
395                                    break ;
396          EndHTML() ;          case "fldr" :
397                    $d = 48 ;
398  } // end function DisplayCode                  break ;
399            case ".htm" :
400  //////////////////////////////////////////////////////////////////          case ".html":
401            case ".asa" :
402  function MockIcon($txt) {          case ".asp" :
403          $tstr = "<SPAN CLASS=MCK>" ;          case ".cfm" :
404            case ".php3":
405          switch (strtolower($txt)) {          case ".php" :
406          case ".bmp" :          case ".phtml" :
407          case ".gif" :          case ".shtml" :
408          case ".jpg" :                  $d = 182 ;
409          case ".jpeg":                  break ;
410          case ".tif" :          case ".pdf" :
411          case ".tiff":                  $d = 38 ;
412                  $d = 176 ;                  break;
413                  break ;          case ".txt" :
414          case ".doc" :          case ".ini" :
415                  $d = 50 ;                  $d = 52 ;
416                  break ;                  break ;
417          case ".exe" :          case ".xls" :
418          case ".bat" :                  $d = 252 ;
419                  $d = 255 ;                  break ;
420                  break ;          case ".zip" :
421          case ".bas" :          case ".arc" :
422          case ".c"   :          case ".sit" :
423          case ".cc"  :          case ".tar" :
424          case ".src" :          case ".gz"  :
425                  $d = 255 ;          case ".tgz" :
426                  break ;          case ".Z"   :
427          case "file" :                  $d = 59 ;
428                  $d = 51 ;                  break ;
429                  break ;          case "view" :
430          case "fldr" :                  $d = 52 ;
431                  $d = 48 ;                  break ;
432                  break ;          case "up" :
433          case ".htm" :                  $d = 199 ;
434          case ".html":                  break ;
435          case ".asa" :          case "blank" :
436          case ".asp" :                  return "&nbsp;&nbsp;</SPAN>" ;
437          case ".cfm" :                  break ;
438          case ".php3":          default :
439          case ".php" :                  $d = 51 ;
440          case ".phtml" :          }
441          case ".shtml" :  
442                  $d = 182 ;          return $tstr . chr($d) . "</SPAN>" ;
443                  break ;  } // end function MockIcon
444          case ".pdf" :  
445                  $d = 38 ;  //////////////////////////////////////////////////////////////////
446                  break;  
447          case ".txt" :  function GifIcon($txt = "") {
448          case ".ini" :          global $gblIconLocation, $gblImages ;
449                  $d = 52 ;  
450                  break ;          switch (strtolower($txt)) {
451          case ".xls" :          case ".doc" :
452                  $d = 252 ;                  $d = "layout.gif" ;
453                  break ;                  break ;
454          case ".zip" :          case ".exe" :
455          case ".arc" :          case ".bat" :
456          case ".sit" :                  $d = "screw2.gif" ;
457          case ".tar" :                  break ;
458          case ".gz"  :          case ".bas" :
459          case ".tgz" :          case ".c"   :
460          case ".Z"   :          case ".cc"  :
461                  $d = 59 ;          case ".src" :
462                  break ;                  $d = "c.gif" ;
463          case "view" :                  break ;
464                  $d = 52 ;          case "file" :
465                  break ;                  $d = "generic.gif" ;
466          case "up" :                  break ;
467                  $d = 199 ;          case "fldr" :
468                  break ;                  $d = "dir.gif" ;
469          case "blank" :                  break ;
470                  return "&nbsp;&nbsp;</SPAN>" ;          case ".phps" :
471                  break ;                  $d = "phps.gif" ;
472          default :                  break ;
473                  $d = 51 ;          case ".php3" :
474          }                  $d = "php3.gif" ;
475                    break ;
476          return $tstr . chr($d) . "</SPAN>" ;          case ".htm" :
477  } // end function MockIcon          case ".html":
478            case ".asa" :
479  //////////////////////////////////////////////////////////////////          case ".asp" :
480            case ".cfm" :
481  function GifIcon($txt) {          case ".php3":
482          global $gblIconLocation ;          case ".php" :
483            case ".phtml" :
484          switch (strtolower($txt)) {          case ".shtml" :
485          case ".bmp" :                  $d = "world1.gif" ;
486          case ".gif" :                  break ;
487          case ".jpg" :          case ".pdf" :
488          case ".jpeg":                  $d = "pdf.gif" ;
489          case ".tif" :                  break;
490          case ".tiff":          case ".txt" :
491                  $d = "image2.gif" ;          case ".ini" :
492                  break ;                  $d = "text.gif" ;
493          case ".doc" :                  break ;
494                  $d = "layout.gif" ;          case ".xls" :
495                  break ;                  $d = "box2.gif" ;
496          case ".exe" :                  break ;
497          case ".bat" :          case ".zip" :
498                  $d = "screw2.gif" ;          case ".arc" :
499                  break ;          case ".sit" :
500          case ".bas" :          case ".tar" :
501          case ".c"   :          case ".gz"  :
502          case ".cc"  :          case ".tgz" :
503          case ".src" :          case ".Z"   :
504                  $d = "c.gif" ;                  $d = "compressed.gif" ;
505                  break ;                  break ;
506          case "file" :          case "view" :
507                  $d = "generic.gif" ;                  $d = "index.gif" ;
508                  break ;                  break ;
509          case "fldr" :          case "up" :
510                  $d = "dir.gif" ;                  $d = "back.gif" ;
511                  break ;                  break ;
512          case ".phps" :          case "blank" :
513                  $d = "phps.gif" ;                  $d = "blank.gif" ;
514                  break ;                  break ;
515          case ".php3" :          case "checkout":
516                  $d = "php3.gif" ;                  $d = "box2.gif";
517                  break ;                  break;
518          case ".htm" :          case "checkin":
519          case ".html":                  $d = "hand.up.gif";
520          case ".asa" :                  break;
521          case ".asp" :          case "locked":
522          case ".cfm" :                  $d = "screw2.gif";
523          case ".php3":                  break;
524          case ".php" :          case "note":
525          case ".phtml" :                  $d = "quill.gif";
526          case ".shtml" :                  break;
527                  $d = "world1.gif" ;          default :
528                  break ;                  if (in_array(strtolower($txt),$gblImages)) {
529          case ".pdf" :                          $d = "image2.gif" ;
530                  $d = "pdf.gif" ;                  } else {
531                  break;                          $d = "generic.gif" ;
532          case ".txt" :                  }
533          case ".ini" :          }
534                  $d = "text.gif" ;  
535                  break ;  
536          case ".xls" :          return "<IMG SRC=\"$gblIconLocation" . $d . "\" BORDER=0>" ;
537                  $d = "box2.gif" ;  } // end function GifIcon
538                  break ;  
539          case ".zip" :  //////////////////////////////////////////////////////////////////
540          case ".arc" :  
541          case ".sit" :  function Navigate($fsRoot,$relDir) {
542          case ".tar" :  
543          case ".gz"  :          global $gblEditable, $gblIcon, $gblModDays, $webRoot, $gblHide,
544          case ".tgz" :                  $gblIgnoreUnknownFileType, $gblRepositoryDir,
545          case ".Z"   :                  $gblLogin, $gblUserName, $gblDateFmt, $gblTimeFmt,
546                  $d = "compressed.gif" ;                  $gblPermNote,
547                  break ;                  $fsRealmDir, $realm, $realm_sep,
548          case "view" :                  $html, $realm_config,
549                  $d = "index.gif" ;                  $HTTP_GET_VARS, $HTTP_SERVER_VARS;
550                  break ;          
551          case "up" :          $self     = $HTTP_SERVER_VARS["PHP_SELF"] ;
552                  $d = "back.gif" ;  
553                  break ;          $relDir = chopsl($relDir)."/";
554          case "blank" :          $fsDir = $fsRoot.$relDir;       // current directory
555                  $d = "blank.gif" ;  
556                  break ;          if (!is_dir($fsDir)) Error("Dir not found","Directory <tt>$relDir<tt> not found on filesystem at <tt>$fsDir</tt>",1) ;
557          case "checkout":  
558                  $d = "box2.gif";          global $debug;
559                  break;          $debug .= "[$gblLogin|$relDir] before >";
560          case "checkin":  
561                  $d = "hand.up.gif";          if (! check_perm($relDir,trperm_b))
562                  break;                  Error("Access denied","User <tt>$gblLogin</tt> tried to access <tt>$relDir</tt> without valid trustee.",1);
563          case "locked":          $debug .= "< afeter";
564                  $d = "screw2.gif";  
565                  break;          $hide_items=",$gblHide,";
566          case "note":  
567                  $d = "quill.gif";          $dirList = array();
568                  break;          $fileList = array();
569          default :  
570                  $d = "generic.gif" ;          // read directory contents
571          }          if ( !($dir = @opendir($fsDir)) )
572                    Error("Read Access denied",$relDir,1) ;
573          return "<IMG SRC=\"$gblIconLocation" . $d . "\" BORDER=0>" ;          while ($item = readdir($dir)) {
574  } // end function GifIcon                  if ( substr($item,0,1) == "." || strstr($hide_items,",$item,") ) continue ;
575                    if (is_dir($fsDir.$item) || is_link ($fsDir.$item)) {
576  //////////////////////////////////////////////////////////////////                          if (check_perm($relDir.$item,trperm_b)) {
577                                    $dirList[$item] = $item ;
578  function Navigate($fsRoot,$relDir) {                                  $dirNote[$item] = ReadNote($fsDir.$item);
579                            }
580          global $gblEditable, $gblIcon, $gblModDays, $webRoot, $gblHide,                  } else if (is_file($fsDir.$item)) {
581                  $gblIgnoreUnknownFileType, $gblRepositoryDir,                          if (check_perm($relDir.$item,trperm_r)) {
582                  $fsRealmDir, $realm, $realm_sep,                                  $fileList[$item] = $item ;              
583                  $HTTP_GET_VARS, $html, $realm_config;                                  $fileDate[$item] = filemtime($fsDir.$item) ;
584                                            $fileSize[$item] = filesize($fsDir.$item) ;
585          $self     = $HTTP_SERVER_VARS["PHP_SELF"] ;                                  $fileNote[$item] = ReadNote($fsDir.$item);
586                            }
587          $relDir = chopsl($relDir)."/";                  } else {
588          $fsDir = $fsRoot.$relDir;       // current directory                          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);
589                    }
590          if (!is_dir($fsDir)) Error("Dir not found","Directory <tt>$relDir<tt> not found on filesystem at <tt>$fsDir</tt>",1) ;          }
591            closedir($dir) ;
592          global $debug;  
593          $debug .= "[$gblLogin|$relDir] before >";          // scan deleted files
594            if ( HTTP_GET_VAR("show_deleted") == 1 && ($dir = @opendir("$fsDir/.del")) ) {
595          if (! check_perm($relDir,(trperm_b | trperm_r)))                  while ($item = readdir($dir)) {
596                  Error("Access denied","User <tt>$gblLogin</tt> tried to access <tt>$relDir</tt> without valid trustee.",1);                          if ( substr($item,0,1) == "." || strstr($hide_items,",$item,") || !check_perm($relDir.$item,trperm_w) ) continue ;
597          $debug .= "< afeter";                          if (is_file($fsDir.".del/$item")) {
598                                    $fileList[$item] = ".del/$item" ;              
599          $hide_items=",$gblHide,";                                  $fileDate[$item] = filemtime($fsDir.".del/$item") ;
600                                    $fileSize[$item] = filesize($fsDir.".del/$item") ;
601          // read directory contents                                  $fileNote[$item] = ReadNote($fsDir.".del/$item");
602          if ( !($dir = @opendir($fsDir)) )                          } else {
603                  Error("Read Access denied",$relDir,1) ;                                  $dirList[$item] = ".del/$item" ;                
604          while ($item = readdir($dir)) {                                  $dirNote[$item] = ReadNote($fsDir.".del/$item");
605                  if ( substr($item,0,1) == "." || strstr($hide_items,",$item,") ) continue ;                          }
606                  if (is_dir($fsDir.$item) || is_link ($fsDir.$item)) {                  }
607                          if (check_perm($relDir.$item,trperm_b)) {                  closedir($dir) ;
608                                  $dirList[$item] = $item ;          }
609                                  $dirNote[$item] = ReadNote($fsDir.$item);  
610                          }          $emptyDir = ! (sizeof($dirList) || sizeof($fileList)) ;
611                  } else if (is_file($fsDir.$item)) {  
612                          if (check_perm($relDir.$item,trperm_r)) {          // start navigation page
613                                  $fileList[$item] = $item ;                        $text  = "Use this page to add, delete";
614                                  $fileDate[$item] = filemtime($fsDir.$item) ;          if (! isset($HTTP_GET_VARS["show_deleted"])) {
615                                  $fileSize[$item] = filesize($fsDir.$item) ;                  $text .= ", <a href=$self?D=".urlencode($relDir)."&show_deleted=1>undelete</a>";
616                                  $fileNote[$item] = ReadNote($fsDir.$item);          }
617                          }          $text .= " or revise files on this web site." ;
618                  } else {          $text .= "<br>Examine list of files <a href=\"$self?A=Ch1\">changed in last day</a> or <a href=\"$self?A=Ch\">all changes</a>.";
619                          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);          StartHTML("(Navigate)",$text) ;
620                  }  
621          }          print "<TABLE BORDER=0 CELLPADDING=2 CELLSPACING=3 WIDTH=\"100%\">" ;
622          closedir($dir) ;  
623            // updir (parent) bar  
624          // scan deleted files          if (chopsl($fsDir) != chopsl($fsRoot)) {
625          if ( $HTTP_GET_VARS["show_deleted"] == 1 && ($dir = @opendir("$fsDir/.del")) ) {                  $parent = dirname($relDir) ;
626                  while ($item = readdir($dir)) {                  if ($parent == "") $parent = "/" ;
627                          if ( substr($item,0,1) == "." || strstr($hide_items,",$item,") || !check_perm($relDir.$item,trperm_w) ) continue ;  
628                          $fileList[$item] = ".del/$item" ;                                include("$html/Navigate-parent.html");
629                          $fileDate[$item] = filemtime($fsDir.".del/$path") ;          }
630                          $fileSize[$item] = filesize($fsDir.".del/$path") ;  
631                          $fileNote[$item] = ReadNote($fsDir.".del/$item");          function plural($name,$count) {
632                  }                  $out="$count $name";
633                  closedir($dir) ;                  if ($count > 1) {
634          }                          $out.="s";
635                    }
636          $emptyDir = ! (sizeof($dirList) || sizeof($fileList)) ;                  return $out;
637            }
638          // start navigation page  
639          $text  = "Use this page to add, delete";          $dsort = HTTP_GET_VAR("dsort");
640          if (! isset($HTTP_GET_VARS[show_deleted])) {          if (! isset($dsort)) $dsort = "name"; // default directory sort
641                  $text .= ", <a href=$self?D=".urlencode($relDir)."&show_deleted=1>undelete</a>";  
642          }          $dsort_arr = array(
643          $text .= " or revise files on this web site." ;                  "name" => array ("rname", "note"),
644          $text .= "<br>Examine list of files <a href=\"$self?A=Ch1\">changed in last day</a> or <a href=\"$self?A=Ch\">all changes</a>.";                  "rname" => array ("name", "note"),
645          StartHTML("(Navigate)",$text) ;                  "note" => array ("name", "rnote"),
646                    "rnote" => array ("name", "note")
647          echo "<TABLE BORDER=0 CELLPADDING=2                  );
648                  CELLSPACING=3 WIDTH=\"100%\">" ;  
649            $fsort = HTTP_GET_VAR("fsort");
650          // updir (parent) bar            if (! isset($fsort)) $fsort = "name"; // default directory sort
651          if (chopsl($fsDir) != chopsl($fsRoot)) {  
652                  $parent = dirname($relDir) ;          $fsort_arr = array(
653                  if ($parent == "") $parent = "/" ;                  "name" => array ("rname", "note", "date", "size"),
654                    "rname" => array ("name", "note", "date", "size"),
655                  include("$html/Navigate-parent.html");                  "note" => array ("name", "rnote", "date", "size"),
656          }                  "rnote" => array ("name", "note", "date", "size"),
657                    "date" => array ("name", "note", "rdate", "size"),
658          function plural($name,$count) {                  "rdate" => array ("name", "note", "date", "size"),
659                  $out="$count $name";                  "size" => array ("name", "note", "date", "rsize"),
660                  if ($count > 1) {                  "rsize" => array ("name", "note", "date", "size")
661                          $out.="s";                  );
662                  }  
663                  return $out;          $D="D=".urlencode($relDir);
664          }  
665            function self_args($arr = array()) {
666          $dsort = $HTTP_GET_VARS[dsort];                  global $self;
667          if (! isset($dsort)) $dsort = "name";   // default directory sort                  $arg = implode("&",$arr);
668                    if ($arg) {
669          $dsort_arr = array(                          return $self."?".$arg;
670                  "name" => array ("rname", "note"),                  } else {
671                  "rname" => array ("name", "note"),                          return $self;
672                  "note" => array ("name", "rnote"),                  }
673                  "rnote" => array ("name", "note")          }
674                  );          // output subdirs
675            if (sizeof($dirList) > 0) {
676          $fsort = $HTTP_GET_VARS[fsort];                  switch ($dsort) {
677          if (! isset($fsort)) $fsort = "name";   // default directory sort                          case "note":
678                                    $items = $dirNote;
679          $fsort_arr = array(                                  asort($items);
680                  "name" => array ("rname", "note", "date", "size"),                                  break;
681                  "rname" => array ("name", "note", "date", "size"),                          case "rnote":
682                  "note" => array ("name", "rnote", "date", "size"),                                  $items = $dirNote;
683                  "rnote" => array ("name", "note", "date", "size"),                                  arsort($items);
684                  "date" => array ("name", "note", "rdate", "size"),                                  break;
685                  "rdate" => array ("name", "note", "date", "size"),                          case "rname":
686                  "size" => array ("name", "note", "date", "rsize"),                                  $items = $dirList;
687                  "rsize" => array ("name", "note", "date", "size")                                  krsort($items);
688                  );                                  break;
689                            default:
690          $D="D=".urlencode($relDir);                                  $items = $dirList;
691                                    ksort($items);
692          function self_args($arr = array()) {                                  break;
693                  $arg = implode("&",$arr);                  }
694                  if ($arg) {                  $durl = self_args(array($D,"dsort=".$dsort_arr[$dsort][0]));
695                          return $self."?".$arg;                  $nurl = self_args(array($D,"dsort=".$dsort_arr[$dsort][1]));
696                  } else {  
697                          return $self;                  include("$html/Navigate-dirHeader.html");
698                  }  
699          }                  while (list($key,$dir) = each($items)) {
700          // output subdirs  
701          if (sizeof($dirList) > 0) {                          $dir = $dirList[$key];
702                  switch ($dsort) {  
703                          case "note":                          $info_url=self_args(array("A"=>"A=E", "F"=>"F=".urlencode($dir), "D"=>$D));
704                                  $items = $dirNote;                          if (substr($dir,0,5) == ".del/") {
705                                  asort($items);                                  $dir = substr($dir,5,strlen($dir)-5);
706                                  break;                                  $deleted = " <a href=\"$info_url#undelete\"><SPAN CLASS=deleted TITLE=\"deleted\">deleted</span></a>";
707                          case "rnote":                          } else {
708                                  $items = $dirNote;                                  $deleted = "";
709                                  arsort($items);                          }
710                                  break;          
711                          case "rname":                          $dir_url=$self."?D=".urlencode(chopsl($relDir)."/".$dir);
712                                  $items = $dirList;                          if (check_perm($relDir.$dir,$gblPermNote)) {
713                                  krsort($items);                                  $note_html="<a href=\"$info_url#note\">".$gblIcon("note")."</a>".$dirNote[$key];
714                                  break;                          } else {
715                          default:                                  $note_html=$dirNote[$key];
716                                  $items = $dirList;                          }
717                                  ksort($items);  
718                                  break;                          $dir_html = isBlank($dir,"directory");
719                  }  
720                  $durl = self_args(array($D,"dsort=".$dsort_arr[$dsort][0]));                          include("$html/Navigate-dirEntry.html");
721                  $nurl = self_args(array($D,"dsort=".$dsort_arr[$dsort][1]));  
722                    }  // iterate over dirs
723                  include("$html/Navigate-dirHeader.html");          }  // end if no dirs
724    
725                  while (list($key,$dir) = each($items)) {          $durl = self_args(array($D,"fsort=".$fsort_arr[$fsort][0]));
726            $nurl = self_args(array($D,"fsort=".$fsort_arr[$fsort][1]));
727                          $dir = $dirList[$key];          $uurl = self_args(array($D,"fsort=".$fsort_arr[$fsort][2]));
728            $surl = self_args(array($D,"fsort=".$fsort_arr[$fsort][3]));
729                          $info_url=self_args(array("A"=>"A=E", "F"=>"F=".urlencode($dir), "D"=>$D));  
730                          $dir_url=$self."?D=".urlencode(chopsl($relDir)."/".$dir);          $html_uri = $webRoot;
731                          include("$html/Navigate-dirEntry.html");  
732            if (substr($relDir,0,1) == "/") {
733                  }  // iterate over dirs                  $html_uri .= substr($relDir,1,strlen($relDir)-1);
734          }  // end if no dirs          } else {
735                    $html_uri .= $relDir;
736          $durl = self_args(array($D,"fsort=".$fsort_arr[$fsort][0]));          }
737          $nurl = self_args(array($D,"fsort=".$fsort_arr[$fsort][1]));  
738          $uurl = self_args(array($D,"fsort=".$fsort_arr[$fsort][2]));          include("$html/Navigate-fileHeader.html");
739          $surl = self_args(array($D,"fsort=".$fsort_arr[$fsort][3]));  
740            if (sizeof($fileList) > 0) {
741          include("$html/Navigate-fileHeader.html");                  switch ($fsort) {
742                            case "note":
743          if (sizeof($fileList) > 0) {                                  $items = $fileNote;
744                  switch ($fsort) {                                  asort($items);
745                          case "note":                                  break;
746                                  $items = $fileNote;                          case "rnote":
747                                  asort($items);                                  $items = $fileNote;
748                                  break;                                  arsort($items);
749                          case "rnote":                                  break;
750                                  $items = $fileNote;                          case "date":
751                                  arsort($items);                                  $items = $fileDate;
752                                  break;                                  asort($items);
753                          case "date":                                  break;
754                                  $items = $fileDate;                          case "rdate":
755                                  asort($items);                                  $items = $fileDate;
756                                  break;                                  arsort($items);
757                          case "rdate":                                  break;
758                                  $items = $fileDate;                          case "size":
759                                  arsort($items);                                  $items = $fileSize;
760                                  break;                                  asort($items);
761                          case "size":                                  break;
762                                  $items = $fileSize;                          case "rsize":
763                                  asort($items);                                  $items = $fileSize;
764                                  break;                                  arsort($items);
765                          case "rsize":                                  break;
766                                  $items = $fileSize;                          case "rname":
767                                  arsort($items);                                  $items = $fileList;
768                                  break;                                  krsort($items);
769                          case "rname":                                  break;
770                                  $items = $fileList;                          default:
771                                  krsort($items);                                  $items = $fileList;
772                                  break;                                  ksort($items);
773                          default:                                  break;
774                                  $items = $fileList;                  }
775                                  ksort($items);  
776                                  break;            while (list($key,$file) = each($items)) {
777                  }                  $file = $fileList[$key];
778                    $path = $fsDir."/".$file ;
779            while (list($key,$file) = each($items)) {                  $mod  = $fileDate[$key];
780                  $file = $fileList[$key];                  $sz   = $fileSize[$key];
781                  $path = $fsDir."/".$file ;          
782                  $mod  = $fileDate[$key];                  if ($sz >= 10240) {
783                  $sz   = $fileSize[$key];                          $sz = (int)(($sz+1023)/1024) . " k" ;
784                            } else {
785                  if ($sz >= 10240) {                          $sz .= " " ;
786                          $sz = (int)(($sz+1023)/1024) . " k" ;                  } // end size
787                  } else {  
788                          $sz .= " " ;                  $a = $b = "" ;
789                  } // end size  
790                    $info_url=$self."?A=E&F=".urlencode($file)."&D=".urlencode($relDir);
791                  $a = $b = "" ;  
792                    if ( ($mod + $gblModDays*86400) > time() ) {
793                  $info_url=$self."?A=E&F=".urlencode($file)."&D=".urlencode($relDir);                          $a  = "<SPAN CLASS=RED TITLE=\"Newer" ;
794                            $a .= " than $gblModDays days\"> * </SPAN>" ;
795                  if ( ($mod + $gblModDays*86400) > time() ) {                  }
796                          $a  = "<SPAN CLASS=RED TITLE=\"Newer" ;  
797                          $a .= " than $gblModDays days\"> * </SPAN>" ;                  $file_lock=CheckLock($path);
798                  }  
799                    $file_url_html="<A HREF=\"$self?A=V&D=".urlencode($relDir)."&F=".urlencode($file);
800                  $file_lock=CheckLock($path);                  $file_url_html.="\" TITLE=\"View file\">" ;
801    
802                  $file_url_html="<A HREF=\"$self?A=V&D=".urlencode($relDir)."&F=".urlencode($file);                  if (substr($file,0,5) != ".del/") {
803                  $file_url_html.="\" TITLE=\"View file\">" ;                          $file_url_html .= isBlank($file) . "</A>" . $a ;
804                    } else {
805                  if (substr($file,0,5) != ".del/") {                          $file_url_html .= isBlank(substr($file,5,strlen($file)-5)) . "</a> <a href=\"$info_url#undelete\"><SPAN CLASS=deleted TITLE=\"deleted\">deleted</span></a>";
806                          $file_url_html .= $file . "</A>" . $a ;                  }
807                  } else {  
808                          $file_url_html .= substr($file,5,strlen($file)-5) . "</a> <SPAN CLASS=RED TITLE=\"deleted\"> <a href=\"$info_url#undelete\">deleted</a> </span>";                  if (check_perm($relDir.$file,$gblPermNote)) {
809                  }                          $note_html="<a href=\"$info_url#note\">".$gblIcon("note")."</a>".$fileNote[$key];
810                    } else {
811                  $note_html="<a href=\"$info_url#note\">".$gblIcon("note")."</a>".ReadNote($path);                          $note_html=$fileNote[$key];
812                    }
813                  $ext = strtolower(strrchr($file,".")) ;  
814                    $ext = strtolower(strrchr($file,".")) ;
815                  if ($file_lock) {  
816                          if ($file_lock == $GLOBALS[gblUserName]) {                  if ($file_lock) {
817                                  $b.="<A HREF=\"$self?A=Ci&D=".urlencode($relDir)."&F=".urlencode($file);                          if ($file_lock == $gblUserName) {
818                                  $b.="\" TITLE=\"Checkin (update) file on server\">" ;                                  $b.="<A HREF=\"$self?A=Ci&D=".urlencode($relDir)."&F=".urlencode($file);
819                                  $file_url_html=$b;                                  $b.="\" TITLE=\"Checkin (update) file on server\">" ;
820                                  $b.=$gblIcon("checkin")."</A>" ;                                  $file_url_html=$b;
821                                  $b.= $gblIcon("blank");                                  $b.=$gblIcon("checkin")."</A>" ;
822                                  $file_url_html.="$file</a> $a";                                  $b.= $gblIcon("blank");
823                                  $note_html = $gblIcon("blank")."<b>Please check-in (update) this file</b>";                                  $file_url_html.="$file</a> $a";
824                          } else {                                  $note_html = $gblIcon("blank")."<b>Please check-in (update) this file</b>";
825                                  $b = $gblIcon("locked");                          } else {
826                                  $b.= $gblIcon("blank");                                  $b = $gblIcon("locked");
827                                  $note_html = $gblIcon("blank")."<b>File locked by $file_lock</b>";                                  $b.= $gblIcon("blank");
828                                  $file_url_html = "$file $a";                                  $note_html = $gblIcon("blank")."<b>File locked by $file_lock</b>";
829                          }                                  $file_url_html = "$file $a";
830                  } else {                          }
831                          $b.="<A HREF=\"$self?A=Co&D=".urlencode($relDir)."&F=".urlencode($file);                  } else {
832                          $b.="\" TITLE=\"Checkout file for edit\">" ;                          if (check_perm($relDir.$file,trperm_w)) {
833                          $b.=$gblIcon("checkout")."</A>";                                  $b.="<A HREF=\"$self?A=Co&D=".urlencode($relDir)."&F=".urlencode($file);
834                                    $b.="\" TITLE=\"Checkout file for edit\">" ;
835                          if ( $ext=="" || strstr(join(" ",$gblEditable),$ext) ) {                                    $b.=$gblIcon("checkout")."</A>";
836                                  $b.="<A HREF=\"$self?A=C&D=".urlencode($relDir)."&F=".urlencode($file);                          }
837                                  $b.="\" TITLE=\"List contents\">" ;  
838                                  $b.=$gblIcon("view")."</A>" ;                          if ( $ext=="" || strstr(join(" ",$gblEditable),$ext) ) {  
839                          } else {                                  $b.="<A HREF=\"$self?A=C&D=".urlencode($relDir)."&F=".urlencode($file);
840                                  $b.= $gblIcon("blank");                                  $b.="\" TITLE=\"List contents\">" ;
841                          }                                  $b.=$gblIcon("view")."</A>" ;
842                  }                          } else {
843                                    $b.= $gblIcon("blank");
844                  $mod = date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]",$mod);                          }
845                    }
846                  include("$html/Navigate-fileEntry.html");  
847                    $mod = date("$gblDateFmt $gblTimeFmt",$mod);
848            }  // iterate over files  
849          } else {  // end if no files                  include("$html/Navigate-fileEntry.html");
850  ?>  
851   <TR><TD></TD><TD COLSPAN=5 CLASS=LST>            }  // iterate over files
852    No files in this directory          } else {  // end if no files
853   </TD></TR>                  include("$html/Navigate-noFiles.html");
854  <?          }
855          }  
856            if ($emptyDir && $relDir != "") {
857          if ($emptyDir && $relDir != "") {                  include("$html/Navigate-emptyDir.html");
858  ?>          } // end if emptyDir
859    
860  <FORM METHOD="POST" ACTION="<?= $self ?>">          include("$html/Navigate-hr.html");      
861   <TR><TD></TD><TD COLSPAN=5 CLASS=BAR>  
862    <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ?>">          if (file_exists("$fsRealmDir/$realm".$realm_sep."info.inc")) {
863    OK TO DELETE THIS EMPTY FOLDER?                  print "<TR><TD></TD><TD COLSPAN=5>";
864    <INPUT TYPE="CHECKBOX" NAME="CONFIRM">                  include("$fsRealmDir/$realm".$realm_sep."info.inc");
865    <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="DELETE">                  print "</TD></TR>";
866   </TD></TR>                  include("$html/Navigate-hr.html");      
867  </FORM>          } elseif (file_exists("$gblRepositoryDir/.info.inc")) {
868                    print "<TR><TD></TD><TD COLSPAN=5>";
869  <?php                  include("$gblRepositoryDir/.info.inc");
870          } // end if emptyDir                  print "</TD></TR>";
871  ?>                  include("$html/Navigate-hr.html");      
872            }
873  <TR><TD></TD><TD COLSPAN=5><HR></TD></TR>  
874            include("$html/Navigate-createNew.html");
875  <?  
876            print "</TABLE>";
877  if (file_exists("$fsRealmDir/$realm".$realm_sep."info.inc")) {  
878          print "<TR><TD></TD><TD COLSPAN=5>";          EndHTML() ;
879          include("$fsRealmDir/$realm".$realm_sep."info.inc");  } // end function Navigate
880          print "</TD></TR><TR><TD></TD><TD COLSPAN=5><HR></TD></TR>";  
881  } elseif (file_exists("$gblRepositoryDir/.info.inc")) {  //////////////////////////////////////////////////////////////////
882          print "<TR><TD></TD><TD COLSPAN=5>";  
883          include("$gblRepositoryDir/.info.inc");  function UploadPage($fsRoot, $relDir, $filename="") {
884          print "</TD></TR><TR><TD></TD><TD COLSPAN=5><HR></TD></TR>";  
885  }          global $html, $HTTP_SERVER_VARS;
886    
887            $self = $HTTP_SERVER_VARS["PHP_SELF"] ;
888  ?>          include("$html/UploadPage.html");
889    
890  <FORM METHOD="POST" ACTION="<?= $self ?>">  } // end function UploadPage
891  <TR><TD></TD><TD COLSPAN=5 CLASS=BAR>CREATE NEW  
892   <INPUT TYPE="RADIO" NAME="T" VALUE="D" CHECKED>DIRECTORY -OR-  //////////////////////////////////////////////////////////////////
893   <INPUT TYPE="RADIO" NAME="T" VALUE="F">FILE : &nbsp;&nbsp;  
894   <NOBR>NAME <INPUT TYPE="TEXT" NAME="FN" SIZE=14>  // Error with sysadmin flag are reported to error_log or hidden from
895   <INPUT TYPE="HIDDEN" NAME="POSTACTION" VALUE="CREATE">  // users
896   <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ?>">  
897   <INPUT TYPE="SUBMIT" VALUE="CREATE" NAME="CREATE">  function Error($title,$text="",$sysadmin=0,$no_404=0) {
898   </NOBR>          global $gblSeparateAdminMessages,
899   <NOBR>OR <A HREF="<?= $self ?>?A=U&D=<?= urlencode($relDir) ?>">UPLOAD</A> A FILE</NOBR>                  $gblMailAdminMessages,$realm,
900  </TD></TR>                  $HTTP_SERVER_VARS;
901  </FORM>          if (! headers_sent() && ! $no_404) header("HTTP/1.0 404 Not Found");
902  </TABLE>          if ($sysadmin) {
903                    if ($gblSeparateAdminMessages) {
904  <?php                          $user="Your administrator ";
905          EndHTML() ;                          if ($gblMailAdminMessages) {
906  } // end function Navigate                                  mail($HTTP_SERVER_VARS["SERVER_ADMIN"], "docman $realm error message: $title", strip_tags($text));
907                                    $user.="<tt>".$HTTP_SERVER_VARS["SERVER_ADMIN"]."</tt> ";
908  //////////////////////////////////////////////////////////////////                          }
909                            $user.="has been notified about error" ;
910  function UploadPage($fsRoot, $relDir, $filename="") {                          StartHTML("($title)",$user);
911                            echo "<P ALIGN=center>Hit your Browser's Back Button.</P>" ;
912          global $html, $HTTP_SERVER_VARS;                          EndHTML();
913                            error_log("docman $realm: ".strip_tags($text));
914          $self = $HTTP_SERVER_VARS["PHP_SELF"] ;                  } else {
915          include("$html/UploadPage.html");                          StartHTML("ADMIN: ".$title,$text) ;
916                            echo "<P ALIGN=center>Hit your Browser's Back Button.</P>" ;
917  } // end function UploadPage                          EndHTML();
918                    }
919  //////////////////////////////////////////////////////////////////          } else {
920                    StartHTML("(".$title.")",$text) ;
921  // Error with sysadmin flag are reported to error_log or hidden from                  echo "<P ALIGN=center>Hit your Browser's Back Button.</P>" ;
922  // users                  EndHTML() ;
923            }
924  function Error($title,$text="",$sysadmin=0,$no_404=0) {          exit ;
925          global $gblSeparateAdminMessages,  } // end function Error
926                  $gblMailAdminMessages,$realm,  
927                  $HTTP_SERVER_VARS;  function LogIt($target,$msg, $changelog=0) {
928          if (! headers_sent() && ! $no_404) header("HTTP/1.0 404 Not Found");  
929          if ($sysadmin) {          global $gblDateFmt, $gblTimeFmt, $gblUserName, $gblFsRoot;
930                  if ($gblSeparateAdminMessages) {  
931                          $user="Your administrator ";          $dir=dirname($target);
932                          if ($gblMailAdminMessages) {          if (! file_exists($dir."/.log")) {
933                                  mail($HTTP_SERVER_VARS["SERVER_ADMIN"], "docman $realm error message: $title", strip_tags($text));                  if (! @mkdir($dir."/.log",0700)) Error("docman installation problem","can't create log directory <tt>$dir/.log</tt>",1);
934                                  $user.="<tt>".$HTTP_SERVER_VARS["SERVER_ADMIN"]."</tt> ";          }
935                          }          $file=basename($target);
936                          $user.="has been notified about error" ;  
937                          StartHTML("($title)",$user);          $log=fopen("$dir/.log/$file","a+");
938                          echo "<P ALIGN=center>Hit your Browser's Back Button.</P>" ;          fputs($log,date("$gblDateFmt\t$gblTimeFmt").
939                          EndHTML();                  "\t$gblUserName\t$msg\n");
940                          error_log("docman $realm: ".strip_tags($text));          fclose($log);
941                  } else {  
942                          StartHTML("ADMIN: ".$title,$text) ;          if (! $changelog) return;
943                          echo "<P ALIGN=center>Hit your Browser's Back Button.</P>" ;  
944                          EndHTML();          $log=fopen("$gblFsRoot/.changelog","a+");
945                  }          if (substr($target,0,strlen($gblFsRoot)) == $gblFsRoot)
946          } else {                  $target=substr($target,strlen($gblFsRoot),strlen($target)-strlen($gblFsRoot));
947                  StartHTML("(".$title.")",$text) ;          $msg=str_replace("\t"," ",$msg);
948                  echo "<P ALIGN=center>Hit your Browser's Back Button.</P>" ;          fputs($log,time()."\t$target\t$gblUserName\t$msg\n");
949                  EndHTML() ;          fclose($log);
950          }  
951          exit ;          // FIX: implement e-mail notification based on $changelog
952  } // end function Error          // permission
953    }
954  function LogIt($target,$msg, $changelog=0) {  
955    
956          $dir=dirname($target);  //////////////////////////////////////////////////////////////////
957          if (! file_exists($dir."/.log")) {  
958                  if (! @mkdir($dir."/.log",0700)) Error("docman installation problem","can't create log directory <tt>$dir/.log</tt>",1);  function WriteNote($target,$msg) {
959          }  
960          $file=basename($target);          $target=stripSlashes($target);
961            $dir=dirname($target);
962          $log=fopen("$dir/.log/$file","a+");          if (! file_exists($dir."/.note")) {
963          fputs($log,date("$GLOBALS[gblDateFmt]\t$GLOBALS[gblTimeFmt]").                  mkdir($dir."/.note",0700);
964                  "\t$GLOBALS[gblUserName]\t$msg\n");          }
965          fclose($log);          $file=basename($target);
966    
967          if (! $changelog) return;          $note=fopen("$dir/.note/$file","w");
968            if (! $note) {
969          global $gblFsRoot;                  Error("Error writing note","Can't open note file <tt>$dir/.note/$file</tt> for writing",1);
970          $log=fopen("$gblFsRoot/.changelog","a+");          }
971          if (substr($target,0,strlen($gblFsRoot)) == $gblFsRoot)          fputs($note,"$msg\n");
972                  $target=substr($target,strlen($gblFsRoot),strlen($target)-strlen($gblFsRoot));          fclose($note);
973          $msg=str_replace("\t"," ",$msg);  
974          fputs($log,time()."\t$target\t$GLOBALS[gblUserName]\t$msg\n");          LogIt($target,"added note $msg");
975          fclose($log);  
976    }
977          // FIX: implement e-mail notification based on $changelog  
978          // permission  function ReadNote($target) {
979  }  
980            $target=stripSlashes($target);
981            $dir=dirname($target);
982  //////////////////////////////////////////////////////////////////          $file=basename($target);
983            $msg="";
984  function WriteNote($target,$msg) {          if (file_exists($dir."/.note/$file")) {
985                    $note=fopen("$dir/.note/$file","r");
986          $target=stripSlashes($target);                  $msg=fgets($note,4096);
987          $dir=dirname($target);                  fclose($note);
988          if (! file_exists($dir."/.note")) {          }
989                  mkdir($dir."/.note",0700);          return HtmlSpecialChars(StripSlashes($msg));
990          }  
991          $file=basename($target);  }
992    
993          $note=fopen("$dir/.note/$file","w");  //////////////////////////////////////////////////////////////////
994          fputs($note,"$msg\n");  
995          fclose($note);  function MoveTo($source,$folder) {
996    
997          LogIt($target,"added note $msg");          $source=stripSlashes($source);
998            $file=basename($source);
999  }          if (! file_exists($folder)) {
1000                    mkdir($folder,0700);
1001  function ReadNote($target) {          }
1002            if (file_exists($source)) {
1003          $target=stripSlashes($target);                  rename($source,"$folder/$file");
1004          $dir=dirname($target);          }
1005          $file=basename($target);  }
1006          $msg="";  
1007          if (file_exists($dir."/.note/$file")) {  //////////////////////////////////////////////////////////////////
1008                  $note=fopen("$dir/.note/$file","r");  
1009                  $msg=fgets($note,4096);  function Lock($target) {
1010                  fclose($note);  
1011          }          global $gblUserName;
1012          return HtmlSpecialChars(StripSlashes($msg));  
1013            $target=stripSlashes($target);
1014  }          $dir=dirname($target);
1015            if (! file_exists($dir."/.lock")) {
1016  //////////////////////////////////////////////////////////////////                  mkdir($dir."/.lock",0700);
1017            }
1018  function MoveTo($source,$folder) {          $file=basename($target);
1019    
1020          $source=stripSlashes($source);          if (file_exists("$dir/.lock/$file")) {
1021          $file=basename($source);                  LogIt($target,"attempt to locked allready locked file!");
1022          if (! file_exists($folder)) {          } else {
1023                  mkdir($folder,0700);                  $lock=fopen("$dir/.lock/$file","w");
1024          }                  fputs($lock,"$gblUserName\n");
1025          if (file_exists($source)) {                  fclose($lock);
1026                  rename($source,"$folder/$file");  
1027          }                  LogIt($target,"file locked");
1028  }          }
1029    
1030  //////////////////////////////////////////////////////////////////  }
1031    
1032  function Lock($target) {  function CheckLock($target) {
1033    
1034          $target=stripSlashes($target);          $target=stripSlashes($target);
1035          $dir=dirname($target);          $dir=dirname($target);
1036          if (! file_exists($dir."/.lock")) {          $file=basename($target);
1037                  mkdir($dir."/.lock",0700);          $msg=0;
1038          }          if (file_exists($dir."/.lock/$file")) {
1039          $file=basename($target);                  $lock=fopen("$dir/.lock/$file","r");
1040                    $msg=fgets($lock,4096);
1041          if (file_exists("$dir/.lock/$file")) {                  fclose($lock);
1042                  LogIt($target,"attempt to locked allready locked file!");          }
1043          } else {          return chop($msg);
1044                  $lock=fopen("$dir/.lock/$file","w");  
1045                  fputs($lock,"$GLOBALS[gblUserName]\n");  }
1046                  fclose($lock);  
1047    function Unlock($target) {
1048                  LogIt($target,"file locked");  
1049          }          $target=stripSlashes($target);
1050            $dir=dirname($target);
1051  }          $file=basename($target);
1052            if (file_exists($dir."/.lock/$file")) {
1053  function CheckLock($target) {                  unlink("$dir/.lock/$file");
1054                    LogIt($target,"file unlocked");
1055          $target=stripSlashes($target);          } else {
1056          $dir=dirname($target);                  LogIt($target,"attempt to unlocked non-locked file!");
1057          $file=basename($target);          }
1058          $msg=0;  
1059          if (file_exists($dir."/.lock/$file")) {  }
1060                  $lock=fopen("$dir/.lock/$file","r");  
1061                  $msg=fgets($lock,4096);  //////////////////////////////////////////////////////////////////
1062                  fclose($lock);  
1063          }  function urlpath($url) {
1064          return chop($msg);          $url=urlencode(StripSlashes("$url"));
1065            $url=str_replace("%2F","/",$url);
1066  }          $url=str_replace("+","%20",$url);
1067            return($url);
1068  function Unlock($target) {  }
1069    
1070          $target=stripSlashes($target);  //////////////////////////////////////////////////////////////////
1071          $dir=dirname($target);  
1072          $file=basename($target);  function safe_rename($fromdir,$fromfile,$tofile) {
1073          if (file_exists($dir."/.lock/$file")) {  
1074                  unlink("$dir/.lock/$file");          global $gblNumBackups;
1075                  LogIt($target,"file unlocked");  
1076          } else {          function try_rename($from,$to) {
1077                  LogIt($target,"attempt to unlocked non-locked file!");  #               print "$from -> $to\n";
1078          }                  if (file_exists($from) && is_writeable(dirname($to))) {
1079                            return rename($from,$to);
1080  }                  } else {
1081                            return 0;
1082  //////////////////////////////////////////////////////////////////                  }
1083            }
1084  function urlpath($url) {  
1085          $url=urlencode(StripSlashes("$url"));          function try_dir($todir) {
1086          $url=str_replace("%2F","/",$url);                  if (! file_exists($todir)) {
1087          $url=str_replace("+","%20",$url);                          @mkdir($todir,0700);
1088          return($url);                  }
1089  }          }
1090    
1091  //////////////////////////////////////////////////////////////////          $to="$fromdir/$tofile";
1092            $todir=dirname($to);
1093  function safe_rename($fromdir,$fromfile,$tofile) {          $tofile=basename($to);
1094          function try_rename($from,$to) {  
1095  #               print "$from -> $to\n";  #       print "<pre>$fromdir / $fromfile -> $todir / $tofile\n\n";
1096                  if (file_exists($from) && is_writeable(dirname($to))) {  
1097                          return rename($from,$to);          if (! try_rename("$fromdir/$fromfile","$todir/$tofile")) Error("Rename error","Can't rename file <tt>$fromfile</tt> to <tt>$tofile</tt>",1);
1098                  } else {          try_dir("$todir/.log");
1099                          return 0;          try_rename("$fromdir/.log/$fromfile","$todir/.log/$tofile");
1100                  }          try_dir("$todir/.note");
1101          }          try_rename("$fromdir/.note/$fromfile","$todir/.note/$tofile");
1102            try_dir("$todir/.lock");
1103          function try_dir($todir) {          try_rename("$fromdir/.lock/$fromfile","$todir/.lock/$tofile");
1104                  if (! file_exists($todir)) {          try_dir("$todir/.bak");
1105                          @mkdir($todir,0700);          for($i=0;$i<=$gblNumBackups;$i++) {
1106                  }                  try_rename("$fromdir/.bak/$i/$fromfile","$todir/.bak/$i/$tofile");
1107          }          }
1108    }
1109          $to="$fromdir/$tofile";  
1110          $todir=dirname($to);  
1111          $tofile=basename($to);  //////////////////////////////////////////////////////////////////
1112    
1113  #       print "<pre>$fromdir / $fromfile -> $todir / $tofile\n\n";  // recursivly delete directory
1114    
1115          if (! try_rename("$fromdir/$fromfile","$todir/$tofile")) Error("Rename error","Can't rename file <tt>$fromfile</tt> to <tt>$tofile</tt>",1);  function rrmdir($dir) {
1116          try_dir("$todir/.log");          $handle=opendir($dir);
1117          try_rename("$fromdir/.log/$fromfile","$todir/.log/$tofile");          while ($file = readdir($handle)) {
1118          try_dir("$todir/.note");                  if ($file != "." && $file != "..") {
1119          try_rename("$fromdir/.note/$fromfile","$todir/.note/$tofile");                          if (is_dir("$dir/$file"))
1120          try_dir("$todir/.lock");                                  rrmdir("$dir/$file");
1121          try_rename("$fromdir/.lock/$fromfile","$todir/.lock/$tofile");                          else
1122          try_dir("$todir/.bak");                                  if (! @unlink("$dir/$file")) return(0);
1123          for($i=0;$i<=$GLOBALS[gblNumBackups];$i++) {                  }
1124                  try_rename("$fromdir/.bak/$i/$fromfile","$todir/.bak/$i/$tofile");          }
1125          }          closedir($handle);
1126  }          return @rmdir($dir);
1127    }
1128    
1129  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
1130    
1131  // recursivly delete directory  function DisplayChangeLog($day) {
1132    
1133  function rrmdir($dir) {          global $gblFsRoot, $gblDateFmt, $gblTimeFmt,
1134          $handle=opendir($dir);                  $HTTP_SERVER_VARS;
1135          while ($file = readdir($handle)) {  
1136                  if ($file != "." && $file != "..") {          $self  = $HTTP_SERVER_VARS["PHP_SELF"];
1137                          if (is_dir("$dir/$file"))  
1138                                  rrmdir("$dir/$file");          if (!file_exists("$gblFsRoot/.changelog")) return;
1139                          else          $log=fopen("$gblFsRoot/.changelog","r");
1140                                  if (! @unlink("$dir/$file")) return(0);          $logarr = array();
1141                  }          while($line = fgetcsv($log,512,"\t")) {
1142          }                  while (sizeof($line) > 4) {
1143          closedir($handle);                          $tmp = array_pop($line);
1144          return @rmdir($dir);                          $line.=" $tmp";
1145  }                  }
1146                    if ($day!=1 || ($day==1 && (time()-$line[0] < 24*60*60))) {
1147  //////////////////////////////////////////////////////////////////                          array_unshift($logarr,array($line[0],$line[1],$line[2],$line[3]));
1148                    }
1149  function DisplayChangeLog($day) {          }
1150            fclose($log);
1151          global $gblFsRoot,$HTTP_SERVER_VARS;          $cl1=" class=LST"; $cl2="";
1152            print "<table border=0 width=100%>\n";
1153          if (!file_exists("$gblFsRoot/.changelog")) return;          while ($e = array_shift($logarr)) {
1154          $log=fopen("$gblFsRoot/.changelog","r");                  $cl=$cl1; $cl1=$cl2; $cl2=$cl;
1155          $logarr = array();                  $date = date($gblDateFmt, $e[0]);
1156          while($line = fgetcsv($log,512,"\t")) {                  $time = date($gblTimeFmt, $e[0]);
1157                  while (sizeof($line) > 4) {                  $dir = dirname($e[1]);
1158                          $tmp = array_pop($line);                  $file = basename($e[1]);
1159                          $line.=" $tmp";                  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";
1160                  }          }
1161                  if ($day!=1 || ($day==1 && (time()-$line[0] < 24*60*60))) {          print "</table>";
1162                          array_unshift($logarr,array($line[0],$line[1],$line[2],$line[3]));          print "<p>".GifIcon("up")." Back to <a href=\"$self\">front page</a>.</p>";
1163                  }  }
1164          }  
1165          fclose($log);  //////////////////////////////////////////////////////////////////
1166          $cl1=" class=LST"; $cl2="";  
1167          print "<table border=0 width=100%>\n";  function Download($path,$force=0) {
1168          while ($e = array_shift($logarr)) {          global $HTTP_SERVER_VARS,$mime_type;
1169                  $cl=$cl1; $cl1=$cl2; $cl2=$cl;  
1170                  $date = date("$GLOBALS[gblDateFmt]", $e[0]);          // default transfer-encoding
1171                  $time = date("$GLOBALS[gblTimeFmt]", $e[0]);          $encoding = "binary";
1172                  $dir = dirname($e[1]);  
1173                  $file = basename($e[1]);          // known transfer encodings
1174                  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";          $encoding_ext = array(
1175          }                  "gz" => "x-gzip",
1176          print "</table>";                  "Z" => "x-compress",
1177          print "<p>".GifIcon(up)." Back to <a href=$HTTP_SERVER_VARS[PHP_SELF]>front page</a>.</p>";          );
1178  }  
1179            $file = basename($path);
1180  //////////////////////////////////////////////////////////////////          $size = filesize($path);
1181    
1182  function Download($path,$force=0) {          $ext_arr = explode(".",$file);
1183          global $HTTP_SERVER_VARS,$mime_type;          $ext = array_pop($ext_arr);
1184            if (isset($encoding_ext[$ext])) {
1185          // default transfer-encoding                  $encoding = $encoding_ext[$ext];
1186          $encoding = "binary";                  $ext = array_pop($ext_arr);
1187            }
1188          // known transfer encodings  
1189          $encoding_ext = array(          if ($force || !isset($mime_type[$ext])) {
1190                  "gz" => "x-gzip",                  header("Content-Type: application/force-download");
1191                  "Z" => "x-compress",          } else {
1192          );                  header("Content-Type: $mime_type[$ext]");
1193            }
1194          $file = basename($path);  
1195          $size = filesize($path);          // IE5.5 just downloads index.php if we don't do this
1196            if(preg_match("/MSIE 5.5/", $HTTP_SERVER_VARS["HTTP_USER_AGENT"])) {
1197          $ext_arr = explode(".",$file);                  header("Content-Disposition: filename=$file");
1198          $ext = array_pop($ext_arr);          } else {
1199          if ($encoding_ext[$ext]) {                  header("Content-Disposition: attachment; filename=$file");
1200                  $encoding = $encoding_ext[$ext];          }
1201                  $ext = array_pop($ext_arr);  
1202          }          header("Content-Transfer-Encoding: $encoding");
1203            $fh = fopen($path, "r");
1204          if ($force || !isset($mime_type[$ext])) {          fpassthru($fh);
1205                  header("Content-Type: application/force-download");  }
1206          } else {  
1207                  header("Content-Type: $mime_type[$ext]");  
1208          }  //////////////////////////////////////////////////////////////////
1209    
1210          // IE5.5 just downloads index.php if we don't do this  function chopsl($path) {
1211          if(preg_match("/MSIE 5.5/", $HTTP_SERVER_VARS[HTTP_USER_AGENT])) {          $path=str_replace("//","/",$path);
1212                  header("Content-Disposition: filename=$file");          if (substr($path,strlen($path)-1,1) == "/") $path=substr($path,0,strlen($path)-1);
1213          } else {          return $path;
1214                  header("Content-Disposition: attachment; filename=$file");  }
1215          }  
1216    //////////////////////////////////////////////////////////////////
1217          header("Content-Transfer-Encoding: $encoding");  /*
1218          $fh = fopen($path, "r");          Document manager ACL implementation
1219          fpassthru($fh);  
1220  }          Written by Dobrica Pavlinusic <dpavlin@rot13.org>
1221    
1222            Based on ideas from Linux trustees code
1223  //////////////////////////////////////////////////////////////////          by Vyacheslav Zavadsky <zavadsky@braysystems.com>
1224    */
1225  function chopsl($path) {  
1226          $path=str_replace("//","/",$path);  define('trmask_not',1 << 0);
1227          if (substr($path,strlen($path)-1,1) == "/") $path=substr($path,0,strlen($path)-1);  define('trmask_clear',1 << 1);
1228          return $path;  define('trmask_deny',1 << 2);
1229  }  define('trmask_one_level',1 << 3);
1230    define('trmask_group',1 << 4);
1231  //////////////////////////////////////////////////////////////////  
1232  /*  define('trperm_r',1 << 5);
1233          Document manager ACL implementation  define('trperm_w',1 << 6);
1234    define('trperm_b',1 << 7);
1235          Written by Dobrica Pavlinusic <dpavlin@rot13.org>  define('trperm_n',1 << 8);
1236    
1237          Based on ideas from Linux trustees code  $trustee_a2n = array(
1238          by Vyacheslav Zavadsky <zavadsky@braysystems.com>          '!' => trmask_not,
1239  */          'C' => trmask_clear,
1240            'D' => trmask_deny,
1241  define(trmask_not,1 << 0);          'O' => trmask_one_level,
1242  define(trmask_clear,1 << 1);          '+' => trmask_group,
1243  define(trmask_deny,1 << 2);          'R' => trperm_r,
1244  define(trmask_one_level,1 << 3);          'W' => trperm_w,
1245  define(trmask_group,1 << 4);          'B' => trperm_b,
1246            'N' => trperm_n,
1247  define(trperm_r,1 << 5);  );
1248  define(trperm_w,1 << 6);  
1249  define(trperm_b,1 << 7);  // debugging function
1250  define(trperm_n,1 << 8);  function display_trustee($t) {
1251            global $trustee_a2n;
1252  $trustee_a2n = array(          $out="";
1253          '!' => trmask_not,          foreach ($trustee_a2n as $c=>$v) {
1254          'C' => trmask_clear,                  if ($t & $v) $out.=$c;
1255          'D' => trmask_deny,          }
1256          'O' => trmask_one_level,          return $out;
1257          '+' => trmask_group,  }
1258          'R' => trperm_r,  function display_all_trustee() {
1259          'W' => trperm_w,          global $trustees;
1260          'B' => trperm_b,          print "trustee dump:<br>\n";
1261          'N' => trperm_n,          foreach ($trustees as $path => $tr) {
1262  );                  print "<br><tt>$path</tt>\n";
1263                    foreach ($tr as $user=>$perm) {
1264  // debugging function                          print "$user == $perm (".display_trustee($perm).")<br>\n";
1265  function display_trustee($t) {                  }
1266          global $trustee_a2n;          }
1267          $out="";  }
1268          foreach ($trustee_a2n as $c=>$v) {  
1269                  if ($t & $v) $out.=$c;  function init_trustee() {
1270          }  
1271          return $out;  global $trustee_conf,$trustee_php,$trustee_a2n,$groups,$trustees;
1272  }  
1273  function display_all_trustee() {  // do we need to re-create compiled trustees?
1274          global $trustees;  if (! file_exists($trustee_conf)) {
1275          print "trustee dump:<br>\n";          # $error="$trustee_conf doesn't exits";
1276          foreach ($trustees as $path => $tr) {          return 0;       # don't use trustees
1277                  print "<br><tt>$path</tt>\n";  } elseif (file_exists($trustee_conf) && !is_readable($trustee_conf)) {
1278                  foreach ($tr as $user=>$perm) {          $error="<tt>$trustee_conf</tt> exits, but is not readable";
1279                          print "$user == $perm (".display_trustee($perm).")<br>\n";  } elseif (!is_writable(dirname($trustee_php))) {
1280                  }          $error="<tt>".dirname($trustee_php)."</tt> must be writable by web server user";
1281          }  } elseif (file_exists($trustee_php) && !is_writable($trustee_php)) {
1282  }          $error="trustees cache file <tt>$trustee_php</tt> exists, but is not writable by web server";
1283    } elseif (@filemtime($trustee_conf) >= @filemtime($trustee_php)) {
1284  function init_trustee() {          $fp_php=@fopen($trustee_php,"w");
1285            fputs($fp_php,"<?php // don't edit by hand!\n");
1286  global $trustee_conf,$trustee_php,$trustee_a2n,$groups,$trustees;  
1287            $fp_conf=fopen($trustee_conf,"r");
1288  // do we need to re-create compiled trustees?  
1289  if (! file_exists($trustee_conf)) {          $groups_arr = array();
1290          # $error="$trustee_conf doesn't exits";          $perm_arr = array();
1291          return 0;       # don't use trustees  
1292  } elseif (file_exists($trustee_conf) && !is_readable($trustee_conf)) {          $tr_arr = array();
1293          $error="<tt>$trustee_conf</tt> exits, but is not readable";  
1294  } elseif (!is_writable(dirname($trustee_php))) {          while (! feof($fp_conf)) {
1295          $error="<tt>".dirname($trustee_php)."</tt> must be writable by web server user";                  $l = trim(fgets($fp_conf,4096));
1296  } elseif (file_exists($trustee_php) && !is_writable($trustee_php)) {                  if (substr($l,0,1) == "+") {    // no comment
1297          $error="trustees cache file <tt>$trustee_php</tt> exists, but is not writable by web server";                          $arr=explode(":",$l);
1298  } elseif (1 || filemtime($trustee_conf) >= filemtime($trustee_php)) {                          $groups_arr[$arr[0]] = str_replace(" ","",$arr[1]) ;
1299          $fp_php=@fopen($trustee_php,"w");                  } elseif (substr($l,0,1) != "#") {
1300          fputs($fp_php,"<?php // don't edit by hand!\n");                          $arr=explode(":",$l);
1301                            $path=array_shift($arr);
1302          $fp_conf=fopen($trustee_conf,"r");                          if ($path == "") continue;
1303                            $sep2="";
1304          $groups_arr = array();                          while ($user=array_shift($arr)) {
1305          $perm_arr = array();                                  $perm=0;
1306                                    if (substr($user,0,1) == "+") {
1307          $tr_arr = array();                                          $perm|=trmask_group;
1308                                            $user=substr($user,1,strlen($user)-1);
1309          while (! feof($fp_conf)) {                                  }
1310                  $l = trim(fgets($fp_conf,4096));                                  $perm_ascii=array_shift($arr);
1311                  if (substr($l,0,1) == "+") {    // no comment                                  for ($i=0;$i<strlen($perm_ascii);$i++) {
1312                          $arr=explode(":",$l);                                          $ch=strtoupper($perm_ascii[$i]);
1313                          $groups_arr[$arr[0]] = $arr[1] ;                                          if (isset($trustee_a2n[$ch])) {
1314                  } elseif (substr($l,0,1) != "#") {                                                  $perm|=$trustee_a2n[$ch];
1315                          $arr=explode(":",$l);                                          } else {
1316                          $path=array_shift($arr);                                                  $error.="trustee error in line '$l' [Unknown modifier '$ch']<br>\n";
1317                          if ($path == "") continue;                                          }
1318                          $sep2="";                                  }
1319                          while ($user=array_shift($arr)) {                                  if (isset($tr_arr[$path][$user])) {
1320                                  $perm=0;                                          $tr_arr[$path][$user] |= $perm;
1321                                  if (substr($user,0,1) == "+") {                                  } else {
1322                                          $perm|=trmask_group;                                          $tr_arr[$path][$user] = $perm;
1323                                          $user=substr($user,1,strlen($user)-1);                                  }
1324                                  }                          }
1325                                  $perm_ascii=array_shift($arr);                  }
1326                                  for ($i=0;$i<strlen($perm_ascii);$i++) {          }
1327                                          $ch=strtoupper($perm_ascii[$i]);  
1328                                          if (isset($trustee_a2n[$ch])) {          fclose($fp_conf);
1329                                                  $perm|=$trustee_a2n[$ch];  
1330                                          } else {          // save trustees
1331                                                  $error.="trustee error in line '$l' [Unknown modifier '$ch']<br>\n";          $tr_out='$trustees = array (';
1332                                          }          $sep1="";
1333                                  }          while (list ($path, $tr) = each ($tr_arr)) {
1334                                  $tr_arr[$path][$user] |= $perm;                  $tr_out.="$sep1\n\t'$path'=>array(";
1335                          }                  $sep2="";
1336                  }                  while (list($user,$perm)=each($tr)) {
1337          }                          $tr_out.="$sep2\n\t\t'$user'=>$perm";
1338                            $sep2=",";
1339          fclose($fp_conf);                  }
1340                    $tr_out.="\n\t)";
1341          // save trustees                  $sep1=",";
1342          $tr_out='$trustees = array (';          }
1343          $sep1="";          $tr_out.="\n);";
1344          while (list ($path, $tr) = each ($tr_arr)) {  
1345                  $tr_out.="$sep1\n\t'$path'=>array(";          // save groups
1346                  $sep2="";          $gr_out='$groups = array (';
1347                  while (list($user,$perm)=each($tr)) {          $sep="";
1348                          $tr_out.="$sep2\n\t\t'$user'=>$perm";          while (list ($group, $members) = each ($groups_arr)) {
1349                          $sep2=",";                  $gr_out.="$sep\n\t'";
1350                  }                  $gr_out.=substr($group,1,strlen($group)-1);
1351                  $tr_out.="\n\t)";                  $gr_out.="'=>array('".join("','",explode(",",$members))."')";
1352                  $sep1=",";                  $sep=",";
1353          }          }
1354          $tr_out.="\n);";          $gr_out.="\n);\n";
1355    
1356          // save groups          fputs($fp_php,$gr_out);
1357          $gr_out='$groups = array (';          fputs($fp_php,$tr_out);
1358          $sep="";          fputs($fp_php,"?>\n");
1359          while (list ($group, $members) = each ($groups_arr)) {          fclose($fp_php);
1360                  $gr_out.="$sep\n\t'";  }
1361                  $gr_out.=substr($group,1,strlen($group)-1);  
1362                  $gr_out.="'=>array('".join("','",explode(",",$members))."')";  if (isset($error)) {
1363                  $sep=",";          Error("Trustee error",$error,1);
1364          }  } else {
1365          $gr_out.="\n);\n";          include_once("$trustee_php");
1366    }
1367          fputs($fp_php,$gr_out);  
1368          fputs($fp_php,$tr_out);  return 1;
1369          fputs($fp_php,"?>\n");  
1370          fclose($fp_php);  }//init_trustee
1371  }  
1372    function in_group($user,$group) {
1373  if ($error) {          global $groups;
1374          Error("Trustee error",$error,1);          return in_array($user,$groups[$group]);
1375  } else {  }
1376          include("$trustee_php");  
1377  }  // helper function
1378    function unroll_perm($u,$t,$perm,$one_level) {
1379  return 1;  
1380            if ($t & trmask_one_level && !$one_level) return $perm;
1381  }//init_trustee  
1382            if ($t & trmask_deny) {
1383  function in_group($user,$group) {                  if ($t & trmask_clear) {
1384          global $groups;                          $perm['deny'] &= ~$t;
1385          return in_array($user,$groups[$group]);                  } else {
1386  }                          $perm['deny'] |= $t;
1387                    }
1388  // helper function          } elseif ($t & trmask_clear) {
1389  function unroll_perm($u,$t,$user,$perm) {                  $perm['allow'] &= ~$t;
1390            } else {
1391          // check user FIX                  $perm['allow'] |= $t;
1392          if ($t & trmask_not && ($u==$user)) continue;          }
1393          if (!($t & trmask_not) && ($u!=$user)) continue;          return $perm;
1394    }// end of helper function
1395          if ($t & trmask_deny) {  
1396                  if ($t & trmask_clear) {  function check_trustee($user,$path) {
1397                          $perm[deny] &= ~$t;          global $trustees,$HAVE_TRUSTEE;
1398                  } else {          $perm['allow'] = 0;
1399                          $perm[deny] |= $t;          $perm['deny'] = 0;
1400                  }  
1401          } elseif ($t & trmask_clear) {          // do we use trustees?
1402                  $perm[allow] &= ~$t;          if (! $HAVE_TRUSTEE) return $perm;
1403          } else {  
1404                  $perm[allow] |= $t;          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);
1405          }  
1406          return $perm;  global $debug;
1407  }// end of helper function  $debug .= "<br>check_trustee $path ... ";
1408    
1409  function check_trustee($user,$path) {          $path_arr=explode("/",$path);
1410          global $trustees;          $tmppath="";
1411          $perm[allow] = 0;          while (count($path_arr)) {
1412          $perm[deny] = 0;                  $p = array_shift($path_arr);
1413    $debug.= "[$p] ";
1414  global $debug;                  # add trailing slash
1415  $debug .= "<br>check_trustee $path ... ";                  if (substr($tmppath,strlen($tmppath)-1,1) != "/") {
1416                            $tmppath.="/";
1417          $path_arr=explode("/",$path);                  }
1418          $tmppath = "/";                  # append currnet dir to tmppath
1419          while (count($path_arr)) {                  if (isset($p)) {
1420                  $tmppath.=array_shift($path_arr);                          $tmppath.=$p;
1421  $debug.= ">> $tmppath ";                  }
1422                  if (substr($tmppath,strlen($tmppath)-1,1) != "/") $tmppath.="/";  $debug.= ">> $tmppath ";
1423                  $tr = $trustees[$tmppath];  
1424                    if (! isset($trustees[$tmppath])) continue;
1425                  # clear one level flag                  $tr = $trustees[$tmppath];
1426                  $perm[allow] &= ~trperm_one_level;  
1427                  $perm[deny] &= ~trperm_one_level;                  $one_level = (!count($path_arr));
1428    $debug.=" O($one_level) ";
1429                  if (isset($tr)) {  
1430                          // first apply trustee for all                  if (isset($tr)) {
1431                          if (isset($tr['*'])) {                          // first apply trustee for all
1432                                  $perm = unroll_perm($user,$tr['*'],$user, $perm);                          if (isset($tr['*']) && $user!="anonymous") {
1433                                  unset($tr['*']);                                  $perm = unroll_perm($user,$tr['*'],$perm, $one_level);
1434                          }                                  unset($tr['*']);
1435                          // then apply group policies                          }
1436                          foreach ($tr as $g=>$t) {                          // then apply not and group policies
1437                                  if ($t & trmask_group && in_group($user,$g)) {                          foreach ($tr as $g=>$t) {
1438                                          // resolv user                                  if ($t & trmask_not && $g != $user) {
1439                                          $t = $t & ~trmask_group;                                          $t = $t & ~trmask_not;
1440                                          $perm = unroll_perm($user,$t,$user, $perm);                                          $perm = unroll_perm($user,$t,$perm, $one_level);
1441                                          unset($tr[$g]);                                          unset($tr[$g]);
1442                                  }  
1443                          }                                  } elseif ($t & trmask_group && in_group($user,$g)) {
1444                          // then apply user policy                                          // resolv user
1445                          if (isset($tr[$user])) {                                          $t = $t & ~trmask_group;
1446                                  $perm = unroll_perm($user,$tr[$user],$user, $perm);                                          $perm = unroll_perm($user,$t,$perm, $one_level);
1447                                  unset($tr[$user]);                                          unset($tr[$g]);
1448                          }                                  }
1449                  }                          }
1450  $debug.="d:".display_trustee($perm[deny])." a:".display_trustee($perm[allow])." ";                          // then apply user policy
1451                            if (isset($tr[$user])) {
1452          }                                  $perm = unroll_perm($user,$tr[$user],$perm,$one_level);
1453  $debug.="<br>check_trustee: user: $user path: $path==$tmppath perm: ";                                  unset($tr[$user]);
1454  $debug.="d: $perm[deny] (".display_trustee($perm[deny]).") a: $perm[allow] (".display_trustee($perm[allow]).")<Br>\n";                          }
1455          return $perm;                  }
1456  }  $debug.="d(".display_trustee($perm['deny']).") a(".display_trustee($perm['allow']).") ";
1457    
1458  // handy functions          }
1459    $debug.="<br>check_trustee: user: $user path: $path==$tmppath perm: ";
1460  function check_perm($path,$trperm) {  $debug.="d: ".$perm['deny']." (".display_trustee($perm['deny']).") a: ".$perm['allow']." (".display_trustee($perm['allow']).")<Br>\n";
1461          global $gblLogin,$HAVE_TRUSTEE;          return $perm;
1462    }
1463          global $debug;  
1464  $debug.="<br>check_perm: <tt>$path</tt> test perm ".display_trustee($perm)."<br>\n";  // handy functions
1465    
1466          $return = ! $HAVE_TRUSTEE;  function check_perm($path,$trperm) {
1467          if ($HAVE_TRUSTEE) {          global $gblLogin,$HAVE_TRUSTEE;
1468                  $perm = check_trustee($gblLogin,$path);  
1469  $debug.=" d: $perm[deny] (".display_trustee($perm[deny]).") a: $perm[allow] (".display_trustee($perm[allow]).") perm to have: $trperm (".display_trustee($trperm).")";          $path = str_replace("//","/",$path);
1470                  if ($perm[deny] & $trperm) $return=0;  
1471                  elseif (($perm[allow] & $trperm) == $trperm) $return=1;          global $debug;
1472          }  $debug.="<br>check_perm: on <tt>$path</tt> for perm ".display_trustee($trperm)."<br>\n";
1473  $debug.=" return: $return<br>\n";  
1474          return($return);          $return = ! $HAVE_TRUSTEE;
1475  }          if ($HAVE_TRUSTEE) {
1476                    $perm = check_trustee($gblLogin,$path);
1477  //////////////////////////////////////////////////////////////////  $debug.=" d: ".$perm['deny']." (".display_trustee($perm['deny']).") a: ".$perm['allow']." (".display_trustee($perm['allow']).") perm to have: $trperm (".display_trustee($trperm).")";
1478                    if ($perm['deny'] & $trperm) $return=0;
1479  function readMime() {                  elseif (($perm['allow'] & $trperm) == $trperm) $return=1;
1480          global $mime_type;          }
1481    $debug.=" return: $return<br>\n";
1482          if (! isset($gblMimeTypes)) {          return($return);
1483                  $gblMimeTypes = "/etc/mime.types";  }
1484          }  
1485    //////////////////////////////////////////////////////////////////
1486          $mime = @fopen($gblMimeTypes,"r");  
1487    function readMime() {
1488          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>");          global $mime_type, $gblMimeTypes;
1489    
1490          while($line = fgets($mime,80)) {          if (! isset($gblMimeTypes)) {
1491                  if (substr($line,0,1) == "#") continue; // skip comment                  $gblMimeTypes = "/etc/mime.types";
1492                  $arr = preg_split("/[\s\t]+/",$line);          }
1493                  $type = array_shift($arr);  
1494                  while ($ext = array_shift($arr)) {          $mime = @fopen($gblMimeTypes,"r");
1495                          $mime_type[$ext] = $type;  
1496                  }          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>");
1497          }  
1498            while($line = fgets($mime,80)) {
1499          fclose($mime);                  if (substr($line,0,1) == "#") continue; // skip comment
1500  }                  $arr = preg_split("/[\s\t]+/",$line);
1501                    $type = array_shift($arr);
1502  //////////////////////////////////////////////////////////////////                  while ($ext = array_shift($arr)) {
1503                            $mime_type[$ext] = $type;
1504  // check for invalid characters in filename and dirname (.. and /)                  }
1505            }
1506  function check_dirname($file) {  
1507          if (strstr($file,"..")) Error("Security violation","No parent dir <tt>..</tt> allowed in directory name <tt>$file</tt>",1);          fclose($mime);
1508  }  }
1509    
1510  function check_filename($file) {  //////////////////////////////////////////////////////////////////
1511          if (strstr($file,"..")) Error("Security violation","No parent dir <tt>..</tt> allowed in file name <tt>$file</tt>",1);  
1512          if (strstr($file,"/")) Error("Security violation","No slashes <tt>/</tt> allowed in file name <tt>$file</tt>",1);  // check for invalid characters in filename and dirname (.. and /)
1513  }  
1514    function check_dirname($file) {
1515  //////////////////////////////////////////////////////////////////          if (strstr($file,"..")) Error("Security violation","No parent dir <tt>..</tt> allowed in directory name <tt>$file</tt>",1);
1516  // MAIN PROGRAM  }
1517    
1518          $gblFilePerms = 0640 ;         // default for new files  function check_filename($file) {
1519          $gblDirPerms  = 0750 ;          // default for new dirs          if (strstr($file,"..")) Error("Security violation","No parent dir <tt>..</tt> allowed in file name <tt>$file</tt>",1);
1520            // remove deleted directory (for undelete to work)
1521          $STYLE = $HTTP_GET_VARS[STYLE];          $file = str_replace(".del/","",$file);
1522          if (isset($STYLE) && $STYLE == "get") {          if (strstr($file,"/")) Error("Security violation","No slashes <tt>/</tt> allowed in file name <tt>$file</tt>",1);
1523                  include("$html/docman.css");  }
1524                  exit;  
1525          }  // bla/blo/../foo will return bla/foo
1526    function remove_parent($path) {
1527          // location of master docman configuration file          while (preg_match(",/[^/]+/\.\./,",$path)) {
1528          $docman_conf = "/etc/docman.conf";                  $path = preg_replace(",/[^/]+/\.\./,","",$path);
1529          if (! file_exists($docman_conf)) {          }
1530                  $error = "Can't find master configuration file $docman_conf. See docman2/doc/upgrade.html#docman_conf for more informations";          if (substr($path,0,1) != "/") $path = "/".$path;
1531                            return $path;
1532                  error_log("docman: $error");  }
1533                  Error("docman not installed completly",$error);  
1534          }  //////////////////////////////////////////////////////////////////
1535          include($docman_conf);  
1536    // functions to move HTTP server variables to global namespace
1537          if (! isset($fsRealmDir)) {  // [replacement for register_globals in php.ini]
1538                  $fsRealmDir = "$gblIncDir/realm";  
1539          }  function HTTP_GET_VAR($var) {
1540            global $HTTP_GET_VARS, ${$var};
1541          // try to add dir to script name to realm var          if (isset($HTTP_GET_VARS[$var])) {
1542          if (is_dir("$fsRealmDir/$realm/".dirname($HTTP_SERVER_VARS[SCRIPT_NAME]))) {                  $$var = stripSlashes($HTTP_GET_VARS[$var]);
1543                  $realm .= dirname($HTTP_SERVER_VARS[SCRIPT_NAME]);                  return $$var;
1544                  $realm_sep = "/";          }
1545          } else {  }
1546                  $realm_sep = ".";  
1547          }  function HTTP_POST_VAR($var) {
1548            global $HTTP_POST_VARS, ${$var};
1549          $realm_config = $fsRealmDir."/".$realm.$realm_sep."conf";          if (isset($HTTP_POST_VARS[$var])) {
1550                    $$var = $HTTP_POST_VARS[$var];
1551          // read user-defined configuration                  return $$var;
1552          if (file_exists($realm_config)) {          }
1553                  include($realm_config);  }
1554          } else {  
1555                  Error("Configuration error","Can't find configuration file at <tt>$realm_config</tt> !");  function HTTP_SERVER_VAR($var) {
1556          }          global $HTTP_SERVER_VARS, ${$var};
1557            if (isset($HTTP_SERVER_VARS[$var])) {
1558          if (! isset($gblRepositoryDir)) Error("Configuration error","<tt>\$gblRepositoryDir</tt> is not setuped in realm configuration file <tt>$realm_config</tt>");                  $$var = $HTTP_SERVER_VARS[$var];
1559                    return $$var;
1560          // where do we get users from?          }
1561          if (file_exists("$gblIncDir/htusers/$gblUsers.php")) {  }
1562                  include("$gblIncDir/htusers/$gblUsers.php");  
1563          } else {  //////////////////////////////////////////////////////////////////
1564                  Error("Configuration error","Can't find user handling module at <tt>$gblIncDir/htusers/$gblUsers.php</tt> ! Please fix <tt>$realm_config</tt>");  
1565          }  function Warn($text) {
1566    }
1567          // take additional login vars  
1568          $relogin = $HTTP_GET_VARS[relogin];  //////////////////////////////////////////////////////////////////
1569          $force_login = $HTTP_GET_VARS[force_login];  
1570    function isBlank($file,$what = "filename") {
1571          // if no password, or empty password logout          if (trim($file) == "") return "<i>whitespace $what</i>";
1572          if (          if ($file == "") return "<i>no $what</i>";
1573                  isset($gblLogin) && (          return $file;
1574                          !isset($relogin) || (  }
1575                                  isset($relogin) && $relogin != md5($gblLogin.$gblPasswd)  
1576                          )  //////////////////////////////////////////////////////////////////
1577                  ) && (  // MAIN PROGRAM
1578                          $gblPasswd == "" || !isset($gblPasswd)  
1579                  ) && !isset($force_login) && $gblLogin != "anonymous"          $gblFilePerms = 0640 ;         // default for new files
1580             ) {          $gblDirPerms  = 0750 ;          // default for new dirs
1581                  StartHTML("Logout completed","Your login credentials has been erased") ;  
1582                  EndHTML() ;          if (isset($HTTP_GET_VARS["STYLE"]) && $HTTP_GET_VARS["STYLE"] == "get") {
1583                  exit ;                  include("$html/docman.css");
1584          }                  exit;
1585            }
1586          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);  
1587            // location of master docman configuration file
1588          // trustee (ACL) file configuration          $docman_conf = "/etc/docman.conf";
1589          $trustee_conf="$fsRealmDir/$realm".$realm_sep."trustee";          if (! file_exists($docman_conf)) {
1590          // compiled version of trustee file                  $error = "Can't find master configuration file <tt>$docman_conf</tt>. See <tt>docman2/doc/upgrade.html#docman_conf</tt> for more informations";
1591          $trustee_php="$gblRepositoryDir/.trustee.php";                  
1592          // get ACL informations                  error_log("docman: $error");
1593          $HAVE_TRUSTEE = init_trustee();                  Error("docman not installed completly",$error);
1594            }
1595          if (strtolower($gblLogin) == "anonymous" || !isset($gblLogin)) {          include($docman_conf);
1596                  $perm = check_trustee("anonymous",$path);  
1597                  // browsing must be explicitly allowed for root directory          if (! isset($fsRealmDir)) {
1598                  // of repository for anonymous user to work!                  $fsRealmDir = "$gblIncDir/realm";
1599                  if ($perm[allow] & trperm_b) {          }
1600                          $gblLogin = $gblPasswd = "anonymous";  
1601                          $secHash = md5($gblLogin.$gblPasswd);          // try to add dir to script name to realm var
1602                          $gblUserName = "Anonymous user";          if (is_dir("$fsRealmDir/$realm/".dirname($HTTP_SERVER_VARS["SCRIPT_NAME"]))) {
1603                  }                  $realm .= dirname($HTTP_SERVER_VARS["SCRIPT_NAME"]);
1604          }                  $realm_sep = "/";
1605            } else {
1606          // authentication failure                  $realm_sep = ".";
1607          if ( md5($gblLogin.$gblPasswd) != $secHash ||          }
1608                  isset($relogin) && $secHash == $relogin) {  
1609                  header("WWW-authenticate: basic realm=\"$realm\"") ;          $realm_config = $fsRealmDir."/".$realm.$realm_sep."conf";
1610                  header("HTTP/1.0 401 Unauthorized") ;  
1611                  Error("401 Unauthorized","No trespassing !",0,1);          // read user-defined configuration
1612          }          if (file_exists($realm_config)) {
1613                    include($realm_config);
1614            } else {
1615          // read mime.types                  Error("Configuration error","Can't find configuration file at <tt>$realm_config</tt> !");
1616          readMime();          }
1617    
1618          if ($HTTP_SERVER_VARS["REQUEST_METHOD"] == "POST") {          if (! isset($gblRepositoryDir)) Error("Configuration error","<tt>\$gblRepositoryDir</tt> is not setuped in realm configuration file <tt>$realm_config</tt>");
1619                  // take variables from server  
1620                  $FN=stripSlashes($HTTP_POST_VARS["FN"]);          // where do we get users from?
1621                  $DIR=stripSlashes($HTTP_POST_VARS["DIR"]);          if (file_exists("$gblIncDir/htusers/$gblUsers.php")) {
1622                  $RELPATH=stripSlashes($HTTP_POST_VARS["RELPATH"]);                  include("$gblIncDir/htusers/$gblUsers.php");
1623                  $T=stripSlashes($HTTP_POST_VARS["T"]);          } else {
1624                  $CONFIRM=stripSlashes($HTTP_POST_VARS["CONFIRM"]);                  Error("Configuration error","Can't find user handling module at <tt>$gblIncDir/htusers/$gblUsers.php</tt> ! Please fix <tt>$realm_config</tt>");
1625            }
1626                  check_filename($FN);  
1627                  check_dirname($DIR);          // take additional login vars
1628                  check_dirname($RELPATH);          HTTP_GET_VAR("relogin");
1629            HTTP_GET_VAR("force_login");
1630                  $relDir = $DIR;  
1631          } else {          // if no password, or empty password logout
1632                  // get          if (
1633                  $A=stripSlashes($HTTP_GET_VARS["A"]);                  isset($gblLogin) && (
1634                  $D=stripSlashes(urldecode($HTTP_GET_VARS["D"]));                          !isset($relogin) || (
1635                  $F=stripSlashes($HTTP_GET_VARS["F"]);                                  isset($relogin) && $relogin != md5($gblLogin.$gblPasswd)
1636                            )
1637                  check_filename($F);                  ) && (
1638                  check_dirname($D);                          $gblPasswd == "" || !isset($gblPasswd)
1639                    ) && !isset($force_login) && $gblLogin != "anonymous"
1640                  $relDir = $D;             ) {
1641          }                  StartHTML("Logout completed","Your login credentials has been erased") ;
1642                    EndHTML() ;
1643          $relScriptDir = dirname($SCRIPT_NAME) ;                          exit ;
1644          // i.e. /docman          }
1645    
1646          // start on server root          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);
1647          $gblFsRoot = $gblRepositoryDir;  
1648          // i.e. /home/httpd/repository          // trustee (ACL) file configuration
1649            $trustee_conf="$fsRealmDir/$realm".$realm_sep."trustee";
1650          $fsDir = $gblFsRoot . $relDir ; // current directory          // compiled version of trustee file
1651          if ( !is_dir($fsDir) ) Error("Dir not found","Can't find <tt>$relDir</tt> which points to <tt>$fsDir</tt>",1) ;          $trustee_php="$gblRepositoryDir/.trustee.php";
1652            // get ACL informations
1653          if ($relDir == "") $relDir="/";          $HAVE_TRUSTEE = init_trustee();
1654    
1655          if (isset($HTTP_SERVER_VARS["HTTPS"]) && $HTTP_SERVER_VARS["HTTPS"] == "on") {          if (strtolower($gblLogin) == "anonymous" || !isset($gblLogin)) {
1656                  $webRoot  = "https://";                  $perm = check_trustee("anonymous","/");
1657          } else {                  // browsing must be explicitly allowed for root directory
1658                  $webRoot  = "http://";                  // of repository for anonymous user to work!
1659          }                  if ($perm['allow'] & trperm_b) {
1660          $webRoot .= $HTTP_SERVER_VARS["HTTP_HOST"] . $relScriptDir;                          $gblLogin = $gblPasswd = "anonymous";
1661                            $secHash = md5($gblLogin.$gblPasswd);
1662          switch ($HTTP_POST_VARS["POSTACTION"]) {                          $gblUserName = "Anonymous user";
1663          case "UPLOAD" :                  }
1664                  $FN_name=stripSlashes($HTTP_POST_FILES["FN"]["tmp_name"]);          }
1665                  $FN=stripSlashes($HTTP_POST_FILES["FN"]["name"]);  
1666                  if (!is_writeable($fsDir)) Error("Write denied",$relDir) ;          // authentication failure
1667            if ( md5($gblLogin.$gblPasswd) != $secHash ||
1668                  $source = $FN_name ;                  isset($relogin) && $secHash == $relogin) {
1669                  if (! file_exists($source)) {                  header("WWW-authenticate: basic realm=\"$realm\"") ;
1670                          Error("You must select file with browse to upload it!");                  header("HTTP/1.0 401 Unauthorized") ;
1671                  }                  Error("401 Unauthorized","No trespassing !",0,1);
1672            }
1673                  $FILENAME = $HTTP_POST_VARS["FILENAME"];  
1674                  check_filename($FILENAME);  
1675            // read mime.types
1676                  if (! isset($FILENAME)) {       // from update file          readMime();
1677                          $target = "$fsDir/".basename($FN);  
1678                  } else {          if (! isset($gblPermNote)) {
1679                          $target = "$fsDir/$FILENAME";                  $gblPermNote = trperm_r;
1680                  }          }
1681    
1682                  // backup old files first          HTTP_POST_VAR("FN");
1683                  $dir=dirname($target);  
1684                  if (! file_exists($dir."/.bak")) {          if ($HTTP_SERVER_VARS["REQUEST_METHOD"] == "POST") {
1685                          mkdir($dir."/.bak",0700);                  // take variables from server
1686                  }                  if (HTTP_POST_VAR("FN"))
1687                  if (! file_exists($dir."/.bak/$GLOBALS[gblNumBackups]")) {                          check_filename($FN);
1688                          mkdir($dir."/.bak/$GLOBALS[gblNumBackups]",0700);                  if (HTTP_POST_VAR("DIR")) {
1689                  }                          check_dirname($DIR);
1690                  $file=basename($target);                          $relDir = $DIR;
1691                  for($i=$GLOBALS[gblNumBackups]-1;$i>0;$i--) {                  } else {
1692                          MoveTo("$dir/.bak/$i/$file","$dir/.bak/".($i+1)."/");                          trigger_error("Can't get DIR",E_USER_WARNING);
1693                  }                          $relDir = "/";
1694                  MoveTo($target,$dir."/.bak/1/");                  }
1695                    if (HTTP_POST_VAR("RELPATH")) check_dirname($RELPATH);
1696                  copy($source,$target) ;                  HTTP_POST_VAR("T");
1697                  chmod($target,$gblFilePerms) ;                  HTTP_POST_VAR("CONFIRM");
1698                  clearstatcache() ;          } else {
1699                  if (isset($FILENAME)) {                  // get
1700                          LogIt($target,"check-in",trperm_r | trperm_w);                  HTTP_GET_VAR("A");
1701                          Unlock($target);                  if (HTTP_GET_VAR("D")) {
1702                  } else {                          check_dirname($D);
1703                          LogIt($target,"uploaded",trperm_r | trperm_w);                          $D=urldecode($D);
1704                  }                          $relDir = $D;
1705                  break ;                  } else {
1706                            //trigger_error("Can't get D",E_USER_WARNING);
1707          case "SAVE" :                          $relDir = "/";
1708                  $path = $gblFsRoot . $RELPATH ;                  }
1709                  $path=stripSlashes($path);                  if (HTTP_GET_VAR("F")) check_filename($F);
1710                  $writable = is_writeable($path) ;          }
1711                  $legaldir = is_writeable(dirname($path)) ;  
1712                  $exists   = (file_exists($path)) ? 1 : 0 ;          $relScriptDir = dirname($HTTP_SERVER_VARS["SCRIPT_NAME"]) ;    
1713  // check for legal extension here as well          // i.e. /docman
1714                  if (!($writable || (!$exists && $legaldir)))  
1715                          Error("Write denied",$RELPATH) ;          // start on server root
1716                  $fh = fopen($path, "w") ;          $gblFsRoot = $gblRepositoryDir;
1717                  $FILEDATA=stripSlashes($FILEDATA);          // i.e. /home/httpd/repository
1718                  fwrite($fh,$FILEDATA) ;  
1719                  fclose($fh) ;          $fsDir = $gblFsRoot . $relDir ; // current directory
1720                  clearstatcache() ;          if ( !is_dir($fsDir) ) Error("Dir not found","Can't find <tt>$relDir</tt> which points to <tt>$fsDir</tt>",1) ;
1721                  LogIt($path,"saved changes",trperm_r);  
1722                  break ;          if ($relDir == "") $relDir="/";
1723    
1724          case "CREATE" :          if (isset($HTTP_SERVER_VARS["HTTPS"]) && $HTTP_SERVER_VARS["HTTPS"] == "on") {
1725                  // we know $fsDir exists                  $webRoot  = "https://";
1726                  if ($FN == "") break;           // no filename!          } else {
1727                  if (!is_writeable($fsDir)) Error("Write denied",$relDir) ;                  $webRoot  = "http://";
1728                  $path = $fsDir . "/" . $FN ;  // file or dir to create          }
1729                  $relPath = $relDir . "/" . $FN ;          $webRoot .= $HTTP_SERVER_VARS["HTTP_HOST"] . $relScriptDir;
1730                  switch ( $T ) {  
1731                  case "D" :  // create a directory          if (HTTP_POST_VAR("POSTACTION")) switch ($POSTACTION) {
1732                          if ( ! @mkdir($path,$gblDirPerms) )          case "UPLOAD" :
1733                                  Error("Mkdir failed",$relPath) ; // eg. if it exists                  $FN_name=stripSlashes($HTTP_POST_FILES["FN"]["tmp_name"]);
1734                          else                  $FN=stripSlashes($HTTP_POST_FILES["FN"]["name"]);
1735                                  LogIt($path."/","dir created",trperm_w);                  if (!is_writeable($fsDir)) Error("Write denied",$relDir) ;
1736                          clearstatcache() ;  
1737                          break ;                  $source = $FN_name ;
1738                  case "F" :  // create a new file                  if (! file_exists($source)) {
1739  // this functionality is doubled in DetailView().                          Error("You must select file with browse to upload it!","If file is too big, you might need to modify php configuration options <tt>post_max_size</tt> and <tt>upload_max_filesize</tt>",1);
1740  // better keep it here altogether                  }
1741  // chmod perms to $gblFilePerms  
1742                          if ( file_exists($path) && !is_writeable($path) )                  if (HTTP_POST_VAR("FILENAME")) check_filename($FILENAME);
1743                                  Error("File not writable", $relPath) ;  
1744                          $fh = fopen($path, "w+") ;                  if (! isset($FILENAME)) {       // from update file
1745                          if ($fh) {                          $target = "$fsDir/".basename($FN);
1746                                  fputs($fh,"\n");                  } else {
1747                                  fclose($fh) ;                          $target = "$fsDir/$FILENAME";
1748                                  LogIt($path,"file created",trperm_r | trperm_w);                  }
1749                          } else {  
1750                                  Error("Creation of file $relPath failed -- $path");                  if (! check_perm("$relDir/".basename($target), trperm_w))
1751                          }                          Error("Access denied","User <tt>$gblLogin</tt> tried to upload <tt>$relDir/".basename($target)."</tt> without valid trustee.",1);
1752                          $tstr = "$PHP_SELF?A=E&D=".urlencode($relDir)."&F=".urlencode($FN) ;  
1753                          header("Location: " . $tstr) ;                  // backup old files first
1754                          exit ;                  $dir=dirname($target);
1755                  }                  if (! file_exists($dir."/.bak")) {
1756                  break ;                          mkdir($dir."/.bak",0700);
1757                    }
1758          case "DELETE" :                    if (! file_exists($dir."/.bak/$gblNumBackups")) {
1759                  if ( $CONFIRM != "on" ) break ;                          mkdir($dir."/.bak/$gblNumBackups",0700);
1760                    }
1761                  $tstr  = "Attempt to delete non-existing object or " ;                  $file=basename($target);
1762                  $tstr .= "insufficient privileges: " ;                  for($i=$gblNumBackups-1;$i>0;$i--) {
1763                            MoveTo("$dir/.bak/$i/$file","$dir/.bak/".($i+1)."/");
1764                  if ( $FN != "") {  // delete file                  }
1765                          $path =  $fsDir . "/" . $FN ;                  MoveTo($target,$dir."/.bak/1/");
1766                    
1767                          $dir=dirname($path);                  copy($source,$target) ;
1768                          $file=basename($path);                  chmod($target,$gblFilePerms) ;
1769                          if (! file_exists("$dir/.del")) {                  clearstatcache() ;
1770                                  mkdir("$dir/.del",0700);                  if (isset($FILENAME)) {
1771                          }                          LogIt($target,"check-in",trperm_r | trperm_w);
1772                            Unlock($target);
1773  //                      if ( ! @unlink($path) ) {                  } else {
1774                          if ( ! rename($path,"$dir/.del/$file") ) {                          LogIt($target,"uploaded",trperm_r | trperm_w);
1775                                  LogIt($path,"file delete failed");                  }
1776                                  Error("File delete failed", $tstr . $path) ;                  break ;
1777                          } else {  
1778                                  LogIt($path,"file deleted",trperm_w);          case "SAVE" :
1779                                  MoveTo("$dir/.log/$file","$dir/.del/.log/");                  $path = $gblFsRoot . $RELPATH ;
1780                                  MoveTo("$dir/.note/$file","$dir/.del/.note/");                  $path=stripSlashes($path);
1781                                  MoveTo("$dir/.lock/$file","$dir/.del/.lock/");  
1782                          }                  if (! check_perm("$RELPATH", trperm_w))
1783                  } else {  // delete directory                          Error("Access denied","User <tt>$gblLogin</tt> tried to save <tt>$RELPATH</tt> without valid trustee.",1);
1784                          if ( ! @rrmdir($fsDir) ) {  
1785                                  Error("Rmdir failed", $tstr . $fsDir) ;                  $writable = is_writeable($path) ;
1786                          } else {                  $legaldir = is_writeable(dirname($path)) ;
1787                                  LogIt($path,"dir deleted",trperm_w);                  $exists   = (file_exists($path)) ? 1 : 0 ;
1788                                  $relDir = dirname($relDir) ;  // move up                  // FIX: more verbose error message
1789                          }                  if (!($writable || (!$exists && $legaldir)))
1790                  }                          Error("Write denied",$RELPATH) ;
1791                  break ;                  $fh = fopen($path, "w") ;
1792                    HTTP_POST_VAR("FILEDATA");
1793          case "UNDELETE" :                    fwrite($fh,$FILEDATA) ;
1794                  if ( $CONFIRM != "on" ) break ;                  fclose($fh) ;
1795                    clearstatcache() ;
1796                  if (substr($FN,0,4) != ".del") break ;                  LogIt($path,"saved changes",trperm_r);
1797                  $file=substr($FN,4,strlen($FN)-4);                  break ;
1798    
1799                  LogIt("$fsDir/.del/$file","undeleted",trperm_w);          case "CREATE" :
1800                  MoveTo("$fsDir/.del/$file","$fsDir/");                  // we know $fsDir exists
1801                  MoveTo("$fsDir/.del/.log/$file","$fsDir/.log/");                  if (! check_perm($relDir, trperm_w))
1802                  MoveTo("$fsDir/.del/.note/$file","$fsDir/.note/");                          Error("Write access denied","You don't have permission to write in <tt>$relDir</tt>");
1803                  MoveTo("$fsDir/.del/.lock/$file","$fsDir/.lock/");                  if ($T == "D") $type = "directory";
1804                    else $type ="file";
1805                  break ;                  if ($FN == "") Error("Can't create $type","You must enter name of $type to create it.");
1806                    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) ;
1807          case "RENAME" :                    $path = "$fsDir/$FN";           // file or dir to create
1808                  if ( $CONFIRM != "on" ) break ;                  $relPath = "$relDir/$FN";
1809    
1810                  $NEWNAME=stripSlashes($HTTP_POST_VARS["NEWNAME"]);                  if (file_exists($path))
1811                  LogIt("$fsDir/$FN","renamed $FN to $NEWNAME",trperm_r);                          Error("Can't create $type","Object <tt>$relPath</tt> allready exists");
1812                  safe_rename($fsDir,$FN,$NEWNAME);  
1813                  break ;                  switch ( $T ) {
1814                    case "D" :  // create a directory
1815          case "NOTE" :                            if ( ! @mkdir($path,$gblDirPerms) )
1816                  $NOTE=stripSlashes($HTTP_POST_VARS["NOTE"]);                                  Error("Mkdir failed",$relPath) ; // eg. if it exists
1817                  WriteNote("$fsDir/$FN","$NOTE");                          else
1818                  break ;                                  LogIt($path."/","dir created",trperm_w);
1819                            clearstatcache() ;
1820          case "UNLOCK" :                            break ;
1821                  if ( $CONFIRM != "on" ) break ;                  case "F" :  // create a new file
1822                  Unlock("$fsDir/$FN");  // this functionality is doubled in DetailView().
1823                  break ;  // better keep it here altogether
1824    // chmod perms to $gblFilePerms
1825          default :                          if ( file_exists($path) && !is_writeable($path) )
1826                  // user hit "CANCEL" or undefined action                                  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) ;
1827          }                          $fh = fopen($path, "w+") ;
1828                            if ($fh) {
1829          // common to all POSTs : redirect to directory view ($relDir)                                  fputs($fh,"\n");
1830          if ( $POSTACTION != "" ) {                                  fclose($fh) ;
1831                  $tstr = $PHP_SELF . "?D=" . urlencode($relDir) ;                                  LogIt($path,"file created",trperm_r | trperm_w);
1832                  header("Location: " . $tstr) ;                            } else {
1833                  exit ;                                  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) ;
1834          }                          }
1835                                    $tstr = $HTTP_SERVER_VARS["PHP_SELF"]."?A=E&D=".urlencode($relDir)."&F=".urlencode($FN) ;
1836          // check for mode.. navigate, code display, upload, or detail?                          header("Location: " . $tstr) ;
1837          // $A=U : upload to path given in $D                          exit ;
1838          // $A=E : display detail of file $D/$F and edit                  }
1839          // $A=C : display code in file $D/$F                  break ;
1840          // $A=Co : checkout file $D/$F  
1841          // $A=Ci : checkin file $D/$F          case "DELETE" :  
1842          // $A=V : view file (do nothing except log)                  if ( $CONFIRM != "on" ) break;
1843          // $A=I : include file .$F.php from [$gblIncDir|realm]/include_php  
1844          // default : display directory $D                  if ( isset($FN) && $FN != "") {
1845                            $path=$fsDir."/".$FN;
1846          switch ($A) {                          $what = "file";
1847          case "U" :                  } elseif (isset($DIR)) {
1848                  // upload to $relDir                          $path=$gblFsRoot."/".$DIR;
1849                  if (! check_perm($relDir, trperm_w))                          $what = "directory";
1850                          Error("Write access denied","You don't have permission to write in <tt>$relDir</tt>");                  } else  {
1851                  if (!is_writeable($gblFsRoot . $relDir))                          Error("Can't delete object","Can't find filename <tt>\$FN</tt> or dirname in <tt>\$DIR</tt>",1);
1852                          Error("Write access denied","User <tt>$gblLogin</tt> has permission on <tt>$relDir</tt>, but directory is not writable",1);                  }
1853                  $text  = "Use this page to upload a single " ;  
1854                  $text .= "file to <B>$realm</B>." ;                  if (! check_perm("$relDir/$FN", trperm_w))
1855                  StartHTML("(Upload Page)", $text) ;                          Error("Access denied","User <tt>$gblLogin</tt> tried to erase $what <tt>$relDir/$FN</tt> without valid trustee.",1);
1856                  UploadPage($gblFsRoot, $relDir) ;  
1857                  EndHTML() ;                  $tstr  = "Attempt to delete non-existing object or insufficient privileges: " ;
1858                  exit ;  
1859          case "E" :                  $dir=dirname($path);
1860                  // detail of $relDir/$F                  $file=basename($path);
1861                  if (is_file("$gblFsRoot/$relDir/$F") || is_dir("$gblFsRoot/$relDir/$F")) DetailPage($gblFsRoot, $relDir, $F) ;  
1862                  exit ;                  if (! file_exists("$dir/.del")) {
1863          case "C" :                          mkdir("$dir/.del",0700);
1864                  $F=stripSlashes($F);                  }
1865                  // listing of $relDir/$F  
1866                  DisplayCode($gblFsRoot, $relDir, $F) ;                  if ( ! @rename($path,"$dir/.del/$file") ) {
1867                  exit ;                          LogIt($path,"$what delete failed");
1868          case "Co" :                          Error("Can't delete $what",$tstr."<tt>".$relDir."/".$FN."</tt>") ;
1869                  // checkout                  } else {
1870                  Lock("$gblFsRoot/$relDir/$F");                          LogIt($path,"$what deleted",trperm_w);
1871                  Download("$gblFsRoot/$relDir/$F",1);                          MoveTo("$dir/.log/$file","$dir/.del/.log/");
1872                  exit;                          MoveTo("$dir/.note/$file","$dir/.del/.note/");
1873          case "Ci" :                          MoveTo("$dir/.lock/$file","$dir/.del/.lock/");
1874                  $F=stripSlashes($F);                  }
1875                  // upload && update to $relDir                  break ;
1876                  if (!is_writeable($gblFsRoot . $relDir))  
1877                          Error("Write access denied",$relDir) ;          case "UNDELETE" :  
1878                  $text  = "Use this page to update a single " ;                  if ( $CONFIRM != "on" ) break ;
1879                  $text .= "file to <B>$realm</B>." ;  
1880                  StartHTML("(Update file Page)", $text) ;                  if (substr($FN,0,4) != ".del") break ;
1881                  UploadPage($gblFsRoot, $relDir, $F) ;                  $file=substr($FN,4,strlen($FN)-4);
1882                  EndHTML() ;  
1883                  exit ;                  if (! check_perm("$relDir/$file", trperm_w))
1884          case "V" :                          Error("Access denied","User <tt>$gblLogin</tt> tried to undelete <tt>$relDir/$file</tt> without valid trustee.",1);
1885                  // view  
1886                  LogIt("$gblFsRoot/$relDir/$F","viewed");                  LogIt("$fsDir/.del/$file","undeleted",trperm_w);
1887                  Download("$gblFsRoot/$relDir/$F",$gblForceDownload);                  MoveTo("$fsDir/.del/$file","$fsDir/");
1888                  exit;                  MoveTo("$fsDir/.del/.log/$file","$fsDir/.log/");
1889          case "Ch" :                  MoveTo("$fsDir/.del/.note/$file","$fsDir/.note/");
1890                  StartHTML("(File changes)","All changes chronologicaly...");                  MoveTo("$fsDir/.del/.lock/$file","$fsDir/.lock/");
1891                  DisplayChangeLog(0);    // all  
1892                  EndHTML() ;                  break ;
1893                  exit;  
1894          case "Ch1" :          case "RENAME" :  
1895                  StartHTML("(File changes)","Changes to files in last day...");                  if ( $CONFIRM != "on" ) break ;
1896                  DisplayChangeLog(1);  
1897                  EndHTML() ;                  if (HTTP_POST_VAR("NEWNAME")) {
1898                  exit;                          $dest = remove_parent($relDir.$NEWNAME);
1899          case "I" :                          if (! check_perm($relDir.$FN, trperm_w) ||
1900                  if (! isset($F) || $F == "")                              ! check_perm($dest, trperm_w) )
1901                          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);                                  Error("Access denied","User <tt>$gblLogin</tt> tried to rename <tt>$relDir$FN</tt> to <tt>$dest</tt> without valid trustee.",1);
1902                  $inc_file="$fsRealmDir/$realm".$realm_sep.$F.".php";                  } else {
1903                  if (! file_exists($inc_file)) {                          Error("Rename error","Can't find new name in var <tt>\$NEWNAME</tt>",1);
1904                          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);                  }
1905                  }                  LogIt("$fsDir/$FN","renamed $FN to $NEWNAME",trperm_r);
1906                  if (!is_readable($inc_file))                  safe_rename($fsDir,$FN,$NEWNAME);
1907                          Error("Read access to include file denied","Can't read PHP include file <tt>$inc_file</tt>. Fix permissions on it.",1);                  break ;
1908                  $text  = "Your include file should define \$text variable which holds this text and \$title variable which is page title";  
1909                  $title = "You should define \$title variable with page title";          case "NOTE" :
1910                  include($inc_file);                  if (! HTTP_POST_VAR("NOTE"))
1911                  StartHTML($title, $text) ;                          Error("Can't add note to object","Can't find var <tt>\$NOTE</tt>",1);
1912                  print "<p>".GifIcon(up)." Back to <a href=$HTTP_SERVER_VARS[PHP_SELF]>front page</a>.</p>";                  if (! check_perm("$relDir/$FN", trperm_w))
1913                  EndHTML() ;                          Error("Access denied","User <tt>$gblLogin</tt> tried to add note to <tt>$relDir/$FN</tt> without valid trustee.",1);
1914                  exit ;  
1915          }                  WriteNote("$fsDir/$FN",$NOTE);
1916                    break ;
1917          // default: display directory $relDir  
1918          Navigate($gblFsRoot,$relDir) ;            case "UNLOCK" :  
1919          exit ;                  if ( $CONFIRM != "on" ) break ;
1920                    if (! check_perm("$relDir/$FN", trperm_w))
1921          Error("Whooah!","By cartesian logic, this never happens",1) ;                          Error("Access denied","User <tt>$gblLogin</tt> tried to unlock <tt>$relDir/$FN</tt> without valid trustee.",1);
1922  ?>                  Unlock("$fsDir/$FN");
1923                    break ;
1924    
1925            default :
1926                    // user hit "CANCEL" or undefined action
1927            }
1928    
1929            // common to all POSTs : redirect to directory view ($relDir)
1930            if (isset($POSTACTION)) {
1931                    $tstr = $HTTP_SERVER_VARS["PHP_SELF"]."?D=".urlencode($relDir);
1932                    header("Location: ".$tstr) ;  
1933                    exit ;
1934            }
1935    
1936            // check for mode.. navigate, code display, upload, or detail?
1937            // $A=U : upload to path given in $D
1938            // $A=E : display detail of file $D/$F and edit
1939            // $A=C : display code in file $D/$F
1940            // $A=Co : checkout file $D/$F
1941            // $A=Ci : checkin file $D/$F
1942            // $A=V : view file (do nothing except log)
1943            // $A=I : include file .$F.php from [$gblIncDir|realm]/include_php
1944            // default : display directory $D
1945    
1946            if (isset($A)) switch ($A) {
1947            case "U" :
1948                    // upload to $relDir
1949                    if (! check_perm($relDir, trperm_w))
1950                            Error("Write access denied","You don't have permission to write in <tt>$relDir</tt>");
1951                    if (!is_writeable($gblFsRoot . $relDir))
1952                            Error("Write access denied","User <tt>$gblLogin</tt> has permission on <tt>$relDir</tt>, but directory is not writable",1);
1953                    $text  = "Use this page to upload a single " ;
1954                    $text .= "file to <B>$realm</B>." ;
1955                    StartHTML("(Upload Page)", $text) ;
1956                    UploadPage($gblFsRoot, $relDir) ;
1957                    EndHTML() ;
1958                    exit ;
1959            case "E" :
1960                    // detail of $relDir/$F
1961                    if (is_file("$gblFsRoot/$relDir/$F") || is_dir("$gblFsRoot/$relDir/$F")) DetailPage($gblFsRoot, $relDir, $F) ;
1962                    exit ;
1963            case "C" :
1964                    $F=stripSlashes($F);
1965                    // listing of $relDir/$F
1966                    DisplayCode($gblFsRoot, $relDir, $F) ;
1967                    exit ;
1968            case "Co" :
1969                    // checkout
1970                    Lock("$gblFsRoot/$relDir/$F");
1971                    Download("$gblFsRoot/$relDir/$F",1);
1972                    exit;
1973            case "Ci" :
1974                    $F=stripSlashes($F);
1975                    // upload && update to $relDir
1976                    if (!is_writeable($gblFsRoot . $relDir))
1977                            Error("Write access denied",$relDir) ;
1978                    $text  = "Use this page to update a single " ;
1979                    $text .= "file to <B>$realm</B>." ;
1980                    StartHTML("(Update file Page)", $text) ;
1981                    UploadPage($gblFsRoot, $relDir, $F) ;
1982                    EndHTML() ;
1983                    exit ;
1984            case "V" :
1985                    // view
1986                    LogIt("$gblFsRoot/$relDir/$F","viewed");
1987                    Download("$gblFsRoot/$relDir/$F",$gblForceDownload);
1988                    exit;
1989            case "Ch" :
1990                    StartHTML("(File changes)","All changes chronologicaly...");
1991                    DisplayChangeLog(0);    // all
1992                    EndHTML() ;
1993                    exit;
1994            case "Ch1" :
1995                    StartHTML("(File changes)","Changes to files in last day...");
1996                    DisplayChangeLog(1);
1997                    EndHTML() ;
1998                    exit;
1999            case "I" :
2000                    if (! isset($F) || $F == "")
2001                            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);
2002                    $inc_file="$fsRealmDir/$realm".$realm_sep.$F.".php";
2003                    if (! file_exists($inc_file)) {
2004                            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);
2005                    }
2006                    if (!is_readable($inc_file))
2007                            Error("Read access to include file denied","Can't read PHP include file <tt>$inc_file</tt>. Fix permissions on it.",1);
2008                    $text  = "Your include file should define \$text variable which holds this text and \$title variable which is page title";
2009                    $title = "You should define \$title variable with page title";
2010                    include($inc_file);
2011                    StartHTML($title, $text) ;
2012                    print "<p>".GifIcon(up)." Back to <a href=$HTTP_SERVER_VARS[PHP_SELF]>front page</a>.</p>";
2013                    EndHTML() ;
2014                    exit ;
2015            }
2016    
2017            // default: display directory $relDir
2018            Navigate($gblFsRoot,$relDir) ;  
2019            exit ;
2020    
2021            Error("Whooah!","By cartesian logic, this never happens",1) ;
2022    ?>
2023    

Legend:
Removed from v.1.18  
changed lines
  Added in v.1.37

  ViewVC Help
Powered by ViewVC 1.1.26