/[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.43 - (hide annotations)
Wed Jun 20 10:29:19 2001 UTC (21 years, 7 months ago) by dpavlin
Branch: MAIN
Changes since 1.42: +15 -36 lines
moved user storage handling in separate file

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

  ViewVC Help
Powered by ViewVC 1.1.26