/[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.30 by dpavlin, Mon Jul 29 12:53:50 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          if (! $note) {  }
1012                  Error("Error writing note","Can't open note file <tt>$dir/.note/$file</tt> for writing",1);  
1013          }  //////////////////////////////////////////////////////////////////
1014          fputs($note,"$msg\n");  
1015          fclose($note);  function MoveTo($source,$folder) {
1016    
1017          LogIt($target,"added note $msg");          $source=stripSlashes($source);
1018            $file=basename($source);
1019  }          if (! file_exists($folder)) {
1020                    mkdir($folder,0700);
1021  function ReadNote($target) {          }
1022            if (file_exists($source)) {
1023          $target=stripSlashes($target);                  rename($source,"$folder/$file");
1024          $dir=dirname($target);          }
1025          $file=basename($target);  }
1026          $msg="";  
1027          if (file_exists($dir."/.note/$file")) {  //////////////////////////////////////////////////////////////////
1028                  $note=fopen("$dir/.note/$file","r");  
1029                  $msg=fgets($note,4096);  function Lock($target) {
1030                  fclose($note);  
1031          }          global $gblUserName;
1032          return HtmlSpecialChars(StripSlashes($msg));  
1033            $target=stripSlashes($target);
1034  }          $dir=dirname($target);
1035            if (! file_exists($dir."/.lock")) {
1036  //////////////////////////////////////////////////////////////////                  mkdir($dir."/.lock",0700);
1037            }
1038  function MoveTo($source,$folder) {          $file=basename($target);
1039    
1040          $source=stripSlashes($source);          if (file_exists("$dir/.lock/$file")) {
1041          $file=basename($source);                  LogIt($target,"attempt to locked allready locked file!");
1042          if (! file_exists($folder)) {          } else {
1043                  mkdir($folder,0700);                  $lock=fopen("$dir/.lock/$file","w");
1044          }                  fputs($lock,"$gblUserName\n");
1045          if (file_exists($source)) {                  fclose($lock);
1046                  rename($source,"$folder/$file");  
1047          }                  LogIt($target,"file locked");
1048  }          }
1049    
1050  //////////////////////////////////////////////////////////////////  }
1051    
1052  function Lock($target) {  function CheckLock($target) {
1053    
1054          global $gblUserName;          $target=stripSlashes($target);
1055            $dir=dirname($target);
1056          $target=stripSlashes($target);          $file=basename($target);
1057          $dir=dirname($target);          $msg=0;
1058          if (! file_exists($dir."/.lock")) {          if (file_exists($dir."/.lock/$file")) {
1059                  mkdir($dir."/.lock",0700);                  $lock=fopen("$dir/.lock/$file","r");
1060          }                  $msg=fgets($lock,4096);
1061          $file=basename($target);                  fclose($lock);
1062            }
1063          if (file_exists("$dir/.lock/$file")) {          return chop($msg);
1064                  LogIt($target,"attempt to locked allready locked file!");  
1065          } else {  }
1066                  $lock=fopen("$dir/.lock/$file","w");  
1067                  fputs($lock,"$gblUserName\n");  function Unlock($target) {
1068                  fclose($lock);  
1069            $target=stripSlashes($target);
1070                  LogIt($target,"file locked");          $dir=dirname($target);
1071          }          $file=basename($target);
1072            if (file_exists($dir."/.lock/$file")) {
1073  }                  unlink("$dir/.lock/$file");
1074                    LogIt($target,"file unlocked");
1075  function CheckLock($target) {          } else {
1076                    LogIt($target,"attempt to unlocked non-locked file!");
1077          $target=stripSlashes($target);          }
1078          $dir=dirname($target);  
1079          $file=basename($target);  }
1080          $msg=0;  
1081          if (file_exists($dir."/.lock/$file")) {  //////////////////////////////////////////////////////////////////
1082                  $lock=fopen("$dir/.lock/$file","r");  
1083                  $msg=fgets($lock,4096);  function urlpath($url) {
1084                  fclose($lock);          $url=urlencode(StripSlashes("$url"));
1085          }          $url=str_replace("%2F","/",$url);
1086          return chop($msg);          $url=str_replace("+","%20",$url);
1087            return($url);
1088  }  }
1089    
1090  function Unlock($target) {  //////////////////////////////////////////////////////////////////
1091    
1092          $target=stripSlashes($target);  function safe_rename($fromdir,$fromfile,$tofile) {
1093          $dir=dirname($target);  
1094          $file=basename($target);          global $gblNumBackups;
1095          if (file_exists($dir."/.lock/$file")) {  
1096                  unlink("$dir/.lock/$file");          function try_rename($from,$to) {
1097                  LogIt($target,"file unlocked");  #               print "$from -> $to\n";
1098          } else {                  if (file_exists($from) && is_writeable(dirname($to))) {
1099                  LogIt($target,"attempt to unlocked non-locked file!");                          return rename($from,$to);
1100          }                  } else {
1101                            return 0;
1102  }                  }
1103            }
1104  //////////////////////////////////////////////////////////////////  
1105            function try_dir($todir) {
1106  function urlpath($url) {                  if (! file_exists($todir)) {
1107          $url=urlencode(StripSlashes("$url"));                          @mkdir($todir,0700);
1108          $url=str_replace("%2F","/",$url);                  }
1109          $url=str_replace("+","%20",$url);          }
1110          return($url);  
1111  }          $to="$fromdir/$tofile";
1112            $todir=dirname($to);
1113  //////////////////////////////////////////////////////////////////          $tofile=basename($to);
1114    
1115  function safe_rename($fromdir,$fromfile,$tofile) {  #       print "<pre>$fromdir / $fromfile -> $todir / $tofile\n\n";
1116    
1117          global $gblNumBackups;          if (! try_rename("$fromdir/$fromfile","$todir/$tofile")) Error("Rename error","Can't rename file <tt>$fromfile</tt> to <tt>$tofile</tt>",1);
1118            try_dir("$todir/.log");
1119          function try_rename($from,$to) {          try_rename("$fromdir/.log/$fromfile","$todir/.log/$tofile");
1120  #               print "$from -> $to\n";          try_dir("$todir/.note");
1121                  if (file_exists($from) && is_writeable(dirname($to))) {          try_rename("$fromdir/.note/$fromfile","$todir/.note/$tofile");
1122                          return rename($from,$to);          try_dir("$todir/.lock");
1123                  } else {          try_rename("$fromdir/.lock/$fromfile","$todir/.lock/$tofile");
1124                          return 0;          try_dir("$todir/.bak");
1125                  }          for($i=0;$i<=$gblNumBackups;$i++) {
1126          }                  try_rename("$fromdir/.bak/$i/$fromfile","$todir/.bak/$i/$tofile");
1127            }
1128          function try_dir($todir) {  }
1129                  if (! file_exists($todir)) {  
1130                          @mkdir($todir,0700);  
1131                  }  //////////////////////////////////////////////////////////////////
1132          }  
1133    // recursivly delete directory
1134          $to="$fromdir/$tofile";  
1135          $todir=dirname($to);  function rrmdir($dir) {
1136          $tofile=basename($to);          $handle=opendir($dir);
1137            while ($file = readdir($handle)) {
1138  #       print "<pre>$fromdir / $fromfile -> $todir / $tofile\n\n";                  if ($file != "." && $file != "..") {
1139                            if (is_dir("$dir/$file"))
1140          if (! try_rename("$fromdir/$fromfile","$todir/$tofile")) Error("Rename error","Can't rename file <tt>$fromfile</tt> to <tt>$tofile</tt>",1);                                  rrmdir("$dir/$file");
1141          try_dir("$todir/.log");                          else
1142          try_rename("$fromdir/.log/$fromfile","$todir/.log/$tofile");                                  if (! @unlink("$dir/$file")) return(0);
1143          try_dir("$todir/.note");                  }
1144          try_rename("$fromdir/.note/$fromfile","$todir/.note/$tofile");          }
1145          try_dir("$todir/.lock");          closedir($handle);
1146          try_rename("$fromdir/.lock/$fromfile","$todir/.lock/$tofile");          return @rmdir($dir);
1147          try_dir("$todir/.bak");  }
1148          for($i=0;$i<=$gblNumBackups;$i++) {  
1149                  try_rename("$fromdir/.bak/$i/$fromfile","$todir/.bak/$i/$tofile");  //////////////////////////////////////////////////////////////////
1150          }  
1151  }  function DisplayChangeLog($day) {
1152    
1153            global $gblFsRoot, $gblDateFmt, $gblTimeFmt,
1154  //////////////////////////////////////////////////////////////////                  $HTTP_SERVER_VARS;
1155    
1156  // recursivly delete directory          $self  = $HTTP_SERVER_VARS["PHP_SELF"];
1157    
1158  function rrmdir($dir) {          if (!file_exists("$gblFsRoot/.changelog")) return;
1159          $handle=opendir($dir);          $log=fopen("$gblFsRoot/.changelog","r");
1160          while ($file = readdir($handle)) {          $logarr = array();
1161                  if ($file != "." && $file != "..") {          while($line = fgetcsv($log,512,"\t")) {
1162                          if (is_dir("$dir/$file"))                  while (sizeof($line) > 4) {
1163                                  rrmdir("$dir/$file");                          $tmp = array_pop($line);
1164                          else                          $line.=" $tmp";
1165                                  if (! @unlink("$dir/$file")) return(0);                  }
1166                  }                  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          closedir($handle);                  }
1169          return @rmdir($dir);          }
1170  }          fclose($log);
1171            $cl1=" class=LST"; $cl2="";
1172  //////////////////////////////////////////////////////////////////          print "<table border=0 width=100%>\n";
1173            while ($e = array_shift($logarr)) {
1174  function DisplayChangeLog($day) {                  $cl=$cl1; $cl1=$cl2; $cl2=$cl;
1175                    $date = date($gblDateFmt, $e[0]);
1176          global $gblFsRoot, $gblDateFmt, $gblTimeFmt,                  $time = date($gblTimeFmt, $e[0]);
1177                  $HTTP_SERVER_VARS;                  $dir = dirname($e[1]);
1178                    $file = basename($e[1]);
1179          $self  = $HTTP_SERVER_VARS["PHP_SELF"];                  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            }
1181          if (!file_exists("$gblFsRoot/.changelog")) return;          print "</table>";
1182          $log=fopen("$gblFsRoot/.changelog","r");          print "<p>".GifIcon("up")." Back to <a href=\"$self\">front page</a>.</p>";
1183          $logarr = array();  }
1184          while($line = fgetcsv($log,512,"\t")) {  
1185                  while (sizeof($line) > 4) {  //////////////////////////////////////////////////////////////////
1186                          $tmp = array_pop($line);  
1187                          $line.=" $tmp";  function Download($path,$force=0) {
1188                  }          global $HTTP_SERVER_VARS,$mime_type;
1189                  if ($day!=1 || ($day==1 && (time()-$line[0] < 24*60*60))) {  
1190                          array_unshift($logarr,array($line[0],$line[1],$line[2],$line[3]));          // default transfer-encoding
1191                  }          $encoding = "binary";
1192          }  
1193          fclose($log);          // known transfer encodings
1194          $cl1=" class=LST"; $cl2="";          $encoding_ext = array(
1195          print "<table border=0 width=100%>\n";                  "gz" => "x-gzip",
1196          while ($e = array_shift($logarr)) {                  "Z" => "x-compress",
1197                  $cl=$cl1; $cl1=$cl2; $cl2=$cl;          );
1198                  $date = date($gblDateFmt, $e[0]);  
1199                  $time = date($gblTimeFmt, $e[0]);          $file = basename($path);
1200                  $dir = dirname($e[1]);          $size = filesize($path);
1201                  $file = basename($e[1]);  
1202                  print "<tr><td$cl>$date</td><td$cl>$time</td><td$cl><a href=\"$HTTP_SERVER_VARS[PHP_SELF]?D=".urlencode($dir)."\">$dir</a>/$file</td><td$cl>$e[2]</td><td$cl>$e[3]</td></tr>\n";          $ext_arr = explode(".",$file);
1203          }          $ext = array_pop($ext_arr);
1204          print "</table>";          if (isset($encoding_ext[$ext])) {
1205          print "<p>".GifIcon("up")." Back to <a href=\"$self\">front page</a>.</p>";                  $encoding = $encoding_ext[$ext];
1206  }                  $ext = array_pop($ext_arr);
1207            }
1208  //////////////////////////////////////////////////////////////////  
1209            if ($force || !isset($mime_type[$ext])) {
1210  function Download($path,$force=0) {                  header("Content-Type: application/force-download");
1211          global $HTTP_SERVER_VARS,$mime_type;          } else {
1212                    header("Content-Type: $mime_type[$ext]");
1213          // default transfer-encoding          }
1214          $encoding = "binary";  
1215            // IE5.5 just downloads index.php if we don't do this
1216          // known transfer encodings          if(preg_match("/MSIE 5.5/", $HTTP_SERVER_VARS["HTTP_USER_AGENT"])) {
1217          $encoding_ext = array(                  header("Content-Disposition: filename=$file");
1218                  "gz" => "x-gzip",          } else {
1219                  "Z" => "x-compress",                  header("Content-Disposition: attachment; filename=$file");
1220          );          }
1221    
1222          $file = basename($path);          header("Content-Transfer-Encoding: $encoding");
1223          $size = filesize($path);          $fh = fopen($path, "r");
1224            fpassthru($fh);
1225          $ext_arr = explode(".",$file);  }
1226          $ext = array_pop($ext_arr);  
1227          if (isset($encoding_ext[$ext])) {  
1228                  $encoding = $encoding_ext[$ext];  //////////////////////////////////////////////////////////////////
1229                  $ext = array_pop($ext_arr);  
1230          }  function chopsl($path) {
1231            $path=str_replace("//","/",$path);
1232          if ($force || !isset($mime_type[$ext])) {          if (substr($path,strlen($path)-1,1) == "/") $path=substr($path,0,strlen($path)-1);
1233                  header("Content-Type: application/force-download");          return $path;
1234          } else {  }
1235                  header("Content-Type: $mime_type[$ext]");  
1236          }  //////////////////////////////////////////////////////////////////
1237    /*
1238          // IE5.5 just downloads index.php if we don't do this          Document manager ACL implementation
1239          if(preg_match("/MSIE 5.5/", $HTTP_SERVER_VARS["HTTP_USER_AGENT"])) {  
1240                  header("Content-Disposition: filename=$file");          Written by Dobrica Pavlinusic <dpavlin@rot13.org>
1241          } else {  
1242                  header("Content-Disposition: attachment; filename=$file");          Based on ideas from Linux trustees code
1243          }          by Vyacheslav Zavadsky <zavadsky@braysystems.com>
1244    */
1245          header("Content-Transfer-Encoding: $encoding");  
1246          $fh = fopen($path, "r");  define('trmask_not',1 << 0);
1247          fpassthru($fh);  define('trmask_clear',1 << 1);
1248  }  define('trmask_deny',1 << 2);
1249    define('trmask_one_level',1 << 3);
1250    define('trmask_group',1 << 4);
1251  //////////////////////////////////////////////////////////////////  
1252    define('trperm_r',1 << 5);
1253  function chopsl($path) {  define('trperm_w',1 << 6);
1254          $path=str_replace("//","/",$path);  define('trperm_b',1 << 7);
1255          if (substr($path,strlen($path)-1,1) == "/") $path=substr($path,0,strlen($path)-1);  define('trperm_n',1 << 8);
1256          return $path;  
1257  }  $trustee_a2n = array(
1258            '!' => trmask_not,
1259  //////////////////////////////////////////////////////////////////          'C' => trmask_clear,
1260  /*          'D' => trmask_deny,
1261          Document manager ACL implementation          'O' => trmask_one_level,
1262            '+' => trmask_group,
1263          Written by Dobrica Pavlinusic <dpavlin@rot13.org>          'R' => trperm_r,
1264            'W' => trperm_w,
1265          Based on ideas from Linux trustees code          'B' => trperm_b,
1266          by Vyacheslav Zavadsky <zavadsky@braysystems.com>          'N' => trperm_n,
1267  */  );
1268    
1269  define('trmask_not',1 << 0);  // debugging function
1270  define('trmask_clear',1 << 1);  function display_trustee($t) {
1271  define('trmask_deny',1 << 2);          global $trustee_a2n;
1272  define('trmask_one_level',1 << 3);          $out="";
1273  define('trmask_group',1 << 4);          foreach ($trustee_a2n as $c=>$v) {
1274                    if ($t & $v) $out.=$c;
1275  define('trperm_r',1 << 5);          }
1276  define('trperm_w',1 << 6);          return $out;
1277  define('trperm_b',1 << 7);  }
1278  define('trperm_n',1 << 8);  function display_all_trustee() {
1279            global $trustees;
1280  $trustee_a2n = array(          print "trustee dump:<br>\n";
1281          '!' => trmask_not,          foreach ($trustees as $path => $tr) {
1282          'C' => trmask_clear,                  print "<br><tt>$path</tt>\n";
1283          'D' => trmask_deny,                  foreach ($tr as $user=>$perm) {
1284          'O' => trmask_one_level,                          print "$user == $perm (".display_trustee($perm).")<br>\n";
1285          '+' => trmask_group,                  }
1286          'R' => trperm_r,          }
1287          'W' => trperm_w,  }
1288          'B' => trperm_b,  
1289          'N' => trperm_n,  function init_trustee() {
1290  );  
1291    global $trustee_conf,$trustee_php,$trustee_a2n,$groups,$trustees;
1292  // debugging function  
1293  function display_trustee($t) {  // do we need to re-create compiled trustees?
1294          global $trustee_a2n;  if (! file_exists($trustee_conf)) {
1295          $out="";          # $error="$trustee_conf doesn't exits";
1296          foreach ($trustee_a2n as $c=>$v) {          return 0;       # don't use trustees
1297                  if ($t & $v) $out.=$c;  } elseif (file_exists($trustee_conf) && !is_readable($trustee_conf)) {
1298          }          $error="<tt>$trustee_conf</tt> exits, but is not readable";
1299          return $out;  } elseif (!is_writable(dirname($trustee_php))) {
1300  }          $error="<tt>".dirname($trustee_php)."</tt> must be writable by web server user";
1301  function display_all_trustee() {  } elseif (file_exists($trustee_php) && !is_writable($trustee_php)) {
1302          global $trustees;          $error="trustees cache file <tt>$trustee_php</tt> exists, but is not writable by web server";
1303          print "trustee dump:<br>\n";  } elseif (@filemtime($trustee_conf) >= @filemtime($trustee_php)) {
1304          foreach ($trustees as $path => $tr) {          $fp_php=@fopen($trustee_php,"w");
1305                  print "<br><tt>$path</tt>\n";          fputs($fp_php,"<?php // don't edit by hand!\n");
1306                  foreach ($tr as $user=>$perm) {  
1307                          print "$user == $perm (".display_trustee($perm).")<br>\n";          $fp_conf=fopen($trustee_conf,"r");
1308                  }  
1309          }          $groups_arr = array();
1310  }          $perm_arr = array();
1311    
1312  function init_trustee() {          $tr_arr = array();
1313    
1314  global $trustee_conf,$trustee_php,$trustee_a2n,$groups,$trustees;          while (! feof($fp_conf)) {
1315                    $l = trim(fgets($fp_conf,4096));
1316  // do we need to re-create compiled trustees?                  if (substr($l,0,1) == "+") {    // no comment
1317  if (! file_exists($trustee_conf)) {                          $arr=explode(":",$l);
1318          # $error="$trustee_conf doesn't exits";                          $groups_arr[$arr[0]] = str_replace(" ","",$arr[1]) ;
1319          return 0;       # don't use trustees                  } elseif (substr($l,0,1) != "#") {
1320  } elseif (file_exists($trustee_conf) && !is_readable($trustee_conf)) {                          $arr=explode(":",$l);
1321          $error="<tt>$trustee_conf</tt> exits, but is not readable";                          $path=array_shift($arr);
1322  } elseif (!is_writable(dirname($trustee_php))) {                          if ($path == "") continue;
1323          $error="<tt>".dirname($trustee_php)."</tt> must be writable by web server user";                          $sep2="";
1324  } elseif (file_exists($trustee_php) && !is_writable($trustee_php)) {                          while ($user=array_shift($arr)) {
1325          $error="trustees cache file <tt>$trustee_php</tt> exists, but is not writable by web server";                                  $perm=0;
1326  } elseif (@filemtime($trustee_conf) >= @filemtime($trustee_php)) {                                  if (substr($user,0,1) == "+") {
1327          $fp_php=@fopen($trustee_php,"w");                                          $perm|=trmask_group;
1328          fputs($fp_php,"<?php // don't edit by hand!\n");                                          $user=substr($user,1,strlen($user)-1);
1329                                    }
1330          $fp_conf=fopen($trustee_conf,"r");                                  $perm_ascii=array_shift($arr);
1331                                    for ($i=0;$i<strlen($perm_ascii);$i++) {
1332          $groups_arr = array();                                          $ch=strtoupper($perm_ascii[$i]);
1333          $perm_arr = array();                                          if (isset($trustee_a2n[$ch])) {
1334                                                    $perm|=$trustee_a2n[$ch];
1335          $tr_arr = array();                                          } else {
1336                                                    $error.="trustee error in line '$l' [Unknown modifier '$ch']<br>\n";
1337          while (! feof($fp_conf)) {                                          }
1338                  $l = trim(fgets($fp_conf,4096));                                  }
1339                  if (substr($l,0,1) == "+") {    // no comment                                  if (isset($tr_arr[$path][$user])) {
1340                          $arr=explode(":",$l);                                          $tr_arr[$path][$user] |= $perm;
1341                          $groups_arr[$arr[0]] = $arr[1] ;                                  } else {
1342                  } elseif (substr($l,0,1) != "#") {                                          $tr_arr[$path][$user] = $perm;
1343                          $arr=explode(":",$l);                                  }
1344                          $path=array_shift($arr);                          }
1345                          if ($path == "") continue;                  }
1346                          $sep2="";          }
1347                          while ($user=array_shift($arr)) {  
1348                                  $perm=0;          fclose($fp_conf);
1349                                  if (substr($user,0,1) == "+") {  
1350                                          $perm|=trmask_group;          // save trustees
1351                                          $user=substr($user,1,strlen($user)-1);          $tr_out='$trustees = array (';
1352                                  }          $sep1="";
1353                                  $perm_ascii=array_shift($arr);          while (list ($path, $tr) = each ($tr_arr)) {
1354                                  for ($i=0;$i<strlen($perm_ascii);$i++) {                  $tr_out.="$sep1\n\t'$path'=>array(";
1355                                          $ch=strtoupper($perm_ascii[$i]);                  $sep2="";
1356                                          if (isset($trustee_a2n[$ch])) {                  while (list($user,$perm)=each($tr)) {
1357                                                  $perm|=$trustee_a2n[$ch];                          $tr_out.="$sep2\n\t\t'$user'=>$perm";
1358                                          } else {                          $sep2=",";
1359                                                  $error.="trustee error in line '$l' [Unknown modifier '$ch']<br>\n";                  }
1360                                          }                  $tr_out.="\n\t)";
1361                                  }                  $sep1=",";
1362                                  if (isset($tr_arr[$path][$user])) {          }
1363                                          $tr_arr[$path][$user] |= $perm;          $tr_out.="\n);";
1364                                  } else {  
1365                                          $tr_arr[$path][$user] = $perm;          // save groups
1366                                  }          $gr_out='$groups = array (';
1367                          }          $sep="";
1368                  }          while (list ($group, $members) = each ($groups_arr)) {
1369          }                  $gr_out.="$sep\n\t'";
1370                    $gr_out.=substr($group,1,strlen($group)-1);
1371          fclose($fp_conf);                  $gr_out.="'=>array('".join("','",explode(",",$members))."')";
1372                    $sep=",";
1373          // save trustees          }
1374          $tr_out='$trustees = array (';          $gr_out.="\n);\n";
1375          $sep1="";  
1376          while (list ($path, $tr) = each ($tr_arr)) {          fputs($fp_php,$gr_out);
1377                  $tr_out.="$sep1\n\t'$path'=>array(";          fputs($fp_php,$tr_out);
1378                  $sep2="";          fputs($fp_php,"?>\n");
1379                  while (list($user,$perm)=each($tr)) {          fclose($fp_php);
1380                          $tr_out.="$sep2\n\t\t'$user'=>$perm";  }
1381                          $sep2=",";  
1382                  }  if (isset($error)) {
1383                  $tr_out.="\n\t)";          Error("Trustee error",$error,1);
1384                  $sep1=",";  } else {
1385          }          include_once("$trustee_php");
1386          $tr_out.="\n);";  }
1387    
1388          // save groups  return 1;
1389          $gr_out='$groups = array (';  
1390          $sep="";  }//init_trustee
1391          while (list ($group, $members) = each ($groups_arr)) {  
1392                  $gr_out.="$sep\n\t'";  function in_group($user,$group) {
1393                  $gr_out.=substr($group,1,strlen($group)-1);          global $groups;
1394                  $gr_out.="'=>array('".join("','",explode(",",$members))."')";          return in_array($user,$groups[$group]);
1395                  $sep=",";  }
1396          }  
1397          $gr_out.="\n);\n";  // helper function
1398    function unroll_perm($u,$t,$perm,$one_level) {
1399          fputs($fp_php,$gr_out);  
1400          fputs($fp_php,$tr_out);          if ($t & trmask_one_level && !$one_level) return $perm;
1401          fputs($fp_php,"?>\n");  
1402          fclose($fp_php);          if ($t & trmask_deny) {
1403  }                  if ($t & trmask_clear) {
1404                            $perm['deny'] &= ~$t;
1405  if (isset($error)) {                  } else {
1406          Error("Trustee error",$error,1);                          $perm['deny'] |= $t;
1407  } else {                  }
1408          include_once("$trustee_php");          } elseif ($t & trmask_clear) {
1409  }                  $perm['allow'] &= ~$t;
1410            } else {
1411  return 1;                  $perm['allow'] |= $t;
1412            }
1413  }//init_trustee          return $perm;
1414    }// end of helper function
1415  function in_group($user,$group) {  
1416          global $groups;  function check_trustee($user,$path) {
1417          return in_array($user,$groups[$group]);          global $trustees,$HAVE_TRUSTEE;
1418  }          $perm['allow'] = 0;
1419            $perm['deny'] = 0;
1420  // helper function  
1421  function unroll_perm($u,$t,$perm,$one_level) {          // do we use trustees?
1422            if (! $HAVE_TRUSTEE) return $perm;
1423          if ($t & trmask_one_level && !$one_level) return $perm;  
1424            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          if ($t & trmask_deny) {  
1426                  if ($t & trmask_clear) {  global $debug;
1427                          $perm['deny'] &= ~$t;  $debug .= "<br>check_trustee $path ... ";
1428                  } else {  
1429                          $perm['deny'] |= $t;          $path_arr=explode("/",$path);
1430                  }          $tmppath="";
1431          } elseif ($t & trmask_clear) {          while (count($path_arr)) {
1432                  $perm['allow'] &= ~$t;                  $p = array_shift($path_arr);
1433          } else {  $debug.= "[$p] ";
1434                  $perm['allow'] |= $t;                  # add trailing slash
1435          }                  if (substr($tmppath,strlen($tmppath)-1,1) != "/") {
1436          return $perm;                          $tmppath.="/";
1437  }// end of helper function                  }
1438                    # append currnet dir to tmppath
1439  function check_trustee($user,$path) {                  if (isset($p)) {
1440          global $trustees,$HAVE_TRUSTEE;                          $tmppath.=$p;
1441          $perm['allow'] = 0;                  }
1442          $perm['deny'] = 0;  $debug.= ">> $tmppath ";
1443    
1444          // do we use trustees?                  if (! isset($trustees[$tmppath])) continue;
1445          if (! $HAVE_TRUSTEE) return $perm;                  $tr = $trustees[$tmppath];
1446    
1447          if (! isset($trustees)) Error("Trustees not found","Can't find in-memory trustee structure <tt>\$trustees</tt>. Probably bug in code. Contact <tt>dpavlin@rot13.org</tt>",1);                  $one_level = (!count($path_arr));
1448    $debug.=" O($one_level) ";
1449  global $debug;  
1450  $debug .= "<br>check_trustee $path ... ";                  if (isset($tr)) {
1451                            // first apply trustee for all
1452          $path_arr=explode("/",$path);                          if (isset($tr['*']) && $user!="anonymous") {
1453          $tmppath = "/";                                  $perm = unroll_perm($user,$tr['*'],$perm, $one_level);
1454          while (count($path_arr)) {                                  unset($tr['*']);
1455                  $tmppath.=array_shift($path_arr);                          }
1456  $debug.= ">> $tmppath ";                          // then apply not and group policies
1457                            foreach ($tr as $g=>$t) {
1458                  if (! isset($trustees[$tmppath])) continue;                                  if ($t & trmask_not && $g != $user) {
1459                  $tr = $trustees[$tmppath];                                          $t = $t & ~trmask_not;
1460                                            $perm = unroll_perm($user,$t,$perm, $one_level);
1461                  $one_level = (!count($path_arr));                                          unset($tr[$g]);
1462  $debug.=" O($one_level) ";  
1463                                    } elseif ($t & trmask_group && in_group($user,$g)) {
1464                  if (isset($tr)) {                                          // resolv user
1465                          // first apply trustee for all                                          $t = $t & ~trmask_group;
1466                          if (isset($tr['*']) && $user!="anonymous") {                                          $perm = unroll_perm($user,$t,$perm, $one_level);
1467                                  $perm = unroll_perm($user,$tr['*'],$perm, $one_level);                                          unset($tr[$g]);
1468                                  unset($tr['*']);                                  }
1469                          }                          }
1470                          // then apply not and group policies                          // then apply user policy
1471                          foreach ($tr as $g=>$t) {                          if (isset($tr[$user])) {
1472                                  if ($t & trmask_not && $g != $user) {                                  $perm = unroll_perm($user,$tr[$user],$perm,$one_level);
1473                                          $t = $t & ~trmask_not;                                  unset($tr[$user]);
1474                                          $perm = unroll_perm($user,$t,$perm, $one_level);                          }
1475                                          unset($tr[$g]);                  }
1476    $debug.="d(".display_trustee($perm['deny']).") a(".display_trustee($perm['allow']).") ";
1477                                  } elseif ($t & trmask_group && in_group($user,$g)) {  
1478                                          // resolv user          }
1479                                          $t = $t & ~trmask_group;  $debug.="<br>check_trustee: user: $user path: $path==$tmppath perm: ";
1480                                          $perm = unroll_perm($user,$t,$perm, $one_level);  $debug.="d: ".$perm['deny']." (".display_trustee($perm['deny']).") a: ".$perm['allow']." (".display_trustee($perm['allow']).")<Br>\n";
1481                                          unset($tr[$g]);          return $perm;
1482                                  }  }
1483                          }  
1484                          // then apply user policy  // handy functions
1485                          if (isset($tr[$user])) {  
1486                                  $perm = unroll_perm($user,$tr[$user],$perm,$one_level);  function check_perm($path,$trperm) {
1487                                  unset($tr[$user]);          global $gblLogin,$HAVE_TRUSTEE;
1488                          }  
1489                  }          $path = str_replace("//","/",$path);
1490  $debug.="d(".display_trustee($perm['deny']).") a(".display_trustee($perm['allow']).") ";  
1491            global $debug;
1492          }  $debug.="<br>check_perm: on <tt>$path</tt> for perm ".display_trustee($trperm)."<br>\n";
1493  $debug.="<br>check_trustee: user: $user path: $path==$tmppath perm: ";  
1494  $debug.="d: ".$perm['deny']." (".display_trustee($perm['deny']).") a: ".$perm['allow']." (".display_trustee($perm['allow']).")<Br>\n";          $return = ! $HAVE_TRUSTEE;
1495          return $perm;          if ($HAVE_TRUSTEE) {
1496  }                  $perm = check_trustee($gblLogin,$path);
1497    $debug.=" d: ".$perm['deny']." (".display_trustee($perm['deny']).") a: ".$perm['allow']." (".display_trustee($perm['allow']).") perm to have: $trperm (".display_trustee($trperm).")";
1498  // handy functions                  if ($perm['deny'] & $trperm) $return=0;
1499                    elseif (($perm['allow'] & $trperm) == $trperm) $return=1;
1500  function check_perm($path,$trperm) {          }
1501          global $gblLogin,$HAVE_TRUSTEE;  $debug.=" return: $return<br>\n";
1502            return($return);
1503          $path = str_replace("//","/",$path);  }
1504    
1505          global $debug;  //////////////////////////////////////////////////////////////////
1506  $debug.="<br>check_perm: on <tt>$path</tt> for perm ".display_trustee($trperm)."<br>\n";  
1507    function readMime() {
1508          $return = ! $HAVE_TRUSTEE;          global $mime_type, $gblMimeTypes;
1509          if ($HAVE_TRUSTEE) {  
1510                  $perm = check_trustee($gblLogin,$path);          if (! isset($gblMimeTypes)) {
1511  $debug.=" d: ".$perm['deny']." (".display_trustee($perm['deny']).") a: ".$perm['allow']." (".display_trustee($perm['allow']).") perm to have: $trperm (".display_trustee($trperm).")";                  $gblMimeTypes = "/etc/mime.types";
1512                  if ($perm['deny'] & $trperm) $return=0;          }
1513                  elseif (($perm['allow'] & $trperm) == $trperm) $return=1;  
1514          }          $mime = @fopen($gblMimeTypes,"r");
1515  $debug.=" return: $return<br>\n";  
1516          return($return);          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            while($line = fgets($mime,80)) {
1519  //////////////////////////////////////////////////////////////////                  if (substr($line,0,1) == "#") continue; // skip comment
1520                    $arr = preg_split("/[\s\t]+/",$line);
1521  function readMime() {                  $type = array_shift($arr);
1522          global $mime_type;                  while ($ext = array_shift($arr)) {
1523                            $mime_type[$ext] = $type;
1524          if (! isset($gblMimeTypes)) {                  }
1525                  $gblMimeTypes = "/etc/mime.types";          }
1526          }  
1527            fclose($mime);
1528          $mime = @fopen($gblMimeTypes,"r");  }
1529    
1530          if (! $mime) Error("Can't read MIME types","<tt>$gblMimeTypes</tt> file not found. You can setup other <tt>mime.types</tt> file using <tt>\$gblMimeTypes</tt> in <tt>$realm_config</tt>");  //////////////////////////////////////////////////////////////////
1531    
1532          while($line = fgets($mime,80)) {  // check for invalid characters in filename and dirname (.. and /)
1533                  if (substr($line,0,1) == "#") continue; // skip comment  
1534                  $arr = preg_split("/[\s\t]+/",$line);  function check_dirname($file) {
1535                  $type = array_shift($arr);          if (strstr($file,"..")) Error("Security violation","No parent dir <tt>..</tt> allowed in directory name <tt>$file</tt>",1);
1536                  while ($ext = array_shift($arr)) {  }
1537                          $mime_type[$ext] = $type;  
1538                  }  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          fclose($mime);          $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    }
1544  //////////////////////////////////////////////////////////////////  
1545    // bla/blo/../foo will return bla/foo
1546  // check for invalid characters in filename and dirname (.. and /)  function remove_parent($path) {
1547            while (preg_match(",/[^/]+/\.\./,",$path)) {
1548  function check_dirname($file) {                  $path = preg_replace(",/[^/]+/\.\./,","",$path);
1549          if (strstr($file,"..")) Error("Security violation","No parent dir <tt>..</tt> allowed in directory name <tt>$file</tt>",1);          }
1550  }          if (substr($path,0,1) != "/") $path = "/".$path;
1551            return $path;
1552  function check_filename($file) {  }
1553          if (strstr($file,"..")) Error("Security violation","No parent dir <tt>..</tt> allowed in file name <tt>$file</tt>",1);  
1554          // remove deleted directory (for undelete to work)  //////////////////////////////////////////////////////////////////
1555          $file = str_replace(".del/","",$file);  
1556          if (strstr($file,"/")) Error("Security violation","No slashes <tt>/</tt> allowed in file name <tt>$file</tt>",1);  // functions to move HTTP server variables to global namespace
1557  }  // [replacement for register_globals in php.ini]
1558    
1559  // bla/blo/../foo will return bla/foo  function HTTP_GET_VAR($var) {
1560  function remove_parent($path) {          global $HTTP_GET_VARS, ${$var};
1561          while (preg_match(",/[^/]+/\.\./,",$path)) {          if (isset($HTTP_GET_VARS[$var])) {
1562                  $path = preg_replace(",/[^/]+/\.\./,","",$path);                  $$var = stripSlashes($HTTP_GET_VARS[$var]);
1563          }                  return $$var;
1564          if (substr($path,0,1) != "/") $path = "/".$path;          }
1565          return $path;  }
1566  }  
1567    function HTTP_POST_VAR($var) {
1568  //////////////////////////////////////////////////////////////////          global $HTTP_POST_VARS, ${$var};
1569            if (isset($HTTP_POST_VARS[$var])) {
1570  // functions to move HTTP server variables to global namespace                  $$var = $HTTP_POST_VARS[$var];
1571  // [replacement for register_globals in php.ini]                  return $$var;
1572            }
1573  function HTTP_GET_VAR($var) {  }
1574          global $HTTP_GET_VARS, ${$var};  
1575          if (isset($HTTP_GET_VARS[$var])) {  function HTTP_SERVER_VAR($var) {
1576                  $$var = stripSlashes($HTTP_GET_VARS[$var]);          global $HTTP_SERVER_VARS, ${$var};
1577                  return $$var;          if (isset($HTTP_SERVER_VARS[$var])) {
1578          }                  $$var = $HTTP_SERVER_VARS[$var];
1579  }                  return $$var;
1580            }
1581  function HTTP_POST_VAR($var) {  }
1582          global $HTTP_POST_VARS, ${$var};  
1583          if (isset($HTTP_POST_VARS[$var])) {  //////////////////////////////////////////////////////////////////
1584                  $$var = $HTTP_POST_VARS[$var];  
1585                  return $$var;  function Warn($text) {
1586          }  }
1587  }  
1588    //////////////////////////////////////////////////////////////////
1589  function HTTP_SERVER_VAR($var) {  
1590          global $HTTP_SERVER_VARS, ${$var};  function isBlank($file,$what = "filename") {
1591          if (isset($HTTP_SERVER_VARS[$var])) {          if (trim($file) == "") return "<i>whitespace $what</i>";
1592                  $$var = $HTTP_SERVER_VARS[$var];          if ($file == "") return "<i>no $what</i>";
1593                  return $$var;          return $file;
1594          }  }
1595  }  
1596    //////////////////////////////////////////////////////////////////
1597  //////////////////////////////////////////////////////////////////  // MAIN PROGRAM
1598    
1599  function Warn($text) {          $gblFilePerms = 0640 ;         // default for new files
1600  }          $gblDirPerms  = 0750 ;          // default for new dirs
1601    
1602  //////////////////////////////////////////////////////////////////          if (isset($HTTP_GET_VARS["STYLE"]) && $HTTP_GET_VARS["STYLE"] == "get") {
1603  // MAIN PROGRAM                  if (! headers_sent()) {
1604                            Header("Content-type: text/css");
1605          $gblFilePerms = 0640 ;         // default for new files                  }
1606          $gblDirPerms  = 0750 ;          // default for new dirs                  include("$html/docman.css");
1607                    exit;
1608          if (isset($HTTP_GET_VARS["STYLE"]) && $HTTP_GET_VARS["STYLE"] == "get") {          }
1609                  include("$html/docman.css");  
1610                  exit;          // set fsRealmDir
1611          }          if (! isset($fsRealmDir)) {
1612                    $fsRealmDir = "$gblIncDir/realm";
1613          // location of master docman configuration file          }
1614          $docman_conf = "/etc/docman.conf";  
1615          if (! file_exists($docman_conf)) {          // try to add dir to script name to realm var
1616                  $error = "Can't find master configuration file <tt>$docman_conf</tt>. See <tt>docman2/doc/upgrade.html#docman_conf</tt> for more informations";          if (is_dir("$fsRealmDir/$realm/".dirname($HTTP_SERVER_VARS["SCRIPT_NAME"]))) {
1617                                    $realm .= dirname($HTTP_SERVER_VARS["SCRIPT_NAME"]);
1618                  error_log("docman: $error");                  $realm_sep = "/";
1619                  Error("docman not installed completly",$error);          } else {
1620          }                  $realm_sep = ".";
1621          include($docman_conf);          }
1622    
1623          if (! isset($fsRealmDir)) {          $realm_config = $fsRealmDir."/".$realm.$realm_sep."conf";
1624                  $fsRealmDir = "$gblIncDir/realm";  
1625          }          // read user-defined configuration
1626            if (file_exists($realm_config)) {
1627          // try to add dir to script name to realm var                  include($realm_config);
1628          if (is_dir("$fsRealmDir/$realm/".dirname($HTTP_SERVER_VARS["SCRIPT_NAME"]))) {          } else {
1629                  $realm .= dirname($HTTP_SERVER_VARS["SCRIPT_NAME"]);                  Error("Configuration error","Can't find configuration file at <tt>$realm_config</tt> !");
1630                  $realm_sep = "/";          }
1631          } else {  
1632                  $realm_sep = ".";          if (! isset($gblRepositoryDir)) Error("Configuration error","<tt>\$gblRepositoryDir</tt> is not setuped in realm configuration file <tt>$realm_config</tt>");
1633          }  
1634            // where do we get users from?
1635          $realm_config = $fsRealmDir."/".$realm.$realm_sep."conf";          if (file_exists("$gblIncDir/htusers/$gblUsers.php")) {
1636                    include("$gblIncDir/htusers/$gblUsers.php");
1637          // read user-defined configuration          } else {
1638          if (file_exists($realm_config)) {                  Error("Configuration error","Can't find user handling module at <tt>$gblIncDir/htusers/$gblUsers.php</tt> ! Please fix <tt>$realm_config</tt>");
1639                  include($realm_config);          }
1640          } else {  
1641                  Error("Configuration error","Can't find configuration file at <tt>$realm_config</tt> !");          // take additional login vars
1642          }          HTTP_GET_VAR("relogin");
1643            HTTP_GET_VAR("force_login");
1644          if (! isset($gblRepositoryDir)) Error("Configuration error","<tt>\$gblRepositoryDir</tt> is not setuped in realm configuration file <tt>$realm_config</tt>");  
1645            // if no password, or empty password logout
1646          // where do we get users from?          if (
1647          if (file_exists("$gblIncDir/htusers/$gblUsers.php")) {                  isset($gblLogin) && (
1648                  include("$gblIncDir/htusers/$gblUsers.php");                          !isset($relogin) || (
1649          } else {                                  isset($relogin) && $relogin != md5($gblLogin.$gblPasswd)
1650                  Error("Configuration error","Can't find user handling module at <tt>$gblIncDir/htusers/$gblUsers.php</tt> ! Please fix <tt>$realm_config</tt>");                          )
1651          }                  ) && (
1652                            $gblPasswd == "" || !isset($gblPasswd)
1653          // take additional login vars                  ) && !isset($force_login) && $gblLogin != "anonymous"
1654          HTTP_GET_VAR("relogin");             ) {
1655          HTTP_GET_VAR("force_login");                  StartHTML("Logout completed","Your login credentials has been erased") ;
1656                    EndHTML() ;
1657          // if no password, or empty password logout                  exit ;
1658          if (          }
1659                  isset($gblLogin) && (  
1660                          !isset($relogin) || (          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                                  isset($relogin) && $relogin != md5($gblLogin.$gblPasswd)  
1662                          )          // trustee (ACL) file configuration
1663                  ) && (          $trustee_conf="$fsRealmDir/$realm".$realm_sep."trustee";
1664                          $gblPasswd == "" || !isset($gblPasswd)          // compiled version of trustee file
1665                  ) && !isset($force_login) && $gblLogin != "anonymous"          $trustee_php="$gblRepositoryDir/.trustee.php";
1666             ) {          // get ACL informations
1667                  StartHTML("Logout completed","Your login credentials has been erased") ;          $HAVE_TRUSTEE = init_trustee();
1668                  EndHTML() ;  
1669                  exit ;          if (strtolower($gblLogin) == "anonymous" || !isset($gblLogin)) {
1670          }                  $perm = check_trustee("anonymous","/");
1671                    // browsing must be explicitly allowed for root directory
1672          if (!is_dir($gblRepositoryDir)) Error("Repository dir not found","Can't find repository directory <tt>$gblRepositoryDir</tt>. Please fix that in <tt>$realm_config</tt> variable <tt>\$gblRepositoryDir</tt>.",1);                  // of repository for anonymous user to work!
1673                    if ($perm['allow'] & trperm_b) {
1674          // trustee (ACL) file configuration                          $gblLogin = $gblPasswd = "anonymous";
1675          $trustee_conf="$fsRealmDir/$realm".$realm_sep."trustee";                          $secHash = md5($gblLogin.$gblPasswd);
1676          // compiled version of trustee file                          $gblUserName = "Anonymous user";
1677          $trustee_php="$gblRepositoryDir/.trustee.php";                  }
1678          // get ACL informations          }
1679          $HAVE_TRUSTEE = init_trustee();  
1680            // authentication failure
1681          if (strtolower($gblLogin) == "anonymous" || !isset($gblLogin)) {          if ( md5($gblLogin.$gblPasswd) != $secHash ||
1682                  $perm = check_trustee("anonymous","/");                  isset($relogin) && $secHash == $relogin) {
1683                  // browsing must be explicitly allowed for root directory                  header("WWW-authenticate: basic realm=\"$realm\"") ;
1684                  // of repository for anonymous user to work!                  header("HTTP/1.0 401 Unauthorized") ;
1685                  if ($perm['allow'] & trperm_b) {                  Error("401 Unauthorized","No trespassing !",0,1);
1686                          $gblLogin = $gblPasswd = "anonymous";          }
1687                          $secHash = md5($gblLogin.$gblPasswd);  
1688                          $gblUserName = "Anonymous user";  
1689                  }          // read mime.types
1690          }          readMime();
1691    
1692          // authentication failure          if (! isset($gblPermNote)) {
1693          if ( md5($gblLogin.$gblPasswd) != $secHash ||                  $gblPermNote = trperm_r;
1694                  isset($relogin) && $secHash == $relogin) {          }
1695                  header("WWW-authenticate: basic realm=\"$realm\"") ;  
1696                  header("HTTP/1.0 401 Unauthorized") ;          HTTP_POST_VAR("FN");
1697                  Error("401 Unauthorized","No trespassing !",0,1);  
1698          }          if ($HTTP_SERVER_VARS["REQUEST_METHOD"] == "POST") {
1699                    // take variables from server
1700                    if (HTTP_POST_VAR("FN"))
1701          // read mime.types                          check_filename($FN);
1702          readMime();                  if (HTTP_POST_VAR("DIR")) {
1703                            check_dirname($DIR);
1704  HTTP_POST_VAR("FN");                          $relDir = $DIR;
1705                    } else {
1706          if ($HTTP_SERVER_VARS["REQUEST_METHOD"] == "POST") {                          trigger_error("Can't get DIR",E_USER_WARNING);
1707                  // take variables from server                          $relDir = "/";
1708                  if (HTTP_POST_VAR("FN"))                  }
1709                          check_filename($FN);                  if (HTTP_POST_VAR("RELPATH")) check_dirname($RELPATH);
1710                  if (HTTP_POST_VAR("DIR")) {                  HTTP_POST_VAR("T");
1711                          check_dirname($DIR);                  HTTP_POST_VAR("CONFIRM");
1712                          $relDir = $DIR;          } else {
1713                  } else {                  // get
1714                          trigger_error("Can't get DIR",E_USER_WARNING);                  HTTP_GET_VAR("A");
1715                          $relDir = "/";                  if (HTTP_GET_VAR("D")) {
1716                  }                          check_dirname($D);
1717                  if (HTTP_POST_VAR("RELPATH")) check_dirname($RELPATH);                          $D=urldecode($D);
1718                  HTTP_POST_VAR("T");                          $relDir = $D;
1719                  HTTP_POST_VAR("CONFIRM");                  } else {
1720          } else {                          //trigger_error("Can't get D",E_USER_WARNING);
1721                  // get                          $relDir = "/";
1722                  HTTP_GET_VAR("A");                  }
1723                  if (HTTP_GET_VAR("D")) {                  if (HTTP_GET_VAR("F")) check_filename($F);
1724                          check_dirname($D);          }
1725                          $D=urldecode($D);  
1726                          $relDir = $D;          $relScriptDir = dirname($HTTP_SERVER_VARS["SCRIPT_NAME"]) ;    
1727                  } else {          // i.e. /docman
1728                          //trigger_error("Can't get D",E_USER_WARNING);  
1729                          $relDir = "/";          // start on server root
1730                  }          $gblFsRoot = $gblRepositoryDir;
1731                  if (HTTP_GET_VAR("F")) check_filename($F);          // i.e. /home/httpd/repository
1732          }  
1733            $fsDir = $gblFsRoot . $relDir ; // current directory
1734          $relScriptDir = dirname($HTTP_SERVER_VARS["SCRIPT_NAME"]) ;              if ( !is_dir($fsDir) ) Error("Dir not found","Can't find <tt>$relDir</tt> which points to <tt>$fsDir</tt>",1) ;
1735          // i.e. /docman  
1736            if ($relDir == "") $relDir="/";
1737          // start on server root  
1738          $gblFsRoot = $gblRepositoryDir;          if (isset($HTTP_SERVER_VARS["HTTPS"]) && $HTTP_SERVER_VARS["HTTPS"] == "on") {
1739          // i.e. /home/httpd/repository                  $webRoot  = "https://";
1740            } else {
1741          $fsDir = $gblFsRoot . $relDir ; // current directory                  $webRoot  = "http://";
1742          if ( !is_dir($fsDir) ) Error("Dir not found","Can't find <tt>$relDir</tt> which points to <tt>$fsDir</tt>",1) ;          }
1743            $webRoot .= $HTTP_SERVER_VARS["HTTP_HOST"] . $relScriptDir;
1744          if ($relDir == "") $relDir="/";  
1745            if (HTTP_POST_VAR("POSTACTION")) switch ($POSTACTION) {
1746          if (isset($HTTP_SERVER_VARS["HTTPS"]) && $HTTP_SERVER_VARS["HTTPS"] == "on") {          case "UPLOAD" :
1747                  $webRoot  = "https://";                  $FN_name=stripSlashes($HTTP_POST_FILES["FN"]["tmp_name"]);
1748          } else {                  $FN=stripSlashes($HTTP_POST_FILES["FN"]["name"]);
1749                  $webRoot  = "http://";                  if (!is_writeable($fsDir)) Error("Write denied",$relDir) ;
1750          }  
1751          $webRoot .= $HTTP_SERVER_VARS["HTTP_HOST"] . $relScriptDir;                  $source = $FN_name ;
1752                    if (! file_exists($source)) {
1753          if (HTTP_POST_VAR("POSTACTION")) switch ($POSTACTION) {                          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          case "UPLOAD" :                  }
1755                  $FN_name=stripSlashes($HTTP_POST_FILES["FN"]["tmp_name"]);  
1756                  $FN=stripSlashes($HTTP_POST_FILES["FN"]["name"]);                  if (HTTP_POST_VAR("FILENAME")) check_filename($FILENAME);
1757                  if (!is_writeable($fsDir)) Error("Write denied",$relDir) ;  
1758                    if (! isset($FILENAME)) {       // from update file
1759                  $source = $FN_name ;                          $target = "$fsDir/".basename($FN);
1760                  if (! file_exists($source)) {                  } else {
1761                          Error("You must select file with browse to upload it!");                          $target = "$fsDir/$FILENAME";
1762                  }                  }
1763    
1764                  if (HTTP_POST_VAR("FILENAME")) check_filename($FILENAME);                  if (! check_perm("$relDir/".basename($target), trperm_w))
1765                            Error("Access denied","User <tt>$gblLogin</tt> tried to upload <tt>$relDir/".basename($target)."</tt> without valid trustee.",1);
1766                  if (! isset($FILENAME)) {       // from update file  
1767                          $target = "$fsDir/".basename($FN);                  // backup old files first
1768                  } else {                  $dir=dirname($target);
1769                          $target = "$fsDir/$FILENAME";                  if (! file_exists($dir."/.bak")) {
1770                  }                          mkdir($dir."/.bak",0700);
1771                    }
1772                  if (! check_perm("$relDir/".basename($target), trperm_w))                  if (! file_exists($dir."/.bak/$gblNumBackups")) {
1773                          Error("Access denied","User <tt>$gblLogin</tt> tried to upload <tt>$relDir/".basename($target)."</tt> without valid trustee.",1);                          mkdir($dir."/.bak/$gblNumBackups",0700);
1774                    }
1775                  // backup old files first                  $file=basename($target);
1776                  $dir=dirname($target);                  for($i=$gblNumBackups-1;$i>0;$i--) {
1777                  if (! file_exists($dir."/.bak")) {                          MoveTo("$dir/.bak/$i/$file","$dir/.bak/".($i+1)."/");
1778                          mkdir($dir."/.bak",0700);                  }
1779                  }                  MoveTo($target,$dir."/.bak/1/");
1780                  if (! file_exists($dir."/.bak/$gblNumBackups")) {  
1781                          mkdir($dir."/.bak/$gblNumBackups",0700);                  copy($source,$target) ;
1782                  }                  chmod($target,$gblFilePerms) ;
1783                  $file=basename($target);                  clearstatcache() ;
1784                  for($i=$gblNumBackups-1;$i>0;$i--) {                  if (isset($FILENAME)) {
1785                          MoveTo("$dir/.bak/$i/$file","$dir/.bak/".($i+1)."/");                          LogIt($target,"check-in",trperm_r | trperm_w);
1786                  }                          Unlock($target);
1787                  MoveTo($target,$dir."/.bak/1/");                  } else {
1788                            LogIt($target,"uploaded",trperm_r | trperm_w);
1789                  copy($source,$target) ;                  }
1790                  chmod($target,$gblFilePerms) ;                  break ;
1791                  clearstatcache() ;  
1792                  if (isset($FILENAME)) {          case "SAVE" :
1793                          LogIt($target,"check-in",trperm_r | trperm_w);                  $path = $gblFsRoot . $RELPATH ;
1794                          Unlock($target);                  $path=stripSlashes($path);
1795                  } else {  
1796                          LogIt($target,"uploaded",trperm_r | trperm_w);                  if (! check_perm("$RELPATH", trperm_w))
1797                  }                          Error("Access denied","User <tt>$gblLogin</tt> tried to save <tt>$RELPATH</tt> without valid trustee.",1);
1798                  break ;  
1799                    $writable = is_writeable($path) ;
1800          case "SAVE" :                  $legaldir = is_writeable(dirname($path)) ;
1801                  $path = $gblFsRoot . $RELPATH ;                  $exists   = (file_exists($path)) ? 1 : 0 ;
1802                  $path=stripSlashes($path);                  // FIX: more verbose error message
1803                    if (!($writable || (!$exists && $legaldir)))
1804                  if (! check_perm("$RELPATH", trperm_w))                          Error("Write denied",$RELPATH) ;
1805                          Error("Access denied","User <tt>$gblLogin</tt> tried to save <tt>$RELPATH</tt> without valid trustee.",1);                  $fh = fopen($path, "w") ;
1806                    HTTP_POST_VAR("FILEDATA");
1807                  $writable = is_writeable($path) ;                  fwrite($fh,stripSlashes($FILEDATA)) ;
1808                  $legaldir = is_writeable(dirname($path)) ;                  fclose($fh) ;
1809                  $exists   = (file_exists($path)) ? 1 : 0 ;                  clearstatcache() ;
1810                  // FIX: more verbose error message                  LogIt($path,"saved changes",trperm_r);
1811                  if (!($writable || (!$exists && $legaldir)))                  break ;
1812                          Error("Write denied",$RELPATH) ;  
1813                  $fh = fopen($path, "w") ;          case "CREATE" :
1814                  HTTP_POST_VAR("FILEDATA");                  // we know $fsDir exists
1815                  fwrite($fh,$FILEDATA) ;                  if (! check_perm($relDir, trperm_w))
1816                  fclose($fh) ;                          Error("Write access denied","You don't have permission to write in <tt>$relDir</tt>");
1817                  clearstatcache() ;                  if ($T == "D") $type = "directory";
1818                  LogIt($path,"saved changes",trperm_r);                  else $type ="file";
1819                  break ;                  if ($FN == "") Error("Can't create $type","You must enter name of $type to create it.");
1820                    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          case "CREATE" :                  $path = "$fsDir/$FN";           // file or dir to create
1822                  // we know $fsDir exists                  $relPath = "$relDir/$FN";
1823                  if (! check_perm($relDir, trperm_w))  
1824                          Error("Write access denied","You don't have permission to write in <tt>$relDir</tt>");                  if (file_exists($path))
1825                  if ($T == "D") $type = "directory";                          Error("Can't create $type","Object <tt>$relPath</tt> allready exists");
1826                  else $type ="file";  
1827                  if ($FN == "") Error("Can't create $type","You must enter name of $type to create it.");                  switch ( $T ) {
1828                  if (!is_writeable($fsDir)) Error("Write denied","User <tt>$gblLogin</tt> has trustee to write in <tt>$relDir</tt> but permissions on <tt>$fsDir</tt> are wrong!", 1) ;                  case "D" :  // create a directory
1829                  $path = "$fsDir/$FN";           // file or dir to create                          if ( ! @mkdir($path,$gblDirPerms) )
1830                  $relPath = "$relDir/$FN";                                  Error("Mkdir failed",$relPath) ; // eg. if it exists
1831                            else
1832                  if (file_exists($path))                                  LogIt($path."/","dir created",trperm_w);
1833                          Error("Can't create $type","Object <tt>$relPath</tt> allready exists");                          clearstatcache() ;
1834                            break ;
1835                  switch ( $T ) {                  case "F" :  // create a new file
1836                  case "D" :  // create a directory  // this functionality is doubled in DetailView().
1837                          if ( ! @mkdir($path,$gblDirPerms) )  // better keep it here altogether
1838                                  Error("Mkdir failed",$relPath) ; // eg. if it exists  // chmod perms to $gblFilePerms
1839                          else                          if ( file_exists($path) && !is_writeable($path) )
1840                                  LogIt($path."/","dir created",trperm_w);                                  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                          clearstatcache() ;                          $fh = fopen($path, "w+") ;
1842                          break ;                          if ($fh) {
1843                  case "F" :  // create a new file                                  fputs($fh,"\n");
1844  // this functionality is doubled in DetailView().                                  fclose($fh) ;
1845  // better keep it here altogether                                  LogIt($path,"file created",trperm_r | trperm_w);
1846  // chmod perms to $gblFilePerms                          } else {
1847                          if ( file_exists($path) && !is_writeable($path) )                                  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                                  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) ;                          }
1849                          $fh = fopen($path, "w+") ;                          $tstr = $HTTP_SERVER_VARS["PHP_SELF"]."?A=E&D=".urlencode($relDir)."&F=".urlencode($FN) ;
1850                          if ($fh) {                          header("Location: " . $tstr) ;
1851                                  fputs($fh,"\n");                          exit ;
1852                                  fclose($fh) ;                  }
1853                                  LogIt($path,"file created",trperm_r | trperm_w);                  break ;
1854                          } else {  
1855                                  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) ;          case "DELETE" :  
1856                          }                  if ( $CONFIRM != "on" ) break;
1857                          $tstr = $HTTP_SERVER_VARS["PHP_SELF"]."?A=E&D=".urlencode($relDir)."&F=".urlencode($FN) ;  
1858                          header("Location: " . $tstr) ;                  if ( isset($FN) && $FN != "") {
1859                          exit ;                          $path=$fsDir."/".$FN;
1860                  }                          $what = "file";
1861                  break ;                  } elseif (isset($DIR)) {
1862                            $path=$gblFsRoot."/".$DIR;
1863          case "DELETE" :                            $what = "directory";
1864                  if ( $CONFIRM != "on" ) break;                  } else  {
1865                            Error("Can't delete object","Can't find filename <tt>\$FN</tt> or dirname in <tt>\$DIR</tt>",1);
1866                  if ( isset($FN) && $FN != "") {                  }
1867                          $path=$fsDir."/".$FN;  
1868                          $what = "file";                  if (! check_perm("$relDir/$FN", trperm_w))
1869                  } elseif (isset($DIR)) {                          Error("Access denied","User <tt>$gblLogin</tt> tried to erase $what <tt>$relDir/$FN</tt> without valid trustee.",1);
1870                          $path=$gblFsRoot."/".$DIR;  
1871                          $what = "directory";                  $tstr  = "Attempt to delete non-existing object or insufficient privileges: " ;
1872                  } else  {  
1873                          Error("Can't delete object","Can't find filename <tt>\$FN</tt> or dirname in <tt>\$DIR</tt>",1);                  $dir=dirname($path);
1874                  }                  $file=basename($path);
1875    
1876                  if (! check_perm("$relDir/$FN", trperm_w))                  if (! file_exists("$dir/.del")) {
1877                          Error("Access denied","User <tt>$gblLogin</tt> tried to erase $what <tt>$relDir/$FN</tt> without valid trustee.",1);                          mkdir("$dir/.del",0700);
1878                    }
1879                  $tstr  = "Attempt to delete non-existing object or insufficient privileges: " ;  
1880                    if ( ! @rename($path,"$dir/.del/$file") ) {
1881                  $dir=dirname($path);                          LogIt($path,"$what delete failed");
1882                  $file=basename($path);                          Error("Can't delete $what",$tstr."<tt>".$relDir."/".$FN."</tt>") ;
1883                    } else {
1884                  if (! file_exists("$dir/.del")) {                          LogIt($path,"$what deleted",trperm_w);
1885                          mkdir("$dir/.del",0700);                          MoveTo("$dir/.log/$file","$dir/.del/.log/");
1886                  }                          MoveTo("$dir/.note/$file","$dir/.del/.note/");
1887                            MoveTo("$dir/.lock/$file","$dir/.del/.lock/");
1888                  if ( ! @rename($path,"$dir/.del/$file") ) {                  }
1889                          LogIt($path,"$what delete failed");                  break ;
1890                          Error("Can't delete $what",$tstr."<tt>".$relDir."/".$FN."</tt>") ;  
1891                  } else {          case "UNDELETE" :  
1892                          LogIt($path,"$what deleted",trperm_w);                  if ( $CONFIRM != "on" ) break ;
1893                          MoveTo("$dir/.log/$file","$dir/.del/.log/");  
1894                          MoveTo("$dir/.note/$file","$dir/.del/.note/");                  if (substr($FN,0,4) != ".del") break ;
1895                          MoveTo("$dir/.lock/$file","$dir/.del/.lock/");                  $file=substr($FN,4,strlen($FN)-4);
1896                  }  
1897                  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          case "UNDELETE" :    
1900                  if ( $CONFIRM != "on" ) break ;                  LogIt("$fsDir/.del/$file","undeleted",trperm_w);
1901                    MoveTo("$fsDir/.del/$file","$fsDir/");
1902                  if (substr($FN,0,4) != ".del") break ;                  MoveTo("$fsDir/.del/.log/$file","$fsDir/.log/");
1903                  $file=substr($FN,4,strlen($FN)-4);                  MoveTo("$fsDir/.del/.note/$file","$fsDir/.note/");
1904                    MoveTo("$fsDir/.del/.lock/$file","$fsDir/.lock/");
1905                  if (! check_perm("$relDir/$file", trperm_w))  
1906                          Error("Access denied","User <tt>$gblLogin</tt> tried to undelete <tt>$relDir/$file</tt> without valid trustee.",1);                  break ;
1907    
1908                  LogIt("$fsDir/.del/$file","undeleted",trperm_w);          case "RENAME" :  
1909                  MoveTo("$fsDir/.del/$file","$fsDir/");                  if ( $CONFIRM != "on" ) break ;
1910                  MoveTo("$fsDir/.del/.log/$file","$fsDir/.log/");  
1911                  MoveTo("$fsDir/.del/.note/$file","$fsDir/.note/");                  if (HTTP_POST_VAR("NEWNAME")) {
1912                  MoveTo("$fsDir/.del/.lock/$file","$fsDir/.lock/");                          $dest = remove_parent($relDir.$NEWNAME);
1913                            if (! check_perm($relDir.$FN, trperm_w) ||
1914                  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          case "RENAME" :                    } else {
1917                  if ( $CONFIRM != "on" ) break ;                          Error("Rename error","Can't find new name in var <tt>\$NEWNAME</tt>",1);
1918                    }
1919                  if (HTTP_POST_VAR("NEWNAME")) {                  LogIt("$fsDir/$FN","renamed $FN to $NEWNAME",trperm_r);
1920                          $dest = remove_parent($relDir.$NEWNAME);                  safe_rename($fsDir,$FN,$NEWNAME);
1921                          if (! check_perm($relDir.$FN, trperm_w) ||                  break ;
1922                              ! check_perm($dest, trperm_w) )  
1923                                  Error("Access denied","User <tt>$gblLogin</tt> tried to rename <tt>$relDir$FN</tt> to <tt>$dest</tt> without valid trustee.",1);          case "NOTE" :
1924                  } else {                  if (! HTTP_POST_VAR("NOTE"))
1925                          Error("Rename error","Can't find new name in var <tt>\$NEWNAME</tt>",1);                          Error("Can't add note to object","Can't find var <tt>\$NOTE</tt>",1);
1926                  }                  if (! check_perm("$relDir/$FN", trperm_w))
1927                  LogIt("$fsDir/$FN","renamed $FN to $NEWNAME",trperm_r);                          Error("Access denied","User <tt>$gblLogin</tt> tried to add note to <tt>$relDir/$FN</tt> without valid trustee.",1);
1928                  safe_rename($fsDir,$FN,$NEWNAME);  
1929                  break ;                  WriteNote("$fsDir/$FN",$NOTE);
1930                    break ;
1931          case "NOTE" :  
1932                  if (! HTTP_POST_VAR("NOTE"))          case "UNLOCK" :  
1933                          Error("Can't add note to object","Can't find var <tt>\$NOTE</tt>",1);                  if ( $CONFIRM != "on" ) break ;
1934                  if (! check_perm("$relDir/$FN", trperm_w))                  if (! check_perm("$relDir/$FN", trperm_w))
1935                          Error("Access denied","User <tt>$gblLogin</tt> tried to add note to <tt>$relDir/$FN</tt> without valid trustee.",1);                          Error("Access denied","User <tt>$gblLogin</tt> tried to unlock <tt>$relDir/$FN</tt> without valid trustee.",1);
1936                    Unlock("$fsDir/$FN");
1937                  WriteNote("$fsDir/$FN",$NOTE);                  break ;
1938                  break ;  
1939            default :
1940          case "UNLOCK" :                    // user hit "CANCEL" or undefined action
1941                  if ( $CONFIRM != "on" ) break ;          }
1942                  Unlock("$fsDir/$FN");  
1943                  break ;          // common to all POSTs : redirect to directory view ($relDir)
1944            if (isset($POSTACTION)) {
1945          default :                  $tstr = $HTTP_SERVER_VARS["PHP_SELF"]."?D=".urlencode($relDir);
1946                  // user hit "CANCEL" or undefined action                  header("Location: ".$tstr) ;  
1947          }                  exit ;
1948            }
1949          // common to all POSTs : redirect to directory view ($relDir)  
1950          if (isset($POSTACTION)) {          // check for mode.. navigate, code display, upload, or detail?
1951                  $tstr = $HTTP_SERVER_VARS["PHP_SELF"]."?D=".urlencode($relDir);          // $A=U : upload to path given in $D
1952                  header("Location: ".$tstr) ;            // $A=E : display detail of file $D/$F and edit
1953                  exit ;          // $A=C : display code in file $D/$F
1954          }          // $A=Co : checkout file $D/$F
1955            // $A=Ci : checkin file $D/$F
1956          // check for mode.. navigate, code display, upload, or detail?          // $A=V : view file (do nothing except log)
1957          // $A=U : upload to path given in $D          // $A=I : include file .$F.php from [$gblIncDir|realm]/include_php
1958          // $A=E : display detail of file $D/$F and edit          // default : display directory $D
1959          // $A=C : display code in file $D/$F  
1960          // $A=Co : checkout file $D/$F          if (isset($A)) switch ($A) {
1961          // $A=Ci : checkin file $D/$F          case "U" :
1962          // $A=V : view file (do nothing except log)                  // upload to $relDir
1963          // $A=I : include file .$F.php from [$gblIncDir|realm]/include_php                  if (! check_perm($relDir, trperm_w))
1964          // default : display directory $D                          Error("Write access denied","You don't have permission to write in <tt>$relDir</tt>");
1965                    if (!is_writeable($gblFsRoot . $relDir))
1966          if (isset($A)) switch ($A) {                          Error("Write access denied","User <tt>$gblLogin</tt> has permission on <tt>$relDir</tt>, but directory is not writable",1);
1967          case "U" :                  $text  = "Use this page to upload a single " ;
1968                  // upload to $relDir                  $text .= "file to <B>$realm</B>." ;
1969                  if (! check_perm($relDir, trperm_w))                  StartHTML("(Upload Page)", $text) ;
1970                          Error("Write access denied","You don't have permission to write in <tt>$relDir</tt>");                  UploadPage($gblFsRoot, $relDir) ;
1971                  if (!is_writeable($gblFsRoot . $relDir))                  EndHTML() ;
1972                          Error("Write access denied","User <tt>$gblLogin</tt> has permission on <tt>$relDir</tt>, but directory is not writable",1);                  exit ;
1973                  $text  = "Use this page to upload a single " ;          case "E" :
1974                  $text .= "file to <B>$realm</B>." ;                  // detail of $relDir/$F
1975                  StartHTML("(Upload Page)", $text) ;                  if (is_file("$gblFsRoot/$relDir/$F") || is_dir("$gblFsRoot/$relDir/$F")) DetailPage($gblFsRoot, $relDir, $F) ;
1976                  UploadPage($gblFsRoot, $relDir) ;                  exit ;
1977                  EndHTML() ;          case "C" :
1978                  exit ;                  $F=stripSlashes($F);
1979          case "E" :                  // listing of $relDir/$F
1980                  // detail of $relDir/$F                  DisplayCode($gblFsRoot, $relDir, $F) ;
1981                  if (is_file("$gblFsRoot/$relDir/$F") || is_dir("$gblFsRoot/$relDir/$F")) DetailPage($gblFsRoot, $relDir, $F) ;                  exit ;
1982                  exit ;          case "Co" :
1983          case "C" :                  // checkout
1984                  $F=stripSlashes($F);                  Lock("$gblFsRoot/$relDir/$F");
1985                  // listing of $relDir/$F                  Download("$gblFsRoot/$relDir/$F",1);
1986                  DisplayCode($gblFsRoot, $relDir, $F) ;                  exit;
1987                  exit ;          case "Ci" :
1988          case "Co" :                  $F=stripSlashes($F);
1989                  // checkout                  // upload && update to $relDir
1990                  Lock("$gblFsRoot/$relDir/$F");                  if (!is_writeable($gblFsRoot . $relDir))
1991                  Download("$gblFsRoot/$relDir/$F",1);                          Error("Write access denied",$relDir) ;
1992                  exit;                  $text  = "Use this page to update a single " ;
1993          case "Ci" :                  $text .= "file to <B>$realm</B>." ;
1994                  $F=stripSlashes($F);                  StartHTML("(Update file Page)", $text) ;
1995                  // upload && update to $relDir                  UploadPage($gblFsRoot, $relDir, $F) ;
1996                  if (!is_writeable($gblFsRoot . $relDir))                  EndHTML() ;
1997                          Error("Write access denied",$relDir) ;                  exit ;
1998                  $text  = "Use this page to update a single " ;          case "V" :
1999                  $text .= "file to <B>$realm</B>." ;                  // view
2000                  StartHTML("(Update file Page)", $text) ;                  LogIt("$gblFsRoot/$relDir/$F","viewed");
2001                  UploadPage($gblFsRoot, $relDir, $F) ;                  Download("$gblFsRoot/$relDir/$F",$gblForceDownload);
2002                  EndHTML() ;                  exit;
2003                  exit ;          case "Ch" :
2004          case "V" :                  StartHTML("(File changes)","All changes chronologicaly...");
2005                  // view                  DisplayChangeLog(0);    // all
2006                  LogIt("$gblFsRoot/$relDir/$F","viewed");                  EndHTML() ;
2007                  Download("$gblFsRoot/$relDir/$F",$gblForceDownload);                  exit;
2008                  exit;          case "Ch1" :
2009          case "Ch" :                  StartHTML("(File changes)","Changes to files in last day...");
2010                  StartHTML("(File changes)","All changes chronologicaly...");                  DisplayChangeLog(1);
2011                  DisplayChangeLog(0);    // all                  EndHTML() ;
2012                  EndHTML() ;                  exit;
2013                  exit;          case "I" :
2014          case "Ch1" :                  if (! isset($F) || $F == "")
2015                  StartHTML("(File changes)","Changes to files in last day...");                          Error("Can't find file to include","Your request didn't specify file to include which should be in variable <tt>F</tt> like <tt>$HTTP_SERVER_VARS[REQUEST_URI]<b>&F=include_php_file</b></tt>",1);
2016                  DisplayChangeLog(1);                  $inc_file="$fsRealmDir/$realm".$realm_sep.$F.".php";
2017                  EndHTML() ;                  if (! file_exists($inc_file)) {
2018                  exit;                          Error("Can't find file to include","Can't find include file <tt>$F.php</tt> in <tt>$fsRealmDir/$realm/</tt>. Meybe you should copy <tt>$gblIncDir/include_php/$F.php</tt> to <tt>$inc_file<tt> ?",1);
2019          case "I" :                  }
2020                  if (! isset($F) || $F == "")                  if (!is_readable($inc_file))
2021                          Error("Can't find file to include","Your request didn't specify file to include which should be in variable <tt>F</tt> like <tt>$HTTP_SERVER_VARS[REQUEST_URI]<b>&F=include_php_file</b></tt>",1);                          Error("Read access to include file denied","Can't read PHP include file <tt>$inc_file</tt>. Fix permissions on it.",1);
2022                  $inc_file="$fsRealmDir/$realm".$realm_sep.$F.".php";                  $text  = "Your include file should define \$text variable which holds this text and \$title variable which is page title";
2023                  if (! file_exists($inc_file)) {                  $title = "You should define \$title variable with page title";
2024                          Error("Can't find file to include","Can't find include file <tt>$F.php</tt> in <tt>$fsRealmDir/$realm/</tt>. Meybe you should copy <tt>$gblIncDir/include_php/$F.php</tt> to <tt>$inc_file<tt> ?",1);                  include($inc_file);
2025                  }                  StartHTML($title, $text) ;
2026                  if (!is_readable($inc_file))                  print "<p>".GifIcon(up)." Back to <a href=$HTTP_SERVER_VARS[PHP_SELF]>front page</a>.</p>";
2027                          Error("Read access to include file denied","Can't read PHP include file <tt>$inc_file</tt>. Fix permissions on it.",1);                  EndHTML() ;
2028                  $text  = "Your include file should define \$text variable which holds this text and \$title variable which is page title";                  exit ;
2029                  $title = "You should define \$title variable with page title";          }
2030                  include($inc_file);  
2031                  StartHTML($title, $text) ;          // default: display directory $relDir
2032                  print "<p>".GifIcon(up)." Back to <a href=$HTTP_SERVER_VARS[PHP_SELF]>front page</a>.</p>";          Navigate($gblFsRoot,$relDir) ;  
2033                  EndHTML() ;          exit ;
2034                  exit ;  
2035          }          Error("Whooah!","By cartesian logic, this never happens",1) ;
2036    ?>
2037          // default: display directory $relDir  
         Navigate($gblFsRoot,$relDir) ;    
         exit ;  
   
         Error("Whooah!","By cartesian logic, this never happens",1) ;  
 ?>  

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

  ViewVC Help
Powered by ViewVC 1.1.26