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

Legend:
Removed from v.1.16  
changed lines
  Added in v.1.40

  ViewVC Help
Powered by ViewVC 1.1.26