/[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.31 - (show annotations)
Mon Jul 29 13:53:56 2002 UTC (21 years, 8 months ago) by dpavlin
Branch: MAIN
Changes since 1.30: +27 -66 lines
Note permission, more trustees, separation of php and html for detail page

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

  ViewVC Help
Powered by ViewVC 1.1.26