/[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.33 - (hide annotations)
Thu Feb 15 22:14:21 2001 UTC (21 years, 11 months ago) by dpavlin
Branch: MAIN
Changes since 1.32: +27 -10 lines
Changes to add comments by Hrvoje Dogan <hdogan@ri.carnet.hr>

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

  ViewVC Help
Powered by ViewVC 1.1.26