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

Legend:
Removed from v.1.29  
changed lines
  Added in v.1.41

  ViewVC Help
Powered by ViewVC 1.1.26