/[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.27 - (show annotations)
Thu Dec 21 08:46:18 2000 UTC (23 years, 3 months ago) by dpavlin
Branch: MAIN
Changes since 1.26: +2 -2 lines
fixed class capitalization which confuses Mozilla

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["HTTP_HOST"] ;
645 } else {
646 $webRoot = "http://" . $GLOBALS["HTTP_HOST"] ;
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 } else { // end if no files
824 ?>
825 <TR><TD></TD><TD COLSPAN=5 CLASS=LST>
826 No files in this directory
827 </TD></TR>
828 <?
829 }
830
831 if ($emptyDir) {
832 ?>
833
834 <FORM METHOD="POST" ACTION="<?= $self ?>">
835 <TR><TD></TD><TD COLSPAN=5 CLASS=BAR>
836 <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ?>">
837 OK TO DELETE THIS EMPTY FOLDER?
838 <INPUT TYPE="CHECKBOX" NAME="CONFIRM">
839 <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="DELETE">
840 </TD></TR>
841 </FORM>
842
843 <?php
844 } // end if emptyDir
845 ?>
846
847 <TR><TD></TD><TD COLSPAN=5><HR></TD></TR>
848
849 <?
850 if (file_exists(".info.inc")) {
851 print "<TR><TD></TD><TD COLSPAN=5>";
852 include(".info.inc");
853 print "</TD></TR>
854 <TR><TD></TD><TD COLSPAN=5><HR></TD></TR>";
855 }
856 ?>
857
858 <FORM METHOD="POST" ACTION="<?= $self ?>">
859 <TR><TD></TD><TD COLSPAN=5 CLASS=BAR>CREATE NEW
860 <INPUT TYPE="RADIO" NAME="T" VALUE="D" CHECKED>DIRECTORY -OR-
861 <INPUT TYPE="RADIO" NAME="T" VALUE="F">FILE : &nbsp;&nbsp;
862 <NOBR>NAME <INPUT TYPE="TEXT" NAME="FN" SIZE=14>
863 <INPUT TYPE="HIDDEN" NAME="POSTACTION" VALUE="CREATE">
864 <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ?>">
865 <INPUT TYPE="SUBMIT" VALUE="CREATE"></NOBR>
866 <NOBR>OR <A HREF="<?= $self ?>?A=U&D=<?= urlencode($relDir) ?>">UPLOAD</A> A FILE
867 </NOBR>
868 </TD></TR>
869 </FORM>
870 </TABLE>
871
872 <?php
873 EndHTML() ;
874 } // end function Navigate
875
876 //////////////////////////////////////////////////////////////////
877
878 function UploadPage($fsRoot, $relDir, $filename="") {
879
880 $self = $GLOBALS["PHP_SELF"] ;
881 if ($relDir == "") $relDir = "/" ;
882 ?>
883
884 <P><TABLE BORDER=0 CELLPADDING=5><TR><TD WIDTH=5></TD><TD CLASS=BAR>
885 <FORM ENCTYPE="multipart/form-data" METHOD="POST"
886 ACTION="<?= $self ?>">
887 DESTINATION DIRECTORY:<B><?= " " . $relDir ?></B>
888 <? if (isset($filename) && $filename!="") { ?>
889 <br>DESTINATION FILE:<B><?= " " . $filename ?></B>
890 <INPUT TYPE="HIDDEN" NAME="FILENAME" VALUE="<?= $filename ?>">
891 <? } ?>
892 <P>PATHNAME OF LOCAL FILE<BR>
893 <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ?>">
894 <INPUT TYPE="HIDDEN" NAME="POSTACTION" VALUE="UPLOAD">
895 <INPUT SIZE=30 TYPE="FILE" NAME="FN"></P>
896 <P><INPUT TYPE="SUBMIT" VALUE="UPLOAD"></P>
897 <P>If the <B>[BROWSE...]</B> button is not displayed,<BR>
898 you must upgrade to an RFC1867-compliant browser.</P>
899 <P>Your browser:<BR><?= $GLOBALS["HTTP_USER_AGENT"] ?></P>
900 </FORM>
901 </TD></TR>
902 <TR><TD></TD><TD>
903 <FORM METHOD="POST" ACTION="<?= $self ?>">
904 <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ?>"><BR>
905 <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="CANCEL">
906 </FORM>
907 </TD></TR></TABLE></P>
908
909 <?php
910 } // end function UploadPage
911
912 //////////////////////////////////////////////////////////////////
913
914 function Error($title,$text="") {
915 StartHTML("(".$title.")",$text) ;
916 echo "<P ALIGN=center>Hit your Browser's Back Button.</P>" ;
917 EndHTML() ;
918 exit ;
919 } // end function Error
920
921 //////////////////////////////////////////////////////////////////
922
923 function CreateHash($user, $pw) {
924
925 global $gblHash ; // hash function to use
926
927 if ($user == "" || $pw == "") {
928 $text = "either no password or no username supplied" ;
929 Error("Create Hash",$text) ;
930 }
931 $title = "(Create Hash)" ;
932 StartHTML($title) ;
933 echo "<P ALIGN=center>" ;
934 echo "<BLOCKQUOTE>Copy the value below and paste it " ;
935 echo "into the<BR>value for \$gblPw in the source of " ;
936 echo "this file<BR><BR><B>" . $gblHash($user.$pw) ;
937 echo "</B><BR><BR>Hash function: " . $gblHash ;
938 echo "</BLOCKQUOTE></P>" ;
939 EndHTML() ;
940 exit ;
941
942 } // end function CreateHash
943
944 //////////////////////////////////////////////////////////////////
945
946 function NoEntry() {
947
948 $user = $GLOBALS["PHP_AUTH_USER"] ;
949 $pw = $GLOBALS["PHP_AUTH_PW"] ;
950 $self = $GLOBALS["PHP_SELF"] ;
951
952 $title = "(401 Unauthorized)" ;
953 $text = "No trespassing !" ;
954 StartHTML($title,$text) ;
955 ?>
956
957 <FORM ACTION="<?= $self ?>?HASH=create" METHOD="POST">
958 <INPUT TYPE="HIDDEN" NAME="USER" VALUE="<?= $user ?>">
959 <INPUT TYPE="HIDDEN" NAME="PW" VALUE="<?= $pw ?>">
960
961 <BLOCKQUOTE><B>If you are a site administrator:</B><BR><BR>
962 Click below to <B>generate a password hash</B><BR>from
963 the username-password pair you just<BR>entered. Then include the hash in
964 the source<BR>of this file.<BR><BR>
965 <INPUT TYPE="SUBMIT" VALUE="CREATE HASH">
966 </BLOCKQUOTE></FORM>
967
968 <?php
969 EndHTML() ;
970 exit ;
971 }
972
973 //////////////////////////////////////////////////////////////////
974
975 function LogIt($target,$msg) {
976
977 $dir=dirname($target);
978 if (! file_exists($dir."/.log")) {
979 mkdir($dir."/.log",0700);
980 }
981 $file=basename($target);
982
983 $log=fopen("$dir/.log/$file","a+");
984 fputs($log,date("$GLOBALS[gblDateFmt]\t$GLOBALS[gblTimeFmt]").
985 "\t$GLOBALS[gblUserName]\t$msg\n");
986 fclose($log);
987
988 }
989
990
991 //////////////////////////////////////////////////////////////////
992
993 function WriteNote($target,$msg) {
994
995 $target=stripSlashes($target);
996 $dir=dirname($target);
997 if (! file_exists($dir."/.note")) {
998 mkdir($dir."/.note",0700);
999 }
1000 $file=basename($target);
1001
1002 $note=fopen("$dir/.note/$file","w");
1003 fputs($note,"$msg\n");
1004 fclose($note);
1005
1006 Logit($target,"added note $msg");
1007
1008 }
1009
1010 function ReadNote($target) {
1011
1012 $target=stripSlashes($target);
1013 $dir=dirname($target);
1014 $file=basename($target);
1015 $msg="";
1016 if (file_exists($dir."/.note/$file")) {
1017 $note=fopen("$dir/.note/$file","r");
1018 $msg=fgets($note,4096);
1019 fclose($note);
1020 }
1021 return StripSlashes($msg);
1022
1023 }
1024
1025 //////////////////////////////////////////////////////////////////
1026
1027 function MoveTo($source,$folder) {
1028
1029 $source=stripSlashes($source);
1030 $file=basename($source);
1031 if (! file_exists($folder)) {
1032 mkdir($folder,0700);
1033 }
1034 if (file_exists($source)) {
1035 rename($source,"$folder/$file");
1036 }
1037 }
1038
1039 //////////////////////////////////////////////////////////////////
1040
1041 function Lock($target) {
1042
1043 $target=stripSlashes($target);
1044 $dir=dirname($target);
1045 if (! file_exists($dir."/.lock")) {
1046 mkdir($dir."/.lock",0700);
1047 }
1048 $file=basename($target);
1049
1050 if (file_exists("$dir/.lock/$file")) {
1051 Logit($target,"attempt to locked allready locked file!");
1052 } else {
1053 $lock=fopen("$dir/.lock/$file","w");
1054 fputs($lock,"$GLOBALS[gblUserName]\n");
1055 fclose($lock);
1056
1057 Logit($target,"file locked");
1058 }
1059
1060 }
1061
1062 function CheckLock($target) {
1063
1064 $target=stripSlashes($target);
1065 $dir=dirname($target);
1066 $file=basename($target);
1067 $msg=0;
1068 if (file_exists($dir."/.lock/$file")) {
1069 $lock=fopen("$dir/.lock/$file","r");
1070 $msg=fgets($lock,4096);
1071 fclose($lock);
1072 }
1073 return chop($msg);
1074
1075 }
1076
1077 function Unlock($target) {
1078
1079 $target=stripSlashes($target);
1080 $dir=dirname($target);
1081 $file=basename($target);
1082 if (file_exists($dir."/.lock/$file")) {
1083 unlink("$dir/.lock/$file");
1084 Logit($target,"file unlocked");
1085 } else {
1086 Logit($target,"attempt to unlocked non-locked file!");
1087 }
1088
1089 }
1090
1091 //////////////////////////////////////////////////////////////////
1092
1093 function urlpath($url) {
1094 $url=urlencode(StripSlashes("$url"));
1095 $url=str_replace("%2F","/",$url);
1096 $url=str_replace("+","%20",$url);
1097 return($url);
1098 }
1099
1100 //////////////////////////////////////////////////////////////////
1101
1102 function safe_rename($from,$to) {
1103 if (file_exists($from) && is_writable(dirname($to))) {
1104 rename($from,$to);
1105 }
1106 }
1107
1108 //////////////////////////////////////////////////////////////////
1109
1110 // recursivly delete directory
1111
1112 function rrmdir($dir) {
1113 $handle=opendir($dir);
1114 while ($file = readdir($handle)) {
1115 if ($file != "." && $file != "..") {
1116 if (is_dir("$dir/$file"))
1117 rrmdir("$dir/$file");
1118 else
1119 if (! @unlink("$dir/$file")) return(0);
1120 }
1121 }
1122 closedir($handle);
1123 return @rmdir($dir);
1124 }
1125
1126 //////////////////////////////////////////////////////////////////
1127
1128 function ChangeLog($target,$msg) {
1129
1130 global $gblFsRoot;
1131 $log=fopen("$gblFsRoot/.changelog","a+");
1132 if (substr($target,0,strlen($gblFsRoot)) == $gblFsRoot)
1133 $target=substr($target,strlen($gblFsRoot),strlen($target)-strlen($gblFsRoot));
1134 fputs($log,time()."\t$target\t$GLOBALS[gblUserName]\t$msg\n");
1135 fclose($log);
1136
1137 }
1138
1139 function DisplayChangeLog($day) {
1140
1141 global $gblFsRoot;
1142 if (!file_exists("$gblFsRoot/.changelog")) return;
1143 $log=fopen("$gblFsRoot/.changelog","r");
1144 $logarr = array();
1145 while($line = fgetcsv($log,255,"\t")) {
1146 if ($day!=1 || ($day==1 && (time()-$line[0] < 24*60*60))) {
1147 array_unshift($logarr,array($line[0],$line[1],$line[2],$line[3]));
1148 }
1149 }
1150 fclose($log);
1151 $cl1=" class=LST"; $cl2="";
1152 print "<table border=0 width=100%>\n";
1153 while ($e = array_shift($logarr)) {
1154 $cl=$cl1; $cl1=$cl2; $cl2=$cl;
1155 $date = date("$GLOBALS[gblDateFmt]", $e[0]);
1156 $time = date("$GLOBALS[gblTimeFmt]", $e[0]);
1157 $dir = dirname($e[1]);
1158 $file = basename($e[1]);
1159 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";
1160 }
1161 print "</table>";
1162 print "<p>".GifIcon(up)." Back to <a href=$GLOBALS[PHP_SELF]>front page</a>.</p>";
1163 }
1164
1165 //////////////////////////////////////////////////////////////////
1166
1167 // MAIN PROGRAM
1168 // ============
1169 // query parameters: capital letters
1170 // local functions : begin with capital letters
1171 // global constants: begin with gbl
1172
1173 $gblFilePerms = 0640 ; // default for new files
1174 $gblDirPerms = 0750 ; // default for new dirs
1175
1176 // phpinfo() ;
1177 // exit ;
1178
1179 // forks before authentication: style sheet and hash
1180 // creation if password not yet set.
1181 if ($STYLE == "get") { CSS() ; exit ; }
1182 if ($HASH != "") {
1183 CreateHash($USER, $PW) ;
1184 exit ;
1185 }
1186
1187 // authentication if $gblAuth == true
1188 if ( $gblAuth && $gblHash($PHP_AUTH_USER.$PHP_AUTH_PW) != $gblPw ||
1189 isset($relogin) && $gblPw == $relogin ) {
1190 header("WWW-authenticate: basic realm=\"$HTTP_HOST\"") ;
1191 header("HTTP/1.0 401 Unauthorized") ;
1192 NoEntry() ;
1193 exit ;
1194 }
1195
1196 // get current directory relative to $gblFsRoot
1197 $relDir = $DIR ; // from POST
1198 if ($relDir == "") { // not defined in POST ?
1199 $relDir = urldecode($D) ; // then use GET
1200 }
1201
1202 if ($relDir == "/") $relDir = "" ;
1203 // default : website root = ""
1204
1205 if (strstr($relDir,"..")) Error("No updirs allowed");
1206
1207 // full paths contain "fs" or "Fs". Paths realitve to root of
1208 // website contain "rel" or "Rel". The script won't let you
1209 // edit anything above directory equal to http://server.com
1210 // i.e. below $gblFsRoot.
1211
1212 $relScriptDir = dirname($SCRIPT_NAME) ;
1213 // i.e. /docman
1214
1215 $fsScriptDir = dirname($SCRIPT_FILENAME) ;
1216 // i.e. /home/httpd/html/docman
1217
1218 // start on server root
1219 // $gblFsRoot = substr($fsScriptDir,0, strlen($fsScriptDir)-strlen($relScriptDir)) ;
1220 // or on script root
1221 $gblFsRoot = $fsScriptDir;
1222 // i.e. /home/httpd/html
1223
1224 $fsDir = $gblFsRoot . $relDir ; // current directory
1225 if ( !is_dir($fsDir) ) Error("Dir not found",$relDir) ;
1226
1227 $FN=stripSlashes($FN);
1228
1229 switch ($POSTACTION) {
1230 case "UPLOAD" :
1231 if (!is_writeable($fsDir)) Error("Write denied",$relDir) ;
1232 if (strstr($FN_name,"/"))
1233 Error("Non-conforming filename") ;
1234 // TODO : should rather check for escapeshellcmds
1235 // but maybe RFC 18xx asserts safe filenames ....
1236 $source = $FN ;
1237 if (! file_exists($source)) {
1238 Error("You must select file with browse to upload it!");
1239 }
1240 if (! isset($FILENAME)) { // from update file
1241 $target = "$fsDir/$FN_name" ;
1242 } else {
1243 $target = "$fsDir/$FILENAME";
1244 }
1245
1246 // backup old files first
1247 $dir=dirname($target);
1248 if (! file_exists($dir."/.bak")) {
1249 mkdir($dir."/.bak",0700);
1250 }
1251 if (! file_exists($dir."/.bak/$GLOBALS[gblNumBackups]")) {
1252 mkdir($dir."/.bak/$GLOBALS[gblNumBackups]",0700);
1253 }
1254 $file=basename($target);
1255 for($i=$GLOBALS[gblNumBackups]-1;$i>0;$i--) {
1256 MoveTo("$dir/.bak/$i/$file","$dir/.bak/".($i+1)."/");
1257 }
1258 MoveTo($target,$dir."/.bak/1/");
1259
1260 copy($source,$target) ;
1261 chmod($target,$gblFilePerms) ;
1262 clearstatcache() ;
1263 Logit($target,"uploaded");
1264 if (isset($FILENAME)) {
1265 Unlock($target);
1266 }
1267 ChangeLog($target,"updated");
1268 break ;
1269
1270 case "SAVE" :
1271 $path = $gblFsRoot . $RELPATH ;
1272 $path=stripSlashes($path);
1273 $writable = is_writeable($path) ;
1274 $legaldir = is_writeable(dirname($path)) ;
1275 $exists = (file_exists($path)) ? 1 : 0 ;
1276 // check for legal extension here as well
1277 if (!($writable || (!$exists && $legaldir)))
1278 Error("Write denied",$RELPATH) ;
1279 $fh = fopen($path, "w") ;
1280 $FILEDATA=stripSlashes($FILEDATA);
1281 fwrite($fh,$FILEDATA) ;
1282 fclose($fh) ;
1283 clearstatcache() ;
1284 Logit($path,"saved changes");
1285 ChangeLog($path,"saved changes");
1286 break ;
1287
1288 case "CREATE" :
1289 // we know $fsDir exists
1290 if ($FN == "") break; // no filename!
1291 if (!is_writeable($fsDir)) Error("Write denied",$relDir) ;
1292 $path = $fsDir . "/" . $FN ; // file or dir to create
1293 $relPath = $relDir . "/" . $FN ;
1294 switch ( $T ) {
1295 case "D" : // create a directory
1296 if ( ! @mkdir($path,$gblDirPerms) )
1297 Error("Mkdir failed",$relPath) ; // eg. if it exists
1298 clearstatcache() ;
1299 break ;
1300 case "F" : // create a new file
1301 // this functionality is doubled in DetailView().
1302 // better keep it here altogether
1303 // chmod perms to $gblFilePerms
1304 if ( file_exists($path) && !is_writable($path) )
1305 Error("File not writable", $relPath) ;
1306 $fh = fopen($path, "w+") ;
1307 if ($fh) {
1308 fputs($fh,"\n");
1309 fclose($fh) ;
1310 LogIt($path,"file created");
1311 } else {
1312 Error("Creation of file $relPath failed -- $path");
1313 }
1314 $tstr = "$PHP_SELF?A=E&D=".urlencode($relDir)."&F=".urlencode($FN) ;
1315 header("Location: " . $tstr) ;
1316 ChangeLog($target,"created");
1317 exit ;
1318 }
1319 break ;
1320
1321 case "DELETE" :
1322 if ( $CONFIRM != "on" ) break ;
1323
1324 $tstr = "Attempt to delete non-existing object or " ;
1325 $tstr .= "insufficient privileges: " ;
1326
1327 if ( $FN != "") { // delete file
1328 $path = $fsDir . "/" . $FN ;
1329
1330 $dir=dirname($path);
1331 $file=basename($path);
1332 if (! file_exists("$dir/.del")) {
1333 mkdir("$dir/.del",0700);
1334 }
1335
1336 // if ( ! @unlink($path) ) {
1337 if ( ! rename($path,"$dir/.del/$file") ) {
1338 Error("File delete failed", $tstr . $path) ;
1339 Logit($path,"file delete failed");
1340 exit ;
1341 } else {
1342 Logit($path,"file deleted");
1343 MoveTo("$dir/.log/$file","$dir/.del/.log/");
1344 MoveTo("$dir/.note/$file","$dir/.del/.note/");
1345 MoveTo("$dir/.lock/$file","$dir/.del/.lock/");
1346 }
1347 }
1348 else { // delete directory
1349 if ( ! @rrmdir($fsDir) ) {
1350 Error("Rmdir failed", $tstr . $fsDir) ;
1351 }
1352 else {
1353 $relDir = dirname($relDir) ; // move up
1354 }
1355 }
1356 break ;
1357
1358 case "UNDELETE" :
1359 if ( $CONFIRM != "on" ) break ;
1360
1361 if (substr($FN,0,4) != ".del") break ;
1362 $file=substr($FN,4,strlen($FN)-4);
1363
1364 Logit("$fsDir/.del/$file","undeleted");
1365 MoveTo("$fsDir/.del/$file","$fsDir/");
1366 MoveTo("$fsDir/.del/.log/$file","$fsDir/.log/");
1367 MoveTo("$fsDir/.del/.note/$file","$fsDir/.note/");
1368 MoveTo("$fsDir/.del/.lock/$file","$fsDir/.lock/");
1369
1370 break ;
1371
1372 case "RENAME" :
1373 if ( $CONFIRM != "on" ) break ;
1374
1375 Logit("$fsDir/$FN","renamed $FN to $NEWNAME");
1376 safe_rename("$fsDir/$FN","$fsDir/$NEWNAME");
1377 safe_rename("$fsDir/.log/$FN","$fsDir/.log/$NEWNAME");
1378 safe_rename("$fsDir/.note/$FN","$fsDir/.note/$NEWNAME");
1379 safe_rename("$fsDir/.lock/$FN","$fsDir/.lock/$NEWNAME");
1380 for($i=0;$i<=$GLOBALS[gblNumBackups];$i++) {
1381 safe_rename("$fsDir/.bak/$i/$FN","$fsDir/.bak/$i/$NEWNAME");
1382 }
1383
1384 break ;
1385
1386 case "NOTE" :
1387 WriteNote("$fsDir/$FN","$NOTE");
1388 break ;
1389
1390 case "UNLOCK" :
1391 if ( $CONFIRM != "on" ) break ;
1392 Unlock("$fsDir/$FN");
1393 break ;
1394
1395 default :
1396 // user hit "CANCEL" or undefined action
1397 }
1398
1399 // common to all POSTs : redirect to directory view ($relDir)
1400 if ( $POSTACTION != "" ) {
1401 $tstr = $PHP_SELF . "?D=" . urlencode($relDir) ;
1402 header("Location: " . $tstr) ;
1403 exit ;
1404 }
1405
1406 // check for mode.. navigate, code display, upload, or detail?
1407 // $A=U : upload to path given in $D
1408 // $A=E : display detail of file $D/$F and edit
1409 // $A=C : display code in file $D/$F
1410 // $A=Co : checkout file $D/$F
1411 // $A=Ci : checkin file $D/$F
1412 // $A=V : view file (do nothing except log)
1413 // default : display directory $D
1414
1415 switch ($A) {
1416 case "U" :
1417 // upload to $relDir
1418 if (!is_writeable($gblFsRoot . $relDir))
1419 Error("Write access denied",$relDir) ;
1420 $text = "Use this page to upload a single " ;
1421 $text .= "file to <B>$HTTP_HOST</B>." ;
1422 StartHTML("(Upload Page)", $text) ;
1423 UploadPage($gblFsRoot, $relDir) ;
1424 EndHTML() ;
1425 exit ;
1426 case "E" :
1427 $F=stripSlashes($F);
1428 // detail of $relDir/$F
1429 if (is_file("$gblFsRoot/$relDir/$F")) DetailPage($gblFsRoot, $relDir, $F) ;
1430 exit ;
1431 case "C" :
1432 $F=stripSlashes($F);
1433 // listing of $relDir/$F
1434 DisplayCode($gblFsRoot, $relDir, $F) ;
1435 exit ;
1436 case "Co" :
1437 // checkout
1438 Lock("$gblFsRoot/$relDir/$F");
1439 header("Content-Disposition: attachment; filename=$F" );
1440 Header("Location: ".urlpath("$relDir/$F"));
1441 exit;
1442 case "Ci" :
1443 $F=stripSlashes($F);
1444 // upload && update to $relDir
1445 if (!is_writeable($gblFsRoot . $relDir))
1446 Error("Write access denied",$relDir) ;
1447 $text = "Use this page to update a single " ;
1448 $text .= "file to <B>$HTTP_HOST</B>." ;
1449 StartHTML("(Update file Page)", $text) ;
1450 UploadPage($gblFsRoot, $relDir, $F) ;
1451 EndHTML() ;
1452 exit ;
1453 case "V" :
1454 // view
1455 LogIt("$gblFsRoot/$relDir/$F","viewed");
1456 header("Content-Disposition: attachment; filename=$F" );
1457 Header("Location: ".urlpath("$relDir/$F"));
1458 exit;
1459 case "Ch" :
1460 StartHTML("(File changes)","All changes chronologicaly...");
1461 DisplayChangeLog(0); // all
1462 EndHTML() ;
1463 exit;
1464 case "Ch1" :
1465 StartHTML("(File changes)","Changes to files in last day...");
1466 DisplayChangeLog(1);
1467 EndHTML() ;
1468 exit;
1469 }
1470
1471 // default: display directory $relDir
1472 Navigate($gblFsRoot,$relDir) ;
1473 exit ;
1474
1475 Error("Whooah!","By cartesian logic, this never happens") ;
1476 ?>

  ViewVC Help
Powered by ViewVC 1.1.26