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

  ViewVC Help
Powered by ViewVC 1.1.26