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

Legend:
Removed from v.1.1.1.1  
changed lines
  Added in v.1.37

  ViewVC Help
Powered by ViewVC 1.1.26