/[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

Contents of /docman.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.19 - (show annotations)
Sun Jul 28 17:31:03 2002 UTC (21 years, 8 months ago) by dpavlin
Branch: MAIN
Changes since 1.18: +109 -72 lines
numerous changes to enable working with turned E_ALL which also squashed
many bugs all over the place, especially in trustee code

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

  ViewVC Help
Powered by ViewVC 1.1.26