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

Diff of /docman.php

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

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

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

  ViewVC Help
Powered by ViewVC 1.1.26