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

Diff of /docman.php

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

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

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

  ViewVC Help
Powered by ViewVC 1.1.26