/[docman2]/docman.php
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /docman.php

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

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

  ViewVC Help
Powered by ViewVC 1.1.26