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

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

  ViewVC Help
Powered by ViewVC 1.1.26