/[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.29 - (show annotations)
Mon Jul 29 12:34:18 2002 UTC (21 years, 9 months ago) by dpavlin
Branch: MAIN
Changes since 1.28: +9 -12 lines
show picture on datail page (by downloading it through docman.php),
show image icon for all pictures in $gblImages

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

  ViewVC Help
Powered by ViewVC 1.1.26