/[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.36 - (hide annotations)
Sun Mar 11 15:42:51 2001 UTC (21 years, 11 months ago) by dpavlin
Branch: MAIN
Changes since 1.35: +7 -5 lines
show file uid&gid also as number

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

  ViewVC Help
Powered by ViewVC 1.1.26