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

Legend:
Removed from v.1.36  
changed lines
  Added in v.1.41

  ViewVC Help
Powered by ViewVC 1.1.26