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

Legend:
Removed from v.1.34  
changed lines
  Added in v.1.46

  ViewVC Help
Powered by ViewVC 1.1.26