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

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

  ViewVC Help
Powered by ViewVC 1.1.26