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

  ViewVC Help
Powered by ViewVC 1.1.26