/[docman2]/docman.php
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /docman.php

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

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

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

  ViewVC Help
Powered by ViewVC 1.1.26