/[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

Annotation of /docman.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.29 - (hide annotations)
Fri Jan 26 09:32:48 2001 UTC (22 years ago) by dpavlin
Branch: MAIN
Changes since 1.28: +32 -69 lines
changes to allow pluggable authentification modules

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

  ViewVC Help
Powered by ViewVC 1.1.26