/[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.25 - (show annotations)
Mon Jul 29 10:17:53 2002 UTC (21 years, 8 months ago) by dpavlin
Branch: MAIN
Changes since 1.24: +41 -23 lines
better support for delete/undelte directories

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

  ViewVC Help
Powered by ViewVC 1.1.26