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

Legend:
Removed from v.1.12  
changed lines
  Added in v.1.39

  ViewVC Help
Powered by ViewVC 1.1.26