/[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.44 - (show annotations)
Thu Jun 21 08:54:54 2001 UTC (21 years, 7 months ago) by dpavlin
Branch: MAIN
Changes since 1.43: +7 -2 lines
new configuration option: gblHide which is a string (separated by ,) with
list of filenames or dirnames to hide

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

  ViewVC Help
Powered by ViewVC 1.1.26