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

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

  ViewVC Help
Powered by ViewVC 1.1.26