/[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.52 - (hide annotations)
Thu Jan 10 18:33:43 2002 UTC (21 years, 1 month ago) by dpavlin
Branch: MAIN
Changes since 1.51: +5 -3 lines
fix login problem after logout with IE5.5

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

  ViewVC Help
Powered by ViewVC 1.1.26