/[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.3 by dpavlin, Sat Jul 27 14:45:30 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>",1);          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), "D"=>$D));                          $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  // Error with sysadmin flag are reported to error_log or hidden from                  if (! @mkdir($dir."/.log",0700)) Error("docman installation problem","can't create log directory <tt>$dir/.log</tt>",1);
934  // users          }
935            $file=basename($target);
936  function Error($title,$text="",$sysadmin=0) {  
937          global $gblSeparateAdminMessages,          $log=fopen("$dir/.log/$file","a+");
938                  $gblMailAdminMessages,$realm,          fputs($log,date("$gblDateFmt\t$gblTimeFmt").
939                  $HTTP_SERVER_VARS;                  "\t$gblUserName\t$msg\n");
940          if ($sysadmin) {          fclose($log);
941                  if ($gblSeparateAdminMessages) {  
942                          $user="Your administrator ";          if (! $changelog) return;
943                          if ($gblMailAdminMessages) {  
944                                  mail($HTTP_SERVER_VARS["SERVER_ADMIN"], "docman $realm error message: $title", strip_tags($text));          $log=fopen("$gblFsRoot/.changelog","a+");
945                                  $user.="<tt>".$HTTP_SERVER_VARS["SERVER_ADMIN"]."</tt> ";          if (substr($target,0,strlen($gblFsRoot)) == $gblFsRoot)
946                          }                  $target=substr($target,strlen($gblFsRoot),strlen($target)-strlen($gblFsRoot));
947                          $user.="has been notified about error" ;          $msg=str_replace("\t"," ",$msg);
948                          StartHTML("($title)",$user);          fputs($log,time()."\t$target\t$gblUserName\t$msg\n");
949                          echo "<P ALIGN=center>Hit your Browser's Back Button.</P>" ;          fclose($log);
950                          EndHTML();  
951                          error_log("docman $realm: ".strip_tags($text));          // FIX: implement e-mail notification based on $changelog
952                  } else {          // permission
953                          StartHTML("ADMIN: ".$title,$text) ;  }
954                          echo "<P ALIGN=center>Hit your Browser's Back Button.</P>" ;  
955                          EndHTML();  
956                  }  //////////////////////////////////////////////////////////////////
957          } else {  
958                  StartHTML("(".$title.")",$text) ;  function WriteNote($target,$msg) {
959                  echo "<P ALIGN=center>Hit your Browser's Back Button.</P>" ;  
960                  EndHTML() ;          $target=stripSlashes($target);
961          }          $dir=dirname($target);
962          exit ;          if (! file_exists($dir."/.note")) {
963  } // end function Error                  mkdir($dir."/.note",0700);
964            }
965  function LogIt($target,$msg, $changelog=0) {          $file=basename($target);
966    
967          $dir=dirname($target);          $note=fopen("$dir/.note/$file","w");
968          if (! file_exists($dir."/.log")) {          if (! $note) {
969                  if (! @mkdir($dir."/.log",0700)) Error("docman installation problem","can't create log directory <tt>$dir/.log</tt>",1);                  Error("Error writing note","Can't open note file <tt>$dir/.note/$file</tt> for writing",1);
970          }          }
971          $file=basename($target);          fputs($note,"$msg\n");
972            fclose($note);
973          $log=fopen("$dir/.log/$file","a+");  
974          fputs($log,date("$GLOBALS[gblDateFmt]\t$GLOBALS[gblTimeFmt]").          LogIt($target,"added note $msg");
975                  "\t$GLOBALS[gblUserName]\t$msg\n");  
976          fclose($log);  }
977    
978          if (! $changelog) return;  function ReadNote($target) {
979    
980          global $gblFsRoot;          $target=stripSlashes($target);
981          $log=fopen("$gblFsRoot/.changelog","a+");          $dir=dirname($target);
982          if (substr($target,0,strlen($gblFsRoot)) == $gblFsRoot)          $file=basename($target);
983                  $target=substr($target,strlen($gblFsRoot),strlen($target)-strlen($gblFsRoot));          $msg="";
984          $msg=str_replace("\t"," ",$msg);          if (file_exists($dir."/.note/$file")) {
985          fputs($log,time()."\t$target\t$GLOBALS[gblUserName]\t$msg\n");                  $note=fopen("$dir/.note/$file","r");
986          fclose($log);                  $msg=fgets($note,4096);
987                    fclose($note);
988          // FIX: implement e-mail notification based on $changelog          }
989          // permission          return HtmlSpecialChars(StripSlashes($msg));
990  }  
991    }
992    
993  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
994    
995  function WriteNote($target,$msg) {  function MoveTo($source,$folder) {
996    
997          $target=stripSlashes($target);          $source=stripSlashes($source);
998          $dir=dirname($target);          $file=basename($source);
999          if (! file_exists($dir."/.note")) {          if (! file_exists($folder)) {
1000                  mkdir($dir."/.note",0700);                  mkdir($folder,0700);
1001          }          }
1002          $file=basename($target);          if (file_exists($source)) {
1003                    rename($source,"$folder/$file");
1004          $note=fopen("$dir/.note/$file","w");          }
1005          fputs($note,"$msg\n");  }
1006          fclose($note);  
1007    //////////////////////////////////////////////////////////////////
1008          LogIt($target,"added note $msg");  
1009    function Lock($target) {
1010  }  
1011            global $gblUserName;
1012  function ReadNote($target) {  
1013            $target=stripSlashes($target);
1014          $target=stripSlashes($target);          $dir=dirname($target);
1015          $dir=dirname($target);          if (! file_exists($dir."/.lock")) {
1016          $file=basename($target);                  mkdir($dir."/.lock",0700);
1017          $msg="";          }
1018          if (file_exists($dir."/.note/$file")) {          $file=basename($target);
1019                  $note=fopen("$dir/.note/$file","r");  
1020                  $msg=fgets($note,4096);          if (file_exists("$dir/.lock/$file")) {
1021                  fclose($note);                  LogIt($target,"attempt to locked allready locked file!");
1022          }          } else {
1023          return HtmlSpecialChars(StripSlashes($msg));                  $lock=fopen("$dir/.lock/$file","w");
1024                    fputs($lock,"$gblUserName\n");
1025  }                  fclose($lock);
1026    
1027  //////////////////////////////////////////////////////////////////                  LogIt($target,"file locked");
1028            }
1029  function MoveTo($source,$folder) {  
1030    }
1031          $source=stripSlashes($source);  
1032          $file=basename($source);  function CheckLock($target) {
1033          if (! file_exists($folder)) {  
1034                  mkdir($folder,0700);          $target=stripSlashes($target);
1035          }          $dir=dirname($target);
1036          if (file_exists($source)) {          $file=basename($target);
1037                  rename($source,"$folder/$file");          $msg=0;
1038          }          if (file_exists($dir."/.lock/$file")) {
1039  }                  $lock=fopen("$dir/.lock/$file","r");
1040                    $msg=fgets($lock,4096);
1041  //////////////////////////////////////////////////////////////////                  fclose($lock);
1042            }
1043  function Lock($target) {          return chop($msg);
1044    
1045          $target=stripSlashes($target);  }
1046          $dir=dirname($target);  
1047          if (! file_exists($dir."/.lock")) {  function Unlock($target) {
1048                  mkdir($dir."/.lock",0700);  
1049          }          $target=stripSlashes($target);
1050          $file=basename($target);          $dir=dirname($target);
1051            $file=basename($target);
1052          if (file_exists("$dir/.lock/$file")) {          if (file_exists($dir."/.lock/$file")) {
1053                  LogIt($target,"attempt to locked allready locked file!");                  unlink("$dir/.lock/$file");
1054          } else {                  LogIt($target,"file unlocked");
1055                  $lock=fopen("$dir/.lock/$file","w");          } else {
1056                  fputs($lock,"$GLOBALS[gblUserName]\n");                  LogIt($target,"attempt to unlocked non-locked file!");
1057                  fclose($lock);          }
1058    
1059                  LogIt($target,"file locked");  }
1060          }  
1061    //////////////////////////////////////////////////////////////////
1062  }  
1063    function urlpath($url) {
1064  function CheckLock($target) {          $url=urlencode(StripSlashes("$url"));
1065            $url=str_replace("%2F","/",$url);
1066          $target=stripSlashes($target);          $url=str_replace("+","%20",$url);
1067          $dir=dirname($target);          return($url);
1068          $file=basename($target);  }
1069          $msg=0;  
1070          if (file_exists($dir."/.lock/$file")) {  //////////////////////////////////////////////////////////////////
1071                  $lock=fopen("$dir/.lock/$file","r");  
1072                  $msg=fgets($lock,4096);  function safe_rename($fromdir,$fromfile,$tofile) {
1073                  fclose($lock);  
1074          }          global $gblNumBackups;
1075          return chop($msg);  
1076            function try_rename($from,$to) {
1077  }  #               print "$from -> $to\n";
1078                    if (file_exists($from) && is_writeable(dirname($to))) {
1079  function Unlock($target) {                          return rename($from,$to);
1080                    } else {
1081          $target=stripSlashes($target);                          return 0;
1082          $dir=dirname($target);                  }
1083          $file=basename($target);          }
1084          if (file_exists($dir."/.lock/$file")) {  
1085                  unlink("$dir/.lock/$file");          function try_dir($todir) {
1086                  LogIt($target,"file unlocked");                  if (! file_exists($todir)) {
1087          } else {                          @mkdir($todir,0700);
1088                  LogIt($target,"attempt to unlocked non-locked file!");                  }
1089          }          }
1090    
1091  }          $to="$fromdir/$tofile";
1092            $todir=dirname($to);
1093  //////////////////////////////////////////////////////////////////          $tofile=basename($to);
1094    
1095  function urlpath($url) {  #       print "<pre>$fromdir / $fromfile -> $todir / $tofile\n\n";
1096          $url=urlencode(StripSlashes("$url"));  
1097          $url=str_replace("%2F","/",$url);          if (! try_rename("$fromdir/$fromfile","$todir/$tofile")) Error("Rename error","Can't rename file <tt>$fromfile</tt> to <tt>$tofile</tt>",1);
1098          $url=str_replace("+","%20",$url);          try_dir("$todir/.log");
1099          return($url);          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  function safe_rename($fromdir,$fromfile,$tofile) {          try_dir("$todir/.bak");
1105          function try_rename($from,$to) {          for($i=0;$i<=$gblNumBackups;$i++) {
1106  #               print "$from -> $to\n";                  try_rename("$fromdir/.bak/$i/$fromfile","$todir/.bak/$i/$tofile");
1107                  if (file_exists($from) && is_writeable(dirname($to))) {          }
1108                          rename($from,$to);  }
1109                  }  
1110          }  
1111    //////////////////////////////////////////////////////////////////
1112          function try_dir($todir) {  
1113                  if (! file_exists($todir)) {  // recursivly delete directory
1114                          mkdir($todir,0700);  
1115                  }  function rrmdir($dir) {
1116          }          $handle=opendir($dir);
1117            while ($file = readdir($handle)) {
1118          $to="$fromdir/$tofile";                  if ($file != "." && $file != "..") {
1119          $todir=dirname($to);                          if (is_dir("$dir/$file"))
1120          $tofile=basename($to);                                  rrmdir("$dir/$file");
1121                            else
1122  #       print "<pre>$fromdir / $fromfile -> $todir / $tofile\n\n";                                  if (! @unlink("$dir/$file")) return(0);
1123                    }
1124          try_rename("$fromdir/$fromfile","$todir/$tofile");          }
1125          try_dir("$todir/.log");          closedir($handle);
1126          try_rename("$fromdir/.log/$fromfile","$todir/.log/$tofile");          return @rmdir($dir);
1127          try_dir("$todir/.note");  }
1128          try_rename("$fromdir/.note/$fromfile","$todir/.note/$tofile");  
1129          try_dir("$todir/.lock");  //////////////////////////////////////////////////////////////////
1130          try_rename("$fromdir/.lock/$fromfile","$todir/.lock/$tofile");  
1131          try_dir("$todir/.bak");  function DisplayChangeLog($day) {
1132          for($i=0;$i<=$GLOBALS[gblNumBackups];$i++) {  
1133                  try_rename("$fromdir/.bak/$i/$fromfile","$todir/.bak/$i/$tofile");          global $gblFsRoot, $gblDateFmt, $gblTimeFmt,
1134          }                  $HTTP_SERVER_VARS;
1135  }  
1136            $self  = $HTTP_SERVER_VARS["PHP_SELF"];
1137    
1138  //////////////////////////////////////////////////////////////////          if (!file_exists("$gblFsRoot/.changelog")) return;
1139            $log=fopen("$gblFsRoot/.changelog","r");
1140  // recursivly delete directory          $logarr = array();
1141            while($line = fgetcsv($log,512,"\t")) {
1142  function rrmdir($dir) {                  while (sizeof($line) > 4) {
1143          $handle=opendir($dir);                          $tmp = array_pop($line);
1144          while ($file = readdir($handle)) {                          $line.=" $tmp";
1145                  if ($file != "." && $file != "..") {                  }
1146                          if (is_dir("$dir/$file"))                  if ($day!=1 || ($day==1 && (time()-$line[0] < 24*60*60))) {
1147                                  rrmdir("$dir/$file");                          array_unshift($logarr,array($line[0],$line[1],$line[2],$line[3]));
1148                          else                  }
1149                                  if (! @unlink("$dir/$file")) return(0);          }
1150                  }          fclose($log);
1151          }          $cl1=" class=LST"; $cl2="";
1152          closedir($handle);          print "<table border=0 width=100%>\n";
1153          return @rmdir($dir);          while ($e = array_shift($logarr)) {
1154  }                  $cl=$cl1; $cl1=$cl2; $cl2=$cl;
1155                    $date = date($gblDateFmt, $e[0]);
1156  //////////////////////////////////////////////////////////////////                  $time = date($gblTimeFmt, $e[0]);
1157                    $dir = dirname($e[1]);
1158  function DisplayChangeLog($day) {                  $file = basename($e[1]);
1159                    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          global $gblFsRoot;          }
1161          if (!file_exists("$gblFsRoot/.changelog")) return;          print "</table>";
1162          $log=fopen("$gblFsRoot/.changelog","r");          print "<p>".GifIcon("up")." Back to <a href=\"$self\">front page</a>.</p>";
1163          $logarr = array();  }
1164          while($line = fgetcsv($log,512,"\t")) {  
1165                  while (sizeof($line) > 4) {  //////////////////////////////////////////////////////////////////
1166                          $tmp = array_pop($line);  
1167                          $line.=" $tmp";  function Download($path,$force=0) {
1168                  }          global $HTTP_SERVER_VARS,$mime_type;
1169                  if ($day!=1 || ($day==1 && (time()-$line[0] < 24*60*60))) {  
1170                          array_unshift($logarr,array($line[0],$line[1],$line[2],$line[3]));          // default transfer-encoding
1171                  }          $encoding = "binary";
1172          }  
1173          fclose($log);          // known transfer encodings
1174          $cl1=" class=LST"; $cl2="";          $encoding_ext = array(
1175          print "<table border=0 width=100%>\n";                  "gz" => "x-gzip",
1176          while ($e = array_shift($logarr)) {                  "Z" => "x-compress",
1177                  $cl=$cl1; $cl1=$cl2; $cl2=$cl;          );
1178                  $date = date("$GLOBALS[gblDateFmt]", $e[0]);  
1179                  $time = date("$GLOBALS[gblTimeFmt]", $e[0]);          $file = basename($path);
1180                  $dir = dirname($e[1]);          $size = filesize($path);
1181                  $file = basename($e[1]);  
1182                  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";          $ext_arr = explode(".",$file);
1183          }          $ext = array_pop($ext_arr);
1184          print "</table>";          if (isset($encoding_ext[$ext])) {
1185          print "<p>".GifIcon(up)." Back to <a href=$GLOBALS[PHP_SELF]>front page</a>.</p>";                  $encoding = $encoding_ext[$ext];
1186  }                  $ext = array_pop($ext_arr);
1187            }
1188  //////////////////////////////////////////////////////////////////  
1189            if ($force || !isset($mime_type[$ext])) {
1190  function Download($path) {                  header("Content-Type: application/force-download");
1191          global $HTTP_USER_AGENT;          } else {
1192          $file=basename($path);                  header("Content-Type: $mime_type[$ext]");
1193          $size = filesize($path);          }
1194          //header("Content-Type: application/octet-stream");  
1195          header("Content-Type: application/force-download");          // IE5.5 just downloads index.php if we don't do this
1196          header("Content-Length: $size");          if(preg_match("/MSIE 5.5/", $HTTP_SERVER_VARS["HTTP_USER_AGENT"])) {
1197          // IE5.5 just downloads index.php if we don't do this                  header("Content-Disposition: filename=$file");
1198          if(preg_match("/MSIE 5.5/", $HTTP_USER_AGENT)) {          } else {
1199                  header("Content-Disposition: filename=$file");                  header("Content-Disposition: attachment; filename=$file");
1200          } else {          }
1201                  header("Content-Disposition: attachment; filename=$file");  
1202          }          header("Content-Transfer-Encoding: $encoding");
1203          header("Content-Transfer-Encoding: binary");          $fh = fopen($path, "r");
1204          $fh = fopen($path, "r");          fpassthru($fh);
1205          fpassthru($fh);  }
1206  }  
1207    
1208    //////////////////////////////////////////////////////////////////
1209  //////////////////////////////////////////////////////////////////  
1210    function chopsl($path) {
1211  function chopsl($path) {          $path=str_replace("//","/",$path);
1212          if (substr($path,strlen($path)-1,1) == "/") $path=substr($path,0,strlen($path)-1);          if (substr($path,strlen($path)-1,1) == "/") $path=substr($path,0,strlen($path)-1);
1213          $path=str_replace("//","/",$path);          return $path;
1214          return $path;  }
1215  }  
1216    //////////////////////////////////////////////////////////////////
1217  //////////////////////////////////////////////////////////////////  /*
1218  /*          Document manager ACL implementation
1219          Document manager ACL implementation  
1220            Written by Dobrica Pavlinusic <dpavlin@rot13.org>
1221          Written by Dobrica Pavlinusic <dpavlin@rot13.org>  
1222            Based on ideas from Linux trustees code
1223          Based on ideas from Linux trustees code          by Vyacheslav Zavadsky <zavadsky@braysystems.com>
1224          by Vyacheslav Zavadsky <zavadsky@braysystems.com>  */
1225  */  
1226    define('trmask_not',1 << 0);
1227  define(trmask_not,1 << 0);  define('trmask_clear',1 << 1);
1228  define(trmask_clear,1 << 1);  define('trmask_deny',1 << 2);
1229  define(trmask_deny,1 << 2);  define('trmask_one_level',1 << 3);
1230  define(trmask_one_level,1 << 3);  define('trmask_group',1 << 4);
1231  define(trmask_group,1 << 4);  
1232    define('trperm_r',1 << 5);
1233  define(trperm_r,1 << 5);  define('trperm_w',1 << 6);
1234  define(trperm_w,1 << 6);  define('trperm_b',1 << 7);
1235  define(trperm_b,1 << 7);  define('trperm_n',1 << 8);
1236  define(trperm_n,1 << 8);  
1237    $trustee_a2n = array(
1238  $trustee_a2n = array(          '!' => trmask_not,
1239          '!' => trmask_not,          'C' => trmask_clear,
1240          'C' => trmask_clear,          'D' => trmask_deny,
1241          'D' => trmask_deny,          'O' => trmask_one_level,
1242          'O' => trmask_one_level,          '+' => trmask_group,
1243          '+' => trmask_group,          'R' => trperm_r,
1244          'R' => trperm_r,          'W' => trperm_w,
1245          'W' => trperm_w,          'B' => trperm_b,
1246          'B' => trperm_b,          'N' => trperm_n,
1247          'N' => trperm_n,  );
1248  );  
1249    // debugging function
1250  // debugging function  function display_trustee($t) {
1251  function display_trustee($t) {          global $trustee_a2n;
1252          global $trustee_a2n;          $out="";
1253          $out="";          foreach ($trustee_a2n as $c=>$v) {
1254          foreach ($trustee_a2n as $c=>$v) {                  if ($t & $v) $out.=$c;
1255                  if ($t & $v) $out.=$c;          }
1256          }          return $out;
1257          return $out;  }
1258  }  function display_all_trustee() {
1259  function display_all_trustee() {          global $trustees;
1260          global $trustees;          print "trustee dump:<br>\n";
1261          print "trustee dump:<br>\n";          foreach ($trustees as $path => $tr) {
1262          foreach ($trustees as $path => $tr) {                  print "<br><tt>$path</tt>\n";
1263                  print "<br><tt>$path</tt>\n";                  foreach ($tr as $user=>$perm) {
1264                  foreach ($tr as $user=>$perm) {                          print "$user == $perm (".display_trustee($perm).")<br>\n";
1265                          print "$user == $perm (".display_trustee($perm).")<br>\n";                  }
1266                  }          }
1267          }  }
1268  }  
1269    function init_trustee() {
1270  function init_trustee() {  
1271    global $trustee_conf,$trustee_php,$trustee_a2n,$groups,$trustees;
1272  global $trustee_conf,$trustee_php,$trustee_a2n,$groups,$trustees;  
1273    // do we need to re-create compiled trustees?
1274  // do we need to re-create compiled trustees?  if (! file_exists($trustee_conf)) {
1275  if (! file_exists($trustee_conf)) {          # $error="$trustee_conf doesn't exits";
1276          # $error="$trustee_conf doesn't exits";          return 0;       # don't use trustees
1277          return 0;       # don't use trustees  } elseif (file_exists($trustee_conf) && !is_readable($trustee_conf)) {
1278  } elseif (file_exists($trustee_conf) && !is_readable($trustee_conf)) {          $error="<tt>$trustee_conf</tt> exits, but is not readable";
1279          $error="<tt>$trustee_conf</tt> exits, but is not readable";  } elseif (!is_writable(dirname($trustee_php))) {
1280  } elseif (!is_writable(dirname($trustee_php))) {          $error="<tt>".dirname($trustee_php)."</tt> must be writable by web server user";
1281          $error="<tt>".dirname($trustee_php)."</tt> must be writable by web server user";  } elseif (file_exists($trustee_php) && !is_writable($trustee_php)) {
1282  } elseif (file_exists($trustee_php) && !is_writable($trustee_php)) {          $error="trustees cache file <tt>$trustee_php</tt> exists, but is not writable by web server";
1283          $error="trustees cache file <tt>$trustee_php</tt> exists, but is not writable by web server";  } elseif (@filemtime($trustee_conf) >= @filemtime($trustee_php)) {
1284  } elseif (1 || filemtime($trustee_conf) >= filemtime($trustee_php)) {          $fp_php=@fopen($trustee_php,"w");
1285          $fp_php=@fopen($trustee_php,"w");          fputs($fp_php,"<?php // don't edit by hand!\n");
1286          fputs($fp_php,"<?php // don't edit by hand!\n");  
1287            $fp_conf=fopen($trustee_conf,"r");
1288          $fp_conf=fopen($trustee_conf,"r");  
1289            $groups_arr = array();
1290          $groups_arr = array();          $perm_arr = array();
1291          $perm_arr = array();  
1292            $tr_arr = array();
1293          $tr_arr = array();  
1294            while (! feof($fp_conf)) {
1295          while (! feof($fp_conf)) {                  $l = trim(fgets($fp_conf,4096));
1296                  $l = trim(fgets($fp_conf,4096));                  if (substr($l,0,1) == "+") {    // no comment
1297                  if (substr($l,0,1) == "+") {    // no comment                          $arr=explode(":",$l);
1298                          $arr=explode(":",$l);                          $groups_arr[$arr[0]] = str_replace(" ","",$arr[1]) ;
1299                          $groups_arr[$arr[0]] = $arr[1] ;                  } elseif (substr($l,0,1) != "#") {
1300                  } elseif (substr($l,0,1) != "#") {                          $arr=explode(":",$l);
1301                          $arr=explode(":",$l);                          $path=array_shift($arr);
1302                          $path=array_shift($arr);                          if ($path == "") continue;
1303                          if ($path == "") continue;                          $sep2="";
1304                          $sep2="";                          while ($user=array_shift($arr)) {
1305                          while ($user=array_shift($arr)) {                                  $perm=0;
1306                                  $perm=0;                                  if (substr($user,0,1) == "+") {
1307                                  if (substr($user,0,1) == "+") {                                          $perm|=trmask_group;
1308                                          $perm|=trmask_group;                                          $user=substr($user,1,strlen($user)-1);
1309                                          $user=substr($user,1,strlen($user)-1);                                  }
1310                                  }                                  $perm_ascii=array_shift($arr);
1311                                  $perm_ascii=array_shift($arr);                                  for ($i=0;$i<strlen($perm_ascii);$i++) {
1312                                  for ($i=0;$i<strlen($perm_ascii);$i++) {                                          $ch=strtoupper($perm_ascii[$i]);
1313                                          $ch=strtoupper($perm_ascii[$i]);                                          if (isset($trustee_a2n[$ch])) {
1314                                          if (isset($trustee_a2n[$ch])) {                                                  $perm|=$trustee_a2n[$ch];
1315                                                  $perm|=$trustee_a2n[$ch];                                          } else {
1316                                          } else {                                                  $error.="trustee error in line '$l' [Unknown modifier '$ch']<br>\n";
1317                                                  $error.="trustee error in line '$l' [Unknown modifier '$ch']<br>\n";                                          }
1318                                          }                                  }
1319                                  }                                  if (isset($tr_arr[$path][$user])) {
1320                                  $tr_arr[$path][$user] |= $perm;                                          $tr_arr[$path][$user] |= $perm;
1321                          }                                  } else {
1322                  }                                          $tr_arr[$path][$user] = $perm;
1323          }                                  }
1324                            }
1325          fclose($fp_conf);                  }
1326            }
1327          // save trustees  
1328          $tr_out='$trustees = array (';          fclose($fp_conf);
1329          $sep1="";  
1330          while (list ($path, $tr) = each ($tr_arr)) {          // save trustees
1331                  $tr_out.="$sep1\n\t'$path'=>array(";          $tr_out='$trustees = array (';
1332                  $sep2="";          $sep1="";
1333                  while (list($user,$perm)=each($tr)) {          while (list ($path, $tr) = each ($tr_arr)) {
1334                          $tr_out.="$sep2\n\t\t'$user'=>$perm";                  $tr_out.="$sep1\n\t'$path'=>array(";
1335                          $sep2=",";                  $sep2="";
1336                  }                  while (list($user,$perm)=each($tr)) {
1337                  $tr_out.="\n\t)";                          $tr_out.="$sep2\n\t\t'$user'=>$perm";
1338                  $sep1=",";                          $sep2=",";
1339          }                  }
1340          $tr_out.="\n);";                  $tr_out.="\n\t)";
1341                    $sep1=",";
1342          // save groups          }
1343          $gr_out='$groups = array (';          $tr_out.="\n);";
1344          $sep="";  
1345          while (list ($group, $members) = each ($groups_arr)) {          // save groups
1346                  $gr_out.="$sep\n\t'";          $gr_out='$groups = array (';
1347                  $gr_out.=substr($group,1,strlen($group)-1);          $sep="";
1348                  $gr_out.="'=>array('".join("','",explode(",",$members))."')";          while (list ($group, $members) = each ($groups_arr)) {
1349                  $sep=",";                  $gr_out.="$sep\n\t'";
1350          }                  $gr_out.=substr($group,1,strlen($group)-1);
1351          $gr_out.="\n);\n";                  $gr_out.="'=>array('".join("','",explode(",",$members))."')";
1352                    $sep=",";
1353          fputs($fp_php,$gr_out);          }
1354          fputs($fp_php,$tr_out);          $gr_out.="\n);\n";
1355          fputs($fp_php,"?>\n");  
1356          fclose($fp_php);          fputs($fp_php,$gr_out);
1357  }          fputs($fp_php,$tr_out);
1358            fputs($fp_php,"?>\n");
1359  if ($error) {          fclose($fp_php);
1360          Error("Trustee error",$error,1);  }
1361  } else {  
1362          include("$trustee_php");  if (isset($error)) {
1363  }          Error("Trustee error",$error,1);
1364    } else {
1365  return 1;          include_once("$trustee_php");
1366    }
1367  }//init_trustee  
1368    return 1;
1369  function in_group($user,$group) {  
1370          return in_array($groups[$group],$user);  }//init_trustee
1371  }  
1372    function in_group($user,$group) {
1373  // helper function          global $groups;
1374  function unroll_perm($u,$t,$user,$perm) {          return in_array($user,$groups[$group]);
1375          // check user  }
1376          if ($t & trmask_not && ($u==$user)) continue;  
1377          if (!($t & trmask_not) && ($u!=$user)) continue;  // helper function
1378    function unroll_perm($u,$t,$perm,$one_level) {
1379          if ($t & trmask_deny) {  
1380                  if ($t & trmask_clear) {          if ($t & trmask_one_level && !$one_level) return $perm;
1381                          $perm[deny] &= ~$t;  
1382                  } else {          if ($t & trmask_deny) {
1383                          $perm[deny] |= $t;                  if ($t & trmask_clear) {
1384                  }                          $perm['deny'] &= ~$t;
1385          } elseif ($t & trmask_clear) {                  } else {
1386                  $perm[allow] &= ~$t;                          $perm['deny'] |= $t;
1387          } else {                  }
1388                  $perm[allow] |= $t;          } elseif ($t & trmask_clear) {
1389          }                  $perm['allow'] &= ~$t;
1390          return $perm;          } else {
1391  }// end of helper function                  $perm['allow'] |= $t;
1392            }
1393  function check_trustee($user,$path) {          return $perm;
1394          global $trustees;  }// end of helper function
1395          $perm[allow] = 0;  
1396          $perm[deny] = 0;  function check_trustee($user,$path) {
1397          $path_arr=explode("/",$path);          global $trustees,$HAVE_TRUSTEE;
1398          $path = "/";          $perm['allow'] = 0;
1399          while (count($path_arr)) {          $perm['deny'] = 0;
1400                  if (substr($path,strlen($path)-1,1) != "/") $path.="/";  
1401                  $path.=array_shift($path_arr);          // do we use trustees?
1402                  $tr = $trustees[$path];          if (! $HAVE_TRUSTEE) return $perm;
1403    
1404                  if (isset($tr)) {          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                          // first apply trustee for all  
1406                          if (isset($tr['*'])) {  global $debug;
1407                                  $perm = unroll_perm($user,$tr['*'],$user, $perm);  $debug .= "<br>check_trustee $path ... ";
1408                                  unset($tr['*']);  
1409                          }          $path_arr=explode("/",$path);
1410                          // then apply group policies          $tmppath="";
1411                          foreach ($tr as $u=>$t) {          while (count($path_arr)) {
1412                                  if ($t & trmask_group && in_group($user,$u)) {                  $p = array_shift($path_arr);
1413                                          // resolv user  $debug.= "[$p] ";
1414                                          $t = $t & ~trmask_group;                  # add trailing slash
1415                                          $u = $user;                  if (substr($tmppath,strlen($tmppath)-1,1) != "/") {
1416                                          $perm = unroll_perm($u,$t,$user, $perm);                          $tmppath.="/";
1417                                          unset($tr[$u]);                  }
1418                                  }                  # append currnet dir to tmppath
1419                          }                  if (isset($p)) {
1420                          // then apply use policy                          $tmppath.=$p;
1421                          if (isset($tr[$user])) {                  }
1422                                  $perm = unroll_perm($user,$tr[$user],$user, $perm);  $debug.= ">> $tmppath ";
1423                                  unset($tr[$user]);  
1424                          }                  if (! isset($trustees[$tmppath])) continue;
1425                    $tr = $trustees[$tmppath];
1426                  }  
1427                    $one_level = (!count($path_arr));
1428          }  $debug.=" O($one_level) ";
1429  #print "<br>user: $user path: $path perm: ";  
1430  #print "d: $perm[deny] (".display_trustee($perm[deny]).") a: $perm[allow] (".display_trustee($perm[allow]).")<Br>\n";                  if (isset($tr)) {
1431          return $perm;                          // first apply trustee for all
1432  }                          if (isset($tr['*']) && $user!="anonymous") {
1433                                    $perm = unroll_perm($user,$tr['*'],$perm, $one_level);
1434  // handy functions                                  unset($tr['*']);
1435                            }
1436  function check_perm($path,$trperm) {                          // then apply not and group policies
1437          global $gblLogin,$HAVE_TRUSTEE;                          foreach ($tr as $g=>$t) {
1438  print "<br>check_perm: <tt>$path</tt> test perm ".display_trustee($perm)."<br>\n";                                  if ($t & trmask_not && $g != $user) {
1439          $return = ! $HAVE_TRUSTEE;                                          $t = $t & ~trmask_not;
1440          if ($HAVE_TRUSTEE) {                                          $perm = unroll_perm($user,$t,$perm, $one_level);
1441                  $perm = check_trustee($gblLogin,$path);                                          unset($tr[$g]);
1442  print " d: $perm[deny] (".display_trustee($perm[deny]).") a: $perm[allow] (".display_trustee($perm[allow]).") perm: $trperm";  
1443                  if ($perm[deny] & $trperm) $return=0;                                  } elseif ($t & trmask_group && in_group($user,$g)) {
1444                  elseif ($perm[allow] & $trperm) $return=1;                                          // resolv user
1445          }                                          $t = $t & ~trmask_group;
1446  print " return: $return<br>\n";                                          $perm = unroll_perm($user,$t,$perm, $one_level);
1447          return($return);                                          unset($tr[$g]);
1448  }                                  }
1449                            }
1450                            // then apply user policy
1451  //////////////////////////////////////////////////////////////////                          if (isset($tr[$user])) {
1452  // MAIN PROGRAM                                  $perm = unroll_perm($user,$tr[$user],$perm,$one_level);
1453                                    unset($tr[$user]);
1454          $gblFilePerms = 0640 ;         // default for new files                          }
1455          $gblDirPerms  = 0750 ;          // default for new dirs                  }
1456    $debug.="d(".display_trustee($perm['deny']).") a(".display_trustee($perm['allow']).") ";
1457          if (isset($STYLE) && $STYLE == "get") {  
1458                  include("$html/docman.css");          }
1459                  exit;  $debug.="<br>check_trustee: user: $user path: $path==$tmppath perm: ";
1460          }  $debug.="d: ".$perm['deny']." (".display_trustee($perm['deny']).") a: ".$perm['allow']." (".display_trustee($perm['allow']).")<Br>\n";
1461            return $perm;
1462          // location of master docman configuration file  }
1463          $docman_conf = "/etc/docman.conf";  
1464          if (! file_exists($docman_conf)) {  // handy functions
1465                  $error = "Can't find master configuration file $docman_conf. See docman2/doc/upgrade.html#docman_conf for more informations";  
1466                    function check_perm($path,$trperm) {
1467                  error_log("docman: $error");          global $gblLogin,$HAVE_TRUSTEE;
1468                  Error("docman not installed completly",$error);  
1469          }          $path = str_replace("//","/",$path);
1470          include($docman_conf);  
1471            global $debug;
1472          if (! isset($fsRealmDir)) {  $debug.="<br>check_perm: on <tt>$path</tt> for perm ".display_trustee($trperm)."<br>\n";
1473                  $fsRealmDir = "$gblIncDir/realm";  
1474          }          $return = ! $HAVE_TRUSTEE;
1475          $realm_config = "$fsRealmDir/$realm.conf";          if ($HAVE_TRUSTEE) {
1476                    $perm = check_trustee($gblLogin,$path);
1477          // read user-defined configuration  $debug.=" d: ".$perm['deny']." (".display_trustee($perm['deny']).") a: ".$perm['allow']." (".display_trustee($perm['allow']).") perm to have: $trperm (".display_trustee($trperm).")";
1478          if (file_exists($realm_config)) {                  if ($perm['deny'] & $trperm) $return=0;
1479                  include($realm_config);                  elseif (($perm['allow'] & $trperm) == $trperm) $return=1;
1480          } else {          }
1481                  Error("Configuration error","Can't find configuration file at <tt>$realm_config</tt> !");  $debug.=" return: $return<br>\n";
1482          }          return($return);
1483    }
1484          if (! isset($gblRepositoryDir)) Error("Configuration error","<tt>\$gblRepositoryDir</tt> is not setuped in realm configuration file <tt>$realm_config</tt>");  
1485    //////////////////////////////////////////////////////////////////
1486          // where do we get users from?  
1487          if (file_exists("$gblIncDir/htusers/$gblUsers.php")) {  function readMime() {
1488                  include("$gblIncDir/htusers/$gblUsers.php");          global $mime_type, $gblMimeTypes;
1489          } else {  
1490                  Error("Configuration error","Can't find user handling module at <tt>$gblIncDir/htusers/$gblUsers.php</tt> ! Please fix <tt>$realm_config</tt>");          if (! isset($gblMimeTypes)) {
1491          }                  $gblMimeTypes = "/etc/mime.types";
1492            }
1493          // if no password, or empty password logout  
1494          if (          $mime = @fopen($gblMimeTypes,"r");
1495                  isset($gblLogin) && (  
1496                          !isset($relogin) || (          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                                  isset($relogin) && $relogin != md5($gblLogin.$gblPasswd)  
1498                          )          while($line = fgets($mime,80)) {
1499                  ) && (                  if (substr($line,0,1) == "#") continue; // skip comment
1500                          $gblPasswd == "" || !isset($gblPasswd)                  $arr = preg_split("/[\s\t]+/",$line);
1501                  ) && !isset($force_login) && $gblLogin != "anonymous"                  $type = array_shift($arr);
1502             ) {                  while ($ext = array_shift($arr)) {
1503                  StartHTML("Logout completed","Your login credentials has been erased") ;                          $mime_type[$ext] = $type;
1504                  EndHTML() ;                  }
1505                  exit ;          }
1506          }  
1507            fclose($mime);
1508          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);  }
1509    
1510          // trustee (ACL) file configuration  //////////////////////////////////////////////////////////////////
1511          $trustee_conf="$gblIncDir/realm/$realm.trustee";  
1512          // compiled version of trustee file  // check for invalid characters in filename and dirname (.. and /)
1513          $trustee_php="$gblRepositoryDir/.trustee.php";  
1514          // get ACL informations  function check_dirname($file) {
1515          $HAVE_TRUSTEE = init_trustee();          if (strstr($file,"..")) Error("Security violation","No parent dir <tt>..</tt> allowed in directory name <tt>$file</tt>",1);
1516    }
1517          if (strtolower($gblLogin) == "anonymous" || !isset($gblPasswd)) {  
1518                  $perm = check_trustee($gblLogin,$path);  function check_filename($file) {
1519                  // browsing must be explicitly allowed for root directory          if (strstr($file,"..")) Error("Security violation","No parent dir <tt>..</tt> allowed in file name <tt>$file</tt>",1);
1520                  // of repository for anonymous user to work!          // remove deleted directory (for undelete to work)
1521                  if ($perm[allow] & trperm_b) {          $file = str_replace(".del/","",$file);
1522                          $secHash = md5($gblLogin.$gblPasswd);          if (strstr($file,"/")) Error("Security violation","No slashes <tt>/</tt> allowed in file name <tt>$file</tt>",1);
1523                          $gblUserName = "Anonymous user";  }
1524                  }  
1525          }  // bla/blo/../foo will return bla/foo
1526    function remove_parent($path) {
1527          // authentication failure          while (preg_match(",/[^/]+/\.\./,",$path)) {
1528          if ( md5($gblLogin.$gblPasswd) != $secHash ||                  $path = preg_replace(",/[^/]+/\.\./,","",$path);
1529                  isset($relogin) && $secHash == $relogin) {          }
1530                  header("WWW-authenticate: basic realm=\"$realm\"") ;          if (substr($path,0,1) != "/") $path = "/".$path;
1531                  header("HTTP/1.0 401 Unauthorized") ;          return $path;
1532                  Error("401 Unauthorized","No trespassing !");  }
1533                  exit ;  
1534          }  //////////////////////////////////////////////////////////////////
1535    
1536          // get current directory relative to $gblFsRoot  // functions to move HTTP server variables to global namespace
1537          $relDir = $DIR ;        // from POST  // [replacement for register_globals in php.ini]
1538          if ($relDir == "") {    // not defined in POST ?  
1539                  $relDir = urldecode($D) ;  // then use GET  function HTTP_GET_VAR($var) {
1540          }                global $HTTP_GET_VARS, ${$var};
1541            if (isset($HTTP_GET_VARS[$var])) {
1542          $relDir=stripSlashes($relDir);                  $$var = stripSlashes($HTTP_GET_VARS[$var]);
1543                    return $$var;
1544          if ($relDir == "/") $relDir = "" ;                }
1545          // default : website root = ""  }
1546    
1547          if (strstr($relDir,"..")) Error("No updirs allowed");  function HTTP_POST_VAR($var) {
1548            global $HTTP_POST_VARS, ${$var};
1549          // full paths contain "fs" or "Fs". Paths realitve to root of          if (isset($HTTP_POST_VARS[$var])) {
1550          // website contain "rel" or "Rel". The script won't let you                  $$var = $HTTP_POST_VARS[$var];
1551          // edit anything above directory equal to http://server.com                  return $$var;
1552          // i.e. below $gblFsRoot.          }
1553    }
1554          $relScriptDir = dirname($SCRIPT_NAME) ;          
1555          // i.e. /docman  function HTTP_SERVER_VAR($var) {
1556            global $HTTP_SERVER_VARS, ${$var};
1557          // start on server root          if (isset($HTTP_SERVER_VARS[$var])) {
1558          $gblFsRoot = $gblRepositoryDir;                  $$var = $HTTP_SERVER_VARS[$var];
1559          // i.e. /home/httpd/html                  return $$var;
1560            }
1561          $fsDir = $gblFsRoot . $relDir ; // current directory  }
1562          if ( !is_dir($fsDir) ) Error("Dir not found",$relDir) ;  
1563    //////////////////////////////////////////////////////////////////
1564          if (isset($GLOBALS["HTTPS"]) && $GLOBALS["HTTPS"] == "on") {  
1565                  $webRoot  = "https://";  function Warn($text) {
1566          } else {  }
1567                  $webRoot  = "http://";  
1568          }  //////////////////////////////////////////////////////////////////
1569          $webRoot .= $GLOBALS["HTTP_HOST"] . $relScriptDir;  
1570    function isBlank($file,$what = "filename") {
1571          $FN=stripSlashes($FN);          if (trim($file) == "") return "<i>whitespace $what</i>";
1572            if ($file == "") return "<i>no $what</i>";
1573          switch ($POSTACTION) {          return $file;
1574          case "UPLOAD" :  }
1575                  if (!is_writeable($fsDir)) Error("Write denied",$relDir) ;  
1576                  if (strstr($FN_name,"/"))  //////////////////////////////////////////////////////////////////
1577                          Error("Non-conforming filename") ;  // MAIN PROGRAM
1578                  // TODO : should rather check for escapeshellcmds  
1579                  // but maybe RFC 18xx asserts safe filenames ....          $gblFilePerms = 0640 ;         // default for new files
1580                  $source = $FN ;          $gblDirPerms  = 0750 ;          // default for new dirs
1581                  if (! file_exists($source)) {  
1582                          Error("You must select file with browse to upload it!");          if (isset($HTTP_GET_VARS["STYLE"]) && $HTTP_GET_VARS["STYLE"] == "get") {
1583                  }                  include("$html/docman.css");
1584                  if (! isset($FILENAME)) {       // from update file                  exit;
1585                          $target = "$fsDir/$FN_name" ;          }
1586                  } else {  
1587                          $target = "$fsDir/$FILENAME";          // location of master docman configuration file
1588                  }          $docman_conf = "/etc/docman.conf";
1589            if (! file_exists($docman_conf)) {
1590                  // backup old files first                  $error = "Can't find master configuration file <tt>$docman_conf</tt>. See <tt>docman2/doc/upgrade.html#docman_conf</tt> for more informations";
1591                  $dir=dirname($target);                  
1592                  if (! file_exists($dir."/.bak")) {                  error_log("docman: $error");
1593                          mkdir($dir."/.bak",0700);                  Error("docman not installed completly",$error);
1594                  }          }
1595                  if (! file_exists($dir."/.bak/$GLOBALS[gblNumBackups]")) {          include($docman_conf);
1596                          mkdir($dir."/.bak/$GLOBALS[gblNumBackups]",0700);  
1597                  }          if (! isset($fsRealmDir)) {
1598                  $file=basename($target);                  $fsRealmDir = "$gblIncDir/realm";
1599                  for($i=$GLOBALS[gblNumBackups]-1;$i>0;$i--) {          }
1600                          MoveTo("$dir/.bak/$i/$file","$dir/.bak/".($i+1)."/");  
1601                  }          // try to add dir to script name to realm var
1602                  MoveTo($target,$dir."/.bak/1/");          if (is_dir("$fsRealmDir/$realm/".dirname($HTTP_SERVER_VARS["SCRIPT_NAME"]))) {
1603                    $realm .= dirname($HTTP_SERVER_VARS["SCRIPT_NAME"]);
1604                  copy($source,$target) ;                  $realm_sep = "/";
1605                  chmod($target,$gblFilePerms) ;          } else {
1606                  clearstatcache() ;                  $realm_sep = ".";
1607                  if (isset($FILENAME)) {          }
1608                          LogIt($target,"check-in",trperm_r | trperm_w);  
1609                          Unlock($target);          $realm_config = $fsRealmDir."/".$realm.$realm_sep."conf";
1610                  } else {  
1611                          LogIt($target,"uploaded",trperm_r | trperm_w);          // read user-defined configuration
1612                  }          if (file_exists($realm_config)) {
1613                  break ;                  include($realm_config);
1614            } else {
1615          case "SAVE" :                  Error("Configuration error","Can't find configuration file at <tt>$realm_config</tt> !");
1616                  $path = $gblFsRoot . $RELPATH ;          }
1617                  $path=stripSlashes($path);  
1618                  $writable = is_writeable($path) ;          if (! isset($gblRepositoryDir)) Error("Configuration error","<tt>\$gblRepositoryDir</tt> is not setuped in realm configuration file <tt>$realm_config</tt>");
1619                  $legaldir = is_writeable(dirname($path)) ;  
1620                  $exists   = (file_exists($path)) ? 1 : 0 ;          // where do we get users from?
1621  // check for legal extension here as well          if (file_exists("$gblIncDir/htusers/$gblUsers.php")) {
1622                  if (!($writable || (!$exists && $legaldir)))                  include("$gblIncDir/htusers/$gblUsers.php");
1623                          Error("Write denied",$RELPATH) ;          } else {
1624                  $fh = fopen($path, "w") ;                  Error("Configuration error","Can't find user handling module at <tt>$gblIncDir/htusers/$gblUsers.php</tt> ! Please fix <tt>$realm_config</tt>");
1625                  $FILEDATA=stripSlashes($FILEDATA);          }
1626                  fwrite($fh,$FILEDATA) ;  
1627                  fclose($fh) ;          // take additional login vars
1628                  clearstatcache() ;          HTTP_GET_VAR("relogin");
1629                  LogIt($path,"saved changes",trperm_r);          HTTP_GET_VAR("force_login");
1630                  break ;  
1631            // if no password, or empty password logout
1632          case "CREATE" :          if (
1633                  // we know $fsDir exists                  isset($gblLogin) && (
1634                  if ($FN == "") break;           // no filename!                          !isset($relogin) || (
1635                  if (!is_writeable($fsDir)) Error("Write denied",$relDir) ;                                  isset($relogin) && $relogin != md5($gblLogin.$gblPasswd)
1636                  $path = $fsDir . "/" . $FN ;  // file or dir to create                          )
1637                  $relPath = $relDir . "/" . $FN ;                  ) && (
1638                  switch ( $T ) {                          $gblPasswd == "" || !isset($gblPasswd)
1639                  case "D" :  // create a directory                  ) && !isset($force_login) && $gblLogin != "anonymous"
1640                          if ( ! @mkdir($path,$gblDirPerms) )             ) {
1641                                  Error("Mkdir failed",$relPath) ; // eg. if it exists                  StartHTML("Logout completed","Your login credentials has been erased") ;
1642                          else                  EndHTML() ;
1643                                  LogIt($path."/","dir created",trperm_w);                  exit ;
1644                          clearstatcache() ;          }
1645                          break ;  
1646                  case "F" :  // create a new file          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  // this functionality is doubled in DetailView().  
1648  // better keep it here altogether          // trustee (ACL) file configuration
1649  // chmod perms to $gblFilePerms          $trustee_conf="$fsRealmDir/$realm".$realm_sep."trustee";
1650                          if ( file_exists($path) && !is_writeable($path) )          // compiled version of trustee file
1651                                  Error("File not writable", $relPath) ;          $trustee_php="$gblRepositoryDir/.trustee.php";
1652                          $fh = fopen($path, "w+") ;          // get ACL informations
1653                          if ($fh) {          $HAVE_TRUSTEE = init_trustee();
1654                                  fputs($fh,"\n");  
1655                                  fclose($fh) ;          if (strtolower($gblLogin) == "anonymous" || !isset($gblLogin)) {
1656                                  LogIt($path,"file created",trperm_r | trperm_w);                  $perm = check_trustee("anonymous","/");
1657                          } else {                  // browsing must be explicitly allowed for root directory
1658                                  Error("Creation of file $relPath failed -- $path");                  // of repository for anonymous user to work!
1659                          }                  if ($perm['allow'] & trperm_b) {
1660                          $tstr = "$PHP_SELF?A=E&D=".urlencode($relDir)."&F=".urlencode($FN) ;                          $gblLogin = $gblPasswd = "anonymous";
1661                          header("Location: " . $tstr) ;                          $secHash = md5($gblLogin.$gblPasswd);
1662                          exit ;                          $gblUserName = "Anonymous user";
1663                  }                  }
1664                  break ;          }
1665    
1666          case "DELETE" :            // authentication failure
1667                  if ( $CONFIRM != "on" ) break ;          if ( md5($gblLogin.$gblPasswd) != $secHash ||
1668                    isset($relogin) && $secHash == $relogin) {
1669                  $tstr  = "Attempt to delete non-existing object or " ;                  header("WWW-authenticate: basic realm=\"$realm\"") ;
1670                  $tstr .= "insufficient privileges: " ;                  header("HTTP/1.0 401 Unauthorized") ;
1671                    Error("401 Unauthorized","No trespassing !",0,1);
1672                  if ( $FN != "") {  // delete file          }
1673                          $path =  $fsDir . "/" . $FN ;  
1674                    
1675                          $dir=dirname($path);          // read mime.types
1676                          $file=basename($path);          readMime();
1677                          if (! file_exists("$dir/.del")) {  
1678                                  mkdir("$dir/.del",0700);          if (! isset($gblPermNote)) {
1679                          }                  $gblPermNote = trperm_r;
1680            }
1681  //                      if ( ! @unlink($path) ) {  
1682                          if ( ! rename($path,"$dir/.del/$file") ) {          HTTP_POST_VAR("FN");
1683                                  Error("File delete failed", $tstr . $path) ;  
1684                                  LogIt($path,"file delete failed");          if ($HTTP_SERVER_VARS["REQUEST_METHOD"] == "POST") {
1685                                  exit ;                  // take variables from server
1686                          } else {                  if (HTTP_POST_VAR("FN"))
1687                                  LogIt($path,"file deleted",trperm_w);                          check_filename($FN);
1688                                  MoveTo("$dir/.log/$file","$dir/.del/.log/");                  if (HTTP_POST_VAR("DIR")) {
1689                                  MoveTo("$dir/.note/$file","$dir/.del/.note/");                          check_dirname($DIR);
1690                                  MoveTo("$dir/.lock/$file","$dir/.del/.lock/");                          $relDir = $DIR;
1691                          }                  } else {
1692                  } else {  // delete directory                          trigger_error("Can't get DIR",E_USER_WARNING);
1693                          if ( ! @rrmdir($fsDir) ) {                          $relDir = "/";
1694                                  Error("Rmdir failed", $tstr . $fsDir) ;                  }
1695                          } else {                  if (HTTP_POST_VAR("RELPATH")) check_dirname($RELPATH);
1696                                  LogIt($path,"dir deleted",trperm_w);                  HTTP_POST_VAR("T");
1697                                  $relDir = dirname($relDir) ;  // move up                  HTTP_POST_VAR("CONFIRM");
1698                          }          } else {
1699                  }                  // get
1700                  break ;                  HTTP_GET_VAR("A");
1701                    if (HTTP_GET_VAR("D")) {
1702          case "UNDELETE" :                            check_dirname($D);
1703                  if ( $CONFIRM != "on" ) break ;                          $D=urldecode($D);
1704                            $relDir = $D;
1705                  if (substr($FN,0,4) != ".del") break ;                  } else {
1706                  $file=substr($FN,4,strlen($FN)-4);                          //trigger_error("Can't get D",E_USER_WARNING);
1707                            $relDir = "/";
1708                  LogIt("$fsDir/.del/$file","undeleted",trperm_w);                  }
1709                  MoveTo("$fsDir/.del/$file","$fsDir/");                  if (HTTP_GET_VAR("F")) check_filename($F);
1710                  MoveTo("$fsDir/.del/.log/$file","$fsDir/.log/");          }
1711                  MoveTo("$fsDir/.del/.note/$file","$fsDir/.note/");  
1712                  MoveTo("$fsDir/.del/.lock/$file","$fsDir/.lock/");          $relScriptDir = dirname($HTTP_SERVER_VARS["SCRIPT_NAME"]) ;    
1713            // i.e. /docman
1714                  break ;  
1715            // start on server root
1716          case "RENAME" :            $gblFsRoot = $gblRepositoryDir;
1717                  if ( $CONFIRM != "on" ) break ;          // i.e. /home/httpd/repository
1718    
1719                  LogIt("$fsDir/$FN","renamed $FN to $NEWNAME",trperm_r);          $fsDir = $gblFsRoot . $relDir ; // current directory
1720                  safe_rename($fsDir,$FN,$NEWNAME);          if ( !is_dir($fsDir) ) Error("Dir not found","Can't find <tt>$relDir</tt> which points to <tt>$fsDir</tt>",1) ;
1721                  break ;  
1722            if ($relDir == "") $relDir="/";
1723          case "NOTE" :    
1724                  WriteNote("$fsDir/$FN","$NOTE");          if (isset($HTTP_SERVER_VARS["HTTPS"]) && $HTTP_SERVER_VARS["HTTPS"] == "on") {
1725                  break ;                  $webRoot  = "https://";
1726            } else {
1727          case "UNLOCK" :                    $webRoot  = "http://";
1728                  if ( $CONFIRM != "on" ) break ;          }
1729                  Unlock("$fsDir/$FN");          $webRoot .= $HTTP_SERVER_VARS["HTTP_HOST"] . $relScriptDir;
1730                  break ;  
1731            if (HTTP_POST_VAR("POSTACTION")) switch ($POSTACTION) {
1732          default :          case "UPLOAD" :
1733                  // user hit "CANCEL" or undefined action                  $FN_name=stripSlashes($HTTP_POST_FILES["FN"]["tmp_name"]);
1734          }                  $FN=stripSlashes($HTTP_POST_FILES["FN"]["name"]);
1735                    if (!is_writeable($fsDir)) Error("Write denied",$relDir) ;
1736          // common to all POSTs : redirect to directory view ($relDir)  
1737          if ( $POSTACTION != "" ) {                  $source = $FN_name ;
1738                  $tstr = $PHP_SELF . "?D=" . urlencode($relDir) ;                  if (! file_exists($source)) {
1739                  header("Location: " . $tstr) ;                            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          }  
1742                            if (HTTP_POST_VAR("FILENAME")) check_filename($FILENAME);
1743          // check for mode.. navigate, code display, upload, or detail?  
1744          // $A=U : upload to path given in $D                  if (! isset($FILENAME)) {       // from update file
1745          // $A=E : display detail of file $D/$F and edit                          $target = "$fsDir/".basename($FN);
1746          // $A=C : display code in file $D/$F                  } else {
1747          // $A=Co : checkout file $D/$F                          $target = "$fsDir/$FILENAME";
1748          // $A=Ci : checkin file $D/$F                  }
1749          // $A=V : view file (do nothing except log)  
1750          // $A=I : include file .$F.php from $gblFsRoot                  if (! check_perm("$relDir/".basename($target), trperm_w))
1751          // default : display directory $D                          Error("Access denied","User <tt>$gblLogin</tt> tried to upload <tt>$relDir/".basename($target)."</tt> without valid trustee.",1);
1752    
1753          switch ($A) {                  // backup old files first
1754          case "U" :                  $dir=dirname($target);
1755                  // upload to $relDir                  if (! file_exists($dir."/.bak")) {
1756                  if (!is_writeable($gblFsRoot . $relDir))                          mkdir($dir."/.bak",0700);
1757                          Error("Write access denied",$relDir) ;                  }
1758                  $text  = "Use this page to upload a single " ;                  if (! file_exists($dir."/.bak/$gblNumBackups")) {
1759                  $text .= "file to <B>$HTTP_HOST</B>." ;                          mkdir($dir."/.bak/$gblNumBackups",0700);
1760                  StartHTML("(Upload Page)", $text) ;                  }
1761                  UploadPage($gblFsRoot, $relDir) ;                  $file=basename($target);
1762                  EndHTML() ;                  for($i=$gblNumBackups-1;$i>0;$i--) {
1763                  exit ;                          MoveTo("$dir/.bak/$i/$file","$dir/.bak/".($i+1)."/");
1764          case "E" :                  }
1765                  $F=stripSlashes($F);                  MoveTo($target,$dir."/.bak/1/");
1766                  // detail of $relDir/$F  
1767                  if (is_file("$gblFsRoot/$relDir/$F") || is_dir("$gblFsRoot/$relDir/$F")) DetailPage($gblFsRoot, $relDir, $F) ;                  copy($source,$target) ;
1768                  exit ;                  chmod($target,$gblFilePerms) ;
1769          case "C" :                  clearstatcache() ;
1770                  $F=stripSlashes($F);                  if (isset($FILENAME)) {
1771                  // listing of $relDir/$F                          LogIt($target,"check-in",trperm_r | trperm_w);
1772                  DisplayCode($gblFsRoot, $relDir, $F) ;                          Unlock($target);
1773                  exit ;                  } else {
1774          case "Co" :                          LogIt($target,"uploaded",trperm_r | trperm_w);
1775                  // checkout                  }
1776                  Lock("$gblFsRoot/$relDir/$F");                  break ;
1777                  Download("$gblFsRoot/$relDir/$F");  
1778                  exit;          case "SAVE" :
1779          case "Ci" :                  $path = $gblFsRoot . $RELPATH ;
1780                  $F=stripSlashes($F);                  $path=stripSlashes($path);
1781                  // upload && update to $relDir  
1782                  if (!is_writeable($gblFsRoot . $relDir))                  if (! check_perm("$RELPATH", trperm_w))
1783                          Error("Write access denied",$relDir) ;                          Error("Access denied","User <tt>$gblLogin</tt> tried to save <tt>$RELPATH</tt> without valid trustee.",1);
1784                  $text  = "Use this page to update a single " ;  
1785                  $text .= "file to <B>$HTTP_HOST</B>." ;                  $writable = is_writeable($path) ;
1786                  StartHTML("(Update file Page)", $text) ;                  $legaldir = is_writeable(dirname($path)) ;
1787                  UploadPage($gblFsRoot, $relDir, $F) ;                  $exists   = (file_exists($path)) ? 1 : 0 ;
1788                  EndHTML() ;                  // FIX: more verbose error message
1789                  exit ;                  if (!($writable || (!$exists && $legaldir)))
1790          case "V" :                          Error("Write denied",$RELPATH) ;
1791                  // view                  $fh = fopen($path, "w") ;
1792                  LogIt("$gblFsRoot/$relDir/$F","viewed");                  HTTP_POST_VAR("FILEDATA");
1793                  if ($gblForceDownload) {                  fwrite($fh,$FILEDATA) ;
1794                          Download("$gblFsRoot/$relDir/$F");                  fclose($fh) ;
1795                  } else {                  clearstatcache() ;
1796                          header("Content-Disposition: attachment; filename=$F" );                  LogIt($path,"saved changes",trperm_r);
1797                          Header("Location: $webRoot".urlpath("$relDir/$F"));                  break ;
1798                  }  
1799                  exit;          case "CREATE" :
1800          case "Ch" :                  // we know $fsDir exists
1801                  StartHTML("(File changes)","All changes chronologicaly...");                  if (! check_perm($relDir, trperm_w))
1802                  DisplayChangeLog(0);    // all                          Error("Write access denied","You don't have permission to write in <tt>$relDir</tt>");
1803                  EndHTML() ;                  if ($T == "D") $type = "directory";
1804                  exit;                  else $type ="file";
1805          case "Ch1" :                  if ($FN == "") Error("Can't create $type","You must enter name of $type to create it.");
1806                  StartHTML("(File changes)","Changes to files in last day...");                  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                  DisplayChangeLog(1);                  $path = "$fsDir/$FN";           // file or dir to create
1808                  EndHTML() ;                  $relPath = "$relDir/$FN";
1809                  exit;  
1810          case "I" :                  if (file_exists($path))
1811                  $F=stripSlashes($F);                          Error("Can't create $type","Object <tt>$relPath</tt> allready exists");
1812                  $inc_file="${gblFsRoot}/.${F}.php";  
1813                  if (!isset($F) || $F == "" || !file_exists($inc_file)) Error("Fatal error $inc_file"); // can't find file to include                  switch ( $T ) {
1814                  if (!is_readable($inc_file))                  case "D" :  // create a directory
1815                          Error("Read access to include file denied",".${F}.php");                          if ( ! @mkdir($path,$gblDirPerms) )
1816                  $text  = "Your include file should define \$text variable which holds this text and \$title variable which is page title";                                  Error("Mkdir failed",$relPath) ; // eg. if it exists
1817                  $title = "You should define \$title variable with page title";                          else
1818                  include($inc_file);                                  LogIt($path."/","dir created",trperm_w);
1819                  StartHTML($title, $text) ;                          clearstatcache() ;
1820                  print "<p>".GifIcon(up)." Back to <a href=$GLOBALS[PHP_SELF]>front page</a>.</p>";                          break ;
1821                  EndHTML() ;                  case "F" :  // create a new file
1822                  exit ;  // this functionality is doubled in DetailView().
1823          }  // better keep it here altogether
1824    // chmod perms to $gblFilePerms
1825          // default: display directory $relDir                          if ( file_exists($path) && !is_writeable($path) )
1826          Navigate($gblFsRoot,$relDir) ;                                    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          exit ;                          $fh = fopen($path, "w+") ;
1828                            if ($fh) {
1829          Error("Whooah!","By cartesian logic, this never happens",1) ;                                  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.3  
changed lines
  Added in v.1.37

  ViewVC Help
Powered by ViewVC 1.1.26