/[docman]/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.42 - (show annotations)
Tue Jun 19 11:08:20 2001 UTC (22 years, 9 months ago) by dpavlin
Branch: MAIN
Changes since 1.41: +1 -1 lines
fixed bug with quotes (") in notes (as reported by Andreas.Kraft(at)t-systems.de)

1 <?php
2
3 /* Copyright 1999 by John Martin d/b/a www.ANYPORTAL.com */
4 /* All Rights Reserved. */
5 /* */
6 /* This software is freeware and is not in the public domain. */
7 /* You are hereby granted the right to freely distribute this */
8 /* software as long as this copyright notice remains in place. */
9 /* */
10 /* Comments or suggestions? email: andmore@alief.com */
11 /* */
12 /* This is the PHP port: AnyPortal(php)-0.1 */
13 /* ======================================== */
14 /* */
15 /* PHP version 2000 by Stefan@Wiesendanger.org */
16 /* No Rights Reserved. What for, anyhow ? */
17 /* */
18 /* Date Remarks */
19 /* --------- ----------------------------------------------- */
20 /* 25 MAY 99 original ASP version */
21 /* 17 SEP 99 change upload from SA-FILEUP to aspSmartUpload */
22 /* 10 APR 00 simplified PHP3 version */
23 /* 18 APR 00 most of PHP3 port working. Slight modifications */
24 /* 22 APR 00 modified syntax highlighting, no absolute paths */
25 /* revealed, PHP builtin authentication, global */
26 /* style sheet as callback, use apache default */
27 /* icons as an alternative to the wingdings font. */
28 /* 25 APR 00 catch some exceptions (not foolproof yet) */
29 /* 26 APR 00 catch some more exceptions, implicit copy */
30 /* function by saving somewhere else in the detail */
31 /* view, MD5 hashed password. */
32 /* 27 APR 00 Fixed authentication bug */
33 /* 12 MAY 00 Fixed trouble with exec() with newer versions of */
34 /* PHP3. Fixed bug which would send you to a non- */
35 /* existent address after file modifications. */
36
37 /*
38
39 This project is now called Directory Manager.
40
41 For more info, please see web pages at
42 http://www.rot13.org/~dpavlin/docman.html
43
44 It's relased under GPL by
45 Dobrica Pavlinusic <dpavlin@rot13.org>
46
47
48 IMPORTANT INSTALLATION NOTE:
49 deny serving of .* (dot-something) files in web server!
50 Otherwise, uses can access your log files, users and/or
51 deleted files!
52
53 .htusers is in form:
54 login:Real Name:[md5(loginpassword)|auth_*]:email@host.dom
55
56
57 TODO:
58 mixed file/directory output (add type to each entry,
59 real support for links)
60 access controll
61
62 */
63
64 //////////////////////////////////////////////////////////////////
65
66 // TODO : Don't let the file be modified itself. Create a hash of
67 // it (kinda hard since it's self-referential ;-). Make better use
68 // of session management. Escapeshellcmd for all user input.
69
70 //////////////////////////////////////////////////////////////////
71
72 // GLOBAL PARAMETERS
73 // =================
74 // Make modifications here to suit docman to your needs
75
76 // error_reporting(4) ; // how verbose ?
77
78 // from where to include auth_*.php modules?
79 $gblIncDir = "/home/httpd/docman";
80
81 // username/password should not be system
82 // usernames/passwords !!
83
84 $gblPw = "";
85
86 // date format
87 // $gblDateFmt="D, F d, Y";
88 $gblDateFmt="Y-m-d";
89
90 // time format
91 // $gblTimeFmt="g:i:sA";
92 $gblTimeFmt="H:i:s";
93
94 // Number of backup files to keep
95 $gblNumBackups=3;
96
97 // show red star if newer than ... days
98 $gblModDays=1;
99
100 // choose GifIcon below unless you have the M$
101 // WingDings font installed on your system
102
103 $gblIcon="GifIcon"; // MockIcon or GifIcon
104
105 // the directory below should be /icons/ or /icons/small/
106 // on Apache; a set of icons is included in the distribution
107
108 $gblIconLocation="/icons/";
109
110 // files you want to be able to edit in text mode
111 // and view with (primitive) syntax highlighting
112
113 $gblEditable = array( ".txt",".asa",".asp",".htm",".html",
114 ".cfm",".php3",".php",".phtml",
115 ".shtml",".css" ) ;
116
117 // files that will display as images on the detail page
118 // (useless if your browser doesn't support them)
119
120 $gblImages = array( ".jpg",".jpeg",".gif",".png",".ico",
121 ".bmp",".xbm") ;
122
123 //////////////////////////////////////////////////////////////////
124
125 function StartHTML($title,$text="") {
126
127 $title = "Document Manager " . $title ;
128 $host = $GLOBALS["HTTP_HOST"] ;
129 $self = $GLOBALS["PHP_SELF"] ;
130 ?>
131
132 <HTML>
133 <HEAD>
134 <TITLE><?= $host . " " . $title ?></TITLE>
135 <META NAME="description" CONTENT="PHP port of AnyPortal Site Manager">
136 <META NAME="keywords" CONTENT="site manager, web site maintenance">
137 <META NAME="robots" CONTENT="noindex">
138 <META HTTP-EQUIV="expires" CONTENT="0">
139 <LINK REL="stylesheet" TYPE="text/css"
140 HREF="<?= $self ?>?STYLE=get">
141 </HEAD>
142 <BODY BGCOLOR="#FFFFFF">
143 <H3 ALIGN="RIGHT"><?= $host ?></H3>
144 <TABLE BORDER=0 WIDTH="100%"><TR>
145 <TD CLASS=INV><?= $title ?></TD></TR></TABLE>
146 <P><?= $text ?></P>
147
148 <?php
149 } // end function StartHTML
150
151 //////////////////////////////////////////////////////////////////
152
153 function EndHTML() {
154 ?>
155
156 <HR>
157 <P CLASS=FTR>
158 <B><?= date($GLOBALS[gblDateFmt]) ?> -
159 <?= date($GLOBALS[gblTimeFmt]) ?> -
160 <?= $GLOBALS[gblUserName] ?>
161 <small> [<a href="<?= $GLOBALS["PHP_SELF"] ?>?relogin=<?= $GLOBALS[gblPw] ?>">logout</a>]</small>
162 </B>
163 <BR>ANYPORTAL(php) Site Manager
164 <br><small>
165 &copy; 1999 by <A HREF="http://www.anyportal.com">ANYPORTAL</A>,
166 &copy; 2000 by <A HREF="http://da.nger.org">d@nger.org</A>,
167 &copy; 2000 by <A HREF="http://www.rot13.org/~dpavlin/">DbP</A>
168 </small>
169 </P>
170 <BR>
171 <? //include(".debug.inc") ?>
172 <BR><BR></BODY></HTML>
173
174 <?php
175 } // end function EndHTML
176
177 //////////////////////////////////////////////////////////////////
178
179 function CSS() {
180 ?>
181
182 BODY,TD,P,H1,H2,H3 { font-family:Verdana,Helvetica,Arial,sans-serif; }
183 .BLK { color:black; }
184 .RED { color:red; }
185 .TOP { color:red; font-size:70%; } /* table headings */
186 .INV { color:white; background-color:navy;
187 font-weight:bold; font-size:120%; } /* title */
188 .FTR { } /* footer */
189 .LST { background-color:#E0E0E0; } /* table cells */
190 .BAR { background-color:#E0E0E0; } /* action bar */
191 PRE { color:blue; font-family:Lucida Console,Courier New,
192 Courier,sans-serif; } /* source code */
193 EM { color:green; font-style:normal; } /* line numbers */
194 .REM { color:silver; }
195 .XML { color:navy; background-color:yellow; }
196 .MCK { color:red; font-family:WingDings; } /* Mock Icons */
197 A:HOVER { color:red; }
198
199 <?php
200 } // end function CSS
201
202 //////////////////////////////////////////////////////////////////
203
204 function DetailPage($fsRoot,$relDir,$fn) {
205
206 global $gblEditable, $gblImages, $webRoot ;
207 $self = $GLOBALS["PHP_SELF"] ;
208
209 $relPath = $relDir . "/" . $fn ;
210 $fsPath = $fsRoot . $relPath ;
211 $fsDir = $fsRoot . $relDir ;
212
213 $exists = file_exists($fsPath) ;
214 $ext = strtolower(strrchr($relPath,".")) ;
215 $editable = ( $ext=="" || strstr(join(" ",$gblEditable),$ext)) ;
216 $writable = is_writeable($fsPath) ;
217 $file_lock = CheckLock($fsPath);
218
219 if (!$editable && !$exists)
220 Error("Creation unsupported for type",$relPath) ;
221 if (!exists && !is_writeable($fsDir) )
222 Error("Creation denied",$relDir) ;
223
224 $text = "Use this page to view, modify or " ;
225 if (is_dir($fsPath)) {
226 $text .="delete a directory on this " ;
227 } else {
228 $text .= "delete a single document on this " ;
229 };
230 $text .= "web site." ;
231 $title = "(Detail Page)" ;
232 StartHTML($title, $text) ;
233
234 echo "<H3>" . $relDir . "/" . $fn . "</H3>" ;
235 if ($exists) { // get file info
236 $fsize = filesize($fsPath) ;
237 $fmodified = date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]", filemtime($fsPath)) ;
238 $faccessed = date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]", fileatime($fsPath)) ;
239 $fuid=fileowner($fsPath);
240 $fgid=filegroup($fsPath);
241 $userinfo = posix_getpwuid($fuid);
242 $grpinfo = posix_getgrgid($fgid);
243 echo "<PRE>";
244 if (!is_dir($fsPath)) echo " file size: " . $fsize . " Bytes<BR>" ;
245 echo "last modified: <B>" . $fmodified . "</B><BR>" ;
246 echo "last accessed: <B>" . $faccessed . "</B><BR>" ;
247 echo " owner: <B>" . $userinfo["name"] . " [$fuid]</B><BR>" ;
248 echo " group: <B>" . $grpinfo["name"] . " [$fgid]</B><BR>" ;
249 echo " permissions: <B>" ;
250 echo printf( "%o", fileperms($fsPath) ) . "</B>" ;
251 echo "</PRE>" ;
252
253 }
254
255 if ( !is_dir($fsPath) && $editable && ($writable || !$exists) && !$file_lock ) {
256 $fh = fopen($fsPath,"a+") ;
257 rewind($fh) ;
258 $fstr = fread($fh,filesize($fsPath)) ;
259 fclose($fh) ;
260 $fstr = htmlentities( $fstr ) ;
261 ?>
262
263 <FORM ACTION="<?= $self ; ?>" METHOD="POST">
264 <SPAN TITLE="Click [SAVE] to store updated contents.">
265 <B>DOCUMENT CONTENTS</B>
266 </SPAN><BR>
267 <TEXTAREA NAME="FILEDATA" ROWS=18 COLS=70 WRAP="OFF"><?php
268 echo($fstr) ; ?></TEXTAREA>
269 <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ; ?>">
270 <INPUT TYPE="HIDDEN" NAME="FN" VALUE="<?= $fn ; ?>">
271 <INPUT TYPE="HIDDEN" NAME="POSTACTION" VALUE="SAVE">
272 <INPUT TYPE="HIDDEN" SIZE=48 MAXLENGTH=255 NAME="RELPATH"
273 VALUE="<?= $relPath ; ?>">
274 <br>
275 <INPUT TYPE="RESET" VALUE="UNDO ALL CHANGES">
276 <INPUT TYPE="SUBMIT" VALUE="SAVE">
277 </FORM>
278
279 <?php
280 }
281 if ( !$file_lock && $ext!="" && strstr(join(' ',$gblImages),$ext) ) {
282 $info = getimagesize($fsPath) ;
283 $tstr = "<IMG SRC=\"$webRoot".urlpath($relPath)."\" BORDER=0 " ;
284 $tstr .= $info[3] . " ALT=\"" . $fn . " - " ;
285 $tstr .= (int)(($fsize+1023)/1024) . "Kb\">" ;
286 // echo htmlentities($tstr) . "<BR><BR>" . $tstr ;
287 echo $tstr ;
288 }
289
290 ?>
291
292 <FORM ACTION="<?= $self ; ?>" METHOD="POST">
293 <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ; ?>">
294 <INPUT TYPE="HIDDEN" NAME="FN" VALUE="<?= $fn ; ?>">
295 <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="CANCEL"><BR>
296
297 <?php
298
299 if ($file_lock) {
300 ?>
301 <hr>
302 <SPAN TITLE="Check OK and click UNLOCK to remove lock on file.">
303 <B>OK TO FORCE LOCK REMOVAL ON "<?= $fn ; ?>" HELD BY <?= $file_lock ?>? </B></SPAN>
304 <INPUT TYPE="CHECKBOX" NAME="CONFIRM">
305 <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="UNLOCK">
306 <?
307 } // file_lock
308
309 if (substr($fn,0,4) == ".del") {
310 $action="UNDELETE";
311 $desc="undelete previously deleted file";
312 } else {
313 $action="DELETE";
314 $desc="delete";
315 }
316
317 if ($exists && $writable) {
318 ?>
319
320 <HR>
321 <a name="undelete">
322 <SPAN TITLE="Check OK and click [<?= $action ?>] to <?= $desc ?>.">
323 <B>OK TO <?= $action ?> "<?= $fn ; ?>"? </B></SPAN>
324 <INPUT TYPE="CHECKBOX" NAME="CONFIRM">
325 <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="<?= $action ?>">
326
327 <HR>
328 <a name="rename">
329 <SPAN TITLE="Check OK and click [RENAME] to rename.">
330 <B>OK TO RENAME "<?= $fn ; ?>" TO
331 <INPUT TYPE="TEXT" SIZE=24 MAXLENGTH=255 NAME="NEWNAME" VALUE="<?= $fn ?>">
332 ? </B></SPAN>
333 <INPUT TYPE="CHECKBOX" NAME="CONFIRM">
334 <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="RENAME">
335
336 <?php
337 } // exists && writable
338 ?>
339 <HR>
340 <a name="note">
341 <B>NOTE FOR "<?= $fn ; ?>":
342 <INPUT TYPE="TEXT" SIZE=50 MAXLENGTH=255 NAME="NOTE" VALUE="<?= ReadNote($fsPath) ?>">
343 </B></SPAN>
344 <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="NOTE">
345
346 </FORM>
347
348 <?php
349
350 $name=basename("$fsDir/$fn");
351 $logname=dirname("$fsDir/$fn")."/.log/$name";
352 $bakdir=dirname("$fsDir/$fn")."/.bak";
353 if (file_exists($logname)) {
354 $log=fopen($logname,"r");
355 $cl1=" class=LST"; $cl2="";
356 $logarr = array();
357 while($line = fgetcsv($log,255,"\t")) {
358 $cl=$cl1; $cl1=$cl2; $cl2=$cl;
359 array_unshift($logarr,array($cl,$line[0],$line[1],$line[2],$line[3]));
360 }
361 fclose($log);
362 if (is_dir("$fsDir/$fn")) {
363 $whatis="DIRECTORY";
364 } else {
365 $whatis="FILE";
366 }
367 print "<hr><br><b>CHANGES TO THIS $whatis</b><br><table border=0 width=100%>\n";
368 $bakcount = 0; // start from 0, skip fist backup (it's current)
369 while ($e = array_shift($logarr)) {
370 if (strstr($e[4],"upload")) {
371 if (file_exists("$bakdir/$bakcount/$name")) {
372 $e[4]="<a href=\"$webRoot".urlpath(dirname($relPath)."/.bak/$bakcount/$name")."\">$e[4]</a>";
373 }
374 $bakcount++;
375 }
376 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";
377 }
378 print "</table>";
379 }
380
381 EndHTML() ;
382
383 } // end function DetailPage
384
385 //////////////////////////////////////////////////////////////////
386
387 function DisplayCode($fsRoot,$relDir,$fn) {
388
389 $path = $fsRoot . $relDir . "/" . $fn ;
390
391 if (!file_exists($path)) Error("File not found",$path) ;
392
393 StartHTML("(".$relDir."/".$fn.")","");
394
395 $tstr = join("",file($path)) ;
396 $tstr = htmlentities($tstr) ;
397
398 // Tabs
399 $tstr = str_replace(chr(9)," ",$tstr) ;
400
401 // ASP tags & XML/PHP tags
402 $aspbeg = "<SPAN CLASS=XML>&lt;%</SPAN><SPAN CLASS=BLK>" ;
403 $aspend = "</SPAN><SPAN CLASS=XML>%&gt;</SPAN>" ;
404 $tstr = str_replace("&lt;%",$aspbeg,$tstr) ;
405 $tstr = str_replace("%&gt;",$aspend,$tstr) ;
406
407 $xmlbeg = "<SPAN CLASS=XML>&lt;?</SPAN><SPAN CLASS=BLK>" ;
408 $xmlend = "</SPAN><SPAN CLASS=XML>?&gt;</SPAN>" ;
409 $tstr = str_replace("&lt;?",$xmlbeg,$tstr) ;
410 $tstr = str_replace("?&gt;",$xmlend,$tstr) ;
411
412 // C style comment
413 $tstr = str_replace("/*","<SPAN CLASS=REM>/*",$tstr) ;
414 $tstr = str_replace("*/","*/</SPAN>",$tstr) ;
415
416 // HTML comments
417 $tstr = str_replace("&lt;!--","<I CLASS=RED>&lt;!--",$tstr) ;
418 $tstr = str_replace("--&gt;","--&gt;</I>",$tstr) ;
419
420 echo "<PRE>" ;
421
422 $tstr = split("\n",$tstr) ;
423 for ($i = 0 ; $i < sizeof($tstr) ; ++$i) {
424 // add line numbers
425 echo "<BR><EM>" ;
426 echo substr(("000" . ($i+1)), -4) . ":</EM> " ;
427 $line = $tstr[$i] ;
428 // C++ style comments
429 $pos = strpos($line,"//") ;
430 // exceptions: two slashes aren't a script comment
431 if (strstr($line,"//") &&
432 ! ($pos>0 && substr($line,$pos-1,1)==":") &&
433 ! (substr($line,$pos,8) == "//--&gt;") &&
434 ! (substr($line,$pos,9) == "// --&gt;")) {
435 $beg = substr($line,0,strpos($line,"//")) ;
436 $end = strstr($line,"//") ;
437 $line = $beg."<SPAN CLASS=REM>".$end."</SPAN>";
438 }
439 // shell & asp style comments
440 $first = substr(ltrim($line),0,1) ;
441 if ($first == "#" || $first == "'") {
442 $line = "<SPAN CLASS=REM>".$line."</SPAN>";
443 }
444 print($line) ;
445 } // next i
446
447 echo "</PRE>" ;
448
449 EndHTML() ;
450
451 } // end function DisplayCode
452
453 //////////////////////////////////////////////////////////////////
454
455 function MockIcon($txt) {
456 $tstr = "<SPAN CLASS=MCK>" ;
457
458 switch (strtolower($txt)) {
459 case ".bmp" :
460 case ".gif" :
461 case ".jpg" :
462 case ".jpeg":
463 case ".tif" :
464 case ".tiff":
465 $d = 176 ;
466 break ;
467 case ".doc" :
468 $d = 50 ;
469 break ;
470 case ".exe" :
471 case ".bat" :
472 $d = 255 ;
473 break ;
474 case ".bas" :
475 case ".c" :
476 case ".cc" :
477 case ".src" :
478 $d = 255 ;
479 break ;
480 case "file" :
481 $d = 51 ;
482 break ;
483 case "fldr" :
484 $d = 48 ;
485 break ;
486 case ".htm" :
487 case ".html":
488 case ".asa" :
489 case ".asp" :
490 case ".cfm" :
491 case ".php3":
492 case ".php" :
493 case ".phtml" :
494 case ".shtml" :
495 $d = 182 ;
496 break ;
497 case ".pdf" :
498 $d = 38 ;
499 break;
500 case ".txt" :
501 case ".ini" :
502 $d = 52 ;
503 break ;
504 case ".xls" :
505 $d = 252 ;
506 break ;
507 case ".zip" :
508 case ".arc" :
509 case ".sit" :
510 case ".tar" :
511 case ".gz" :
512 case ".tgz" :
513 case ".Z" :
514 $d = 59 ;
515 break ;
516 case "view" :
517 $d = 52 ;
518 break ;
519 case "up" :
520 $d = 199 ;
521 break ;
522 case "blank" :
523 return "&nbsp;&nbsp;</SPAN>" ;
524 break ;
525 default :
526 $d = 51 ;
527 }
528
529 return $tstr . chr($d) . "</SPAN>" ;
530 } // end function MockIcon
531
532 //////////////////////////////////////////////////////////////////
533
534 function GifIcon($txt) {
535 global $gblIconLocation ;
536
537 switch (strtolower($txt)) {
538 case ".bmp" :
539 case ".gif" :
540 case ".jpg" :
541 case ".jpeg":
542 case ".tif" :
543 case ".tiff":
544 $d = "image2.gif" ;
545 break ;
546 case ".doc" :
547 $d = "layout.gif" ;
548 break ;
549 case ".exe" :
550 case ".bat" :
551 $d = "screw2.gif" ;
552 break ;
553 case ".bas" :
554 case ".c" :
555 case ".cc" :
556 case ".src" :
557 $d = "c.gif" ;
558 break ;
559 case "file" :
560 $d = "generic.gif" ;
561 break ;
562 case "fldr" :
563 $d = "dir.gif" ;
564 break ;
565 case ".phps" :
566 $d = "phps.gif" ;
567 break ;
568 case ".php3" :
569 $d = "php3.gif" ;
570 break ;
571 case ".htm" :
572 case ".html":
573 case ".asa" :
574 case ".asp" :
575 case ".cfm" :
576 case ".php3":
577 case ".php" :
578 case ".phtml" :
579 case ".shtml" :
580 $d = "world1.gif" ;
581 break ;
582 case ".pdf" :
583 $d = "pdf.gif" ;
584 break;
585 case ".txt" :
586 case ".ini" :
587 $d = "text.gif" ;
588 break ;
589 case ".xls" :
590 $d = "box2.gif" ;
591 break ;
592 case ".zip" :
593 case ".arc" :
594 case ".sit" :
595 case ".tar" :
596 case ".gz" :
597 case ".tgz" :
598 case ".Z" :
599 $d = "compressed.gif" ;
600 break ;
601 case "view" :
602 $d = "index.gif" ;
603 break ;
604 case "up" :
605 $d = "back.gif" ;
606 break ;
607 case "blank" :
608 $d = "blank.gif" ;
609 break ;
610 case "checkout":
611 $d = "box2.gif";
612 break;
613 case "checkin":
614 $d = "hand.up.gif";
615 break;
616 case "locked":
617 $d = "screw2.gif";
618 break;
619 case "note":
620 $d = "quill.gif";
621 break;
622 default :
623 $d = "generic.gif" ;
624 }
625
626 return "<IMG SRC=\"$gblIconLocation" . $d . "\" BORDER=0>" ;
627 } // end function GifIcon
628
629 //////////////////////////////////////////////////////////////////
630
631 function Navigate($fsRoot,$relDir) {
632
633 global $gblEditable, $gblIcon, $gblModDays, $webRoot ;
634
635 $self = $GLOBALS["PHP_SELF"] ;
636
637 $fsDir = $fsRoot . $relDir . "/" ; // current directory
638
639 if (!is_dir($fsDir)) Error("Dir not found",$relDir) ;
640
641 // read directory contents
642 if ( !($dir = @opendir($fsDir)) )
643 Error("Read Access denied",$relDir) ;
644 while ($item = readdir($dir)) {
645 if ( $item == ".." || $item == "." || substr($item,0,1) == "." ) continue ;
646 if ( is_dir($fsDir . $item) ) {
647 $dirList[] = $item ;
648 } else if ( is_file($fsDir . $item) ) {
649 $fileList[] = $item ;
650 } else if ( is_link($fsDir . $item) ) {
651 $dirList[] = $item ;
652 } else {
653 // unknown file type
654 // $text = "Could not determine file type of " ;
655 // Error("File Error", $text.$relDir."/".$item) ;
656 // exit ;
657 }
658 }
659 closedir($dir) ;
660
661 // scan deleted files
662 if ( $GLOBALS[show_deleted] == 1 && ($dir = @opendir("$fsDir/.del")) ) {
663 while ($item = readdir($dir)) {
664 if ( substr($item,0,1) == "." ) continue ;
665 $fileList[] = ".del/$item" ;
666 }
667 closedir($dir) ;
668 }
669
670 $emptyDir = ! (sizeof($dirList) || sizeof($fileList)) ;
671
672 // start navigation page
673 $text = "Use this page to add, delete";
674 if (! isset($show_deleted)) {
675 $text .= ", <a href=$self?D=".urlencode($relDir)."&show_deleted=1>undelete</a>";
676 }
677 $text .= " or revise files on this web site." ;
678 $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>.";
679 StartHTML("(Navigate)",$text) ;
680
681 echo "<TABLE BORDER=0 CELLPADDING=2
682 CELLSPACING=3 WIDTH=\"100%\">" ;
683
684 // updir bar
685 if ($fsDir != $fsRoot) {
686 $parent = dirname($relDir) ;
687 if ($parent == "") $parent = "/" ;
688 ?>
689
690 <TR><TD><?= $gblIcon("up") ?></TD><TD COLSPAN=5 CLASS=LST>
691 <A HREF="<?= $self ?>?D=<?= urlencode($parent) ?>">
692 <B><?= $parent ?></B></A></TD></TR>
693
694 <?php
695 }
696
697 function plural($name,$count) {
698 $out="$count $name";
699 if ($count > 1) {
700 $out.="s";
701 }
702 return $out;
703 }
704
705 // output subdirs
706 if (sizeof($dirList) > 0) {
707 sort($dirList) ;
708 ?>
709
710 <TR><TD></TD><TD COLSPAN=2 CLASS=TOP>DIRECTORY NAME (<?= plural("dir",sizeof($dirList)) ?>)</TD><TD COLSPAN=3 CLASS=TOP>DIRECTORY NOTE</TR>
711
712 <?php
713 while (list($key,$dir) = each($dirList)) {
714
715 $info_url=$self."?A=E&F=".urlencode($dir)."&D=".urlencode($relDir);
716 $tstr = "<A HREF=\"" . $self . "?D=" ;
717 $tstr .= urlencode($relDir."/".$dir) ;
718 $tstr .= "\">" . $dir . "/</A>" ;
719 $note_html="<a href=\"$info_url#note\">".$gblIcon("note")."</a>".ReadNote($fsDir.$dir);
720 ?>
721
722 <TR><TD>
723 <A HREF="<?= $info_url ?>" TITLE="View/Edit">
724 <?= $gblIcon("fldr") ?></A></TD>
725 <TD COLSPAN=2 CLASS=LST><?= $tstr ?></TD>
726 <TD COLSPAN=3 CLASS=LST><?= $note_html ?></TD></TR>
727
728 <?php
729 } // iterate over dirs
730 } // end if no dirs
731 ?>
732
733 <TR><TD></TD><TD COLSPAN=5><HR><B><?= $webRoot . $relDir ?>
734 </B></TD></TR>
735 <TR><TD></TD><TD CLASS=TOP>DOCUMENT NAME (<?= plural("file",sizeof($fileList)) ?>)</TD>
736 <TD><?= $gblIcon("blank").$gblIcon("blank") ?></TD>
737 <TD CLASS=TOP>NOTE</TD>
738 <TD CLASS=TOP>LAST UPDATE</TD><TD CLASS=TOP>FILE SIZE</TD></TR>
739
740 <?php
741 if (sizeof($fileList) > 0) {
742 sort($fileList) ;
743 while (list($key,$file) = each($fileList)) {
744 $path = $fsDir."/".$file ;
745 $mod = filemtime($path) ;
746 $sz = filesize($path) ;
747
748 if ($sz >= 10240) {
749 $sz = (int)(($sz+1023)/1024) . " k" ;
750 } else {
751 $sz .= " " ;
752 } // end size
753
754 $a = $b = "" ;
755
756 $info_url=$self."?A=E&F=".urlencode($file)."&D=".urlencode($relDir);
757
758 if ( ($mod + $gblModDays*86400) > time() ) {
759 $a = "<SPAN CLASS=RED TITLE=\"Newer" ;
760 $a .= " than $gblModDays days\"> * </SPAN>" ;
761 }
762
763 $file_lock=CheckLock($path);
764
765 $file_url_html="<A HREF=\"$self?A=V&F=".urlencode($file);
766 $file_url_html.="&D=".urlencode($relDir);
767 $file_url_html.="\" TITLE=\"View file\">" ;
768
769 if (substr($file,0,5) != ".del/") {
770 $file_url_html .= $file . "</A>" . $a ;
771 } else {
772 $file_url_html .= substr($file,5,strlen($file)-5) . "</a> <SPAN CLASS=RED TITLE=\"deleted\"> <a href=\"$info_url#undelete\">deleted</a> </span>";
773 }
774
775 $note_html="<a href=\"$info_url#note\">".$gblIcon("note")."</a>".ReadNote($path);
776
777 $ext = strtolower(strrchr($file,".")) ;
778
779 if ($file_lock) {
780 if ($file_lock == $GLOBALS[gblUserName]) {
781 $b.="<A HREF=\"$self?A=Ci&F=".urlencode($file);
782 $b.="&D=".urlencode($relDir);
783 $b.="\" TITLE=\"Checkin (update) file on server\">" ;
784 $file_url_html=$b;
785 $b.=$gblIcon("checkin")."</A>" ;
786 $b.= $gblIcon("blank");
787 $file_url_html.="$file</a> $a";
788 $note_html = $gblIcon("blank")."<b>Please check-in (update) this file</b>";
789 } else {
790 $b = $gblIcon("locked");
791 $b.= $gblIcon("blank");
792 $note_html = $gblIcon("blank")."<b>File locked by $file_lock</b>";
793 $file_url_html = "$file $a";
794 }
795 } else {
796 $b.="<A HREF=\"$self?A=Co&F=".urlencode($file);
797 $b.="&D=".urlencode($relDir);
798 $b.="\" TITLE=\"Checkout file for edit\">" ;
799 $b.=$gblIcon("checkout")."</A>" ;
800
801 if ( $ext=="" || strstr(join(" ",$gblEditable),$ext) ) {
802 $b.="<A HREF=\"$self?A=C&F=".urlencode($file);
803 $b.="&D=".urlencode($relDir);
804 $b.="\" TITLE=\"List contents\">" ;
805 $b.=$gblIcon("view")."</A>" ;
806 } else {
807 $b.= $gblIcon("blank");
808 }
809 }
810
811
812 ?>
813
814 <TR><TD>
815 <A HREF="<?= $info_url ?>" TITLE="View/Edit">
816 <?= $gblIcon($ext) ?></A></TD>
817 <TD CLASS=LST><?= $file_url_html ?></TD>
818 <TD CLASS=LST ALIGN=center><?= $b ?></TD>
819 <TD CLASS=LST ALIGN=left><?= $note_html ?></TD>
820 <TD CLASS=LST><?= date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]",$mod) ?></TD>
821 <TD CLASS=LST><?= $sz ?>Bytes</TD></TR>
822
823 <?php
824 } // iterate over files
825 } else { // end if no files
826 ?>
827 <TR><TD></TD><TD COLSPAN=5 CLASS=LST>
828 No files in this directory
829 </TD></TR>
830 <?
831 }
832
833 if ($emptyDir) {
834 ?>
835
836 <FORM METHOD="POST" ACTION="<?= $self ?>">
837 <TR><TD></TD><TD COLSPAN=5 CLASS=BAR>
838 <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ?>">
839 OK TO DELETE THIS EMPTY FOLDER?
840 <INPUT TYPE="CHECKBOX" NAME="CONFIRM">
841 <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="DELETE">
842 </TD></TR>
843 </FORM>
844
845 <?php
846 } // end if emptyDir
847 ?>
848
849 <TR><TD></TD><TD COLSPAN=5><HR></TD></TR>
850
851 <?
852 if (file_exists(".info.inc")) {
853 print "<TR><TD></TD><TD COLSPAN=5>";
854 include(".info.inc");
855 print "</TD></TR>
856 <TR><TD></TD><TD COLSPAN=5><HR></TD></TR>";
857 }
858 ?>
859
860 <FORM METHOD="POST" ACTION="<?= $self ?>">
861 <TR><TD></TD><TD COLSPAN=5 CLASS=BAR>CREATE NEW
862 <INPUT TYPE="RADIO" NAME="T" VALUE="D" CHECKED>DIRECTORY -OR-
863 <INPUT TYPE="RADIO" NAME="T" VALUE="F">FILE : &nbsp;&nbsp;
864 <NOBR>NAME <INPUT TYPE="TEXT" NAME="FN" SIZE=14>
865 <INPUT TYPE="HIDDEN" NAME="POSTACTION" VALUE="CREATE">
866 <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ?>">
867 <INPUT TYPE="SUBMIT" VALUE="CREATE" NAME="CREATE">
868 </NOBR>
869 <NOBR>OR <A HREF="<?= $self ?>?A=U&D=<?= urlencode($relDir) ?>">UPLOAD</A> A FILE
870 </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 $self = $GLOBALS["PHP_SELF"] ;
884 if ($relDir == "") $relDir = "/" ;
885 ?>
886
887 <P><TABLE BORDER=0 CELLPADDING=5><TR><TD WIDTH=5></TD><TD CLASS=BAR>
888 <FORM ENCTYPE="multipart/form-data" METHOD="POST"
889 ACTION="<?= $self ?>">
890 DESTINATION DIRECTORY:<B><?= " " . $relDir ?></B>
891 <? if (isset($filename) && $filename!="") { ?>
892 <br>DESTINATION FILE:<B><?= " " . $filename ?></B>
893 <INPUT TYPE="HIDDEN" NAME="FILENAME" VALUE="<?= $filename ?>">
894 <? } ?>
895 <P>PATHNAME OF LOCAL FILE<BR>
896 <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ?>">
897 <INPUT TYPE="HIDDEN" NAME="POSTACTION" VALUE="UPLOAD">
898 <INPUT SIZE=30 TYPE="FILE" NAME="FN"></P>
899 <P><INPUT TYPE="SUBMIT" VALUE="UPLOAD"></P>
900 <P>If the <B>[BROWSE...]</B> button is not displayed,<BR>
901 you must upgrade to an RFC1867-compliant browser.</P>
902 <P>Your browser:<BR><?= $GLOBALS["HTTP_USER_AGENT"] ?></P>
903 </FORM>
904 </TD></TR>
905 <TR><TD></TD><TD>
906 <FORM METHOD="POST" ACTION="<?= $self ?>">
907 <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ?>"><BR>
908 <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="CANCEL">
909 </FORM>
910 </TD></TR></TABLE></P>
911
912 <?php
913 } // end function UploadPage
914
915 //////////////////////////////////////////////////////////////////
916
917 function Error($title,$text="") {
918 StartHTML("(".$title.")",$text) ;
919 echo "<P ALIGN=center>Hit your Browser's Back Button.</P>" ;
920 EndHTML() ;
921 exit ;
922 } // end function Error
923
924 //////////////////////////////////////////////////////////////////
925
926 function NoEntry() {
927
928 $user = $GLOBALS["PHP_AUTH_USER"] ;
929 $pw = $GLOBALS["PHP_AUTH_PW"] ;
930 $self = $GLOBALS["PHP_SELF"] ;
931
932 $title = "(401 Unauthorized)" ;
933 $text = "No trespassing !" ;
934 StartHTML($title,$text) ;
935
936 EndHTML() ;
937 exit ;
938 }
939
940 //////////////////////////////////////////////////////////////////
941
942 function LogIt($target,$msg) {
943
944 $dir=dirname($target);
945 if (! file_exists($dir."/.log")) {
946 mkdir($dir."/.log",0700);
947 }
948 $file=basename($target);
949
950 $log=fopen("$dir/.log/$file","a+");
951 fputs($log,date("$GLOBALS[gblDateFmt]\t$GLOBALS[gblTimeFmt]").
952 "\t$GLOBALS[gblUserName]\t$msg\n");
953 fclose($log);
954
955 }
956
957
958 //////////////////////////////////////////////////////////////////
959
960 function WriteNote($target,$msg) {
961
962 $target=stripSlashes($target);
963 $dir=dirname($target);
964 if (! file_exists($dir."/.note")) {
965 mkdir($dir."/.note",0700);
966 }
967 $file=basename($target);
968
969 $note=fopen("$dir/.note/$file","w");
970 fputs($note,"$msg\n");
971 fclose($note);
972
973 Logit($target,"added note $msg");
974
975 }
976
977 function ReadNote($target) {
978
979 $target=stripSlashes($target);
980 $dir=dirname($target);
981 $file=basename($target);
982 $msg="";
983 if (file_exists($dir."/.note/$file")) {
984 $note=fopen("$dir/.note/$file","r");
985 $msg=fgets($note,4096);
986 fclose($note);
987 }
988 return HtmlSpecialChars(StripSlashes($msg));
989
990 }
991
992 //////////////////////////////////////////////////////////////////
993
994 function MoveTo($source,$folder) {
995
996 $source=stripSlashes($source);
997 $file=basename($source);
998 if (! file_exists($folder)) {
999 mkdir($folder,0700);
1000 }
1001 if (file_exists($source)) {
1002 rename($source,"$folder/$file");
1003 }
1004 }
1005
1006 //////////////////////////////////////////////////////////////////
1007
1008 function Lock($target) {
1009
1010 $target=stripSlashes($target);
1011 $dir=dirname($target);
1012 if (! file_exists($dir."/.lock")) {
1013 mkdir($dir."/.lock",0700);
1014 }
1015 $file=basename($target);
1016
1017 if (file_exists("$dir/.lock/$file")) {
1018 Logit($target,"attempt to locked allready locked file!");
1019 } else {
1020 $lock=fopen("$dir/.lock/$file","w");
1021 fputs($lock,"$GLOBALS[gblUserName]\n");
1022 fclose($lock);
1023
1024 Logit($target,"file locked");
1025 }
1026
1027 }
1028
1029 function CheckLock($target) {
1030
1031 $target=stripSlashes($target);
1032 $dir=dirname($target);
1033 $file=basename($target);
1034 $msg=0;
1035 if (file_exists($dir."/.lock/$file")) {
1036 $lock=fopen("$dir/.lock/$file","r");
1037 $msg=fgets($lock,4096);
1038 fclose($lock);
1039 }
1040 return chop($msg);
1041
1042 }
1043
1044 function Unlock($target) {
1045
1046 $target=stripSlashes($target);
1047 $dir=dirname($target);
1048 $file=basename($target);
1049 if (file_exists($dir."/.lock/$file")) {
1050 unlink("$dir/.lock/$file");
1051 Logit($target,"file unlocked");
1052 } else {
1053 Logit($target,"attempt to unlocked non-locked file!");
1054 }
1055
1056 }
1057
1058 //////////////////////////////////////////////////////////////////
1059
1060 function urlpath($url) {
1061 $url=urlencode(StripSlashes("$url"));
1062 $url=str_replace("%2F","/",$url);
1063 $url=str_replace("+","%20",$url);
1064 return($url);
1065 }
1066
1067 //////////////////////////////////////////////////////////////////
1068
1069 function safe_rename($fromdir,$fromfile,$tofile) {
1070 function try_rename($from,$to) {
1071 # print "$from -> $to\n";
1072 if (file_exists($from) && is_writeable(dirname($to))) {
1073 rename($from,$to);
1074 }
1075 }
1076
1077 function try_dir($todir) {
1078 if (! file_exists($todir)) {
1079 mkdir($todir,0700);
1080 }
1081 }
1082
1083 $to="$fromdir/$tofile";
1084 $todir=dirname($to);
1085 $tofile=basename($to);
1086
1087 # print "<pre>$fromdir / $fromfile -> $todir / $tofile\n\n";
1088
1089 try_rename("$fromdir/$fromfile","$todir/$tofile");
1090 try_dir("$todir/.log");
1091 try_rename("$fromdir/.log/$fromfile","$todir/.log/$tofile");
1092 try_dir("$todir/.note");
1093 try_rename("$fromdir/.note/$fromfile","$todir/.note/$tofile");
1094 try_dir("$todir/.lock");
1095 try_rename("$fromdir/.lock/$fromfile","$todir/.lock/$tofile");
1096 try_dir("$todir/.bak");
1097 for($i=0;$i<=$GLOBALS[gblNumBackups];$i++) {
1098 try_rename("$fromdir/.bak/$i/$fromfile","$todir/.bak/$i/$tofile");
1099 }
1100 }
1101
1102
1103 //////////////////////////////////////////////////////////////////
1104
1105 // recursivly delete directory
1106
1107 function rrmdir($dir) {
1108 $handle=opendir($dir);
1109 while ($file = readdir($handle)) {
1110 if ($file != "." && $file != "..") {
1111 if (is_dir("$dir/$file"))
1112 rrmdir("$dir/$file");
1113 else
1114 if (! @unlink("$dir/$file")) return(0);
1115 }
1116 }
1117 closedir($handle);
1118 return @rmdir($dir);
1119 }
1120
1121 //////////////////////////////////////////////////////////////////
1122
1123 function ChangeLog($target,$msg) {
1124
1125 global $gblFsRoot;
1126 $log=fopen("$gblFsRoot/.changelog","a+");
1127 if (substr($target,0,strlen($gblFsRoot)) == $gblFsRoot)
1128 $target=substr($target,strlen($gblFsRoot),strlen($target)-strlen($gblFsRoot));
1129 fputs($log,time()."\t$target\t$GLOBALS[gblUserName]\t$msg\n");
1130 fclose($log);
1131
1132 }
1133
1134 function DisplayChangeLog($day) {
1135
1136 global $gblFsRoot;
1137 if (!file_exists("$gblFsRoot/.changelog")) return;
1138 $log=fopen("$gblFsRoot/.changelog","r");
1139 $logarr = array();
1140 while($line = fgetcsv($log,255,"\t")) {
1141 if ($day!=1 || ($day==1 && (time()-$line[0] < 24*60*60))) {
1142 array_unshift($logarr,array($line[0],$line[1],$line[2],$line[3]));
1143 }
1144 }
1145 fclose($log);
1146 $cl1=" class=LST"; $cl2="";
1147 print "<table border=0 width=100%>\n";
1148 while ($e = array_shift($logarr)) {
1149 $cl=$cl1; $cl1=$cl2; $cl2=$cl;
1150 $date = date("$GLOBALS[gblDateFmt]", $e[0]);
1151 $time = date("$GLOBALS[gblTimeFmt]", $e[0]);
1152 $dir = dirname($e[1]);
1153 $file = basename($e[1]);
1154 print "<tr><td$cl>$date</td><td$cl>$time</td><td$cl><a href=\"$GLOBALS[PHP_SELF]?D=".urlencode($dir)."\">$dir</a>/$file</td><td$cl>$e[2]</td><td$cl>$e[3]</td></tr>\n";
1155 }
1156 print "</table>";
1157 print "<p>".GifIcon(up)." Back to <a href=$GLOBALS[PHP_SELF]>front page</a>.</p>";
1158 }
1159
1160 //////////////////////////////////////////////////////////////////
1161
1162 // MAIN PROGRAM
1163 // ============
1164 // query parameters: capital letters
1165 // local functions : begin with capital letters
1166 // global constants: begin with gbl
1167
1168 $gblFilePerms = 0640 ; // default for new files
1169 $gblDirPerms = 0750 ; // default for new dirs
1170
1171 // phpinfo() ;
1172 // exit ;
1173
1174 // forks before authentication: style sheet and hash
1175 // creation if password not yet set.
1176 if ($STYLE == "get") { CSS() ; exit ; }
1177
1178 $htusers_file=dirname($SCRIPT_FILENAME)."/.htusers";
1179 if (! file_exists($htusers_file)) {
1180 if (is_writeable(dirname($SCRIPT_FILENAME))) {
1181 $htusers=fopen($htusers_file,"a+");
1182 fputs($htusers,"# Change owner of $htusers_file to root !!\n");
1183 fputs($htusers,"demo:full name:[md5_hash|auth_*]:e-mail\n");
1184 fclose($htusers);
1185 Error("Proto user file created!","Please edit <tt>$htusers_file</tt> and set it correct permissions (<B>not writable by web server as it is now!</b>). You can add users using <tt>adduser.pl</tt> script!");
1186 exit;
1187 } else {
1188 Error("Can't create proto user file!","Please make directory <tt>".dirname($htusers_file)."</tt> writable or create <tt>.htusers</tt> file by hand using <tt>adduser.pl</tt> script!");
1189 exit;
1190 }
1191 }
1192 $htusers=fopen($htusers_file,"r");
1193 while($user = fgetcsv($htusers,255,":")) {
1194 if ($user[0] == $GLOBALS["PHP_AUTH_USER"]) {
1195 $gblUserName=$user[1];
1196 $gblPw=$user[2];
1197 if (substr($gblPw,0,5) == "auth_" && file_exists("$gblIncDir/$gblPw.php")) {
1198 require("$gblIncDir/$gblPw.php");
1199 if ($gblPw($user)) {
1200 $gblPw=md5($PHP_AUTH_USER.$PHP_AUTH_PW);
1201 } else {
1202 $gblPw="error".md5($PHP_AUTH_USER.$PHP_AUTH_PW);
1203 }
1204 }
1205 $gblEmail=$user[3];
1206 continue ;
1207 }
1208 }
1209 fclose($htusers);
1210
1211 // authentication failure
1212 if ( md5($PHP_AUTH_USER.$PHP_AUTH_PW) != $gblPw ||
1213 isset($relogin) && $gblPw == $relogin ) {
1214 header("WWW-authenticate: basic realm=\"$HTTP_HOST\"") ;
1215 header("HTTP/1.0 401 Unauthorized") ;
1216 NoEntry() ;
1217 exit ;
1218 }
1219
1220 // get current directory relative to $gblFsRoot
1221 $relDir = $DIR ; // from POST
1222 if ($relDir == "") { // not defined in POST ?
1223 $relDir = urldecode($D) ; // then use GET
1224 }
1225
1226 $relDir=stripSlashes($relDir);
1227
1228 if ($relDir == "/") $relDir = "" ;
1229 // default : website root = ""
1230
1231 if (strstr($relDir,"..")) Error("No updirs allowed");
1232
1233 // full paths contain "fs" or "Fs". Paths realitve to root of
1234 // website contain "rel" or "Rel". The script won't let you
1235 // edit anything above directory equal to http://server.com
1236 // i.e. below $gblFsRoot.
1237
1238 $relScriptDir = dirname($SCRIPT_NAME) ;
1239 // i.e. /docman
1240
1241 $fsScriptDir = dirname($SCRIPT_FILENAME) ;
1242 // i.e. /home/httpd/html/docman
1243
1244 // start on server root
1245 // $gblFsRoot = substr($fsScriptDir,0, strlen($fsScriptDir)-strlen($relScriptDir)) ;
1246 // or on script root
1247 $gblFsRoot = $fsScriptDir;
1248 // i.e. /home/httpd/html
1249
1250 $fsDir = $gblFsRoot . $relDir ; // current directory
1251 if ( !is_dir($fsDir) ) Error("Dir not found",$relDir) ;
1252
1253 if (isset($GLOBALS["HTTPS"]) && $GLOBALS["HTTPS"] == "on") {
1254 $webRoot = "https://";
1255 } else {
1256 $webRoot = "http://";
1257 }
1258 $webRoot .= $GLOBALS["HTTP_HOST"] . $relScriptDir;
1259
1260 $FN=stripSlashes($FN);
1261
1262 if (file_exists("$fsScriptDir/.docman.conf")) {
1263 include("$fsScriptDir/.docman.conf");
1264 }
1265
1266 switch ($POSTACTION) {
1267 case "UPLOAD" :
1268 if (!is_writeable($fsDir)) Error("Write denied",$relDir) ;
1269 if (strstr($FN_name,"/"))
1270 Error("Non-conforming filename") ;
1271 // TODO : should rather check for escapeshellcmds
1272 // but maybe RFC 18xx asserts safe filenames ....
1273 $source = $FN ;
1274 if (! file_exists($source)) {
1275 Error("You must select file with browse to upload it!");
1276 }
1277 if (! isset($FILENAME)) { // from update file
1278 $target = "$fsDir/$FN_name" ;
1279 } else {
1280 $target = "$fsDir/$FILENAME";
1281 }
1282
1283 // backup old files first
1284 $dir=dirname($target);
1285 if (! file_exists($dir."/.bak")) {
1286 mkdir($dir."/.bak",0700);
1287 }
1288 if (! file_exists($dir."/.bak/$GLOBALS[gblNumBackups]")) {
1289 mkdir($dir."/.bak/$GLOBALS[gblNumBackups]",0700);
1290 }
1291 $file=basename($target);
1292 for($i=$GLOBALS[gblNumBackups]-1;$i>0;$i--) {
1293 MoveTo("$dir/.bak/$i/$file","$dir/.bak/".($i+1)."/");
1294 }
1295 MoveTo($target,$dir."/.bak/1/");
1296
1297 copy($source,$target) ;
1298 chmod($target,$gblFilePerms) ;
1299 clearstatcache() ;
1300 Logit($target,"uploaded");
1301 if (isset($FILENAME)) {
1302 Unlock($target);
1303 }
1304 ChangeLog($target,"updated");
1305 break ;
1306
1307 case "SAVE" :
1308 $path = $gblFsRoot . $RELPATH ;
1309 $path=stripSlashes($path);
1310 $writable = is_writeable($path) ;
1311 $legaldir = is_writeable(dirname($path)) ;
1312 $exists = (file_exists($path)) ? 1 : 0 ;
1313 // check for legal extension here as well
1314 if (!($writable || (!$exists && $legaldir)))
1315 Error("Write denied",$RELPATH) ;
1316 $fh = fopen($path, "w") ;
1317 $FILEDATA=stripSlashes($FILEDATA);
1318 fwrite($fh,$FILEDATA) ;
1319 fclose($fh) ;
1320 clearstatcache() ;
1321 Logit($path,"saved changes");
1322 ChangeLog($path,"saved changes");
1323 break ;
1324
1325 case "CREATE" :
1326 // we know $fsDir exists
1327 if ($FN == "") break; // no filename!
1328 if (!is_writeable($fsDir)) Error("Write denied",$relDir) ;
1329 $path = $fsDir . "/" . $FN ; // file or dir to create
1330 $relPath = $relDir . "/" . $FN ;
1331 switch ( $T ) {
1332 case "D" : // create a directory
1333 if ( ! @mkdir($path,$gblDirPerms) )
1334 Error("Mkdir failed",$relPath) ; // eg. if it exists
1335 clearstatcache() ;
1336 break ;
1337 case "F" : // create a new file
1338 // this functionality is doubled in DetailView().
1339 // better keep it here altogether
1340 // chmod perms to $gblFilePerms
1341 if ( file_exists($path) && !is_writeable($path) )
1342 Error("File not writable", $relPath) ;
1343 $fh = fopen($path, "w+") ;
1344 if ($fh) {
1345 fputs($fh,"\n");
1346 fclose($fh) ;
1347 LogIt($path,"file created");
1348 } else {
1349 Error("Creation of file $relPath failed -- $path");
1350 }
1351 $tstr = "$PHP_SELF?A=E&D=".urlencode($relDir)."&F=".urlencode($FN) ;
1352 header("Location: " . $tstr) ;
1353 ChangeLog($target,"created");
1354 exit ;
1355 }
1356 break ;
1357
1358 case "DELETE" :
1359 if ( $CONFIRM != "on" ) break ;
1360
1361 $tstr = "Attempt to delete non-existing object or " ;
1362 $tstr .= "insufficient privileges: " ;
1363
1364 if ( $FN != "") { // delete file
1365 $path = $fsDir . "/" . $FN ;
1366
1367 $dir=dirname($path);
1368 $file=basename($path);
1369 if (! file_exists("$dir/.del")) {
1370 mkdir("$dir/.del",0700);
1371 }
1372
1373 // if ( ! @unlink($path) ) {
1374 if ( ! rename($path,"$dir/.del/$file") ) {
1375 Error("File delete failed", $tstr . $path) ;
1376 Logit($path,"file delete failed");
1377 exit ;
1378 } else {
1379 Logit($path,"file deleted");
1380 MoveTo("$dir/.log/$file","$dir/.del/.log/");
1381 MoveTo("$dir/.note/$file","$dir/.del/.note/");
1382 MoveTo("$dir/.lock/$file","$dir/.del/.lock/");
1383 }
1384 }
1385 else { // delete directory
1386 if ( ! @rrmdir($fsDir) ) {
1387 Error("Rmdir failed", $tstr . $fsDir) ;
1388 }
1389 else {
1390 $relDir = dirname($relDir) ; // move up
1391 }
1392 }
1393 break ;
1394
1395 case "UNDELETE" :
1396 if ( $CONFIRM != "on" ) break ;
1397
1398 if (substr($FN,0,4) != ".del") break ;
1399 $file=substr($FN,4,strlen($FN)-4);
1400
1401 Logit("$fsDir/.del/$file","undeleted");
1402 MoveTo("$fsDir/.del/$file","$fsDir/");
1403 MoveTo("$fsDir/.del/.log/$file","$fsDir/.log/");
1404 MoveTo("$fsDir/.del/.note/$file","$fsDir/.note/");
1405 MoveTo("$fsDir/.del/.lock/$file","$fsDir/.lock/");
1406
1407 break ;
1408
1409 case "RENAME" :
1410 if ( $CONFIRM != "on" ) break ;
1411
1412 Logit("$fsDir/$FN","renamed $FN to $NEWNAME");
1413 safe_rename($fsDir,$FN,$NEWNAME);
1414 break ;
1415
1416 case "NOTE" :
1417 WriteNote("$fsDir/$FN","$NOTE");
1418 break ;
1419
1420 case "UNLOCK" :
1421 if ( $CONFIRM != "on" ) break ;
1422 Unlock("$fsDir/$FN");
1423 break ;
1424
1425 default :
1426 // user hit "CANCEL" or undefined action
1427 }
1428
1429 // common to all POSTs : redirect to directory view ($relDir)
1430 if ( $POSTACTION != "" ) {
1431 $tstr = $PHP_SELF . "?D=" . urlencode($relDir) ;
1432 header("Location: " . $tstr) ;
1433 exit ;
1434 }
1435
1436 // check for mode.. navigate, code display, upload, or detail?
1437 // $A=U : upload to path given in $D
1438 // $A=E : display detail of file $D/$F and edit
1439 // $A=C : display code in file $D/$F
1440 // $A=Co : checkout file $D/$F
1441 // $A=Ci : checkin file $D/$F
1442 // $A=V : view file (do nothing except log)
1443 // default : display directory $D
1444
1445 switch ($A) {
1446 case "U" :
1447 // upload to $relDir
1448 if (!is_writeable($gblFsRoot . $relDir))
1449 Error("Write access denied",$relDir) ;
1450 $text = "Use this page to upload a single " ;
1451 $text .= "file to <B>$HTTP_HOST</B>." ;
1452 StartHTML("(Upload Page)", $text) ;
1453 UploadPage($gblFsRoot, $relDir) ;
1454 EndHTML() ;
1455 exit ;
1456 case "E" :
1457 $F=stripSlashes($F);
1458 // detail of $relDir/$F
1459 if (is_file("$gblFsRoot/$relDir/$F") || is_dir("$gblFsRoot/$relDir/$F")) DetailPage($gblFsRoot, $relDir, $F) ;
1460 exit ;
1461 case "C" :
1462 $F=stripSlashes($F);
1463 // listing of $relDir/$F
1464 DisplayCode($gblFsRoot, $relDir, $F) ;
1465 exit ;
1466 case "Co" :
1467 // checkout
1468 Lock("$gblFsRoot/$relDir/$F");
1469 header("Content-Disposition: attachment; filename=$F" );
1470 Header("Location: $webRoot".urlpath("$relDir/$F"));
1471 exit;
1472 case "Ci" :
1473 $F=stripSlashes($F);
1474 // upload && update to $relDir
1475 if (!is_writeable($gblFsRoot . $relDir))
1476 Error("Write access denied",$relDir) ;
1477 $text = "Use this page to update a single " ;
1478 $text .= "file to <B>$HTTP_HOST</B>." ;
1479 StartHTML("(Update file Page)", $text) ;
1480 UploadPage($gblFsRoot, $relDir, $F) ;
1481 EndHTML() ;
1482 exit ;
1483 case "V" :
1484 // view
1485 LogIt("$gblFsRoot/$relDir/$F","viewed");
1486 header("Content-Disposition: attachment; filename=$F" );
1487 Header("Location: $webRoot".urlpath("$relDir/$F"));
1488 exit;
1489 case "Ch" :
1490 StartHTML("(File changes)","All changes chronologicaly...");
1491 DisplayChangeLog(0); // all
1492 EndHTML() ;
1493 exit;
1494 case "Ch1" :
1495 StartHTML("(File changes)","Changes to files in last day...");
1496 DisplayChangeLog(1);
1497 EndHTML() ;
1498 exit;
1499 }
1500
1501 // default: display directory $relDir
1502 Navigate($gblFsRoot,$relDir) ;
1503 exit ;
1504
1505 Error("Whooah!","By cartesian logic, this never happens") ;
1506 ?>

  ViewVC Help
Powered by ViewVC 1.1.26