/[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.32 - (show annotations)
Mon Jul 29 14:17:05 2002 UTC (21 years, 8 months ago) by dpavlin
Branch: MAIN
Changes since 1.31: +38 -54 lines
more php/html separation, sorting works again

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

  ViewVC Help
Powered by ViewVC 1.1.26