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

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

  ViewVC Help
Powered by ViewVC 1.1.26