/[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.49 - (show annotations)
Fri Dec 14 17:28:06 2001 UTC (21 years, 1 month ago) by dpavlin
Branch: MAIN
Changes since 1.48: +22 -1 lines
support for include php files. example: docman?A=I&F=foo will try to include
.foo.php from docman's repository root
fixed unnecessary parent icon

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

  ViewVC Help
Powered by ViewVC 1.1.26