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

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

  ViewVC Help
Powered by ViewVC 1.1.26