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

Diff of /docman.php

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

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

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

  ViewVC Help
Powered by ViewVC 1.1.26