/[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.24 - (show annotations)
Tue Oct 10 14:32:07 2000 UTC (22 years, 4 months ago) by dpavlin
Branch: MAIN
Changes since 1.23: +14 -21 lines
start in script directory (and not on server root)

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

  ViewVC Help
Powered by ViewVC 1.1.26