/[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.51 - (hide annotations)
Mon Dec 17 10:00:51 2001 UTC (21 years, 1 month ago) by dpavlin
Branch: MAIN
Changes since 1.50: +0 -1 lines
removed debugging output when logging out

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

  ViewVC Help
Powered by ViewVC 1.1.26